Commit 9df83c42 authored by 水落(YangLei)'s avatar 水落(YangLei)

feat: 完善角色管理

parent 8846a011
...@@ -11,3 +11,7 @@ export function getMenuDataApi() { ...@@ -11,3 +11,7 @@ export function getMenuDataApi() {
export function addMenuApi(data) { export function addMenuApi(data) {
return postReq('/api/v1/menus', data); return postReq('/api/v1/menus', data);
} }
export function addRoleApi(data) {
return postReq('/api/v1/roles', data);
}
<template>
<a-tree
:checkedKeys="value"
:selectable="false"
checkable
:replaceFields="replaceFields"
:tree-data="treeData"
style="max-height:400px"
class="tw-overflow-y-auto"
v-bind="$attrs"
v-on="$listeners"
/>
</template>
<script>
import { getMenuDataApi } from '@/api';
import { convertListToTree } from '@/utils';
export default {
model: {
prop: 'value',
event: 'check',
},
props: {
value: [Object, Array],
showMenu: Boolean,
},
data() {
return {
treeData: [],
replaceFields: {
title: 'menuName',
key: 'menuId',
},
};
},
async mounted() {
this.rawData = await getMenuDataApi();
this.treeData = convertListToTree(this.rawData, !this.showMenu);
},
methods: {
get() {
if (Array.isArray(this.value)) return this.rawData.filter(m => this.value.includes(m.menuId));
return [];
},
},
};
</script>
<template> <template>
<a-popconfirm title="确认是否删除" ok-text="确认" cancel-text="取消" @confirm="onOk" @cancel="onCancel"> <a-popconfirm title="确认是否删除" ok-text="确认" cancel-text="取消" @confirm="onOk">
<a>删除</a> <a>删除</a>
</a-popconfirm> </a-popconfirm>
</template> </template>
<script> <script>
import { EMPTY_FUN } from '@/utils'; import { EMPTY_FUN } from '@/utils';
import { delReq } from '@/utils';
export default { export default {
props: { props: {
onOk: Function, url: String,
onCancel: { cb: {
type: Function, type: Function,
default: EMPTY_FUN, default: EMPTY_FUN,
}, },
}, },
methods: {
async onOk() {
await delReq(this.url);
this.cb();
},
},
}; };
</script> </script>
...@@ -124,6 +124,7 @@ export default { ...@@ -124,6 +124,7 @@ export default {
this.submitLoading = true; this.submitLoading = true;
try { try {
await this.addBtn?.onOk(); await this.addBtn?.onOk();
this.getData();
} catch (error) { } catch (error) {
// todo // todo
} }
...@@ -133,9 +134,6 @@ export default { ...@@ -133,9 +134,6 @@ export default {
showAdd() { showAdd() {
this.addVisible = true; this.addVisible = true;
}, },
refresh() {
this.getData();
},
}, },
}; };
</script> </script>
......
...@@ -7,12 +7,6 @@ ...@@ -7,12 +7,6 @@
noPage noPage
ref="table" ref="table"
> >
<template #search="{query}">
<a-form-model-item label="菜单、目录名称">
<a-input v-model="query.name" />
</a-form-model-item>
</template>
<template #add> <template #add>
<Form ref="addForm" /> <Form ref="addForm" />
</template> </template>
...@@ -44,9 +38,8 @@ export default { ...@@ -44,9 +38,8 @@ export default {
text: '新建', text: '新建',
title: '菜单配置', title: '菜单配置',
width: 400, width: 400,
async onOk() { onOk() {
await vm.$refs['addForm']?.submit(); return vm.$refs['addForm']?.submit();
vm.refreshTable();
}, },
}, },
sortOrder: 'ascend', sortOrder: 'ascend',
...@@ -57,7 +50,7 @@ export default { ...@@ -57,7 +50,7 @@ export default {
methods: { methods: {
formatData: convertListToTree, formatData: convertListToTree,
refreshTable() { refreshTable() {
this.$refs['table'].refresh(); this.$refs['table'].getData();
}, },
async delMenu(id) { async delMenu(id) {
await delMenuApi(id); await delMenuApi(id);
......
<template> <template>
<a-form-model layout="vertical" :model="form" :rules="rules"> <a-form-model layout="vertical" :model="form" :rules="rules">
<a-form-model-item label="父级" v-if="isAdd"> <a-form-model-item label="父级" v-if="isAdd">
<a-tree <MenuTree @check="onCheck" :value="checkedKeys" checkStrictly />
v-model="checkedKeys"
:selectable="false"
checkable
checkStrictly
:replaceFields="replaceFields"
:tree-data="treeData"
@check="onCheck"
style="max-height:400px"
class="tw-overflow-y-auto"
/>
</a-form-model-item> </a-form-model-item>
<a-form-model-item label="类型"> <a-form-model-item label="类型">
<a-radio-group v-model="form.menuType" :disabled="isEdit"> <a-radio-group v-model="form.menuType" :disabled="isEdit">
...@@ -41,10 +31,11 @@ ...@@ -41,10 +31,11 @@
</template> </template>
<script> <script>
import { getMenuDataApi, addMenuApi } from '@/api'; import { addMenuApi } from '@/api';
import { convertListToTree } from '@/utils'; import MenuTree from '@/components/menu_tree/index.vue';
export default { export default {
components: { MenuTree },
data: () => ({ data: () => ({
type: 0, type: 0,
form: { form: {
...@@ -55,19 +46,11 @@ export default { ...@@ -55,19 +46,11 @@ export default {
rules: { rules: {
menuUrl: [{ required: true }], menuUrl: [{ required: true }],
}, },
replaceFields: {
title: 'menuName',
key: 'menuId',
},
checkedKeys: { checkedKeys: {
checked: [], checked: [],
halfChecked: [], halfChecked: [],
}, },
treeData: [],
}), }),
mounted() {
this.getMenuData();
},
computed: { computed: {
isAdd() { isAdd() {
return this.type === 0; return this.type === 0;
...@@ -77,15 +60,12 @@ export default { ...@@ -77,15 +60,12 @@ export default {
}, },
}, },
methods: { methods: {
async getMenuData() {
this.treeData = convertListToTree(await getMenuDataApi(), true);
console.log(this.treeData);
},
submit() { submit() {
return addMenuApi({ ...this.form, parentMenuId: this.checkedKeys.checked[0] ?? 0 }); return addMenuApi({ ...this.form, parentMenuId: this.checkedKeys.checked[0] ?? 0 });
}, },
onCheck(checkedKeys) { onCheck(checkedKeys) {
this.checkedKeys.checked = checkedKeys.checked.slice(-1); const checked = checkedKeys.checked.slice(-1);
this.checkedKeys = { checked };
}, },
setEdit(data) { setEdit(data) {
this.type = 1; this.type = 1;
......
<template> <template>
<h1>Menu Management</h1> <my-table url="/api/v1/roles" rowKey="roleId" :addBtn="addBtn" ref="table">
<template #add>
<Form ref="form" />
</template>
<a-table-column title="名称" data-index="roleName" />
<a-table-column title="说明" data-index="remark" />
<a-table-column title="操作">
<template #default="row">
<a @click="() => view(row, 2)">查看</a>
<a-divider type="vertical" />
<a @click="() => view(row, 1)">编辑</a>
<a-divider type="vertical" />
<PopconfirmDelete :url="`/api/v1/roles/${row.roleId}`" :cb="refreshTable" />
</template>
</a-table-column>
</my-table>
</template> </template>
\ No newline at end of file <script>
import Form from './form.vue';
import PopconfirmDelete from '@/components/popconfirm_delete/index.vue';
export default {
components: { Form, PopconfirmDelete },
data() {
return {
addBtn: { width: 400, onOk: () => this.$refs['form']?.submit() },
};
},
methods: {
refreshTable() {
this.$refs['table']?.getData();
},
view(data, type) {
this.$refs['table']?.showAdd();
this.$nextTick(() => {
this.$refs['form'].setData(data, type);
});
},
},
};
</script>
<template>
<a-form-model layout="vertical" :model="form" :rules="rules">
<a-form-model-item label="角色名称">
<a-input v-model="form.roleName" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="角色编码">
<a-input v-model="form.roleCode" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="角色说明" prop="remark">
<a-input v-model="form.remark" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="菜单权限">
<MenuTree v-model="checkedKeys" showMenu ref="menuTree" :disabled="isView" />
</a-form-model-item>
</a-form-model>
</template>
<script>
import MenuTree from '@/components/menu_tree/index.vue';
import { addRoleApi } from '@/api';
export default {
components: { MenuTree },
data() {
return {
type: 0,
form: {},
rules: {},
checkedKeys: [],
};
},
computed: {
isEdit() {
return this.type === 1;
},
isView() {
return this.type === 2;
},
},
methods: {
submit() {
return addRoleApi({ ...this.form, authorityList: this.$refs['menuTree'].get() });
},
setData(data, type) {
this.form = data;
this.type = type;
},
},
};
</script>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment