From 8b85040d9522ec80e82e8a2dea17f39b6de343f1 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Mon, 09 Oct 2023 09:39:37 +0800
Subject: [PATCH] 计划库查询时间默认前三天到后三天

---
 src/types/task.ts                 |   31 +++++++--------
 src/components/task/TaskPanel.vue |   14 ++++++
 src/utils/time.ts                 |   48 ++++++++++++++++++++++++
 src/api/wayline.ts                |    2 
 4 files changed, 76 insertions(+), 19 deletions(-)

diff --git a/src/api/wayline.ts b/src/api/wayline.ts
index 4e5750d..8021fa3 100644
--- a/src/api/wayline.ts
+++ b/src/api/wayline.ts
@@ -76,7 +76,7 @@
   rth_altitude: number // 相对机场返航高度 20 - 500
   out_of_control_action: OutOfControlAction // 失控动作
 
-  //重复规则值
+  // 重复规则值
   rep_rule_val?:[]
 }
 // 新增计划
diff --git a/src/components/task/TaskPanel.vue b/src/components/task/TaskPanel.vue
index 7c5f05e..d842268 100644
--- a/src/components/task/TaskPanel.vue
+++ b/src/components/task/TaskPanel.vue
@@ -166,6 +166,7 @@
 import { getErrorMessage } from '/@/utils/error-code/index'
 import { commonColor } from '/@/utils/color'
 import { ExclamationCircleOutlined, UploadOutlined } from '@ant-design/icons-vue'
+import { timestampToTime } from '/@/utils/time'
 
 const store = useMyStore()
 const workspaceId = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
@@ -193,9 +194,17 @@
 const searchQuery = reactive<TaskQueryParam>({
   taskType: ''
 })
+
+function getSearchTime (n:number) {
+  const nowStamp = new Date().getTime()
+  const timestamp = nowStamp + (n * 60 * 60 * 1000 * 24)
+  const time = timestampToTime(timestamp)
+  return time
+}
+
 const statusArr = reactive([])
 const timeRangeArr = reactive({
-  data: [] as string[]
+  data: [getSearchTime(-3), getSearchTime(3)] as string[]
 })
 
 const body: IPage = {
@@ -343,6 +352,9 @@
 }
 
 function getPlans () {
+  searchQuery.startTime = timeRangeArr.data[0]
+  searchQuery.endTime = timeRangeArr.data[1]
+
   console.log('计划查询请求参数', searchQuery)
   tableLoading.value = true
   getWaylineJobs(workspaceId, body, searchQuery).then(res => {
diff --git a/src/types/task.ts b/src/types/task.ts
index 3e854eb..4639db0 100644
--- a/src/types/task.ts
+++ b/src/types/task.ts
@@ -22,7 +22,7 @@
   { value: TaskType.Continuous, label: TaskTypeMap[TaskType.Continuous] },
 ]
 
-//频率类型
+// 频率类型
 export enum FrequencyType {
   day = 1, // 日
   week = 2, // 周
@@ -35,13 +35,11 @@
   [FrequencyType.month]: '月',
 }
 
-
 export const FrequencyTypeOptions = [
-  { value: FrequencyType.month, label: FrequencyTypeMap[FrequencyType.month]},
+  { value: FrequencyType.month, label: FrequencyTypeMap[FrequencyType.month] },
   { value: FrequencyType.week, label: FrequencyTypeMap[FrequencyType.week] },
   { value: FrequencyType.day, label: FrequencyTypeMap[FrequencyType.day] },
 ]
-
 
 // 重复规则类型
 export enum RepeatRuleType {
@@ -54,27 +52,26 @@
   [RepeatRuleType.week]: '按星期',
 }
 
-export const RepeatRuleTypeOptions=[
+export const RepeatRuleTypeOptions = [
   { value: RepeatRuleType.day, label: RepeatRuleTypeMap[RepeatRuleType.day] },
   { value: RepeatRuleType.week, label: RepeatRuleTypeMap[RepeatRuleType.week] },
 ]
 
 export const WhichWeekOptions = [
-  {value: 1, label: '第一个'},
-  {value: 2, label: '第二个'},
-  {value: 3, label: '第三个'},
-  {value: 4, label: '第四个'},
+  { value: 1, label: '第一个' },
+  { value: 2, label: '第二个' },
+  { value: 3, label: '第三个' },
+  { value: 4, label: '第四个' },
 ]
 export const WhichDayOptions = [
-  {value: 7, label: '周日',checked:false},
-  {value: 1, label: '周一',checked:false},
-  {value: 2, label: '周二',checked:false},
-  {value: 3, label: '周三',checked:false},
-  {value: 4, label: '周四',checked:false},
-  {value: 5, label: '周五',checked:false},
-  {value: 6, label: '周六',checked:false},
+  { value: 7, label: '周日', checked: false },
+  { value: 1, label: '周一', checked: false },
+  { value: 2, label: '周二', checked: false },
+  { value: 3, label: '周三', checked: false },
+  { value: 4, label: '周四', checked: false },
+  { value: 5, label: '周五', checked: false },
+  { value: 6, label: '周六', checked: false },
 ]
-
 
 // 失控动作
 export enum OutOfControlAction {
diff --git a/src/utils/time.ts b/src/utils/time.ts
index 31f3717..8720c21 100644
--- a/src/utils/time.ts
+++ b/src/utils/time.ts
@@ -13,3 +13,51 @@
 export function formatUnixTime (time: number, format = DATE_FORMAT): string {
   return time ? moment.unix(time).format(format) : DEFAULT_PLACEHOLDER
 }
+
+export function dateFormat(date:any, format:string) {
+  format = format || 'yyyy-MM-dd hh:mm:ss';
+  if (date !== 'Invalid Date') {
+    let o = {
+      "M+": date.getMonth() + 1, //month
+      "d+": date.getDate(), //day
+      "h+": date.getHours(), //hour
+      "m+": date.getMinutes(), //minute
+      "s+": date.getSeconds(), //second
+      "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
+      "S": date.getMilliseconds() //millisecond
+    }
+    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
+        (date.getFullYear() + "").substr(4 - RegExp.$1.length));
+    for (let k in o)
+      if (new RegExp("(" + k + ")").test(format))
+        format = format.replace(RegExp.$1,
+            RegExp.$1.length === 1 ? o[k] :
+                ("00" + o[k]).substr(("" + o[k]).length));
+    return format;
+  }
+  return '';
+
+}
+
+export function convertTimestampToDate(timestamp:any, format:string) {
+  if (timestamp && (typeof timestamp === "string") && timestamp.indexOf("-") > -1) {
+    timestamp = timestamp.replace(/\-/g, "/")
+  }
+  let time = new Date(timestamp)
+  let formatterTime = dateFormat(time, format)
+  return formatterTime
+}
+
+// 返回年月日
+export const timestampToTime = (timestamp:number) => {
+  if (!timestamp) return
+  // 时间戳为10位需*1000,时间戳为13位不需乘1000
+  var date = new Date(timestamp);
+  var Y = date.getFullYear() + "-";
+  var M =
+      (date.getMonth() + 1 < 10
+          ? "0" + (date.getMonth() + 1)
+          : date.getMonth() + 1) + "-";
+  var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
+  return Y + M + D;
+}

--
Gitblit v1.9.3