39 lines
1.1 KiB
Vue
39 lines
1.1 KiB
Vue
<script setup lang="ts">
|
||
import {
|
||
TimeField,
|
||
TimeFieldGroup,
|
||
TimeFieldInput,
|
||
TimeFieldSegment,
|
||
Label,
|
||
Description,
|
||
Button,
|
||
} from "@heroui-vue/components";
|
||
import { shallowRef } from "vue";
|
||
import { Time, getLocalTimeZone, now } from "@internationalized/date";
|
||
import type { TimeValue } from "@heroui-vue/components";
|
||
const value = shallowRef<TimeValue | null>(null);
|
||
function setCurrent() {
|
||
const current = now(getLocalTimeZone());
|
||
value.value = new Time(current.hour, current.minute, current.second);
|
||
}
|
||
</script>
|
||
<template>
|
||
<div class="flex flex-col gap-4">
|
||
<TimeField class="w-[256px]" name="time" v-model="value">
|
||
<Label>时间</Label>
|
||
<TimeFieldGroup>
|
||
<TimeFieldInput v-slot="{ segment }">
|
||
<TimeFieldSegment :segment="segment" />
|
||
</TimeFieldInput>
|
||
</TimeFieldGroup>
|
||
<Description>
|
||
当前值:{{ value ? value.toString() : "(空)" }}
|
||
</Description>
|
||
</TimeField>
|
||
<div class="flex gap-2">
|
||
<Button variant="tertiary" @click="setCurrent">设为当前时间</Button>
|
||
<Button variant="tertiary" @click="value = null">清空</Button>
|
||
</div>
|
||
</div>
|
||
</template>
|