This commit is contained in:
2025-11-28 17:40:40 +08:00
commit 135696ef93
244 changed files with 37401 additions and 0 deletions
+162
View File
@@ -0,0 +1,162 @@
import website from '@/config/website';
const modules = import.meta.glob('../**/**/*.vue');
function isURL(s) {
return /^http[s]?:\/\/.*/.test(s);
}
let RouterPlugin = function () {
this.$router = null;
this.$store = null;
};
RouterPlugin.install = function (option = {}) {
this.$router = option.router;
this.$store = option.store;
let i18n = option.i18n.global;
this.$router.$avueRouter = {
safe: this,
// 设置标题
setTitle: title => {
const defaultTitle = i18n.t('title');
title = title ? `${title} | ${defaultTitle}` : defaultTitle;
document.title = title;
},
closeTag: value => {
let tag = value || this.$store.getters.tag;
if (typeof value === 'string') {
tag = this.$store.getters.tagList.find(ele => ele.fullPath === value);
}
this.$store.commit('DEL_TAG', tag);
},
generateTitle: (item, props = {}) => {
let query = item[props.query || 'query'] || {};
let title = query.name || item[props.label || 'label'];
let meta = item[props.meta || 'meta'] || {};
let key = meta.i18n;
if (key) {
const hasKey = i18n.te('route.' + key);
if (hasKey) return i18n.t('route.' + key);
}
return title;
},
//动态路由
formatRoutes: function (aMenu = [], first) {
const aRouter = [];
const propsDefault = website.menu;
if (aMenu && aMenu.length === 0) return;
for (let i = 0; i < aMenu.length; i++) {
const oMenu = aMenu[i];
let path = oMenu[propsDefault.path],
isComponent = true,
component = oMenu.component,
name = oMenu[propsDefault.label],
icon = oMenu[propsDefault.icon],
children = oMenu[propsDefault.children],
query = oMenu[propsDefault.query],
meta = oMenu[propsDefault.meta];
if (option.keepAlive) {
meta.keepAlive = option.keepAlive;
}
const isChild = !!(children && children.length !== 0);
const oRouter = {
path: path,
component: (() => {
// 判断是否为首路由
if (first) {
return modules[
option.store.getters.isMacOs
? '../page/index/layout.vue'
: '../page/index/index.vue'
];
// 判断是否为多层路由
} else if (isChild && !first) {
return modules['../page/index/layout.vue'];
// 判断是否为最终的页面视图
} else {
let result = modules[`../${component}.vue`];
if (result) result().then(mod => (mod.default.name = path));
else {
isComponent = false;
}
return result;
}
})(),
name,
icon,
meta,
query,
redirect: (() => {
if (!isChild && first) return `${path}`;
else return '';
})(),
// 处理是否为一级路由
children: !isChild
? (() => {
if (first) {
oMenu[propsDefault.path] = `${path}`;
let result = modules[`../${component}.vue`];
if (result) result().then(mod => (mod.default.name = path));
else {
isComponent = false;
}
return [
{
component: result,
icon: icon,
name: name,
meta: meta,
query: query,
path: '',
},
];
}
return [];
})()
: (() => {
return this.formatRoutes(children, false);
})(),
};
if (!isURL(path) && isComponent) aRouter.push(oRouter);
}
if (first) {
aRouter.forEach(ele => this.safe.$router.addRoute(ele));
} else {
return aRouter;
}
},
};
};
export const formatPath = (ele, first) => {
const propsDefault = website.menu;
const icon = ele[propsDefault.icon];
ele[propsDefault.icon] = !icon ? propsDefault.iconDefault : icon;
ele.meta = { keepAlive: ele.isOpen === 2 };
const iframeComponent = 'components/iframe/main';
const iframeSrc = href => {
return href.replace(/&/g, '#');
};
const isChild = !!(ele[propsDefault.children] && ele[propsDefault.children].length !== 0);
if (!isChild && first) {
ele.component = 'views' + ele[propsDefault.path];
if (isURL(ele[propsDefault.href])) {
let href = ele[propsDefault.href];
ele.component = iframeComponent;
ele[propsDefault.query] = { url: iframeSrc(href) };
}
} else {
ele[propsDefault.children] &&
ele[propsDefault.children].forEach(child => {
child.component = 'views' + child[propsDefault.path];
child.meta = { keepAlive: child.isOpen === 2 };
if (isURL(child[propsDefault.href])) {
let href = child[propsDefault.href];
child[propsDefault.path] = ele[propsDefault.path] + '/' + child.code;
child.component = iframeComponent;
child[propsDefault.query] = { url: iframeSrc(href) };
}
formatPath(child);
});
}
};
export default RouterPlugin;
+37
View File
@@ -0,0 +1,37 @@
import { createRouter, createWebHistory } from 'vue-router';
import PageRouter from './page/';
import ViewsRouter from './views/';
import AvueRouter from './avue-router';
import i18n from '@/lang';
import Store from '@/store/';
import Layout from '@/page/index/index.vue';
//创建路由
const Router = createRouter({
base: import.meta.env.VITE_APP_BASE,
history: createWebHistory(import.meta.env.VITE_APP_BASE),
routes: [
...PageRouter,
...ViewsRouter,
],
});
AvueRouter.install({
store: Store,
router: Router,
i18n: i18n,
});
Router.$avueRouter.formatRoutes(Store.getters.menuAll, true);
export function resetRouter() {
// 重置路由 比如用于身份验证失败,需要重新登录时 先清空当前的路有权限
const newRouter = createRouter();
Router.matcher = newRouter.matcher; // reset router
AvueRouter.install(Vue, {
router: Router,
store: Store,
i18n: i18n,
});
}
export default Router;
+72
View File
@@ -0,0 +1,72 @@
import Store from '@/store/';
export default [
{
path: '/login',
name: '登录页',
component: () =>
Store.getters.isMacOs ? import('@/mac/login.vue') : import('@/page/login/index.vue'),
meta: {
keepAlive: true,
isTab: false,
isAuth: false,
},
},
{
path: '/oauth/redirect/:source',
name: '第三方登录',
component: () =>
Store.getters.isMacOs ? import('@/mac/login.vue') : import('@/page/login/index.vue'),
meta: {
keepAlive: true,
isTab: false,
isAuth: false,
},
},
{
path: '/lock',
name: '锁屏页',
component: () =>
Store.getters.isMacOs ? import('@/mac/lock.vue') : import('@/page/lock/index.vue'),
meta: {
keepAlive: true,
isTab: false,
isAuth: false,
},
},
{
path: '/404',
component: () => import(/* webpackChunkName: "page" */ '@/components/error-page/404.vue'),
name: '404',
meta: {
keepAlive: true,
isTab: false,
isAuth: false,
},
},
{
path: '/403',
component: () => import(/* webpackChunkName: "page" */ '@/components/error-page/403.vue'),
name: '403',
meta: {
keepAlive: true,
isTab: false,
isAuth: false,
},
},
{
path: '/500',
component: () => import(/* webpackChunkName: "page" */ '@/components/error-page/500.vue'),
name: '500',
meta: {
keepAlive: true,
isTab: false,
isAuth: false,
},
},
{
path: '/',
name: '主页',
redirect: '/wel',
},
];
+45
View File
@@ -0,0 +1,45 @@
import Layout from '@/page/index/index.vue';
import Store from '@/store/';
export default [
{
path: '/wel',
component: () =>
Store.getters.isMacOs ? import('@/mac/index.vue') : import('@/page/index/index.vue'),
redirect: '/wel/index',
children: [
{
path: 'index',
name: '首页',
meta: {
i18n: 'dashboard',
},
component: () => import(/* webpackChunkName: "views" */ '@/views/wel/index.vue'),
},
{
path: 'dashboard',
name: '控制台',
meta: {
i18n: 'dashboard',
menu: false,
},
component: () => import(/* webpackChunkName: "views" */ '@/views/wel/dashboard.vue'),
},
],
},
{
path: '/info',
component: Layout,
redirect: '/info/index',
children: [
{
path: 'index',
name: '个人信息',
meta: {
i18n: 'info',
},
component: () => import(/* webpackChunkName: "views" */ '@/views/system/userinfo.vue'),
},
],
},
];