Skip to content

Commit

Permalink
refactor: durationText (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoJohw authored Nov 7, 2024
1 parent 5b04542 commit 10bf04c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
15 changes: 1 addition & 14 deletions src/pages/src/components/SyncRecords.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import Empty from '@/components/SearchEmpty.vue';
import SQLFile from '@/components/sql-file/SQLFile.vue';
import { getSyncLogs, getSyncRecords } from '@/http';
import { t } from '@/language/index';
import { dataRecordStatus } from '@/utils';
import { dataRecordStatus, durationText } from '@/utils';
const props = defineProps({
dataSource: {
Expand Down Expand Up @@ -173,19 +173,6 @@ const getSyncRecordsList = async () => {
}
};
const durationText = (value: string) => {
if (value) {
const [hour, min, sec] = value.split(':').map(Number);
const roundedSec = Math.round(sec);
if (min < 1) {
return `<1 ${t('分钟')}`;
} if (hour < 1) {
return `${min} ${t('分钟')}${roundedSec > 0 ? ` ${roundedSec} ${t('秒')}` : ''}`;
}
return `${hour}小时${min}分钟`;
}
};
const dataRecordFilter = ({ checked }) => {
if (checked.length === 0) {
pagination.current = 1;
Expand Down
13 changes: 13 additions & 0 deletions src/pages/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,16 @@ export const handleSwitchLocale = (locale: string) => {
document.querySelector('html')?.setAttribute('lang', locale);
window.location.reload();
};

export const durationText = (value: string) => {
if (value) {
const [hour, min, sec] = value.split(':').map(Number);
const roundedSec = Math.round(sec);
if (min < 1) {
return `<1 ${t('分钟')}`;
} if (hour < 1) {
return `${min} ${t('分钟')}${roundedSec > 0 ? ` ${roundedSec} ${t('秒')}` : ''}`;
}
return `${hour}小时${min}分钟`;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ import { useTableMaxHeight } from '@/hooks';
import { getCollaborationSyncRecords, getCollaborationSyncRecordsLogs, getFromStrategies, putFromStrategiesStatus } from '@/http';
import { t } from '@/language/index';
import { useMainViewStore, useUser } from '@/store';
import { dataRecordStatus, dataSourceStatus } from '@/utils';
import { dataRecordStatus, dataSourceStatus, durationText } from '@/utils';
const props = defineProps({
active: {
Expand Down Expand Up @@ -481,19 +481,6 @@ const handleRowExpand = async ({ row }) => {
});
}
};
const durationText = (value: string) => {
if (value) {
const [hour, min, sec] = value.split(':').map(Number);
const roundedSec = Math.round(sec);
if (min < 1) {
return `<1 ${t('分钟')}`;
} if (hour < 1) {
return `${min} ${t('分钟')}${roundedSec > 0 ? ` ${roundedSec} ${t('秒')}` : ''}`;
}
return `${hour}小时${min}分钟`;
}
};
</script>
<style lang="less" scoped>
Expand Down

0 comments on commit 10bf04c

Please sign in to comment.