Przeglądaj źródła

支持范围选择

icssoa 8 miesięcy temu
rodzic
commit
d6da3d768c

+ 32 - 1
pages/demo/form/select-date.uvue

@@ -35,6 +35,15 @@
 				<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.date5"
+					type="date"
+					rangeable
+					:shortcuts="shortcuts"
+				></cl-select-date>
+			</demo-item>
+
 			<demo-item :label="t('自定义')">
 				<cl-select-date
 					v-model="form.date6"
@@ -118,7 +127,8 @@
 import { computed, reactive, ref } from "vue";
 import DemoItem from "../components/item.uvue";
 import { t } from "@/locale";
-import { useUi } from "@/uni_modules/cool-ui";
+import { useUi, type ClSelectDateShortcut } from "@/uni_modules/cool-ui";
+import { dayUts } from "@/cool";
 
 const ui = useUi();
 
@@ -240,4 +250,25 @@ function openSelect4() {
 		});
 	});
 }
+
+const shortcuts = ref<ClSelectDateShortcut[]>([
+	{
+		label: "昨日",
+		value: [dayUts().subtract(1, "day").format("YYYY-MM-DD"), dayUts().format("YYYY-MM-DD")]
+	},
+	{
+		label: "本周",
+		value: [
+			dayUts().startOf("week").format("YYYY-MM-DD"),
+			dayUts().endOf("week").format("YYYY-MM-DD")
+		]
+	},
+	{
+		label: "本月",
+		value: [
+			dayUts().startOf("month").format("YYYY-MM-DD"),
+			dayUts().endOf("month").format("YYYY-MM-DD")
+		]
+	}
+]);
 </script>

+ 1 - 1
uni_modules/cool-ui/components/cl-select-date/cl-select-date.uvue

@@ -319,7 +319,7 @@ const valueFormat = computed(() => {
 });
 
 // 快捷选项索引
-const shortcutsIndex = ref<number>(0);
+const shortcutsIndex = ref<number>(-1);
 
 // 快捷选项列表
 const shortcuts = computed<ClSelectDateShortcut[]>(() => {