| | |
| | | import { ElMessage, ElMessageBox } from 'element-plus'; |
| | | import { ElMessage, ElMessageBox, ElMessageBoxOptions } 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 解析,数字会转为字符串处理 |
| | | * 用法:JSONbigString.parse(jsonStr)) |
| | |
| | | |
| | | export const getImg = (name) => `src/assets/images/${name}`; |
| | | |
| | | export const downloadJSON = (jsonData: Object, fileName: String) => { |
| | | const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(jsonData)); |
| | | export const downloadJSON = (jsonData: string, fileName: String) => { |
| | | const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(jsonData); |
| | | const downloadAnchorNode = document.createElement('a'); |
| | | downloadAnchorNode.setAttribute('href', dataStr); |
| | | downloadAnchorNode.setAttribute('download', fileName + '.json'); |
| | |
| | | ) => { |
| | | 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) { |
| | |
| | | |
| | | if (value[childrenKey] && value[childrenKey].length !== 0) { |
| | | // 递归跳出 |
| | | const callResult = travelTree(value[childrenKey], callback, value, markParent); |
| | | const callResult = travelTree(value[childrenKey], callback, value, markParent, childrenKey); |
| | | if (callResult) { |
| | | return true; |
| | | } |
| | |
| | | * @param tableData |
| | | * @returns |
| | | */ |
| | | export const flatten = (tableData: any[], removeChild?: boolean, children = 'Children'): any[] => { |
| | | export const flatten = (tableData: any[], removeChild?: boolean, children = 'children'): any[] => { |
| | | const flattenedData: any[] = []; |
| | | |
| | | for (const item of tableData) { |
| | |
| | | * 最近 n 天的 startDate、endDate |
| | | * @param dates |
| | | */ |
| | | export const getRecentDateRange = (dates: number) => { |
| | | export const getRecentDateRange = (dates: number, includesCurrent = true) => { |
| | | dates = includesCurrent ? dates - 1 : dates; |
| | | // 获取当前日期 |
| | | const endDate = new Date(); |
| | | const startDate = new Date(); |
| | | startDate.setTime(startDate.getTime() - 3600 * 1000 * 24 * dates); |
| | | startDate.setHours(0, 0, 0, 0); |
| | | endDate.setHours(23, 59, 59, 59); |
| | | return [startDate, endDate]; |
| | | }; |
| | | |
| | |
| | | */ |
| | | export const toMyFixed = (num, precision) => { |
| | | if (num == null) return ''; |
| | | return num.toFixed(precision).replace(/\.?0+$/, ''); |
| | | if (!precision) return num + ''; |
| | | const factor = Math.pow(10, precision); |
| | | return Math.round(Number(num) * factor) / factor + ''; |
| | | }; |
| | | |
| | | |
| | | type GetTextWidthOption = { |
| | | size?: string; |
| | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | export const elConfirm = ( |
| | | message, |
| | | options: ElMessageBoxOptions = { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning', |
| | | } |
| | | ) => { |
| | | return new Promise((resolve, reject) => { |
| | | ElMessageBox.confirm(message, '提示', options) |
| | | .then(() => resolve(true)) |
| | | .catch(() => reject(false)); |
| | | }); |
| | | }; |