This commit is contained in:
张成
2025-10-28 15:51:56 +08:00
parent 42c977b815
commit 0a723c4dfe
3 changed files with 14 additions and 12 deletions

View File

@@ -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) {

View File

@@ -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
}