feat:添加返回
This commit is contained in:
parent
103b376945
commit
c77d8f4ec2
1
auto-imports.d.ts
vendored
1
auto-imports.d.ts
vendored
@ -21,6 +21,7 @@ declare global {
|
|||||||
const deleteChildDict: typeof import('./src/api/dictApi')['deleteChildDict']
|
const deleteChildDict: typeof import('./src/api/dictApi')['deleteChildDict']
|
||||||
const deleteMenu: typeof import('./src/api/menu')['deleteMenu']
|
const deleteMenu: typeof import('./src/api/menu')['deleteMenu']
|
||||||
const deleteParentDict: typeof import('./src/api/dictApi')['deleteParentDict']
|
const deleteParentDict: typeof import('./src/api/dictApi')['deleteParentDict']
|
||||||
|
const deleteRole: typeof import('./src/api/roleApi')['deleteRole']
|
||||||
const deleteUser: typeof import('./src/api/roleApi')['deleteUser']
|
const deleteUser: typeof import('./src/api/roleApi')['deleteUser']
|
||||||
const editParentMenu: typeof import('./src/api/menu')['editParentMenu']
|
const editParentMenu: typeof import('./src/api/menu')['editParentMenu']
|
||||||
const effectScope: typeof import('vue')['effectScope']
|
const effectScope: typeof import('vue')['effectScope']
|
||||||
|
@ -35,6 +35,7 @@ export interface RoleListReturn {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
normalizedName: string;
|
normalizedName: string;
|
||||||
|
ChineseName:string
|
||||||
}
|
}
|
||||||
export function getRoleList(): Promise<RoleListReturn[]> {
|
export function getRoleList(): Promise<RoleListReturn[]> {
|
||||||
return http({
|
return http({
|
||||||
@ -48,24 +49,27 @@ interface EnableRoleQuery {
|
|||||||
userId: string;
|
userId: string;
|
||||||
roleName: string;
|
roleName: string;
|
||||||
}
|
}
|
||||||
export function enableRole(data: EnableRoleQuery) {
|
export function enableRole(params: EnableRoleQuery) {
|
||||||
return http({
|
return http({
|
||||||
url: "/api/v1/AdminRoleControllers/role",
|
url: "/api/v1/AdminRoleControllers/role/endow",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data,
|
params,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加新角色
|
// 添加新角色
|
||||||
interface NewRoleReq{
|
interface NewRoleReq{
|
||||||
rolename:string
|
rolename:string
|
||||||
normalizedname:string
|
ChineseName:string
|
||||||
}
|
}
|
||||||
export function addNewRole(params:NewRoleReq){
|
export function addNewRole(params:NewRoleReq){
|
||||||
return http({
|
return http({
|
||||||
url:'/api/v1/AdminRoleControllers/role',
|
url:'/api/v1/AdminRoleControllers/role',
|
||||||
method:'POST',
|
method:'POST',
|
||||||
params
|
params:{
|
||||||
|
...params,
|
||||||
|
normalizedname:'suibiantiande'
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,3 +86,14 @@ export function assignMenu(data:MenuRequest) {
|
|||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除指定角色
|
||||||
|
export function deleteRole(id:string){
|
||||||
|
return http({
|
||||||
|
url:'/api/v1/AdminRoleControllers/role',
|
||||||
|
method:'DELETE',
|
||||||
|
params:{
|
||||||
|
id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
@ -12,9 +12,11 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="item in list" :key="item.id">
|
<tr v-for="item in list" :key="item.id">
|
||||||
<td>{{ item.name }}</td>
|
<td>{{ item.name }}</td>
|
||||||
<td>{{ item.normalizedName }}</td>
|
<td>{{ item.chineseName }}</td>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
<n-button type="primary" size="small" @click="chooseRole(item)">选择</n-button>
|
<n-button type="primary" size="small" @click="chooseRole(item)"
|
||||||
|
style="margin-right: 12px;">选择</n-button>
|
||||||
|
<n-button type="error" size="small" @click="handleDelteRole(item.id)">删除</n-button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-show="showNewTr">
|
<tr v-show="showNewTr">
|
||||||
@ -22,10 +24,10 @@
|
|||||||
<n-input-group>
|
<n-input-group>
|
||||||
<n-input v-model:value="addRole.rolename" placeholder="请输入角色编码(英文)"
|
<n-input v-model:value="addRole.rolename" placeholder="请输入角色编码(英文)"
|
||||||
:style="{ width: '40%' }" size="small" :disabled="loading" clearable />
|
:style="{ width: '40%' }" size="small" :disabled="loading" clearable />
|
||||||
<n-input v-model:value="addRole.normalizedname" placeholder="请输入角色中文"
|
<n-input v-model:value="addRole.ChineseName" placeholder="请输入角色中文"
|
||||||
:style="{ width: '40%' }" size="small" :disabled="loading" clearable />
|
:style="{ width: '40%' }" size="small" :disabled="loading" clearable />
|
||||||
<n-button :style="{ width: '20%' }" size="small" type="primary" @click="handleAddNewRole"
|
<n-button :style="{ width: '20%' }" size="small" type="primary"
|
||||||
:disabled="loading">新增</n-button>
|
@click="handleAddNewRole" :disabled="loading">新增</n-button>
|
||||||
</n-input-group>
|
</n-input-group>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -43,7 +45,7 @@
|
|||||||
|
|
||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
import { getRoleList, addNewRole } from '@/api/roleApi';
|
import { getRoleList, addNewRole } from '@/api/roleApi';
|
||||||
import { useMessage } from 'naive-ui';
|
import { useDialog, useMessage } from 'naive-ui';
|
||||||
import type { RoleListReturn } from '@/api/roleApi';
|
import type { RoleListReturn } from '@/api/roleApi';
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(event: 'choose', row: RoleListReturn): void
|
(event: 'choose', row: RoleListReturn): void
|
||||||
@ -53,9 +55,10 @@ const loading = ref(false);
|
|||||||
const showNewTr = ref(false);
|
const showNewTr = ref(false);
|
||||||
const list = ref([]);
|
const list = ref([]);
|
||||||
const message = useMessage();
|
const message = useMessage();
|
||||||
|
const dialog = useDialog();
|
||||||
const addRole = ref({
|
const addRole = ref({
|
||||||
rolename: '',
|
rolename: '',
|
||||||
normalizedname: ''
|
ChineseName: ''
|
||||||
});
|
});
|
||||||
const chooseRole = (row: RoleListReturn) => {
|
const chooseRole = (row: RoleListReturn) => {
|
||||||
emit('choose', toRaw(row));
|
emit('choose', toRaw(row));
|
||||||
@ -66,10 +69,13 @@ const openDialog = () => {
|
|||||||
}
|
}
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
try {
|
try {
|
||||||
|
loading.value = true;
|
||||||
const result = await getRoleList();
|
const result = await getRoleList();
|
||||||
list.value = result;
|
list.value = result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(error instanceof Error ? error.message : error);
|
message.error(error instanceof Error ? error.message : error);
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
init();
|
init();
|
||||||
@ -79,7 +85,7 @@ const handleAddNewRole = async () => {
|
|||||||
await addNewRole(addRole.value);
|
await addNewRole(addRole.value);
|
||||||
message.success('新增角色成功!');
|
message.success('新增角色成功!');
|
||||||
addRole.value.rolename = void 0;
|
addRole.value.rolename = void 0;
|
||||||
addRole.value.normalizedname = void 0;
|
addRole.value.ChineseName = void 0;
|
||||||
init();
|
init();
|
||||||
showNewTr.value = false;
|
showNewTr.value = false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -88,6 +94,27 @@ const handleAddNewRole = async () => {
|
|||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 删除用户角色
|
||||||
|
const handleDelteRole = (id: string) => {
|
||||||
|
dialog.warning({
|
||||||
|
title: '警告',
|
||||||
|
content: '你确定删除这个用户角色吗?',
|
||||||
|
positiveText: '确定',
|
||||||
|
negativeText: '不确定',
|
||||||
|
draggable: true,
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
await deleteRole(id);
|
||||||
|
message.success('操作成功!');
|
||||||
|
init();
|
||||||
|
} catch (error) {
|
||||||
|
message.error(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
defineExpose({
|
defineExpose({
|
||||||
openDialog
|
openDialog
|
||||||
})
|
})
|
||||||
|
@ -282,6 +282,7 @@ const handleEnableRole = async () => {
|
|||||||
await enableRole(query);
|
await enableRole(query);
|
||||||
init();
|
init();
|
||||||
message.success('授权成功!');
|
message.success('授权成功!');
|
||||||
|
addRoleDialog.value = false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(error.message);
|
message.error(error.message);
|
||||||
}
|
}
|
||||||
@ -311,7 +312,7 @@ const initRoleList = async () => {
|
|||||||
const result = await getRoleList();
|
const result = await getRoleList();
|
||||||
options.value = result.map(item => {
|
options.value = result.map(item => {
|
||||||
return {
|
return {
|
||||||
label: item.normalizedName,
|
label: item.ChineseName,
|
||||||
value: item.name
|
value: item.name
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user