From 0a723c4dfee7bd803084dc589621de4290b8522d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Tue, 28 Oct 2025 15:51:56 +0800 Subject: [PATCH] 1 --- src/utils/http.js | 3 +-- src/utils/uiTool.js | 21 ++++++++++++--------- 快速开始.md | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/utils/http.js b/src/utils/http.js index fe689c1..222ee0c 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -210,8 +210,7 @@ class Http { let res = await axios.post(url, formData, config) filename = filename || res.headers['content-disposition'].split('filename=')[1].split(';')[0] - // 开头和结尾去掉 中间不去掉 - filename = filename.replace(/^[_-]+|[_-]+$/g, '') + // 直接下载 if (is_down) { diff --git a/src/utils/uiTool.js b/src/utils/uiTool.js index ff9cb43..08c4471 100644 --- a/src/utils/uiTool.js +++ b/src/utils/uiTool.js @@ -4,7 +4,7 @@ import http from './http' const componentMap = {} export default class uiTool { - + /** * 设置组件映射表 * @param {Object} map - 组件映射对象 @@ -12,7 +12,7 @@ export default class uiTool { static setComponentMap(map) { Object.assign(componentMap, map) } - + /** * 根据路径获取组件 * @param {String} componentPath - 组件路径(如 "system/sys_user.vue") @@ -34,6 +34,9 @@ export default class uiTool { * @param {String} fileName - 文件名(可选,默认为时间戳.csv) */ static downloadFile(res, fileName) { + // 开头和结尾去掉 中间不去掉 + fileName = fileName.replace(/^[_-]+|[_-]+$/g, '') + const blob = new Blob([res.data || res]) const downloadElement = document.createElement('a') const href = window.URL.createObjectURL(blob) @@ -188,10 +191,10 @@ export default class uiTool { } else if (item.type === '页面' || item.type === '功能') { try { let componentPath = item.component - + // 从组件映射表中获取组件 let component = uiTool.getComponent(componentPath) - + if (component) { // 找到了对应的组件 item.component = component @@ -296,7 +299,7 @@ export default class uiTool { // 递归检查所有层级中是否有首页路由 const hasHomeInRoutes = (routes) => { if (!routes || !Array.isArray(routes)) return false - + for (let route of routes) { // 检查当前路由的 path if (route.path === '/home' || route.path === 'home') { @@ -314,7 +317,7 @@ export default class uiTool { const homeRoute = mainRoute.children.find(r => r.path === '/home') const hasHome = hasHomeInRoutes(curRoutes) - + if (hasHome) { // 如果权限路由中有 home,使用权限路由的 home(不添加默认首页) mainRoute.children = curRoutes @@ -329,14 +332,14 @@ export default class uiTool { // 优先查找首页路由,如果没有则使用第一个菜单项 const findFirstRoute = (routes) => { if (!routes || routes.length === 0) return null - + for (let route of routes) { // 优先查找 /home 路由 if (route.path === '/home' || route.path === 'home') { return route.path.startsWith('/') ? route.path : '/' + route.path } } - + // 如果没有 home,使用第一个页面路由 for (let route of routes) { if (route.type !== '菜单' && route.path) { @@ -348,7 +351,7 @@ export default class uiTool { if (childRoute) return childRoute } } - + return null } diff --git a/快速开始.md b/快速开始.md index 5b99345..1964d1c 100644 --- a/快速开始.md +++ b/快速开始.md @@ -168,7 +168,7 @@ this.$tools.formatDate(new Date()) this.$tools.deepClone(obj) // 文件下载 -this.$funTool.downloadFile(response, 'filename.xlsx') +this.$uiTool.downloadFile(response, 'filename.xlsx') // 配置信息 this.$config.title