|
@@ -101,7 +101,8 @@
|
|
|
:headers="headers"
|
|
:headers="headers"
|
|
|
:value="indexes"
|
|
:value="indexes"
|
|
|
:columns="columns"
|
|
:columns="columns"
|
|
|
- @change="onChange"
|
|
|
|
|
|
|
+ :reset-on-change="false"
|
|
|
|
|
+ @change-value="onChange"
|
|
|
></cl-picker-view>
|
|
></cl-picker-view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
@@ -514,12 +515,19 @@ const indexes = computed(() => {
|
|
|
if (isEmpty(value.value)) {
|
|
if (isEmpty(value.value)) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// 遍历每一列,查找当前值在选项中的下标
|
|
// 遍历每一列,查找当前值在选项中的下标
|
|
|
return value.value.map((e, i) => {
|
|
return value.value.map((e, i) => {
|
|
|
- const index = list.value[i].findIndex((a) => a.value == e);
|
|
|
|
|
- // 如果未找到,返回0
|
|
|
|
|
|
|
+ let index = list.value[i].findIndex((a) => a.value == e) as number;
|
|
|
|
|
+
|
|
|
|
|
+ // 如果未找到,返回最后一个
|
|
|
if (index == -1) {
|
|
if (index == -1) {
|
|
|
- return 0;
|
|
|
|
|
|
|
+ index = list.value[i].length - 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果小于0,返回0
|
|
|
|
|
+ if (index < 0) {
|
|
|
|
|
+ index = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
return index;
|
|
@@ -548,6 +556,58 @@ function toDate() {
|
|
|
return parts.join("");
|
|
return parts.join("");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 检查边界值
|
|
|
|
|
+function checkDate(values: number[]): number[] {
|
|
|
|
|
+ if (values.length == 0) {
|
|
|
|
|
+ return values;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 确保至少有6个元素,缺失的用默认值填充
|
|
|
|
|
+ const checkedValues = [...values];
|
|
|
|
|
+ const defaultValues = [2000, 1, 1, 0, 0, 0];
|
|
|
|
|
+ for (let i = checkedValues.length; i < 6; i++) {
|
|
|
|
|
+ checkedValues.push(defaultValues[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let [year, month, date, hour, minute, second] = checkedValues;
|
|
|
|
|
+
|
|
|
|
|
+ // 检查日期边界(根据年份和月份确定最大天数)
|
|
|
|
|
+ // 判断是否为闰年
|
|
|
|
|
+ const isLeapYear = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
|
|
|
|
|
+ // 每月天数数组,2月根据闰年判断
|
|
|
|
|
+ const daysInMonth = [31, isLeapYear ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
|
|
|
+ const maxDay = daysInMonth[month - 1];
|
|
|
|
|
+
|
|
|
|
|
+ if (date < 1) {
|
|
|
|
|
+ date = 1;
|
|
|
|
|
+ } else if (date > maxDay) {
|
|
|
|
|
+ date = maxDay;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查小时边界 (0-23)
|
|
|
|
|
+ if (hour < 0) {
|
|
|
|
|
+ hour = 0;
|
|
|
|
|
+ } else if (hour > 23) {
|
|
|
|
|
+ hour = 23;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查分钟边界 (0-59)
|
|
|
|
|
+ if (minute < 0) {
|
|
|
|
|
+ minute = 0;
|
|
|
|
|
+ } else if (minute > 59) {
|
|
|
|
|
+ minute = 59;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查秒钟边界 (0-59)
|
|
|
|
|
+ if (second < 0) {
|
|
|
|
|
+ second = 0;
|
|
|
|
|
+ } else if (second > 59) {
|
|
|
|
|
+ second = 59;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [year, month, date, hour, minute, second];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 显示文本,展示当前选中的日期字符串
|
|
// 显示文本,展示当前选中的日期字符串
|
|
|
const text = ref("");
|
|
const text = ref("");
|
|
|
|
|
|
|
@@ -563,19 +623,19 @@ function getText() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 选择器值改变事件,更新value
|
|
// 选择器值改变事件,更新value
|
|
|
-async function onChange(arr: number[]) {
|
|
|
|
|
- const data = [] as number[];
|
|
|
|
|
-
|
|
|
|
|
- for (let i = 0; i < arr.length; i++) {
|
|
|
|
|
- const item = list.value[i][arr[i]];
|
|
|
|
|
|
|
+async function onChange(data: number[]) {
|
|
|
|
|
+ // 更新value
|
|
|
|
|
+ value.value = checkDate(data);
|
|
|
|
|
|
|
|
- if (!isNull(item)) {
|
|
|
|
|
- data.push(item.value as number);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 不能大于结束日期
|
|
|
|
|
+ if (dayUts(toDate()).isAfter(dayUts(props.end))) {
|
|
|
|
|
+ value.value = dayUts(props.end).toArray();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 更新value
|
|
|
|
|
- value.value = data;
|
|
|
|
|
|
|
+ // 不能小于开始日期
|
|
|
|
|
+ if (dayUts(toDate()).isBefore(dayUts(props.start))) {
|
|
|
|
|
+ value.value = dayUts(props.start).toArray();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 设置范围值
|
|
// 设置范围值
|
|
|
if (props.rangeable) {
|
|
if (props.rangeable) {
|
|
@@ -597,10 +657,10 @@ function setValue(val: string) {
|
|
|
|
|
|
|
|
// 如果值为空,使用当前时间
|
|
// 如果值为空,使用当前时间
|
|
|
if (isNull(val) || isEmpty(val)) {
|
|
if (isNull(val) || isEmpty(val)) {
|
|
|
- value.value = dayUts().toArray();
|
|
|
|
|
|
|
+ value.value = checkDate(dayUts().toArray());
|
|
|
} else {
|
|
} else {
|
|
|
// 否则解析为数组
|
|
// 否则解析为数组
|
|
|
- value.value = dayUts(val).toArray();
|
|
|
|
|
|
|
+ value.value = checkDate(dayUts(val).toArray());
|
|
|
getText();
|
|
getText();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -669,8 +729,7 @@ function close() {
|
|
|
|
|
|
|
|
// 选择器关闭后
|
|
// 选择器关闭后
|
|
|
function onClosed() {
|
|
function onClosed() {
|
|
|
- value.value = [];
|
|
|
|
|
- values.value = [];
|
|
|
|
|
|
|
+ values.value = ["", ""];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 清空选择器,重置显示文本并触发事件
|
|
// 清空选择器,重置显示文本并触发事件
|
|
@@ -761,6 +820,14 @@ watch(
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+// 更新显示文本
|
|
|
|
|
+watch(
|
|
|
|
|
+ computed(() => props.labelFormat),
|
|
|
|
|
+ () => {
|
|
|
|
|
+ getText();
|
|
|
|
|
+ }
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
defineExpose({
|
|
defineExpose({
|
|
|
open,
|
|
open,
|
|
|
close,
|
|
close,
|