Skip to content

Commit d6021c4

Browse files
author
sunshine824
committed
添加动态路由功能
1 parent 34858db commit d6021c4

File tree

18 files changed

+342
-39
lines changed

18 files changed

+342
-39
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=/api

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=/api

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dependencies": {
99
"ant-design-vue": "2.2.2",
1010
"axios": "^0.21.1",
11+
"codemirror": "^5.62.2",
1112
"crypto-js": "^4.0.0",
1213
"qs": "^6.10.1",
1314
"spark-md5": "^3.0.1",
@@ -27,6 +28,7 @@
2728
"eslint-plugin-vue": "^7.11.1",
2829
"less": "^4.1.1",
2930
"less-loader": "^10.0.0",
31+
"mockjs": "^1.1.0",
3032
"prettier": "^2.3.1",
3133
"typescript": "^4.3.2",
3234
"vite": "^2.3.7",

src/api/user.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import qs from 'qs'
44
// 用户登录
55
export const login = (params: any): any => service({
66
method: 'post',
7-
url: '/sys/login',
7+
url: '/login',
88
data: params,
9-
});
9+
});
10+
11+
// 用户登出
12+
export const logout = (params: any) => service({
13+
method: 'get',
14+
url: '/logout',
15+
data: params,
16+
});
17+
18+
// 获取权限列表
19+
export const getPermissionsList = (params: any) => service({
20+
method: 'get',
21+
url: '/navPerson',
22+
data: qs.stringify(params),
23+
});

src/components/GlobalHeader/Menus.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent, ref, watch, computed } from 'vue'
1+
import { defineComponent, onMounted, ref, watch, computed } from 'vue'
22
import { useRoute, useRouter, RouteRecordRaw } from 'vue-router'
33
import { Menu } from 'ant-design-vue'
44

@@ -30,6 +30,10 @@ const Menus = defineComponent({
3030
return getMenus().filter((item) => !item?.meta?.hidden)
3131
})
3232

33+
onMounted(() => {
34+
console.log(getMenus())
35+
})
36+
3337
// 获取路由列表
3438
const getMenus = () => {
3539
let menuList: RouteRecordRaw[] = []

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import router from './router'
44
import App from './App'
55
import { setupAntd } from './plugins/antd'
66

7+
import '@/mock';
8+
79
import './public/css/base.css'
810
import './public/css/init.less'
911
import '@/public/font/iconfont.css';
12+
import 'ant-design-vue/dist/antd.css';
1013

1114
const app = createApp(App)
1215

src/mock/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Mock from 'mockjs';
2+
import '@/mock/user/login';
3+
import '@/mock/user/permission';
4+
import '@/mock/user/logout';
5+
6+
// 设置全局延时
7+
Mock.setup({
8+
timeout: '300-600'
9+
});

src/mock/result.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export class Result {
2+
public code?: number;
3+
4+
public data?: any;
5+
6+
public status?: boolean;
7+
8+
public msg?: string
9+
10+
constructor(code = 200, data?: any, status = true, msg?: string) {
11+
this.code = code;
12+
this.data = data;
13+
this.status = status;
14+
this.msg = msg;
15+
}
16+
}

src/mock/user/login.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Mock from 'mockjs'
2+
import { uuid } from '@/utils/util'
3+
import { Result } from '../result';
4+
5+
const BaseUrl = import.meta.env.VITE_API_BASE_URL as string
6+
7+
const user = Mock.mock({
8+
username: 'admin',
9+
address: '成都市高新区天府四街'
10+
});
11+
12+
Mock.mock(`${BaseUrl}/login`, 'post', ({ body }: { body: string }) => {
13+
const result = new Result();
14+
const { username, password } = JSON.parse(body);
15+
16+
if (username !== 'admin' || password !== '666666') {
17+
result.status = false;
18+
result.msg = '账户名或密码错误(admin/666666)';
19+
} else {
20+
result.data = {
21+
userInfo: user,
22+
token: uuid()
23+
};
24+
}
25+
return result;
26+
});

src/mock/user/logout.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Mock from 'mockjs'
2+
import { Result } from '../result';
3+
4+
const BaseUrl = import.meta.env.VITE_API_BASE_URL as string
5+
6+
Mock.mock(`${BaseUrl}/logout`, 'get', () => {
7+
const result = new Result();
8+
result.msg = '退出成功!';
9+
return result;
10+
});

0 commit comments

Comments
 (0)