From 99634a49d7df6dfc95a0561da3c06c9b240dbad3 Mon Sep 17 00:00:00 2001 From: zouzhibing Date: Mon, 22 Aug 2022 14:46:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 + .env.production | 2 + .env.test | 2 + src/permission.ts | 9 +-- src/router/index.ts | 64 +++++++++++--------- src/views/table/components/comprehensive.vue | 2 +- tsconfig.json | 1 + vite.config.ts | 12 +++- 8 files changed, 58 insertions(+), 36 deletions(-) create mode 100644 .env.development create mode 100644 .env.production create mode 100644 .env.test diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..42e2996 --- /dev/null +++ b/.env.development @@ -0,0 +1,2 @@ +# 本地环境 +NODE_ENV = 'development' diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..919d1bb --- /dev/null +++ b/.env.production @@ -0,0 +1,2 @@ +# 线上环境 +NODE_ENV = "production" diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..1077f31 --- /dev/null +++ b/.env.test @@ -0,0 +1,2 @@ +# 测试环境 +NODE_ENV = "test" diff --git a/src/permission.ts b/src/permission.ts index 5c9d706..107faa4 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -17,13 +17,12 @@ router.beforeEach(async(to, from, next) => { if(typeof(to.meta.title) === 'string'){ document.title = to.meta.title ||'vue-admin-perfect' } - // 确定用户是否已登录 + // 确定用户是否已登录过,存在Token const hasToken = getToken() if (hasToken) { if (to.path === '/login') { // 如果已登录,请重定向到主页 next({ path: '/' }) - NProgress.done() } else { try { // 路由添加进去了没有及时更新 需要重新进去一次拦截 @@ -40,7 +39,6 @@ router.beforeEach(async(to, from, next) => { } catch (error) { next(`/login?redirect=${to.path}`) } - NProgress.done() } }else{ if (whiteList.indexOf(to.path) !== -1) { @@ -49,8 +47,11 @@ router.beforeEach(async(to, from, next) => { next(`/login?redirect=${to.path}`) } - NProgress.done() } }) +router.afterEach(() => { + NProgress.done(); +}); + diff --git a/src/router/index.ts b/src/router/index.ts index 5ef3416..ed4be59 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,11 @@ import { createRouter, createWebHistory, RouteRecordRaw,createWebHashHistory,Router } from 'vue-router' import Layout from "@/layout/index.vue"; +// 扩展继承属性 +interface extendRoute { + hidden?:boolean +} + // 引入组件 import chartsRouter from './modules/charts' import chatRouter from './modules/chat' @@ -14,19 +19,24 @@ import excelRouter from './modules/excel' import nestedRouter from './modules/nested' import systemRouter from './modules/system' - -interface extendRoute { - hidden?:boolean -} - /** - * alwaysShow 如果设置为true,将始终显示根菜单,无论其子路由长度如何 - * hidden 如果“hidden:true”不会显示在侧边栏中(默认值为false) - * keepAlive 设为true 缓存 + * path ==> 路由路径 + * name ==> 路由名称 + * component ==> 路由组件 + * redirect ==> 路由重定向 + * alwaysShow ==> 如果设置为true,将始终显示根菜单,无论其子路由长度如何 + * hidden ==> 如果“hidden:true”不会显示在侧边栏中(默认值为false) + * keepAlive ==> 设为true 缓存 + * meta ==> 路由元信息 + * meta.title ==> 路由标题 + * meta.icon ==> 菜单icon */ - export const constantRoutes: Array = [ + { + path: "/", + redirect: { name: "login" } + }, { path: '/login', name: 'Login', @@ -34,7 +44,6 @@ export const constantRoutes: Array = [ hidden: true, meta: { title: '登录',} }, - { path: '/', name: 'layout', @@ -49,7 +58,6 @@ export const constantRoutes: Array = [ }, ] }, - ] const clipboardTable = { @@ -95,37 +103,33 @@ const zipRoutes = { ] } -// + // // 异步组件 export const asyncRoutes = [ - tableRouter, - chartsRouter, - chatRouter, - componentsRouter, - othersRouter, - nestedRouter, + tableRouter, + chartsRouter, + chatRouter, + componentsRouter, + othersRouter, + nestedRouter, excelRouter, zipRoutes, - errorRouter, - externalLink, - clipboardTable, + errorRouter, + externalLink, + clipboardTable, systemRouter, - permissionRouter, + permissionRouter, - { - path: '/:pathMatch(.*)', - redirect: '/error/404' - } + { + path: '/:pathMatch(.*)', + redirect: '/error/404' + } ] - const router = createRouter({ // history: createWebHistory(process.env.BASE_URL), // history history: createWebHashHistory(), // hash routes:constantRoutes }) - - - export default router diff --git a/src/views/table/components/comprehensive.vue b/src/views/table/components/comprehensive.vue index 73bf7e8..68a0978 100644 --- a/src/views/table/components/comprehensive.vue +++ b/src/views/table/components/comprehensive.vue @@ -21,7 +21,7 @@ 重置 查询 - {{ isExpand ? '合并' : '展开' }} diff --git a/tsconfig.json b/tsconfig.json index 5ff41d7..00d0ae7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "isolatedModules": true, "esModuleInterop": true, "lib": ["ESNext", "DOM"], + // 跳过库检查,解决打包失败 "skipLibCheck": true }, "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], diff --git a/vite.config.ts b/vite.config.ts index cf93607..45d6b28 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -22,6 +22,7 @@ export default defineConfig({ // Components({ // resolvers: [ElementPlusResolver()], // }), + // * 使用 svg 图标 createSvgIconsPlugin({ // 指定需要缓存的图标文件夹 iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')], @@ -55,11 +56,20 @@ export default defineConfig({ }, //启动服务配置 server: { + // 服务器主机名,如果允许外部访问,可设置为 "0.0.0.0" 也可设置成你的ip地址 host: '0.0.0.0', port: 8100, open: true, https: false, - proxy: {}, + cors: true, + // 代理跨域(模拟示例) + proxy: { + // "/api": { + // target: "", // easymock + // changeOrigin: true, + // rewrite: path => path.replace(/^\/api/, "") + // } + } }, // 生产环境打包配置 //去除 console debugger