From a7e6761ba0cfccdf33ed552eb2d3b783c8e4ab4a Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Wed, 16 Apr 2025 20:49:12 +0800
Subject: [PATCH] feat:事件弹窗显示调整
---
src/components/CommonDateTime.vue | 69 ++++++++++++++++++++++++++++------
1 files changed, 57 insertions(+), 12 deletions(-)
diff --git a/src/components/CommonDateTime.vue b/src/components/CommonDateTime.vue
index efd1c5a..3876c6c 100644
--- a/src/components/CommonDateTime.vue
+++ b/src/components/CommonDateTime.vue
@@ -1,34 +1,79 @@
<template>
<div class="common-date-time">
<el-date-picker
- v-model="newTime"
+ v-model="model"
type="daterange"
+ value-format="YYYY-MM-DD"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
- >
- </el-date-picker>
+ @change="change"
+ disabled
+ />
<div class="time-card">
<div
class="card-item"
- :class="item == checked ? 'active' : ''"
- v-for="item in timeList"
- @click="timeClick(item)"
+ :class="item === checked ? 'active' : ''"
+ v-for="(item, index) in timeList"
+ @click="timeClick(item,index)"
>
- {{ item }}
+ {{ timeListStr[index] }}
</div>
</div>
</div>
</template>
<script setup>
-const newTime = ref([]);
-let timeList = ['今日', '本周', '本月', '本年'];
+import dayjs from 'dayjs';
+import { useStore } from 'vuex'
+import { ref, defineEmits } from 'vue';
-let checked = ref('今日');
-let timeClick = item => {
- checked.value = item;
+const store = useStore()
+const emit = defineEmits(['change']);
+
+const model = defineModel();
+
+let timeList = ['today', 'week', 'month', 'year'];
+let timeListStr = ['今日', '本周', '本月', '本年'];
+let timeListEnum = ['TODAY', 'CURRENT_WEEK', 'CURRENT_MONTH', 'CURRENT_YEAR'];
+let checked = ref('today');
+
+const getDateRange = unit => {
+ if (unit === 'today') {
+ return [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')];
+ }
+ return [dayjs().startOf(unit).format('YYYY-MM-DD'), dayjs().endOf(unit).format('YYYY-MM-DD')];
};
+
+const dateRanges = {
+ today: getDateRange('today'),
+ week: getDateRange('week'),
+ month: getDateRange('month'),
+ year: getDateRange('year'),
+};
+
+const change = value => {
+ // todo 待对接
+ // emit('change', value);
+};
+
+let timeClick = (item,index) => {
+ checked.value = item;
+ const newDateRange = dateRanges[item];
+ model.value = newDateRange;
+ emit('change', newDateRange, timeListEnum[index],checked.value);
+};
+onMounted(() => {
+ // 如果父组件传入了值,就使用父组件的值 by cpz
+ if (model.value && model.value.length === 2) {
+ // 根据传入的日期判断是哪个时间范围
+ const startDate = model.value[0];
+ const endDate = model.value[1];
+ if (startDate !== endDate) {
+ checked.value = 'week';
+ }
+ }
+});
</script>
<style scoped lang="scss">
--
Gitblit v1.9.3