Skip to content

Commit fdff786

Browse files
committed
疑难杂症解决
1 parent 4de4370 commit fdff786

File tree

23 files changed

+280
-86
lines changed

23 files changed

+280
-86
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Description: 请输入....
33
* @Author: Gavin
44
* @Date: 2021-05-01 00:48:47
5-
* @LastEditTime: 2021-11-18 14:28:21
5+
* @LastEditTime: 2021-11-19 18:46:28
66
* @LastEditors: Gavin
77
-->
88

@@ -24,9 +24,14 @@ Artemis Admin英文不太好先写中文了。本项目基于vue3.2+ts+antd-vue+
2424
- 单点登录功能
2525
- 动态路由加载
2626
- 主题色替换
27+
- 个人主页已经权限配置
2728

2829

2930

31+
## 疑难杂症日记
32+
* 热更新白页内存移除=>store配置初始化
33+
* 热更新还是无法使用内容白页=>keep-alive和router-view 需要加key保证他的唯一性
34+
3035
## Project setup
3136

3237
```

mock/Dao/User.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Interface } from "readline"
44
* @Description: User Tao声明
55
* @Author: Gavin
66
* @Date: 2021-08-04 16:55:59
7-
* @LastEditTime: 2021-10-26 16:53:50
7+
* @LastEditTime: 2021-11-19 15:27:08
88
* @LastEditors: Gavin
99
*/
1010
export interface UserInfo {
@@ -16,12 +16,13 @@ export interface UserInfo {
1616
avatar?: string
1717
gender?: string
1818
token?: string,
19+
catchPhrase?:string,
1920
roles?: Array<string>,
20-
content?: string,
21-
unlike?: number | string,
22-
like?: number | string,
23-
action?:number,
24-
action1?:number,
21+
// content?: string,
22+
// unlike?: number | string,
23+
// like?: number | string,
24+
// action?:number,
25+
// action1?:number,
2526
setName?(name: string | number)
2627
}
2728
// const userData:userInfo={
@@ -40,10 +41,11 @@ class User implements UserInfo {
4041
roles
4142
content
4243
level
44+
catchPhrase
4345
setName(name: string | number) {
4446
this.name = name
4547
}
46-
constructor({ age, jobType, avatar, name, token, roles, content,level }: UserInfo) {
48+
constructor({ age, jobType, avatar, name, token, roles, content,level,catchPhrase }: UserInfo) {
4749
this.age = age
4850
this.jobType = jobType
4951
this.level=level
@@ -52,23 +54,30 @@ class User implements UserInfo {
5254
this.setName(name)
5355
this.roles = roles
5456
this.content = content
57+
this.catchPhrase=catchPhrase
5558
}
5659
}
5760
export default User
5861

62+
interface Comment extends UserInfo {
63+
content?: string,
64+
unlike?: number | string,
65+
like?: number | string,
66+
action?:number,
67+
action1?:number,
68+
}
5969

60-
61-
export class CommentItem extends User {
70+
export class CommentItem extends User implements Comment {
6271
like
6372
unlike
6473
content
6574
action
6675
action1
67-
constructor(obj: UserInfo) {
76+
constructor({like,unlike,content,...obj}:Comment) {
6877
super(obj)
69-
this.unlike = obj.like
70-
this.like = obj.unlike
71-
this.content=obj.content
78+
this.unlike = like
79+
this.like = unlike
80+
this.content=content
7281
this.action=0
7382
this.action1=0
7483
}

mock/user.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Description: 请输入....
33
* @Author: Gavin
44
* @Date: 2021-08-04 11:34:38
5-
* @LastEditTime: 2021-10-26 16:50:38
5+
* @LastEditTime: 2021-11-19 15:41:05
66
* @LastEditors: Gavin
77
*/
88
import { MockMethod } from 'vite-plugin-mock'
@@ -27,12 +27,13 @@ export const userInfo: AccountList = {
2727
token: faker.datatype.uuid(),
2828
getUserInfo() {
2929
return new User({
30-
name: faker.name.findName(),
30+
name: faker.name.lastName() + faker.name.firstName(),
3131
age: faker.random.number(),
3232
jobType: faker.name.jobType(),
3333
avatar: faker.image.avatar(),
3434
level: "admin",
35-
roles: ['admin']
35+
roles: ['admin'],
36+
catchPhrase: faker.company.catchPhrase()
3637

3738
})
3839

@@ -43,14 +44,15 @@ export const userInfo: AccountList = {
4344
token: faker.datatype.uuid(),
4445
getUserInfo() {
4546
return new User({
46-
name: faker.name.findName(),
47+
name: faker.name.lastName() + faker.name.firstName(),
4748
age: faker.random.number(),
4849
jobType: faker.name.jobType(),
4950
avatar: faker.image.avatar(),
5051
level: "user",
5152
roles: ['user', "/account"
5253
, "/account/center"
53-
, "/account/settings"]
54+
, "/account/settings"],
55+
catchPhrase: faker.company.catchPhrase()
5456

5557
})
5658

src/components/transition/router-transition.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<script lang="ts">
2121
import { defineComponent, computed } from 'vue'
22-
import { useStore } from '@/store'
22+
import { useStore } from 'vuex'
2323

2424
export default defineComponent({
2525
name: 'RouterTransition',

src/hooks/router/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Description: 请输入....
33
* @Author: Gavin
44
* @Date: 2021-08-06 10:00:31
5-
* @LastEditTime: 2021-10-27 11:03:02
5+
* @LastEditTime: 2021-11-19 17:40:12
66
* @LastEditors: Gavin
77
*/
88

@@ -95,7 +95,7 @@ export function filterAsyncRoutes(routes: Array<RouteRecordRaw>=asyncRoutes, rol
9595
tmp.children = filterAsyncRoutes(tmp.children, roles,key);
9696
}
9797
// 如果有权限当前路由加入数组
98-
console.error(tmp);
98+
// console.error(tmp);
9999

100100
res.push(tmp);
101101
}

src/layout/components/Navbar/Navbar.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</div>
6666
</template>
6767
<script lang='ts' setup>
68-
import { useStore } from '@/store'
68+
import { useStore } from 'vuex'
6969
import { useRoute } from 'vue-router'
7070
import {
7171
GithubOutlined,

src/layout/components/Navbar/components/TagsView.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Description: 标签层机翻勿6^Gavin^
33
* @Author: Gavin
44
* @Date: 2021-09-01 14:05:34
5-
* @LastEditTime: 2021-09-03 19:01:30
5+
* @LastEditTime: 2021-11-19 17:40:21
66
* @LastEditors: Gavin
77
-->
88
<template>
@@ -35,7 +35,7 @@
3535

3636
import { watch, watchEffect, onMounted, computed } from 'vue'
3737
import { useRoute, useRouter } from 'vue-router'
38-
import { useStore } from '@/store'
38+
import { useStore } from 'vuex'
3939
import { filterChildren as filterAffixTags } from "@/hooks/router"
4040

4141
import {
@@ -85,7 +85,7 @@ const closeOtherLabels = (tag) => {
8585

8686
}
8787
watch(() => visitedViews.value, () => {
88-
console.error(visitedViews.value, "watchEffect");
88+
// console.error(visitedViews.value, "watchEffect");
8989

9090
if (visitedViews.value.some(item => {
9191
return item.name === $route.name

src/layout/components/Settings/Settings.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Description: 配置选项
33
* @Author: Gavin
44
* @Date: 2021-09-08 17:29:16
5-
* @LastEditTime: 2021-11-18 14:11:13
5+
* @LastEditTime: 2021-11-19 17:40:25
66
* @LastEditors: Gavin
77
-->
88
<template>
@@ -45,7 +45,7 @@ import { useDark, useToggle } from '@vueuse/core'
4545
import { ref, reactive, watch } from 'vue'
4646
import type { UnwrapRef } from 'vue'
4747
import type { FormProp } from '@/components/Form/interface'
48-
import { useStore } from '@/store'
48+
import { useStore } from 'vuex'
4949
import { SettingFilled} from '@ant-design/icons-vue'
5050

5151
const visible = ref<boolean>(false)
@@ -57,7 +57,7 @@ const afterVisibleChange = (bool: boolean) => {
5757
const showDrawer = () => {
5858
visible.value = true
5959
}
60-
console.error($store.state.tagsView.isShow)
60+
// console.error($store.state.tagsView.isShow)
6161
interface FormState {
6262
tabViews: boolean
6363
color: string

src/layout/components/Sidebar/components/MenuList.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Description: 请输入....
33
* @Author: Gavin
44
* @Date: 2021-08-08 22:07:59
5-
* @LastEditTime: 2021-11-17 17:13:04
5+
* @LastEditTime: 2021-11-19 17:40:28
66
* @LastEditors: Gavin
77
-->
88

@@ -28,7 +28,7 @@ import { reactive, computed, watch, onMounted} from 'vue'
2828

2929

3030

31-
import { useStore } from '@/store'
31+
import { useStore } from 'vuex'
3232
import { useRouter, useRoute } from 'vue-router'
3333
import { filterAsyncRoutes as isHidden } from '@/hooks/router'
3434
import MenuItem from '../components/MenuItem.vue'
@@ -82,7 +82,7 @@ watch(
8282
() => $route.fullPath,
8383
() => {
8484
if ($route.name == 'Login' || props.collapsed) return
85-
console.error("OpenKey", getOpenKeys(), $route);
85+
// console.error("OpenKey", getOpenKeys(), $route);
8686
state.openKeys = getOpenKeys()
8787
state.selectedKeys = [$route.name]
8888
}

src/layout/components/TagsView/TagsView.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Description: 标签层机翻勿6^Gavin^
33
* @Author: Gavin
44
* @Date: 2021-09-01 14:05:34
5-
* @LastEditTime: 2021-10-22 15:32:41
5+
* @LastEditTime: 2021-11-19 17:40:32
66
* @LastEditors: Gavin
77
-->
88
<template>
@@ -37,7 +37,7 @@
3737

3838
import { watch, watchEffect, onMounted, computed, unref } from 'vue'
3939
import { useRoute, useRouter } from 'vue-router'
40-
import { useStore } from '@/store'
40+
import { useStore } from 'vuex'
4141
import { filterChildren as filterAffixTags, filterAsyncRoutes as filterHidden } from "@/hooks/router"
4242

4343
import {
@@ -90,7 +90,7 @@ const closeOtherLabels = (tag) => {
9090

9191
}
9292
watch(() => visitedViews.value, () => {
93-
console.error(visitedViews.value, "watchEffect");
93+
// console.error(visitedViews.value, "watchEffect");
9494

9595
if (visitedViews.value.some(item => {
9696
return item.name === $route.name

src/layout/index.vue

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Description: 主页框架布局
33
* @Author: Gavin
44
* @Date: 2021-07-31 17:06:32
5-
* @LastEditTime: 2021-11-04 14:07:43
5+
* @LastEditTime: 2021-11-19 18:34:13
66
* @LastEditors: Gavin
77
-->
88
<template>
@@ -50,9 +50,9 @@
5050
>
5151
<router-view v-slot="{ Component, route }">
5252
<transition name="fade" mode="out-in">
53-
<keep-alive>
54-
<component :is="Component" :key="route.full" />
55-
</keep-alive>
53+
<keep-alive :key="$route.full">
54+
<component :is="Component" :key="$route.full" />
55+
</keep-alive>
5656
</transition>
5757
</router-view>
5858
</section>
@@ -74,12 +74,12 @@ import {
7474
} from '@/layout/components/index'
7575
import { useRoute } from 'vue-router'
7676
import { ref, computed, provide, watch } from 'vue'
77-
import { useStore } from '@/store'
77+
import { useStore } from 'vuex'
7878
//hook
7979
import { getPointerLocationByElement } from '@/hooks/global/common/index'
8080
import { useStorage } from '@vueuse/core'
8181
const collapsed = ref<boolean>(false)
82-
// const $route = useRoute()
82+
const $route = useRoute()
8383
const $store = useStore()
8484
const pointerLocation = getPointerLocationByElement()
8585
const offsetWidth = document.body.offsetWidth
@@ -88,6 +88,8 @@ const op = computed(() => {
8888
return offsetWidth - pointerLocation.x > offsetWidth * 0.08 ? 0 : 1
8989
})
9090
const storage = useStorage<boolean>('storg', true, sessionStorage)
91+
92+
9193

9294
</script>
9395
<style lang="scss" scope>

src/router/permission.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Description: 路由守卫
33
* @Author: Gavin
44
* @Date: 2021-07-21 09:53:05
5-
* @LastEditTime: 2021-11-10 15:35:50
5+
* @LastEditTime: 2021-11-19 17:40:36
66
* @LastEditors: Gavin
77
*/
88
import { isNavigationFailure, Router, RouteRecordRaw, RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
@@ -90,7 +90,7 @@ export function createGuardHook(router: Router): void {
9090
router.afterEach((to: RouteLocationNormalized, from: RouteLocationNormalized) => {
9191
const htmlTitle = useTitle()
9292
htmlTitle.value = to.meta.title as string
93-
console.error("导航完成", to);
93+
// console.error("导航完成", to);
9494

9595
NProgress.done()
9696
})

src/store/getters.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
* @Description: 请输入....
33
* @Author: Gavin
44
* @Date: 2021-07-20 16:33:10
5-
* @LastEditTime: 2021-09-17 18:42:56
5+
* @LastEditTime: 2021-11-19 15:59:46
66
* @LastEditors: Gavin
77
*/
88

99

10+
1011
const getters = {
1112
sidebar: (state:any)=> state.app.name,
1213
userInfo:(state:any)=> state.user,
1314
visitedViews:(state:any)=>state.tagsView.visitedViews,
1415
themeBackgroundColor:(state:any)=>state.theme.themeBackgroundColor,
1516
isNavShow:(state:any)=>state.tagsView.isShow,
16-
17-
1817
}
1918
export default getters

0 commit comments

Comments
 (0)