Просмотр исходного кода

解决 cl-select-date 快捷按钮需点击两次的问题

icssoa 7 месяцев назад
Родитель
Сommit
3200ab2bf8

+ 3 - 1
cool/utils/day.ts

@@ -135,7 +135,9 @@ export class DayUts {
 				newDate.setMilliseconds(999);
 				break;
 			case "week":
-				newDate.setDate(newDate.getDate() + 7);
+				const day = newDate.getDay();
+				const diff = 6 - day;
+				newDate.setDate(newDate.getDate() + diff);
 				newDate.setHours(23);
 				newDate.setMinutes(59);
 				newDate.setSeconds(59);

+ 2 - 2
pages/demo/form/select-date.uvue

@@ -271,8 +271,8 @@ const shortcuts = ref<ClSelectDateShortcut[]>([
 	{
 		label: "本周",
 		value: [
-			dayUts().startOf("week").format("YYYY-MM-DD"),
-			dayUts().endOf("week").format("YYYY-MM-DD")
+			dayUts().startOf("week").add(1, "day").format("YYYY-MM-DD"),
+			dayUts().endOf("week").add(1, "day").format("YYYY-MM-DD")
 		]
 	},
 	{

+ 6 - 1
uni_modules/cool-ui/components/cl-picker-view/cl-picker-view.uvue

@@ -56,7 +56,7 @@
 </template>
 
 <script setup lang="ts">
-import { forInObject, isDark, parseClass, rpx2px } from "@/cool";
+import { forInObject, isDark, isEqual, parseClass, rpx2px } from "@/cool";
 import type { ClSelectOption } from "../../types";
 import { parseRpx } from "@/cool";
 import { computed } from "vue";
@@ -153,6 +153,11 @@ function onChange(e: UniPickerViewChangeEvent) {
 	// 获取选择器当前选中值数组
 	const indexs = e.detail.value;
 
+	// 相同值不触发事件
+	if (isEqual(indexs, props.value)) {
+		return;
+	}
+
 	// 获取所有列的值
 	const values = props.columns.map((c, i) => {
 		return c[indexs[i]].value;