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 87660bd commit fc0b262
Show file tree
Hide file tree
Showing 40 changed files with 185 additions and 887 deletions.
3 changes: 0 additions & 3 deletions eslintrc/.eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
"isReadonly": true,
"isRef": true,
"langTitle": true,
"loginOutReq": true,
"loginReq": true,
"markRaw": true,
"nextTick": true,
"onActivated": true,
Expand Down Expand Up @@ -93,7 +91,6 @@
"useSlots": true,
"useTable": true,
"useTagsViewStore": true,
"userInfoReq": true,
"watch": true,
"watchEffect": true,
"watchPostEffect": true,
Expand Down
26 changes: 16 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<!DOCTYPE html>
<html lang="en" class="base-theme">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= title %></title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
<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 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.js"></script>
</body>
</html>
File renamed without changes.
25 changes: 25 additions & 0 deletions mock/system.js
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
]
31 changes: 31 additions & 0 deletions src/api/system.js
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.js

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
13 changes: 8 additions & 5 deletions src/layout/app-main/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</div>
</template>

<script setup lang="ts">
<script setup >
import { nextTick } from 'vue'
import { CaretBottom } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
Expand All @@ -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.js
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);
}
},
};
4 changes: 4 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ 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
26 changes: 4 additions & 22 deletions src/permission.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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'
import settings from "@/settings";

//路由进入前拦截
//to:将要进入的页面 vue-router4.0 不推荐使用next()
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 fc0b262

Please sign in to comment.