manager 升级到vue3

This commit is contained in:
pikachu1995@126.com
2026-05-25 10:49:09 +08:00
parent e7350899bf
commit 615ee91511
239 changed files with 22907 additions and 30841 deletions

View File

@@ -1,56 +1,46 @@
import Vue from 'vue';
import ViewUI from 'view-design';
import Util from '../libs/util';
import VueRouter from 'vue-router';
import Cookies from 'js-cookie';
import {routers} from './router';
import { createRouter, createWebHistory } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import Util from "../libs/util";
import Cookies from "js-cookie";
import store from "@/store";
import { routers } from "./router";
Vue.use(VueRouter);
NProgress.configure({ showSpinner: false });
// 路由配置
const RouterConfig = {
mode: 'history',
routes: routers
};
/**
* 解决重复点击菜单会控制台报错bug
*/
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return routerPush.call(this, location).catch(error=> error)
}
export const router = new VueRouter(RouterConfig);
export const router = createRouter({
history: createWebHistory(),
routes: routers,
});
router.beforeEach((to, from, next) => {
ViewUI.LoadingBar.start();
NProgress.start();
Util.title(to.meta.title);
next();
const name = to.name;
const hasToken = Cookies.get("userInfoManager");
if (!Cookies.get('userInfoManager') && name !== 'login') {
// 判断是否已经登录且前往的页面不是登录页
next({
name: 'login'
});
} else if (Cookies.get('userInfoManager') && name === 'login') {
// 判断是否已经登录且前往的是登录页
Util.title();
next({
name: 'home_index'
});
} else {
Util.toDefaultPage([...routers], name, router, next);
if (!hasToken && name !== "login") {
next({ name: "login" });
return;
}
if (hasToken && name === "login") {
Util.title();
next({ name: "home_index" });
return;
}
if (hasToken) {
Util.toDefaultPage([...routers], name, router, next);
return;
}
next();
});
router.afterEach((to) => {
Util.openNewPage(router.app, to.name, to.params, to.query);
ViewUI.LoadingBar.finish();
Util.openNewPage({ $store: store }, to.name, to.params, to.query);
NProgress.done();
window.scrollTo(0, 0);
});