日期下拉默认修改

This commit is contained in:
stt
2025-12-04 10:30:19 +08:00
parent 5687367602
commit 3accaf3079
5 changed files with 84 additions and 13 deletions

View File

@@ -5,7 +5,7 @@
style="min-width: 90px; width: 90px; margin-right: 10px"
@change="timeChange"
>
<el-option v-for="item in timeOptions" :key="item.value" :label="item.label" :value="item.value" />
<el-option v-for="item in filteredTimeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-date-picker
v-model.trim="timeValue"
@@ -35,13 +35,15 @@ interface Props {
theCurrentTime?: boolean
initialInterval?: number
initialTimeValue?: any
timeKeyList?: string[] //日期下拉
}
const props = withDefaults(defineProps<Props>(), {
nextFlag: false,
theCurrentTime: true,
initialInterval: 3,
initialTimeValue: undefined
initialTimeValue: undefined,
timeKeyList: () => []
})
const emit = defineEmits(['change'])
@@ -89,6 +91,18 @@ const shortcuts = [
}
}
]
// 计算过滤后的 timeOptions
const filteredTimeOptions = computed(() => {
if (!props.timeKeyList || props.timeKeyList.length === 0) {
return timeOptions.value
}
return timeOptions.value.filter((option: any) =>
props.timeKeyList.includes(option.value.toString())
)
})
onMounted(() => {
// 使用传入的初始值
if (props.initialInterval !== undefined) {