| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- <template>
- <cl-page>
- <view class="p-3">
- <demo-item :label="t('基础用法')">
- <cl-select-date
- v-model="form.date1"
- type="date"
- @change="onDateChange"
- ></cl-select-date>
- </demo-item>
- <demo-item :label="t('固定开始、结束日期')">
- <cl-select-date
- v-model="form.date3"
- start="2025-06-01"
- end="2027-08-01"
- type="date"
- ></cl-select-date>
- </demo-item>
- <demo-item :label="t('自定义触发器')">
- <view class="flex flex-row">
- <cl-button @tap="openSelect4">{{ t("打开选择器") }}</cl-button>
- </view>
- <cl-select-date
- ref="selectRef4"
- v-model="form.date4"
- type="date"
- :show-trigger="false"
- ></cl-select-date>
- </demo-item>
- <demo-item :label="t('范围选择')">
- <cl-text :pt="{ className: 'mb-3' }">{{ form.date5 }}</cl-text>
- <cl-select-date v-model:values="form.date5" type="date" rangeable></cl-select-date>
- </demo-item>
- <demo-item :label="t('自定义快捷选项')">
- <cl-select-date
- v-model:values="form.date6"
- type="date"
- rangeable
- :shortcuts="shortcuts"
- ></cl-select-date>
- </demo-item>
- <demo-item :label="t('自定义')">
- <cl-select-date
- v-model="form.date7"
- :type="type"
- :label-format="labelFormat"
- :disabled="isDisabled"
- ></cl-select-date>
- <cl-list
- border
- :pt="{
- className: 'mt-3'
- }"
- >
- <cl-list-item label="YYYY">
- <cl-switch v-model="isYear"></cl-switch>
- </cl-list-item>
- <cl-list-item label="YYYY-MM">
- <cl-switch v-model="isMonth"></cl-switch>
- </cl-list-item>
- <cl-list-item
- label="YYYY-MM-DD"
- :pt="{
- label: {
- className: 'flex-[2]'
- }
- }"
- >
- <cl-switch v-model="isDate"></cl-switch>
- </cl-list-item>
- <cl-list-item
- label="YYYY-MM-DD HH"
- :pt="{
- label: {
- className: 'flex-[2]'
- }
- }"
- >
- <cl-switch v-model="isHour"></cl-switch>
- </cl-list-item>
- <cl-list-item
- label="YYYY-MM-DD HH:mm"
- :pt="{
- label: {
- className: 'flex-[2]'
- }
- }"
- >
- <cl-switch v-model="isMinute"></cl-switch>
- </cl-list-item>
- <cl-list-item
- label="YYYY-MM-DD HH:mm:ss"
- :pt="{
- label: {
- className: 'flex-[2]'
- }
- }"
- >
- <cl-switch v-model="isSecond"></cl-switch>
- </cl-list-item>
- <cl-list-item :label="t('标签格式化')">
- <cl-switch v-model="isFormat"></cl-switch>
- </cl-list-item>
- <cl-list-item :label="t('禁用')">
- <cl-switch v-model="isDisabled"></cl-switch>
- </cl-list-item>
- </cl-list>
- </demo-item>
- </view>
- </cl-page>
- </template>
- <script lang="ts" setup>
- import { computed, reactive, ref } from "vue";
- import DemoItem from "../components/item.uvue";
- import { t } from "@/locale";
- import { useUi, type ClSelectDateShortcut } from "@/uni_modules/cool-ui";
- import { dayUts } from "@/cool";
- const ui = useUi();
- // 测试日期选择变化事件
- function onDateChange(value: string) {
- console.log("日期选择变化:", value);
- ui.showToast({
- message: `选择了日期: ${value}`,
- type: "success"
- });
- }
- type Form = {
- date1: string;
- date2: string;
- date3: string;
- date4: string;
- date5: string[];
- date6: string[];
- date7: string;
- };
- const form = reactive<Form>({
- date1: "2023-06-24",
- date2: "",
- date3: "",
- date4: "",
- date5: [],
- date6: [],
- date7: ""
- });
- const isDisabled = ref(false);
- const isYear = ref(false);
- const isMonth = ref(false);
- const isDate = ref(true);
- const isHour = ref(false);
- const isMinute = ref(false);
- const isSecond = ref(false);
- const isFormat = ref(false);
- const type = computed(() => {
- if (isSecond.value) {
- return "second";
- }
- if (isMinute.value) {
- return "minute";
- }
- if (isHour.value) {
- return "hour";
- }
- if (isDate.value) {
- return "date";
- }
- if (isMonth.value) {
- return "month";
- }
- if (isYear.value) {
- return "year";
- }
- return "second";
- });
- const labelFormat = computed(() => {
- if (isFormat.value) {
- if (isSecond.value) {
- return "YYYY年MM月DD日 HH时mm分ss秒";
- }
- if (isMinute.value) {
- return "YYYY年MM月DD日 HH时mm分";
- }
- if (isHour.value) {
- return "YYYY年MM月DD日 HH时";
- }
- if (isDate.value) {
- return "YYYY年MM月DD日";
- }
- if (isMonth.value) {
- return "YYYY年MM月";
- }
- if (isYear.value) {
- return "YYYY年";
- }
- } else {
- if (isSecond.value) {
- return "YYYY-MM-DD HH:mm:ss";
- }
- if (isMinute.value) {
- return "YYYY-MM-DD HH:mm";
- }
- if (isHour.value) {
- return "YYYY-MM-DD HH";
- }
- if (isDate.value) {
- return "YYYY-MM-DD";
- }
- if (isMonth.value) {
- return "YYYY-MM";
- }
- if (isYear.value) {
- return "YYYY";
- }
- }
- return "YYYY-MM-DD HH:mm:ss";
- });
- const selectRef4 = ref<ClSelectDateComponentPublicInstance | null>(null);
- function openSelect4() {
- selectRef4.value!.open((value) => {
- ui.showToast({
- message: `你选择了:${value}`
- });
- });
- }
- const shortcuts = ref<ClSelectDateShortcut[]>([
- {
- label: "昨日",
- value: [dayUts().subtract(1, "day").format("YYYY-MM-DD"), dayUts().format("YYYY-MM-DD")]
- },
- {
- label: "本周",
- value: [
- dayUts().startOf("week").add(1, "day").format("YYYY-MM-DD"),
- dayUts().endOf("week").add(1, "day").format("YYYY-MM-DD")
- ]
- },
- {
- label: "本月",
- value: [
- dayUts().startOf("month").format("YYYY-MM-DD"),
- dayUts().endOf("month").format("YYYY-MM-DD")
- ]
- }
- ]);
- </script>
|