From 72b184063d43ac2153955d5b9bcb73db6e1264ba Mon Sep 17 00:00:00 2001
From: yangyin <1850366751@qq.com>
Date: 星期四, 10 十月 2024 11:54:04 +0800
Subject: [PATCH] 指标探索默认选择前7天

---
 src/utils/istation/common.js                                 |   37 +++++++++++++++---
 src/views/project/yw/systemManage/metricMgr/MetricDetail.vue |   48 ++++++------------------
 src/utils/util.ts                                            |   10 ++--
 3 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/src/utils/istation/common.js b/src/utils/istation/common.js
index b689e93..5d291f9 100644
--- a/src/utils/istation/common.js
+++ b/src/utils/istation/common.js
@@ -1,3 +1,5 @@
+
+import moment from 'moment';
 /**
  * 鑾峰彇璺濈date鐨刣ayCount澶╂暟( 骞存湀鏃�)
  * @param {*} dayCount 璺濈date鐨勫ぉ鏁�
@@ -89,16 +91,16 @@
 		if (l) {
 			a1 < 2
 				? (b =
-						n / Math.pow(10, a1) - parseInt(n / Math.pow(10, a1)) > 0.5
-							? Math.round(n / Math.pow(10, a1)) * Math.pow(10, a1)
-							: (parseInt(n / Math.pow(10, a1)) + 0.5) * Math.pow(10, a1))
+					n / Math.pow(10, a1) - parseInt(n / Math.pow(10, a1)) > 0.5
+						? Math.round(n / Math.pow(10, a1)) * Math.pow(10, a1)
+						: (parseInt(n / Math.pow(10, a1)) + 0.5) * Math.pow(10, a1))
 				: (b = Math.ceil(n / Math.pow(10, 1)) * Math.pow(10, 1));
 		} else {
 			a1 < 2
 				? (b =
-						n / Math.pow(10, a1) - parseInt(n / Math.pow(10, a1)) > 0.5
-							? (parseInt(n / Math.pow(10, a1)) + 0.5) * Math.pow(10, a1)
-							: Math.floor(n / Math.pow(10, a1)) * Math.pow(10, a1))
+					n / Math.pow(10, a1) - parseInt(n / Math.pow(10, a1)) > 0.5
+						? (parseInt(n / Math.pow(10, a1)) + 0.5) * Math.pow(10, a1)
+						: Math.floor(n / Math.pow(10, a1)) * Math.pow(10, a1))
 				: (b = Math.floor(n / Math.pow(10, 1)) * Math.pow(10, 1));
 		}
 		return l ? (-20 <= a1 ? +b.toFixed(a1 < 0 ? -a1 + 1 : 0) : b) : b;
@@ -584,3 +586,26 @@
 export const $ = (name) => document.querySelector(name);
 
 export const getContainerSize = (dom) => ({ width: dom.getBoundingClientRect().width, height: dom.getBoundingClientRect().height });
+export const getDefaultPeriod = (selectedPeriod) => {
+	// 鏍规嵁閫夋嫨鐨勫懆鏈熻繑鍥炵浉搴旂殑鏃ユ湡鑼冨洿
+	let startDate, endDate;
+	switch (selectedPeriod) {
+		case '7Days':
+			startDate = moment().subtract(7, 'days');
+			endDate = moment();
+			break;
+		case 'ThisMonth':
+			startDate = moment().startOf('month');
+			endDate = moment();
+			break;
+		case 'ThisYear':
+			startDate = moment().startOf('year');
+			endDate = moment();
+			break;
+		default:
+			// 澶勭悊鏈尮閰嶅埌鐨勬儏鍐�
+			startDate = moment().subtract(7, 'days');
+			endDate = moment();
+	}
+	return { startDate, endDate };
+};
\ No newline at end of file
diff --git a/src/utils/util.ts b/src/utils/util.ts
index 3f95fee..0ec84b8 100644
--- a/src/utils/util.ts
+++ b/src/utils/util.ts
@@ -1,11 +1,11 @@
 import { ElMessage, ElMessageBox } from 'element-plus';
 import JSONbig from 'json-bigint';
+
 import { storeToRefs } from 'pinia';
 import { unref, type Ref } from 'vue';
 import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
 import { useThemeConfig } from '/@/stores/themeConfig';
 import request from '/@/utils/request';
-
 /**
  * @description 褰撶鍒� JSON 涓瓨鍦ㄨ繃闀跨殑鏁板瓧鏃讹紝浣跨敤 JSONbigString 瑙f瀽锛屾暟瀛椾細杞负瀛楃涓插鐞�
  * 鐢ㄦ硶锛欽SONbigString.parse(jsonStr)锛�
@@ -709,7 +709,6 @@
 	return num.toFixed(precision).replace(/\.?0+$/, '');
 };
 
-
 type GetTextWidthOption = {
 	size?: string;
 	family?: string;
@@ -735,12 +734,13 @@
 	return width;
 }
 
-
 export function decodeFormData(formDataString) {
 	const params = new URLSearchParams(formDataString);
 	const decodedData = {};
 	for (const [key, value] of params) {
-	  decodedData[key] = decodeURIComponent(value);
+		decodedData[key] = decodeURIComponent(value);
 	}
 	return decodedData;
-  }
\ No newline at end of file
+}
+
+
diff --git a/src/views/project/yw/systemManage/metricMgr/MetricDetail.vue b/src/views/project/yw/systemManage/metricMgr/MetricDetail.vue
index 967ea66..2aaa7a0 100644
--- a/src/views/project/yw/systemManage/metricMgr/MetricDetail.vue
+++ b/src/views/project/yw/systemManage/metricMgr/MetricDetail.vue
@@ -42,14 +42,15 @@
 								<div class="h100">
 									<div class="set_explore">
 										<div class="set_explore_pad">
-											<el-form ref="exploreFormRef" :model="state.exploreForm" label-width="100px">
+											<el-form ref="exploreFormRef" :model="state.exploreForm" label-width="80px" label-position="left">
 												<el-form-item label="鏃ユ湡鍖洪棿:">
 													<div style="width: 300px">
 														<el-date-picker
 															v-model="state.exploreForm.dateRangeExplore"
 															type="daterange"
 															range-separator="~"
-															:shortcuts="shortcuts"
+															value-format="YYYY-MM-DD HH:mm:ss"
+															:default-time="defaultTime"
 														/>
 													</div>
 												</el-form-item>
@@ -114,8 +115,8 @@
 							</el-tab-pane>
 						</el-tabs>
 					</div>
-					<div class="list_btn">
-						<el-button style="width: 40px" link @click="handleExitFlow">
+					<div class="list_btn" @click="handleExitFlow">
+						<el-button style="width: 40px" link>
 							<el-icon style="font-size: 16px !important; color: #1677ff">
 								<ArrowLeft />
 							</el-icon>
@@ -177,10 +178,11 @@
 
 <script setup lang="ts">
 import * as echarts from 'echarts';
-import { onMounted, reactive, ref, nextTick } from 'vue';
+import { nextTick, onMounted, reactive, ref } from 'vue';
 import { useRoute, useRouter } from 'vue-router';
-import { formatTime } from '/@/utils/istation/common.js';
+import { formatTime, getDefaultPeriod } from '/@/utils/istation/common.js';
 import { eDimensionFilter_Ops, eDrilling_Ops } from '/@/views/types/metrics/index';
+const defaultTime = ref<[Date, Date]>([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]);
 const router = useRouter();
 const route = useRoute();
 // 瀹氫箟鍙橀噺鍐呭
@@ -228,7 +230,7 @@
 		],
 	},
 	exploreForm: {
-		dateRangeExplore: [] as any,
+		dateRangeExplore: '' as any,
 		dimensionDrilling: 0,
 		dimensionFiltering: {
 			user: '',
@@ -252,35 +254,6 @@
 	],
 	chartStatus: false,
 });
-const shortcuts = [
-	{
-		text: '鏈�杩戜竴鍛�',
-		value: () => {
-			const end = new Date();
-			const start = new Date();
-			start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
-			return [start, end];
-		},
-	},
-	{
-		text: '鏈�杩戜竴鏈�',
-		value: () => {
-			const end = new Date();
-			const start = new Date();
-			start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
-			return [start, end];
-		},
-	},
-	{
-		text: '鏈�杩戜笁鏈�',
-		value: () => {
-			const end = new Date();
-			const start = new Date();
-			start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
-			return [start, end];
-		},
-	},
-];
 
 //杩斿洖鍒扮煡璇嗗簱鍒楄〃
 const handleExitFlow = () => {
@@ -415,6 +388,9 @@
 	const { id, name } = route.query;
 	state.metricInfo.name = name;
 	state.metricInfo.id = id;
+	const { startDate, endDate } = getDefaultPeriod('7Days');
+	const dateRange = [startDate.format('YYYY-MM-DD HH:mm:ss'), endDate.format('YYYY-MM-DD HH:mm:ss')];
+	state.exploreForm.dateRangeExplore = dateRange;
 });
 </script>
 <style scoped lang="scss">

--
Gitblit v1.9.3