116 lines
2.9 KiB
Vue
116 lines
2.9 KiB
Vue
<script lang="ts" setup>
|
||
import { $baseMessage } from '@/utils';
|
||
|
||
const props = defineProps({
|
||
modelValue: {
|
||
type: Number,
|
||
},
|
||
});
|
||
|
||
const emits = defineEmits(['update:modelValue']);
|
||
|
||
const timeZone = reactive<{
|
||
sign: number | undefined;
|
||
hour: number | undefined;
|
||
minute: string | undefined;
|
||
}>({
|
||
sign: undefined,
|
||
hour: undefined,
|
||
minute: undefined,
|
||
});
|
||
watch(
|
||
() => props.modelValue,
|
||
(val) => {
|
||
if (val !== undefined && val !== null) {
|
||
// 转换成三个值date.date是否正数,正数设置为1,负数为-1
|
||
timeZone.sign = val >= 0 ? 1 : -1;
|
||
// 获取val小数点前和小数点后的数字
|
||
const time = Math.abs(val);
|
||
const hh = Math.floor(time);
|
||
const mm = Math.floor((time - hh) * 10);
|
||
timeZone.hour = hh;
|
||
timeZone.minute = mm.toString();
|
||
}
|
||
},
|
||
{
|
||
immediate: true,
|
||
}
|
||
);
|
||
|
||
watch(
|
||
() => timeZone,
|
||
(val) => {
|
||
const hh = val.hour || val.hour === 0 ? val.hour : undefined;
|
||
const mm = val.minute ? val.minute : undefined;
|
||
if (val.sign && hh !== undefined && mm !== undefined) {
|
||
const time = Number(`${hh}.${mm}`);
|
||
if (Number.isNaN(time))
|
||
return $baseMessage(t('common.inputValidTime'), 'error');
|
||
emits('update:modelValue', time * val.sign);
|
||
} else {
|
||
emits('update:modelValue', undefined);
|
||
}
|
||
},
|
||
{
|
||
deep: true,
|
||
}
|
||
);
|
||
</script>
|
||
|
||
<template>
|
||
<div class="flex items-center">
|
||
<div class="w-40% flex items-center">
|
||
<div class="mr-1 w-30px text-12px"> GMT </div>
|
||
<a-select
|
||
v-model="timeZone.sign"
|
||
class="mr-1"
|
||
style="width: calc(100% - 30px)"
|
||
placeholder=""
|
||
>
|
||
<a-option :value="1" label="+" />
|
||
<a-option :value="-1" label="-" />
|
||
</a-select>
|
||
</div>
|
||
<div class="w-60% flex items-center">
|
||
<a-select
|
||
v-model="timeZone.hour"
|
||
filterable
|
||
style="width: calc(50% - 3px)"
|
||
placeholder=""
|
||
>
|
||
<a-option
|
||
v-for="(_, index) in 13"
|
||
:key="index"
|
||
:label="index < 10 ? `0${index}+''` : index + ''"
|
||
:value="index"
|
||
>
|
||
<template #default>
|
||
{{ index < 10 ? `0${index}` : index }}
|
||
</template>
|
||
</a-option>
|
||
</a-select>
|
||
<div class="w-6px text-center text-12px"> : </div>
|
||
<a-select
|
||
v-model="timeZone.minute"
|
||
filterable
|
||
style="width: calc(50% - 3px)"
|
||
placeholder=""
|
||
>
|
||
<a-option
|
||
v-for="item in [
|
||
{ label: '00', value: '0' },
|
||
{ label: '30', value: '5' },
|
||
]"
|
||
:key="item.label"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
>
|
||
<template #default>
|
||
{{ item.label }}
|
||
</template>
|
||
</a-option>
|
||
</a-select>
|
||
</div>
|
||
</div>
|
||
</template>
|