Files
admin_core/src/store/app.js
张成 e039ae8c62 1
2025-10-28 11:24:11 +08:00

80 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { getBreadCrumbList, getHomeRoute } from '../utils/tools'
import paramSetupServer from '../api/system/paramSetupServer'
export default {
namespaced: true,
state: {
sysFormModel: { title: '', logoUrl: '' },
breadCrumbList: [],
homeRoute: {}
},
getters: {
sysFormModel: state => state.sysFormModel,
breadCrumbList: state => state.breadCrumbList,
homeRoute: state => state.homeRoute
},
mutations: {
setBreadCrumb(state, route) {
state.breadCrumbList = getBreadCrumbList(route, state.homeRoute)
},
setHomeRoute(state, routes) {
state.homeRoute = getHomeRoute(routes, 'home')
},
setSysTitle(state, reload) {
state.sysFormModel = reload
}
},
actions: {
async getSysTitle({ state, commit, rootState }, { defaultTitle, defaultLogo = '' } = {}) {
// 如果没有传入 defaultTitle尝试从框架配置中获取
if (!defaultTitle && window.framework && window.framework.config) {
defaultTitle = window.framework.config.title || '智能代码平台'
} else if (!defaultTitle) {
defaultTitle = '智能代码平台'
}
let formModel = {
title: defaultTitle,
logoUrl: defaultLogo
}
// 检查是否已登录(有 token
const token = rootState.user.token
if (token) {
// 已登录,尝试从后端获取系统标题
try {
console.log('开始获取系统标题...')
let res1 = await paramSetupServer.getOne('sys_title')
console.log('获取系统标题返回:', res1)
if (res1 && res1.code === 0 && res1.data && res1.data.value) {
formModel.title = res1.data.value
document.title = res1.data.value
console.log('系统标题已更新为:', res1.data.value)
} else {
console.warn('后端未返回有效的系统标题,使用默认标题:', defaultTitle)
document.title = formModel.title
}
let res2 = await paramSetupServer.getOne('sys_logo')
if (res2 && res2.code === 0 && res2.data && res2.data.value) {
formModel.logoUrl = res2.data.value
}
} catch (error) {
console.warn('获取系统标题失败,使用默认标题:', error.message || error)
// 使用默认标题
document.title = formModel.title
}
} else {
// 未登录,直接使用默认标题
console.log('未登录,使用默认标题:', defaultTitle)
document.title = formModel.title
}
commit('setSysTitle', formModel)
}
}
}