代码格式修改
This commit is contained in:
@@ -6,8 +6,7 @@
|
||||
placeholder="选择日期"
|
||||
:picker-options="pickerOptions"
|
||||
@change="handleDateChange"
|
||||
>
|
||||
</el-date-picker>
|
||||
/>
|
||||
|
||||
<div class="selected-dates">
|
||||
<el-tag
|
||||
@@ -40,55 +39,55 @@ export default {
|
||||
// 可选:禁用已选择的日期,避免重复
|
||||
return this.selectedDates.some(
|
||||
selected => this.isSameDay(selected, date)
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value(newVal) {
|
||||
this.selectedDates = [...newVal];
|
||||
this.selectedDates = [...newVal]
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleDateChange(date) {
|
||||
if (!date) return;
|
||||
if (!date) return
|
||||
|
||||
// 检查是否已存在相同日期
|
||||
const isExist = this.selectedDates.some(
|
||||
selected => this.isSameDay(selected, date)
|
||||
);
|
||||
)
|
||||
|
||||
if (!isExist) {
|
||||
this.selectedDates.push(date);
|
||||
this.emitUpdate();
|
||||
this.selectedDates.push(date)
|
||||
this.emitUpdate()
|
||||
}
|
||||
|
||||
this.selectedDate = null; // 清空选择器以便再次选择
|
||||
this.selectedDate = null // 清空选择器以便再次选择
|
||||
},
|
||||
removeDate(index) {
|
||||
this.selectedDates.splice(index, 1);
|
||||
this.emitUpdate();
|
||||
this.selectedDates.splice(index, 1)
|
||||
this.emitUpdate()
|
||||
},
|
||||
isSameDay(date1, date2) {
|
||||
return (
|
||||
date1.getFullYear() === date2.getFullYear() &&
|
||||
date1.getMonth() === date2.getMonth() &&
|
||||
date1.getDate() === date2.getDate()
|
||||
);
|
||||
)
|
||||
},
|
||||
formatDate(date) {
|
||||
return date.toLocaleDateString('zh-CN');
|
||||
return date.toLocaleDateString('zh-CN')
|
||||
},
|
||||
emitUpdate() {
|
||||
// 按照日期排序
|
||||
this.selectedDates.sort((a, b) => a - b);
|
||||
this.selectedDates.sort((a, b) => a - b)
|
||||
// 触发更新事件
|
||||
this.$emit('input', [...this.selectedDates]);
|
||||
this.$emit('change', [...this.selectedDates]);
|
||||
this.$emit('input', [...this.selectedDates])
|
||||
this.$emit('change', [...this.selectedDates])
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user