通过配置加载一些配置项

This commit is contained in:
lxd 2024-11-15 17:50:54 +08:00
parent ddb75bae18
commit 76e9332870
5 changed files with 37 additions and 11 deletions

View File

@ -8,7 +8,7 @@ import { useUserStore } from '@/store/modules/user'
import LockDialog from './components/LockDialog.vue' import LockDialog from './components/LockDialog.vue'
import LockPage from './components/LockPage.vue' import LockPage from './components/LockPage.vue'
import { useLockStore } from '@/store/modules/lock' import { useLockStore } from '@/store/modules/lock'
import * as ConfigApi from '@/api/infra/config'//
defineOptions({ name: 'UserInfo' }) defineOptions({ name: 'UserInfo' })
const { t } = useI18n() const { t } = useI18n()
@ -36,6 +36,7 @@ const lockScreen = () => {
const loginOut = async () => { const loginOut = async () => {
try { try {
const configdata= await ConfigApi.getConfigKey('url.loginOut')// 退
await ElMessageBox.confirm(t('common.loginOutMessage'), t('common.reminder'), { await ElMessageBox.confirm(t('common.loginOutMessage'), t('common.reminder'), {
confirmButtonText: t('common.ok'), confirmButtonText: t('common.ok'),
cancelButtonText: t('common.cancel'), cancelButtonText: t('common.cancel'),
@ -43,7 +44,9 @@ const loginOut = async () => {
}) })
await userStore.loginOut() await userStore.loginOut()
tagsViewStore.delAllViews() tagsViewStore.delAllViews()
replace('/login?redirect=/index') // replace('/login?redirect=/index')
replace(configdata)
} catch {} } catch {}
} }
const toProfile = async () => { const toProfile = async () => {

View File

@ -8,7 +8,7 @@ import { usePageLoading } from '@/hooks/web/usePageLoading'
import { useDictStoreWithOut } from '@/store/modules/dict' import { useDictStoreWithOut } from '@/store/modules/dict'
import { useUserStoreWithOut } from '@/store/modules/user' import { useUserStoreWithOut } from '@/store/modules/user'
import { usePermissionStoreWithOut } from '@/store/modules/permission' import { usePermissionStoreWithOut } from '@/store/modules/permission'
import * as ConfigApi from '@/api/infra/config'//李晓东
const { start, done } = useNProgress() const { start, done } = useNProgress()
const { loadStart, loadDone } = usePageLoading() const { loadStart, loadDone } = usePageLoading()
@ -94,7 +94,8 @@ router.beforeEach(async (to, from, next) => {
if (whiteList.indexOf(to.path) !== -1) { if (whiteList.indexOf(to.path) !== -1) {
next() next()
} else { } else {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 //next(`/login?redirect=/diagnosis/patientexamlistPathology`)
next(await ConfigApi.getConfigKey('url.loginOut')) //李晓东 // 否则全部重定向到登录页 病理需要 李晓东 临时解决办法 直接指向某个固定页面 /diagnosis/patientexamlistPathology 原先写法next(`/login?redirect=${to.fullPath}`)
} }
} }
}) })

View File

@ -38,7 +38,7 @@ export const usePermissionStore = defineStore('permission', {
if (wsCache.get(CACHE_KEY.ROLE_ROUTERS)) { if (wsCache.get(CACHE_KEY.ROLE_ROUTERS)) {
res = wsCache.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[] res = wsCache.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[]
} }
const routerMap: AppRouteRecordRaw[] = generateRoute(res) const routerMap: AppRouteRecordRaw[] =await generateRoute(res)
// 动态路由404一定要放到最后面 // 动态路由404一定要放到最后面
// 李晓东 // 李晓东
this.addRouters = routerMap.concat([ this.addRouters = routerMap.concat([

View File

@ -3,7 +3,7 @@ import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { isUrl } from '@/utils/is' import { isUrl } from '@/utils/is'
import { cloneDeep, omit } from 'lodash-es' import { cloneDeep, omit } from 'lodash-es'
import qs from 'qs' import qs from 'qs'
import * as ConfigApi from '@/api/infra/config'//李晓东
const modules = import.meta.glob('../views/**/*.{vue,tsx}') const modules = import.meta.glob('../views/**/*.{vue,tsx}')
/** /**
* *
@ -61,9 +61,10 @@ export const getRawRoute = (route: RouteLocationNormalized): RouteLocationNormal
} }
// 后端控制路由生成 // 后端控制路由生成
export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecordRaw[] => { export const generateRoute = async (routes: AppCustomRouteRecordRaw[]): Promise<AppRouteRecordRaw[]> => {
const res: AppRouteRecordRaw[] = [] const res: AppRouteRecordRaw[] = []
const modulesRoutesKeys = Object.keys(modules) const modulesRoutesKeys = Object.keys(modules)
const Title=await getTitle()//李晓东
for (const route of routes) { for (const route of routes) {
// 1. 生成 meta 菜单元数据 // 1. 生成 meta 菜单元数据
const meta = { const meta = {
@ -74,7 +75,8 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
alwaysShow: alwaysShow:
route.children && route.children &&
route.children.length === 1 && route.children.length === 1 &&
(route.alwaysShow !== undefined ? route.alwaysShow : true) (route.alwaysShow !== undefined ? route.alwaysShow : true),
affix: route.name ===Title//李晓东 目前 写死是判断固定的菜单不可关闭 后面做成配置
} as any } as any
// 特殊逻辑:如果后端配置的 MenuDO.component 包含 ?,则表示需要传递参数 // 特殊逻辑:如果后端配置的 MenuDO.component 包含 ?,则表示需要传递参数
// 此时,我们需要解析参数,并且将参数放到 meta.query 中 // 此时,我们需要解析参数,并且将参数放到 meta.query 中
@ -141,7 +143,7 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
data.component = modules[modulesRoutesKeys[index]] data.component = modules[modulesRoutesKeys[index]]
} }
if (route.children) { if (route.children) {
data.children = generateRoute(route.children) data.children =await generateRoute(route.children)
} }
} }
res.push(data as AppRouteRecordRaw) res.push(data as AppRouteRecordRaw)
@ -251,3 +253,16 @@ const toCamelCase = (str: string, upperCaseFirst: boolean) => {
return str return str
} }
async function getTitle() {//李晓东
try {
// 等待 Promise 解析并获取值
const title = await ConfigApi.getConfigKey('isclose');
return title; // 返回标题
} catch (error) {
console.error('Failed to get title:', error);
throw error; // 重新抛出错误,或者处理错误
}
}

View File

@ -32,7 +32,7 @@
<div class="my-top"> <div class="my-top">
<img class="top-image" src="@/assets/imgs/FLY.png" /> <img class="top-image" src="@/assets/imgs/FLY.png" />
<div class="text-container"> <div class="text-container">
<span style="font-size: 4.32vh">医共体医学影像系统</span> <span style="font-size: 4.32vh">{{headTitle}}</span>
<span style="font-size: 1.64vh">The Medical Community Medical Imaging Systems</span> <span style="font-size: 1.64vh">The Medical Community Medical Imaging Systems</span>
</div> </div>
</div> </div>
@ -93,7 +93,7 @@ import { useDesign } from '@/hooks/web/useDesign'
import { useAppStore } from '@/store/modules/app' import { useAppStore } from '@/store/modules/app'
import { ThemeSwitch } from '@/layout/components/ThemeSwitch' import { ThemeSwitch } from '@/layout/components/ThemeSwitch'
import { LocaleDropdown } from '@/layout/components/LocaleDropdown' import { LocaleDropdown } from '@/layout/components/LocaleDropdown'
import * as ConfigApi from '@/api/infra/config'//
import { LoginForm, MobileForm, QrCodeForm, RegisterForm, SSOLoginVue } from './components' import { LoginForm, MobileForm, QrCodeForm, RegisterForm, SSOLoginVue } from './components'
defineOptions({ name: 'Login' }) defineOptions({ name: 'Login' })
@ -102,6 +102,13 @@ const { t } = useI18n()
const appStore = useAppStore() const appStore = useAppStore()
const { getPrefixCls } = useDesign() const { getPrefixCls } = useDesign()
const prefixCls = getPrefixCls('login') const prefixCls = getPrefixCls('login')
const headTitle = ref('医共体医学影像系统')
onMounted(async() => {
headTitle.value= await ConfigApi.getConfigKey('headTitle')//李晓东 通过配置项取退出后重定向页面 原先定向首页= await ConfigApi.getConfigKey('url.loginOut')//李晓东 通过配置项取退出后重定向页面 原先定向首页
console.log('系统名称'+headTitle.value)
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>