From 0e982d78030d36d6048532f5d4a848ad9a22a13f Mon Sep 17 00:00:00 2001 From: yangyin <1850366751@qq.com> Date: 星期一, 15 七月 2024 10:51:37 +0800 Subject: [PATCH] fix: 修改办公助手 --- src/utils/util.ts | 75 +++++++++++++++++++++++++++++-------- 1 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/utils/util.ts b/src/utils/util.ts index 5821a21..13bfb8d 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -1,15 +1,49 @@ -import type { Ref } from 'vue'; -import JSONbig from 'json-bigint'; import { ElMessage, ElMessageBox } from 'element-plus'; +import JSONbig from 'json-bigint'; +import { storeToRefs } from 'pinia'; +import type { Ref } from 'vue'; import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes'; import { useThemeConfig } from '/@/stores/themeConfig'; -import { storeToRefs } from 'pinia'; import request from '/@/utils/request'; // 瀵煎叆渚濊禆 +import axios from 'axios'; import FileSaver from 'file-saver'; import * as XLSX from 'xlsx'; -import axios from 'axios'; import { MAIN_URL } from '../constants'; + +/** + * 鏅�氬璞¤浆涓� formData + * @param obj + */ +export const toFormData = (obj: any) => { + const formData = new FormData(); + + const addFormData = (subObj, prePrefix = '', isArray = false) => { + for (const key in subObj) { + if (Object.prototype.hasOwnProperty.call(subObj, key)) { + const value = subObj[key]; + let currentKey = ''; + if (prePrefix === '') { + currentKey = key; + } else if (isArray) { + currentKey = `${prePrefix}[${key}]`; + } else { + currentKey = `${prePrefix}.${key}`; + } + + if (value != null && Array.isArray(value) && value.length > 0) { + addFormData(value, currentKey, true); + } else if (value != null && typeof value === 'object' && Object.values(value).length > 0) { + addFormData(value, currentKey, false); + } else { + formData.append(currentKey, value); + } + } + } + }; + addFormData(obj); + return formData; +}; /** * @description 褰撶鍒� JSON 涓瓨鍦ㄨ繃闀跨殑鏁板瓧鏃讹紝浣跨敤 JSONbigString 瑙f瀽锛屾暟瀛椾細杞负瀛楃涓插鐞� @@ -254,7 +288,7 @@ ) => { if (!treeData || treeData.length === 0) return; if (!parent) parent = treeData; - + for (let index = 0; index < treeData.length; index++) { const value = treeData[index] as any; if (markParent) { @@ -503,28 +537,35 @@ themeConfig.value.isTagsview = !isHide; }; - /** * 鏈�杩� n 澶╃殑 startDate銆乪ndDate * @param dates */ export const getRecentDateRange = (dates: number) => { // 鑾峰彇褰撳墠鏃ユ湡 - const currentDate = new Date(); - + const endDate = new Date(); const startDate = new Date(); - startDate.setDate(currentDate.getDate() - dates + 1); - // 灏嗘椂鍒嗙璁句负0 - startDate.setHours(0); - startDate.setMinutes(0); - startDate.setSeconds(0); - // 鑾峰彇褰撳墠鏃ユ湡浣滀负缁堟鑺傜偣 - const endDate = currentDate; - return { startDate, endDate }; + startDate.setTime(startDate.getTime() - 3600 * 1000 * 24 * dates); + startDate.setHours(0, 0, 0, 0); + return [startDate, endDate]; +}; + +/** + * 鏈�杩� n 澶╃殑 date + * @param dates + */ +export const getRecentDate = (dates: number) => { + // 鑾峰彇褰撳墠鏃ユ湡 + const recentDate = new Date(); + recentDate.setTime(recentDate.getTime() - 3600 * 1000 * 24 * dates); + recentDate.setHours(0, 0, 0, 0); + return recentDate; }; //#region ====================== 鏈�杩戞椂闂� ====================== -export const getAWeek = () => getRecentDateRange(7); +export const getAWeek = () => { + return getRecentDateRange(7); +}; export const getHalfMonth = () => getRecentDateRange(15); export const getAMonth = () => getRecentDateRange(30); export const getThreeMonth = () => getRecentDateRange(90); -- Gitblit v1.9.3