Skip to content

Commit 0e55b02

Browse files
committed
feat✨(用户管理+角色管理):
1 parent e26f37e commit 0e55b02

File tree

24 files changed

+469
-81
lines changed

24 files changed

+469
-81
lines changed

components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ declare module 'vue' {
3232
ASelect: typeof import('ant-design-vue/es')['Select']
3333
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
3434
ASubMenu: typeof import('ant-design-vue/es')['SubMenu']
35+
ASwitch: typeof import('ant-design-vue/es')['Switch']
3536
ATable: typeof import('ant-design-vue/es')['Table']
3637
ATabPane: typeof import('ant-design-vue/es')['TabPane']
3738
ATabs: typeof import('ant-design-vue/es')['Tabs']
3839
ATree: typeof import('ant-design-vue/es')['Tree']
40+
ATreeSelect: typeof import('ant-design-vue/es')['TreeSelect']
3941
Breadcrumb: typeof import('./src/components/Layout/header/modules/breadcrumb.vue')['default']
4042
Buoy: typeof import('./src/components/widget/Buoy.vue')['default']
4143
Content: typeof import('./src/components/Layout/content/index.vue')['default']

src/api/modules/api.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@ import http from '../request';
22
import { ApiListRespType } from '@/types/api';
33

44
// 新增APi
5-
export const createApi = (data: IProgressReq & { path: string }): Promise<IProgressResp<ApiListRespType>> => {
5+
export const createApi = (data: ApiListRespType): Promise<string> => {
66
return http.get('/v1/sys/api/createApi', data);
77
};
88

99
// 获取api列表
1010
export const getApiList = (data: IProgressReq & { path: string }): Promise<IProgressResp<ApiListRespType>> => {
1111
return http.get('/v1/sys/api/getApiList', data);
1212
};
13+
// 获取全部api列表
14+
export const getAllApiList = (): Promise<{ apiList: ApiListRespType[] }> => {
15+
return http.get('/v1/sys/api/getAllApiList');
16+
};
1317
// 删除
14-
export const deleteApi = (data: IProgressReq & { path: string }): Promise<IProgressResp<ApiListRespType>> => {
18+
export const deleteApi = (data: { ids: string[] }): Promise<string> => {
1519
return http.post('/v1/sys/api/deleteApi', data);
1620
};
21+
22+
// 批删除
23+
export const deleteApisByIds = (ids: string[]): Promise<string> => {
24+
return http.delete('/v1/sys/api/deleteApisByIds', { ids });
25+
};

src/api/modules/authority.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import http from '../request';
22
import { MenuRespType } from '@/types/layout';
33
import { AuthorityType, AuthorityMenuRespType } from '@/types/authority';
44
// 获取角色列表
5-
export const getAuthorityList = (): Promise<{ list: AuthorityType[] }> => {
6-
return http.get('/v1/sys/authority/getAuthorityList');
5+
export const getAuthorityList = (data: IProgressReq): Promise<{ list: AuthorityType[] }> => {
6+
return http.get('/v1/sys/authority/getAuthorityList', data);
77
};
88
// 角色绑定菜单
99
export const addAuthorityMenu = (data: AuthorityMenuRespType) => {

src/api/modules/userList.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import http from '../request';
2+
import { UserListType, EditUserInfoType } from '@/types/userList';
3+
4+
// 获取用户列表
5+
export const getUserList = (data: IProgressReq): Promise<IProgressResp<UserListType>> => {
6+
return http.get('/v1/sys/getUserList', data);
7+
};
8+
9+
// 修改用户信息
10+
export const editUserList = (data: EditUserInfoType) => {
11+
return http.put('/v1/sys/updateUserInfo', data);
12+
};

src/api/request.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface Http {
66
get<T>(url: string, params?: unknown): Promise<any>;
77
post<T>(url: string, params?: unknown): Promise<any>;
88
put<T>(url: string, params?: unknown): Promise<any>;
9+
delete<T>(url: string, params?: unknown): Promise<any>;
910
upload<T>(url: string, params: unknown): Promise<any>;
1011
download(url: string): void;
1112
}
@@ -56,6 +57,21 @@ const http: Http = {
5657
});
5758
});
5859
},
60+
delete(url, params) {
61+
return new Promise((resolve, reject) => {
62+
NProgress.start();
63+
axios
64+
.delete(url, { params })
65+
.then(res => {
66+
NProgress.done();
67+
resolve(res);
68+
})
69+
.catch(err => {
70+
NProgress.done();
71+
reject(err);
72+
});
73+
});
74+
},
5975
upload(url, file) {
6076
return new Promise((resolve, reject) => {
6177
NProgress.start();

src/components/sysTable/index.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useAttrs, watchEffect, reactive, onMounted } from 'vue';
1111
import { usePagination } from 'vue-request';
1212
interface Props {
1313
getList?: Function; //请求列表的方法
14+
asyncListCallback?: Function; //更新列表回调
1415
pageSize?: number; //每页显示条数
1516
}
1617
const props = withDefaults(defineProps<Props>(), {
@@ -56,8 +57,11 @@ const {
5657
});
5758
watchEffect(() => {
5859
const data = _data as any;
59-
if (data) {
60+
if (data.value) {
6061
emits('update:data', data.value?.list);
62+
if (props.asyncListCallback) {
63+
props.asyncListCallback();
64+
}
6165
}
6266
});
6367
const pagination = reactive({

src/hooks/baseSelectHooks.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ref, computed } from 'vue';
22
import { getIcon } from '@/utils/iconList';
3-
3+
import type { AuthorityType } from '@/types/authority';
4+
import { getAuthorityList } from '@/api/modules/authority';
45
export const useSelectHooks = () => {
56
// 是否选项
67
const selectYesNo = ref<SelectType[]>([
@@ -24,8 +25,21 @@ export const useSelectHooks = () => {
2425
};
2526
});
2627
});
28+
29+
// 角色列表【树形结构】
30+
const authorityListTree = ref<AuthorityType[]>([]);
31+
async function getAuthList() {
32+
const res = await getAuthorityList({
33+
pageNo: 1,
34+
pageSize: 99999,
35+
});
36+
authorityListTree.value = res.list;
37+
}
38+
2739
return {
2840
selectYesNo,
2941
selectIcon,
42+
authorityListTree,
43+
getAuthList,
3044
};
3145
};

src/store/modules/user.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { store } from '../index';
22
import { defineStore } from 'pinia';
33
import { getStorageToken, setStorageToken, removeStorageToken } from '@/utils/auth';
4+
import { checkThemebg, checkTextColor } from '@/utils/changeTheme';
45
import router from '@/router/index';
56
import { LoginRespType, LoginType } from '@/types/login';
67
import lodash from 'lodash';
@@ -10,8 +11,9 @@ const defaultUserInfo: LoginRespType = {
1011
userInfo: {
1112
userName: '',
1213
nickName: '',
13-
bgColor: '#001529',
14+
baseColor: '#001529',
1415
textColor: '#ffffff',
16+
activeColor: '',
1517
authority: {
1618
authorityId: 0,
1719
authorityName: '',
@@ -20,6 +22,7 @@ const defaultUserInfo: LoginRespType = {
2022
menus: [],
2123
defaultRouter: '',
2224
showMenuIds: '',
25+
children: [],
2326
},
2427
},
2528
};
@@ -54,6 +57,12 @@ export const useUserStore = defineStore({
5457
setUserInfo(info: LoginRespType) {
5558
setStorageToken(info.accessToken);
5659
this.loginResp = info;
60+
this.setColor();
61+
},
62+
setColor() {
63+
// 设置颜色
64+
checkThemebg(this.loginResp.userInfo.activeColor);
65+
checkTextColor(this.loginResp.userInfo.textColor);
5766
},
5867
},
5968
persist: true,

src/styles/mixin.scss

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@
4242

4343
/*渐变(方向,颜色1,颜色2,颜色3)*/
4444
// 使用 @include linear-gradient(right, green, red, blue);
45-
@mixin linear-gradient(
46-
$direction: bottom,
47-
$color1: transparent,
48-
$color2: #306eff,
49-
$color3: transparent
50-
) {
45+
@mixin linear-gradient($direction: bottom, $color1: transparent, $color2: #306eff, $color3: transparent) {
5146
//background: -webkit-linear-gradient($direction,$colorTop, $colorCenter, $colorBottom); /* Safari 5.1 - 6.0 */
5247
background: -o-linear-gradient($direction, $color1, $color2, $color3);
5348
/* Opera 11.1 - 12.0 */
@@ -58,12 +53,7 @@
5853
}
5954
/*渐变(角度,颜色1,颜色2,颜色3)*/
6055
// 使用 @include linear-gradient(90edg, green, red, blue);
61-
@mixin linear-gradient-edg(
62-
$edg: 0edg,
63-
$color1: transparent,
64-
$color2: #306eff,
65-
$color3: transparent
66-
) {
56+
@mixin linear-gradient-edg($edg: 0edg, $color1: transparent, $color2: #306eff, $color3: transparent) {
6757
//background: -webkit-linear-gradient($direction,$colorTop, $colorCenter, $colorBottom); /* Safari 5.1 - 6.0 */
6858
background: -o-linear-gradient($edg, $color1, $color2, $color3);
6959
/* Opera 11.1 - 12.0 */
@@ -74,14 +64,7 @@
7464
}
7565

7666
/* 定义滚动条样式 圆角和阴影不需要则传入null */
77-
@mixin scrollBar(
78-
$width: 10px,
79-
$height: 10px,
80-
$outColor: $bgColor,
81-
$innerColor: $bgGrey,
82-
$radius: 5px,
83-
$shadow: null
84-
) {
67+
@mixin scrollBar($width: 10px, $height: 10px, $outColor: $baseColor, $innerColor: $bgGrey, $radius: 5px, $shadow: null) {
8568
/*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
8669
&::-webkit-scrollbar {
8770
width: $width;

src/tailwind.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@
1717
.theme-nord {
1818
--color-primary: 94 129 172;
1919
}
20+
.ant-switch {
21+
background-color: #bfbfbf;
22+
}

src/types/login.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export interface LoginRespType {
1717
userInfo: {
1818
userName: string;
1919
nickName: string;
20-
bgColor: string;
20+
baseColor: string;
21+
activeColor: string;
2122
textColor: string;
2223
authority: AuthorityType;
2324
};
@@ -32,4 +33,5 @@ export interface AuthorityType {
3233
menus: string[];
3334
defaultRouter: string;
3435
showMenuIds: string;
36+
children: AuthorityType[];
3537
}

src/types/userList.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { AuthorityType } from './authority';
2+
3+
export interface UserListType {
4+
uuid: string;
5+
userName: string;
6+
nickName: string;
7+
sideMode: string;
8+
headerImg: string;
9+
baseColor: string;
10+
activeColor: string;
11+
authorityId: number;
12+
authority: AuthorityType;
13+
authorities: AuthorityType[];
14+
phone: string;
15+
email: string;
16+
enable: number;
17+
ID: number;
18+
// 编辑使用
19+
selectIds?: number[]; //用户角色
20+
}
21+
22+
// 修改用户信息
23+
export interface EditUserInfoType {
24+
ID: number;
25+
nickName?: string; // 用户昵称
26+
sideMode?: string; // 用户侧边主题
27+
headerImg?: string;
28+
phone?: string;
29+
email?: string;
30+
enable?: number; //用户是否被冻结 1正常 2冻结
31+
authorityIds?: number[];
32+
}
33+
34+
// 新增用户
35+
export interface AddUserInfoType {
36+
userName: string;
37+
passWord: string;
38+
nickName: string;
39+
authorityId: number;
40+
authorityIds: number[];
41+
}

src/utils/changeTheme.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// src/style.css
22

33
// 修改背景颜色
4-
function checkThemebg(color: string) {
4+
export function checkThemebg(color: string) {
55
document.documentElement.style.setProperty(`--themebg`, color);
66
}
77
// 修改背景颜色
8-
function checkTextColor(color: string) {
8+
export function checkTextColor(color: string) {
99
document.documentElement.style.setProperty(`--textColor`, color);
1010
}

src/views/superAdmin/api/api.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<a-button type="primary" @click="showAddApi('添加API', true)"
1212
><template #icon> <PlusOutlined /> </template>添加</a-button
1313
>
14-
<a-button class="ml-3" :disabled="selectedRowKeys.length <= 0"
14+
<a-button @click="removeByIds(selectedRowKeys)" class="ml-3" :disabled="selectedRowKeys.length <= 0"
1515
><template #icon> <DeleteOutlined /> </template>删除</a-button
1616
>
1717
<SysTable
@@ -33,7 +33,7 @@
3333
<a-button type="link" @click="showAddApi('编辑', false, record)"
3434
><template #icon> <EditOutlined /> </template>编辑</a-button
3535
>
36-
<a-button type="link"
36+
<a-button type="link" @click="removeByIds([record.ID])"
3737
><template #icon> <DeleteOutlined /> </template>删除</a-button
3838
>
3939
</div>
@@ -48,7 +48,7 @@
4848
import { ref, reactive } from 'vue';
4949
import SysTable from '@/components/sysTable/index.vue';
5050
import SysSearch from '@/components/sysSearch/index.vue';
51-
import { getApiList } from '@/api/modules/api';
51+
import { getApiList, deleteApisByIds } from '@/api/modules/api';
5252
import AddModal from './modules/addModal.vue';
5353
import { selectMethods } from './modules/data';
5454
import { ApiListRespType } from '@/types/api';
@@ -90,6 +90,12 @@ const selectedRowKeys = ref<string[]>([]);
9090
const onSelectChange = (_selectedRowKeys: string[]) => {
9191
selectedRowKeys.value = _selectedRowKeys;
9292
};
93+
94+
// 删除
95+
function removeByIds(ids: string[]) {
96+
deleteApisByIds(ids);
97+
getList();
98+
}
9399
</script>
94100

95101
<style scoped></style>

src/views/superAdmin/api/modules/addModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<SysModal width="800px" @ok="ok">
2+
<SysModal width="800px" @ok="ok" :formRef="formRef">
33
<div class="flex items-center w-full bg-[#fffae6] p-2">
44
<div class="bg-[#f08c0e] w-[12px] h-[12px] flex justify-center items-center rounded-full text-xs text-white mr-1">!</div>
55
<span class="text-[#f08c0e] text-xs"> 新增API,需要在角色管理内配置权限才可使用</span>

src/views/superAdmin/api/modules/data.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { Rule } from 'ant-design-vue/es/form';
2-
import { ApiType, ApiMethodEnum } from '@/types/api';
2+
import { ApiListRespType, ApiMethodEnum } from '@/types/api';
33
import { ref } from 'vue';
4-
export const defaultData: ApiType = {
4+
export const defaultData: ApiListRespType = {
55
path: '',
66
apiGroup: '',
77
method: 'GET',
88
description: '',
9+
ID: 0,
910
};
1011

1112
// 是否选项

src/views/superAdmin/authority/authority.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ const loading = ref(false);
9090
const expandedKeys = ref<number[]>([]); // 存储展开的节点的 key
9191
async function getList() {
9292
loading.value = true;
93-
const res = await getAuthorityList();
93+
const res = await getAuthorityList({
94+
pageNo: 1,
95+
pageSize: 99999,
96+
});
9497
loading.value = false;
9598
dataSource.value = res.list;
9699
removeChildren(dataSource.value);

src/views/superAdmin/authority/modules/addModal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<div class="pt-[20px]">
44
<a-form layout="horizontal" ref="formRef" @finishFailed="finishFailed" :rules="rules" :model="authData" name="basic" :labelCol="{ span: 3 }" :wrapper-col="{ span: 24 }">
55
<a-form-item name="parentId" label="父级角色" class="w-full">
6-
<a-select allowClear v-model:value="authData.parentId" placeholder="父级角色" :options="selectYesNo" />
6+
<a-select :disabled="attrs.title == '添加子角色'" allowClear v-model:value="authData.parentId" placeholder="父级角色" :options="selectYesNo" />
77
</a-form-item>
88
<a-form-item name="authorityId" label="角色ID" class="w-full">
9-
<a-input v-model:value="authData.authorityId" placeholder="角色ID" />
9+
<a-input :disabled="attrs.title == '编辑角色'" v-model:value="authData.authorityId" placeholder="角色ID" />
1010
</a-form-item>
1111
<a-form-item name="authorityName" label="角色姓名" class="w-full">
1212
<a-input v-model:value="authData.authorityName" placeholder="角色姓名" />

0 commit comments

Comments
 (0)