Skip to content

Commit

Permalink
add init loading page and remove $ref
Browse files Browse the repository at this point in the history
  • Loading branch information
jzfai committed Apr 20, 2023
1 parent dc5f3b2 commit 644acde
Show file tree
Hide file tree
Showing 52 changed files with 149 additions and 1,004 deletions.
1 change: 0 additions & 1 deletion eslintrc/.eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"useSlots": true,
"useTable": true,
"useTagsViewStore": true,
"userInfoReq": true,
"watch": true,
"watchEffect": true,
"watchPostEffect": true,
Expand Down
3 changes: 1 addition & 2 deletions eslintrc/eslint-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module.exports = defineConfig({
node: true
},
globals: {
defineOptions: true,
$ref: true
defineOptions: true
},
plugins: ['@typescript-eslint', 'prettier', 'unicorn'],
extends: [
Expand Down
8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<link rel="stylesheet" href="src/styles/init-loading.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= title %></title>
</head>
<body>
<div id="app"></div>
<div id="app">
<div class="loader-wrapper">
<img src="src/assets/gif/dianchi.gif" class="loading-gif">
<div class="load_title">正在加载系统资源,请耐心等待</div>
</div>
</div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions mock/system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const system = {
url: '/mock/login',
method: 'post',
response: () => {
return {
code: 20000,
jwtToken:"666666"
}
}
}

const loginOut = {
url: '/mock/loginOut',
method: 'post',
response: () => {
return {
code: 200,
title: 'mock请求测试'
}
}
}

export default [
system,loginOut
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@element-plus/icons-vue": "^2.0.4",
"axios": "0.21.3",
"echarts": "5.3.2",
"element-plus": "^2.2.9",
"element-plus": "2.2.27",
"js-error-collection": "^1.0.7",
"mitt": "3.0.0",
"moment-mini": "2.22.1",
Expand Down
31 changes: 31 additions & 0 deletions src/api/system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//获取用户信息
import axiosReq from 'axios'
// export const userInfoReq = (): Promise<any> => {
// return new Promise((resolve) => {
// const reqConfig = {
// url: '/basis-func/user/getUserInfo',
// params: { plateFormId: 2 },
// method: 'post'
// }
// axiosReq(reqConfig).then(({ data }) => {
// resolve(data)
// })
// })
// }

//登录
export const loginReq = (subForm) => {
return axiosReq({
url: '/mock/login',
params: subForm,
method: 'post'
})
}

//退出登录
export const loginOutReq = () => {
return axiosReq({
url: '/mock/loginOut',
method: 'post'
})
}
31 changes: 0 additions & 31 deletions src/api/user.ts

This file was deleted.

Binary file added src/assets/gif/dianchi.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 6 additions & 10 deletions src/icons/SvgIcon.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<svg :class="svgClass" aria-hidden="true">
<use :xlink:href="iconName" />
<use :xlink:href="iconName" :fill="color" />
</svg>
</template>

Expand All @@ -14,7 +14,11 @@ const props = defineProps({
className: {
type: String,
default: ''
}
},
color: {
type: String,
default: ''
},
})
const iconName = computed(() => `#icon-${props.iconClass}`)
Expand All @@ -27,14 +31,6 @@ const svgClass = computed(() => {
</script>

<style scoped lang="scss">
.sub-el-icon,
.nav-icon {
display: inline-block;
font-size: 15px;
margin-right: 12px;
position: relative;
}
.svg-icon {
width: 1em;
height: 1em;
Expand Down
11 changes: 7 additions & 4 deletions src/layout/app-main/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { resetState } from '@/hooks/use-permission'
import { elMessage } from '@/hooks/use-element'
import { useBasicStore } from '@/store/basic'
import { langTitle } from '@/hooks/use-common'
import {loginOutReq} from "@/api/system";
const basicStore = useBasicStore()
const { settings, sidebar, setToggleSideBar } = basicStore
Expand All @@ -56,10 +57,12 @@ const toggleSideBar = () => {
//退出登录
const router = useRouter()
const loginOut = () => {
elMessage('退出登录成功')
router.push(`/login?redirect=/`)
nextTick(() => {
resetState()
loginOutReq().then(()=>{
elMessage('退出登录成功')
router.push(`/login?redirect=/`)
nextTick(() => {
resetState()
})
})
}
</script>
Expand Down
2 changes: 2 additions & 0 deletions src/layout/app-main/TagsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ const { visible, top, left, selectedTag } = toRefs(state)
.tags-view-container {
height: var(--tag-view-height);
width: 100%;
position: relative;
z-index: 10;
background: var(--tags-view-background);
border-bottom: 1px solid var(--tags-view-border-bottom);
box-shadow: var(--tags-view-box-shadow);
Expand Down
21 changes: 10 additions & 11 deletions src/layout/sidebar/MenuIcon.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<template>
<!-- 如果有 elSvgIcon 显示 elSvgIcon 没有显示 icon-->
<el-icon v-if="meta?.elSvgIcon" class="el-svg-icon">
<component :is="ElSvg[meta.elSvgIcon]" />
<el-icon v-if="meta?.elSvgIcon" >
<component :is="meta.elSvgIcon" />
</el-icon>
<svg-icon v-else-if="meta?.icon" :icon-class="meta?.icon" class="nav-icon" />
<div v-else-if="meta?.icon" class="menu-svg-class"><svg-icon :icon-class="meta?.icon" /></div>
</template>

<script setup lang="ts">
import * as ElSvg from '@element-plus/icons-vue'
// import * as ElSvg from '@element-plus/icons-vue'
defineProps({
meta: { type: Object, default: null }
})
</script>

<style scoped lang="scss">
.el-svg-icon {
width: 1em;
height: 1em;
position: relative;
right: 3px;
font-size: var(--sidebar-el-icon-size);
text-align: left !important;
.menu-svg-class {
vertical-align: middle;
margin-left: 1px;
width: 29px;
padding-left: 5px;
text-align: left;
}
</style>
10 changes: 10 additions & 0 deletions src/lib/el-svg-icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as components from '@element-plus/icons-vue'

export default {
install: (app) => {
for (const key in components) {
const componentConfig = components[key];
app.component(componentConfig.name, componentConfig);
}
},
};
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import './permission'
import 'element-plus/dist/index.css'
const app = createApp(App)

//import element-plus svg icon
import ElSvgIcon from "@/lib/el-svg-icon"
app.use(ElSvgIcon)


//router
app.use(router)

Expand Down
24 changes: 3 additions & 21 deletions src/permission.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import router from '@/router'
import { filterAsyncRouter, progressClose, progressStart } from '@/hooks/use-permission'
import {progressClose, progressStart } from '@/hooks/use-permission'
import { useBasicStore } from '@/store/basic'
import { userInfoReq } from '@/api/user'
import { langTitle } from '@/hooks/use-common'
import settings from "@/settings";

Expand All @@ -22,25 +21,8 @@ router.beforeEach(async (to) => {
if (to.path === '/login') {
return '/'
} else {
//2.判断是否获取用户信息
if (!basicStore.getUserInfo) {
try {
const userData = await userInfoReq()
//3.动态路由权限筛选
filterAsyncRouter(userData)
//4.保存用户信息到store
basicStore.setUserInfo(userData)
//5.再次执行路由跳转
return { ...to, replace: true }
} catch (e) {
console.error(`route permission error${e}`)
basicStore.resetState()
progressClose()
return `/login?redirect=${to.path}`
}
} else {
return true
}
basicStore.setFilterAsyncRoutes([])
return true
}
} else {
if (!whiteList.includes(to.path)) {
Expand Down
Loading

0 comments on commit 644acde

Please sign in to comment.