调度app重新提交2

This commit is contained in:
sunhaoyuan 2025-10-18 15:11:35 +08:00
parent b0ec12ae6a
commit 6aff30cd75

View File

@ -0,0 +1,97 @@
<template>
<view class="date-range-selector">
<u-subsection :list="dateRangeList" keyName="label" :current="selected" @change="handleSubsectionChange" />
<uni-datetime-picker :value="internalDateRange" type="daterange" @change="handleDatePickerChange" />
</view>
</template>
<script>
import {
getDateRange
} from "@/utils/utils";
export default {
props: {
// v-model
value: {
type: [Array, Object],
required: true
},
//
dateRangeList: {
type: Array,
default: () => [{
label: "本日",
value: "day"
},
{
label: "本月",
value: "month"
}
]
},
// 'array' 'object'
returnType: {
type: String,
default: "array", // ["2025-10-13", "2025-10-19"]
validator: val => ["array", "object"].includes(val)
}
},
data() {
return {
selected: 0,
internalDateRange: this.value
};
},
watch: {
value(newVal) {
if (JSON.stringify(newVal) !== JSON.stringify(this.internalDateRange)) {
this.internalDateRange = newVal;
this.resetSelectedIndex();
}
},
internalDateRange(newVal) {
this.$emit("input", newVal);
this.$emit("subsection-change", newVal);
}
},
methods: {
handleSubsectionChange(index) {
this.selected = index;
const {
value
} = this.dateRangeList[index];
// asObject
const asObject = this.returnType === "object";
this.internalDateRange = getDateRange(value, asObject);
},
handleDatePickerChange(newRange) {
this.internalDateRange = newRange;
},
resetSelectedIndex() {
const asObject = this.returnType === "object";
const isPreset = this.dateRangeList.some((item, index) => {
const range = getDateRange(item.value, asObject);
return JSON.stringify(range) === JSON.stringify(this.internalDateRange);
});
if (!isPreset) {
this.selected = 0;
}
}
},
created() {
this.resetSelectedIndex();
}
};
</script>
<style scoped>
.date-range-selector {
display: flex;
flex-direction: column;
gap: 10rpx;
}
</style>