feat: ✨ 完善角色管理api
This commit is contained in:
parent
d3727202a3
commit
7e6e60c3fc
@ -1,11 +1,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { insertRule } from '@/api/system/role';
|
import { insertRule, updateRule } from '@/api/system/role';
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
formRoleValue: {
|
formRoleValue: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({}),
|
default: () => ({}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const emit = defineEmits(['reloadTable']);
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
const { formRoleValue } = toRefs(props);
|
const { formRoleValue } = toRefs(props);
|
||||||
const roleTitle = ref('新增角色');
|
const roleTitle = ref('新增角色');
|
||||||
@ -18,6 +19,7 @@ const rules = {
|
|||||||
trigger: 'blur',
|
trigger: 'blur',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const confirmForm = () => {
|
const confirmForm = () => {
|
||||||
formRef.value.validate(async (errors: any) => {
|
formRef.value.validate(async (errors: any) => {
|
||||||
@ -28,7 +30,19 @@ const confirmForm = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 修改
|
// 修改
|
||||||
const updateRuleApi = () => {};
|
const updateRuleApi = async () => {
|
||||||
|
const { roleName, description, status, id } = formRoleValue.value;
|
||||||
|
const params = {
|
||||||
|
id,
|
||||||
|
roleName,
|
||||||
|
description,
|
||||||
|
status,
|
||||||
|
};
|
||||||
|
const res = await updateRule(params);
|
||||||
|
if (res.status === 200) window['$message'].success('修改成功!');
|
||||||
|
close();
|
||||||
|
emit('reloadTable');
|
||||||
|
};
|
||||||
|
|
||||||
// 新增
|
// 新增
|
||||||
const insertRuleApi = async () => {
|
const insertRuleApi = async () => {
|
||||||
@ -40,16 +54,17 @@ const insertRuleApi = async () => {
|
|||||||
};
|
};
|
||||||
const res = await insertRule(params);
|
const res = await insertRule(params);
|
||||||
if (res.status === 200) window['$message'].success('新增成功!');
|
if (res.status === 200) window['$message'].success('新增成功!');
|
||||||
|
close();
|
||||||
|
emit('reloadTable');
|
||||||
};
|
};
|
||||||
|
|
||||||
const init = (str: string) => {
|
const init = (str: string) => {
|
||||||
if (str === 'add') {
|
str === 'add'
|
||||||
roleTitle.value = '新增角色';
|
? (roleTitle.value = '新增角色')
|
||||||
} else {
|
: (roleTitle.value = '编辑角色');
|
||||||
roleTitle.value = '编辑角色';
|
|
||||||
}
|
|
||||||
showRoleModal.value = true;
|
showRoleModal.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
showRoleModal.value = false;
|
showRoleModal.value = false;
|
||||||
};
|
};
|
||||||
@ -84,8 +99,8 @@ defineExpose({
|
|||||||
<n-form-item label="状态">
|
<n-form-item label="状态">
|
||||||
<n-radio-group v-model:value="formRoleValue.status" name="radiogroup1">
|
<n-radio-group v-model:value="formRoleValue.status" name="radiogroup1">
|
||||||
<n-space>
|
<n-space>
|
||||||
<n-radio :value="0"> 冻结 </n-radio>
|
<n-radio :value="false"> 冻结 </n-radio>
|
||||||
<n-radio :value="1"> 启用 </n-radio>
|
<n-radio :value="true"> 启用 </n-radio>
|
||||||
</n-space>
|
</n-space>
|
||||||
</n-radio-group>
|
</n-radio-group>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
|
|||||||
@ -27,7 +27,11 @@
|
|||||||
</n-card>
|
</n-card>
|
||||||
|
|
||||||
<!-- 添加角色 -->
|
<!-- 添加角色 -->
|
||||||
<RoleModal ref="formRole" :formRoleValue="formRoleValue" />
|
<RoleModal
|
||||||
|
ref="formRole"
|
||||||
|
:formRoleValue="formRoleValue"
|
||||||
|
@reload-table="reloadTable()"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- 菜单权限 -->
|
<!-- 菜单权限 -->
|
||||||
<n-modal
|
<n-modal
|
||||||
@ -39,7 +43,6 @@
|
|||||||
<div class="py-3 menu-list">
|
<div class="py-3 menu-list">
|
||||||
<n-tree
|
<n-tree
|
||||||
block-line
|
block-line
|
||||||
cascade
|
|
||||||
checkable
|
checkable
|
||||||
:virtual-scroll="true"
|
:virtual-scroll="true"
|
||||||
:data="treeData"
|
:data="treeData"
|
||||||
@ -82,9 +85,11 @@ import { BasicTable, TableAction } from '@/components/Table';
|
|||||||
import { columns } from './columns';
|
import { columns } from './columns';
|
||||||
import { PlusOutlined } from '@vicons/antd';
|
import { PlusOutlined } from '@vicons/antd';
|
||||||
import { getTreeAll } from '@/utils';
|
import { getTreeAll } from '@/utils';
|
||||||
import { getRuleList } from '@/api/system/role';
|
import { getRuleList, deleteRule } from '@/api/system/role';
|
||||||
import { getMenuTreeAll } from '@/api/system/menu';
|
import { getMenuTreeAll } from '@/api/system/menu';
|
||||||
import { queryMenuByRole, saveRoleMenu } from '@/api/system/roleMenu';
|
import { queryMenuByRole, saveRoleMenu } from '@/api/system/roleMenu';
|
||||||
|
import { zsDialog } from '@/utils';
|
||||||
|
import { DialogEnum } from '@/enums/pluginEnum';
|
||||||
|
|
||||||
const actionRef = ref();
|
const actionRef = ref();
|
||||||
const formRole = ref();
|
const formRole = ref();
|
||||||
@ -92,7 +97,7 @@ const formRoleValue = reactive({
|
|||||||
id: null,
|
id: null,
|
||||||
roleName: '',
|
roleName: '',
|
||||||
roleCode: null,
|
roleCode: null,
|
||||||
status: 1,
|
status: true,
|
||||||
description: '',
|
description: '',
|
||||||
});
|
});
|
||||||
const lastMenuIds = ref([]);
|
const lastMenuIds = ref([]);
|
||||||
@ -157,6 +162,13 @@ const mapTreeData = (data) => {
|
|||||||
// 新增按钮
|
// 新增按钮
|
||||||
const addRole = () => {
|
const addRole = () => {
|
||||||
formRole.value.init('add');
|
formRole.value.init('add');
|
||||||
|
Object.assign(formRoleValue, {
|
||||||
|
id: null,
|
||||||
|
roleName: '',
|
||||||
|
roleCode: null,
|
||||||
|
status: true,
|
||||||
|
description: '',
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadDataTable = async (res: any) => {
|
const loadDataTable = async (res: any) => {
|
||||||
@ -193,11 +205,21 @@ async function confirmForm(e: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleEdit(record: Recordable) {
|
function handleEdit(record: Recordable) {
|
||||||
console.log('点击了编辑', record);
|
Object.assign(formRoleValue, record);
|
||||||
|
formRole.value.init('edit');
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDelete(record: Recordable) {
|
async function handleDelete(record: Recordable) {
|
||||||
console.log('点击了删除', record);
|
zsDialog({
|
||||||
|
type: DialogEnum.ERROR,
|
||||||
|
message: `您确定要删除 ${record.roleName} 角色吗?`,
|
||||||
|
positiveButtonProps: { type: 'primary', ghost: false },
|
||||||
|
onPositiveCallback: async () => {
|
||||||
|
const data = await deleteRule({ id: record.id });
|
||||||
|
if (data.status === 200) reloadTable();
|
||||||
|
window['$message'].success('删除成功');
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleMenuAuth(record: Recordable) {
|
async function handleMenuAuth(record: Recordable) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user