first commit

This commit is contained in:
仲么了
2023-12-21 16:42:39 +08:00
commit 0f7b59f55b
79 changed files with 7638 additions and 0 deletions

75
src/router/index.ts Normal file
View File

@@ -0,0 +1,75 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import staticRoutes from '@/router/static'
const router = createRouter({
history: createWebHashHistory(),
routes: staticRoutes
})
// router.beforeEach((to, from, next) => {
// NProgress.configure({ showSpinner: false })
// NProgress.start()
// if (!window.existLoading) {
// loading.show()
// window.existLoading = true
// }
// // 按需动态加载页面的语言包-start
// let loadPath: string[] = []
// const config = useConfig()
// if (to.path in langAutoLoadMap) {
// loadPath.push(...langAutoLoadMap[to.path as keyof typeof langAutoLoadMap])
// }
// let prefix = ''
// if (isAdminApp(to.fullPath)) {
// prefix = './backend/' + config.lang.defaultLang
// // 去除 path 中的 /admin
// const adminPath = to.path.slice(to.path.indexOf(adminBaseRoutePath) + adminBaseRoutePath.length)
// if (adminPath) loadPath.push(prefix + adminPath + '.ts')
// } else {
// prefix = './frontend/' + config.lang.defaultLang
// loadPath.push(prefix + to.path + '.ts')
// }
// // 根据路由 name 加载的语言包
// if (to.name) {
// loadPath.push(prefix + '/' + to.name.toString() + '.ts')
// }
// if (!window.loadLangHandle.publicMessageLoaded) window.loadLangHandle.publicMessageLoaded = []
// const publicMessagePath = prefix + '.ts'
// if (!window.loadLangHandle.publicMessageLoaded.includes(publicMessagePath)) {
// loadPath.push(publicMessagePath)
// window.loadLangHandle.publicMessageLoaded.push(publicMessagePath)
// }
// // 去重
// loadPath = uniq(loadPath)
// for (const key in loadPath) {
// loadPath[key] = loadPath[key].replaceAll('${lang}', config.lang.defaultLang)
// if (loadPath[key] in window.loadLangHandle) {
// window.loadLangHandle[loadPath[key]]().then((res: { default: anyObj }) => {
// const pathName = loadPath[key].slice(
// loadPath[key].lastIndexOf(prefix) + (prefix.length + 1),
// loadPath[key].lastIndexOf('.')
// )
// mergeMessage(res.default, pathName)
// })
// }
// }
// // 动态加载语言包-end
// next()
// })
// // 路由加载后
// router.afterEach(() => {
// if (window.existLoading) {
// loading.hide()
// }
// NProgress.done()
// })
export default router

62
src/router/static.ts Normal file
View File

@@ -0,0 +1,62 @@
import type { RouteRecordRaw } from 'vue-router'
const pageTitle = (name: string): string => {
return `pagesTitle.${name}`
}
/**
* 后台基础路由路径
*/
export const adminBaseRoutePath = '/admin'
export const adminBaseRoute = {
path: adminBaseRoutePath,
name: 'admin',
component: () => import('@/layouts/admin/index.vue'),
// 直接重定向到 loading 路由
redirect: adminBaseRoutePath + '/loading',
meta: {
title: `pagesTitle.admin`
},
children: [
{
path: 'loading/:to?',
name: 'adminMainLoading',
component: () => import('@/layouts/common/components/loading.vue'),
meta: {
title: `pagesTitle.loading`
}
}
]
}
/*
* 静态路由
* 自动加载 ./static 目录的所有文件,并 push 到以下数组
*/
const staticRoutes: Array<RouteRecordRaw> = [
adminBaseRoute,
{
// 管理员登录页 - 不放在 adminBaseRoute.children 因为登录页不需要使用后台的布局
path: '/login',
name: 'login',
component: () => import('@/views/user/login.vue'),
meta: {
title: pageTitle('login')
}
},
{
path: '/:path(.*)*',
redirect: '/404'
},
{
// 404
path: '/404',
name: 'notFound',
component: () => import('@/views/common/error/404.vue'),
meta: {
title: pageTitle('notFound') // 页面不存在
}
}
]
export default staticRoutes