进行优化

This commit is contained in:
zouzhibing 2022-08-22 14:46:05 +08:00
parent 7cfca66ac4
commit 99634a49d7
8 changed files with 58 additions and 36 deletions

2
.env.development Normal file
View File

@ -0,0 +1,2 @@
# 本地环境
NODE_ENV = 'development'

2
.env.production Normal file
View File

@ -0,0 +1,2 @@
# 线上环境
NODE_ENV = "production"

2
.env.test Normal file
View File

@ -0,0 +1,2 @@
# 测试环境
NODE_ENV = "test"

View File

@ -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();
});

View File

@ -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:truefalse
* keepAlive true
* path ==>
* name ==>
* component ==>
* redirect ==>
* alwaysShow ==> true
* hidden ==> hidden:truefalse
* keepAlive ==> true
* meta ==>
* meta.title ==>
* meta.icon ==> icon
*/
export const constantRoutes: Array<RouteRecordRaw&extendRoute> = [
{
path: "/",
redirect: { name: "login" }
},
{
path: '/login',
name: 'Login',
@ -34,7 +44,6 @@ export const constantRoutes: Array<RouteRecordRaw&extendRoute> = [
hidden: true,
meta: { title: '登录',}
},
{
path: '/',
name: 'layout',
@ -49,7 +58,6 @@ export const constantRoutes: Array<RouteRecordRaw&extendRoute> = [
},
]
},
]
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

View File

@ -21,7 +21,7 @@
<el-form-item>
<el-button @click="reset(ruleFormRef)">重置</el-button>
<el-button type="primary" @click="onSubmit">查询</el-button>
<el-button type="text" @click="isExpand = !isExpand"
<el-button link @click="isExpand = !isExpand"
>{{ isExpand ? '合并' : '展开'
}}<el-icon>
<arrow-down v-if="!isExpand" />

View File

@ -11,6 +11,7 @@
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
//
"skipLibCheck": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],

View File

@ -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