feat:添加返回

This commit is contained in:
fangyunong 2025-07-19 23:03:46 +08:00
parent 103b376945
commit c77d8f4ec2
4 changed files with 58 additions and 14 deletions

1
auto-imports.d.ts vendored
View File

@ -21,6 +21,7 @@ declare global {
const deleteChildDict: typeof import('./src/api/dictApi')['deleteChildDict']
const deleteMenu: typeof import('./src/api/menu')['deleteMenu']
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 editParentMenu: typeof import('./src/api/menu')['editParentMenu']
const effectScope: typeof import('vue')['effectScope']

View File

@ -35,6 +35,7 @@ export interface RoleListReturn {
id: string;
name: string;
normalizedName: string;
ChineseName:string
}
export function getRoleList(): Promise<RoleListReturn[]> {
return http({
@ -48,24 +49,27 @@ interface EnableRoleQuery {
userId: string;
roleName: string;
}
export function enableRole(data: EnableRoleQuery) {
export function enableRole(params: EnableRoleQuery) {
return http({
url: "/api/v1/AdminRoleControllers/role",
url: "/api/v1/AdminRoleControllers/role/endow",
method: "POST",
data,
params,
});
}
// 添加新角色
interface NewRoleReq{
rolename:string
normalizedname:string
ChineseName:string
}
export function addNewRole(params:NewRoleReq){
return http({
url:'/api/v1/AdminRoleControllers/role',
method:'POST',
params
params:{
...params,
normalizedname:'suibiantiande'
}
})
}
@ -82,3 +86,14 @@ export function assignMenu(data:MenuRequest) {
data,
});
}
// 删除指定角色
export function deleteRole(id:string){
return http({
url:'/api/v1/AdminRoleControllers/role',
method:'DELETE',
params:{
id
}
})
}

View File

@ -12,9 +12,11 @@
<tbody>
<tr v-for="item in list" :key="item.id">
<td>{{ item.name }}</td>
<td>{{ item.normalizedName }}</td>
<td>{{ item.chineseName }}</td>
<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>
</tr>
<tr v-show="showNewTr">
@ -22,10 +24,10 @@
<n-input-group>
<n-input v-model:value="addRole.rolename" placeholder="请输入角色编码(英文)"
: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 />
<n-button :style="{ width: '20%' }" size="small" type="primary" @click="handleAddNewRole"
:disabled="loading">新增</n-button>
<n-button :style="{ width: '20%' }" size="small" type="primary"
@click="handleAddNewRole" :disabled="loading">新增</n-button>
</n-input-group>
</td>
</tr>
@ -43,7 +45,7 @@
<script setup lang='ts'>
import { getRoleList, addNewRole } from '@/api/roleApi';
import { useMessage } from 'naive-ui';
import { useDialog, useMessage } from 'naive-ui';
import type { RoleListReturn } from '@/api/roleApi';
const emit = defineEmits<{
(event: 'choose', row: RoleListReturn): void
@ -53,9 +55,10 @@ const loading = ref(false);
const showNewTr = ref(false);
const list = ref([]);
const message = useMessage();
const dialog = useDialog();
const addRole = ref({
rolename: '',
normalizedname: ''
ChineseName: ''
});
const chooseRole = (row: RoleListReturn) => {
emit('choose', toRaw(row));
@ -66,10 +69,13 @@ const openDialog = () => {
}
const init = async () => {
try {
loading.value = true;
const result = await getRoleList();
list.value = result;
} catch (error) {
message.error(error instanceof Error ? error.message : error);
} finally {
loading.value = false;
}
};
init();
@ -79,7 +85,7 @@ const handleAddNewRole = async () => {
await addNewRole(addRole.value);
message.success('新增角色成功!');
addRole.value.rolename = void 0;
addRole.value.normalizedname = void 0;
addRole.value.ChineseName = void 0;
init();
showNewTr.value = false;
} catch (error) {
@ -88,6 +94,27 @@ const handleAddNewRole = async () => {
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({
openDialog
})

View File

@ -282,6 +282,7 @@ const handleEnableRole = async () => {
await enableRole(query);
init();
message.success('授权成功!');
addRoleDialog.value = false;
} catch (error) {
message.error(error.message);
}
@ -311,7 +312,7 @@ const initRoleList = async () => {
const result = await getRoleList();
options.value = result.map(item => {
return {
label: item.normalizedName,
label: item.ChineseName,
value: item.name
}
});