|
|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
|
- <div class="flex justify-end gap-2 date-search">
|
|
|
+ <div class="flex gap-2 date-search" :class="{'justify-end': position === 'right', 'justify-start': position === 'left', 'justify-center': position === 'center'}">
|
|
|
<div class="quick-select">
|
|
|
<el-button
|
|
|
:type="activeQuickSelect === 7 ? 'primary' : ''"
|
|
|
@@ -34,7 +34,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, watch } from "vue";
|
|
|
+import { ref, watch, nextTick } from "vue";
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
|
const props = defineProps({
|
|
|
@@ -42,6 +42,10 @@ const props = defineProps({
|
|
|
type: Array,
|
|
|
default: () => [],
|
|
|
},
|
|
|
+ position: {
|
|
|
+ type: String,
|
|
|
+ default: "right",
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
const emit = defineEmits(["update:modelValue", "search"]);
|
|
|
@@ -72,15 +76,26 @@ const handleQuickSelect = (days) => {
|
|
|
activeQuickSelect.value = days;
|
|
|
const end = dayjs();
|
|
|
const start = dayjs().subtract(days, "day");
|
|
|
- dateRange.value = [start.format("YYYY-MM-DD"), end.format("YYYY-MM-DD")];
|
|
|
- emit("search", dateRange.value);
|
|
|
+ const newDateRange = [start.format("YYYY-MM-DD"), end.format("YYYY-MM-DD")];
|
|
|
+
|
|
|
+ // 先更新日期范围
|
|
|
+ dateRange.value = newDateRange;
|
|
|
+
|
|
|
+ // 使用 nextTick 确保数据更新后再触发搜索
|
|
|
+ nextTick(() => {
|
|
|
+ emit("search", newDateRange);
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// 日期选择变化
|
|
|
const handleDateChange = (val) => {
|
|
|
// 清除快捷选项的选中状态
|
|
|
activeQuickSelect.value = null;
|
|
|
- emit("search", val);
|
|
|
+
|
|
|
+ // 使用 nextTick 确保数据更新后再触发搜索
|
|
|
+ nextTick(() => {
|
|
|
+ emit("search", val);
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// 搜索按钮点击
|