fix:修复套餐管理和格式化工具的中英适配
This commit is contained in:
@@ -81,6 +81,12 @@ const local: any = {
|
|||||||
},
|
},
|
||||||
tablePaginationTotal: 'Total {total} items',
|
tablePaginationTotal: 'Total {total} items',
|
||||||
inputPlease: 'Please input',
|
inputPlease: 'Please input',
|
||||||
|
time:{
|
||||||
|
second: 's',
|
||||||
|
minute: 'Min',
|
||||||
|
hour: 'Hour',
|
||||||
|
day: 'Day'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 组件
|
// 组件
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
@@ -81,6 +81,12 @@ const local:any = {
|
|||||||
},
|
},
|
||||||
tablePaginationTotal: '总共 {total} 条',
|
tablePaginationTotal: '总共 {total} 条',
|
||||||
inputPlease: '请输入',
|
inputPlease: '请输入',
|
||||||
|
time:{
|
||||||
|
second: '秒',
|
||||||
|
minute: '分钟',
|
||||||
|
hour: '小时',
|
||||||
|
day: '天'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 组件
|
// 组件
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import {useI18n} from "vue-i18n";
|
||||||
// 带宽单位转换
|
// 带宽单位转换
|
||||||
export type BandwidthUnit = 'Kbps' | 'Mbps' | 'Gbps';
|
export type BandwidthUnit = 'Kbps' | 'Mbps' | 'Gbps';
|
||||||
|
|
||||||
@@ -57,15 +58,24 @@ export function formatStorage(byteValue: number): { value: number; unit: Storage
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 时间单位转换
|
// 时间单位转换
|
||||||
export type TimeUnit = '秒' | '分钟' | '小时' | '天';
|
export type TimeUnit = 'second' | 'minute' | 'hour' | 'day';
|
||||||
|
|
||||||
export const timeUnits: TimeUnit[] = ['秒', '分钟', '小时', '天'];
|
export const useTimeUnits = () => {
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
return computed(() => ([
|
||||||
|
{ key: 'second', label: t('common.time.second') },
|
||||||
|
{ key: 'minute', label: t('common.time.minute') },
|
||||||
|
{ key: 'hour', label: t('common.time.hour') },
|
||||||
|
{ key: 'day', label: t('common.time.day') }
|
||||||
|
]));
|
||||||
|
};
|
||||||
|
|
||||||
export const timeFactors: Record<TimeUnit, number> = {
|
export const timeFactors: Record<TimeUnit, number> = {
|
||||||
'秒': 1,
|
'second': 1,
|
||||||
'分钟': 60,
|
'minute': 60,
|
||||||
'小时': 3600,
|
'hour': 3600,
|
||||||
'天': 86400
|
'day': 86400
|
||||||
};
|
};
|
||||||
|
|
||||||
export function convertTime(value: number, fromUnit: TimeUnit, toUnit: TimeUnit): number {
|
export function convertTime(value: number, fromUnit: TimeUnit, toUnit: TimeUnit): number {
|
||||||
@@ -74,13 +84,25 @@ export function convertTime(value: number, fromUnit: TimeUnit, toUnit: TimeUnit)
|
|||||||
return (value * fromFactor) / toFactor;
|
return (value * fromFactor) / toFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatTime(secondsValue: number): { value: number; unit: TimeUnit } {
|
export const useFormatTime = () => {
|
||||||
if (secondsValue >= 86400) {
|
const { t } = useI18n();
|
||||||
return { value: secondsValue / 86400, unit: '天' };
|
|
||||||
} else if (secondsValue >= 3600) {
|
return (secondsValue: number): { value: number; unit: TimeUnit; display: string } => {
|
||||||
return { value: secondsValue / 3600, unit: '小时' };
|
let result: { value: number; unit: TimeUnit };
|
||||||
} else if (secondsValue >= 60) {
|
|
||||||
return { value: secondsValue / 60, unit: '分钟' };
|
if (secondsValue >= 86400) {
|
||||||
}
|
result = { value: secondsValue / 86400, unit: 'day' };
|
||||||
return { value: secondsValue, unit: '秒' };
|
} else if (secondsValue >= 3600) {
|
||||||
}
|
result = { value: secondsValue / 3600, unit: 'hour' };
|
||||||
|
} else if (secondsValue >= 60) {
|
||||||
|
result = { value: secondsValue / 60, unit: 'minute' };
|
||||||
|
} else {
|
||||||
|
result = { value: secondsValue, unit: 'second' };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
display: `${result.value} ${t(`common.time.${result.unit}`)}`
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -127,7 +127,9 @@
|
|||||||
/>
|
/>
|
||||||
<ASelect
|
<ASelect
|
||||||
v-model:value="formState.durationUnit"
|
v-model:value="formState.durationUnit"
|
||||||
:options="timeUnits.map(unit => ({ label: unit, value: unit }))"
|
:options="timeUnits.map(item => ({
|
||||||
|
label: item.label,
|
||||||
|
value: item.key }))"
|
||||||
style="width: 100px"
|
style="width: 100px"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -168,17 +170,18 @@ import type { Rule } from 'ant-design-vue/es/form';
|
|||||||
import {
|
import {
|
||||||
formatBandwidth,
|
formatBandwidth,
|
||||||
formatStorage,
|
formatStorage,
|
||||||
formatTime,
|
useFormatTime,
|
||||||
convertStorage,
|
convertStorage,
|
||||||
convertTime,
|
convertTime,
|
||||||
storageUnits,
|
storageUnits,
|
||||||
timeUnits,
|
useTimeUnits,
|
||||||
type StorageUnit,
|
type StorageUnit,
|
||||||
type TimeUnit
|
type TimeUnit
|
||||||
} from '@/utils/units';
|
} from '@/utils/units';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const timeUnits = useTimeUnits();
|
||||||
|
const formatTime = useFormatTime();
|
||||||
const wrapperEl = shallowRef<HTMLElement | null>(null);
|
const wrapperEl = shallowRef<HTMLElement | null>(null);
|
||||||
const { height: wrapperElHeight } = useElementSize(wrapperEl);
|
const { height: wrapperElHeight } = useElementSize(wrapperEl);
|
||||||
|
|
||||||
@@ -355,7 +358,7 @@ const formState = ref<PackageForm>({
|
|||||||
rateLimitId: undefined,
|
rateLimitId: undefined,
|
||||||
durationEnable: false,
|
durationEnable: false,
|
||||||
duration: 0,
|
duration: 0,
|
||||||
durationUnit: t('page.package.hour'),
|
durationUnit: 'hour',
|
||||||
clientNumEnable: false,
|
clientNumEnable: false,
|
||||||
clientNum: 0,
|
clientNum: 0,
|
||||||
packageEnable: true
|
packageEnable: true
|
||||||
@@ -468,7 +471,7 @@ const handleCancel = () => {
|
|||||||
rateLimitId: undefined,
|
rateLimitId: undefined,
|
||||||
durationEnable: false,
|
durationEnable: false,
|
||||||
duration: 0,
|
duration: 0,
|
||||||
durationUnit:`${t('page.package.hour')}`,
|
durationUnit:'hour',
|
||||||
clientNumEnable: false,
|
clientNumEnable: false,
|
||||||
clientNum: 0,
|
clientNum: 0,
|
||||||
packageEnable: true
|
packageEnable: true
|
||||||
|
|||||||
Reference in New Issue
Block a user