Commit 30a50196 authored by 水落(YangLei)'s avatar 水落(YangLei)

feat: 角色权限相关问题修复

parent 11014c33
import { delReq, getReq, postReq } from '@/utils'; import { delReq, getReq, postReq, putReq } from '@/utils';
export function delMenuApi(id) { export function delMenuApi(id) {
return delReq(`/api/v1/menus/${id}`); return delReq(`/api/v1/menus/${id}`);
...@@ -15,3 +15,11 @@ export function addMenuApi(data) { ...@@ -15,3 +15,11 @@ export function addMenuApi(data) {
export function addRoleApi(data) { export function addRoleApi(data) {
return postReq('/api/v1/roles', data); return postReq('/api/v1/roles', data);
} }
export function getRoleApi(id) {
return getReq(`/api/v1/roles/${id}`);
}
export function updateRoleApi(data) {
return putReq('/api/v1/roles', data);
}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
:tree-data="treeData" :tree-data="treeData"
style="max-height:400px" style="max-height:400px"
class="tw-overflow-y-auto" class="tw-overflow-y-auto"
:expandedKeys.sync="expandedKeys"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="$listeners"
/> />
...@@ -24,6 +25,7 @@ export default { ...@@ -24,6 +25,7 @@ export default {
props: { props: {
value: [Object, Array], value: [Object, Array],
showMenu: Boolean, showMenu: Boolean,
defaultCheckedKeys: Array,
}, },
data() { data() {
return { return {
...@@ -32,11 +34,21 @@ export default { ...@@ -32,11 +34,21 @@ export default {
title: 'menuName', title: 'menuName',
key: 'menuId', key: 'menuId',
}, },
expandedKeys: [],
}; };
}, },
async mounted() { async mounted() {
this.rawData = await getMenuDataApi(); this.rawData = await getMenuDataApi();
this.treeData = convertListToTree(this.rawData, !this.showMenu); this.treeData = convertListToTree(this.rawData, !this.showMenu);
this.$emit('check', this.defaultCheckedKeys);
this.expandedKeys = this.defaultCheckedKeys;
},
watch: {
defaultCheckedKeys(val) {
this.$emit('check', val);
this.expandedKeys = val;
},
}, },
methods: { methods: {
......
...@@ -11,14 +11,20 @@ ...@@ -11,14 +11,20 @@
</a-form-model-item> </a-form-model-item>
<a-form-model-item label="菜单权限"> <a-form-model-item label="菜单权限">
<MenuTree v-model="checkedKeys" showMenu ref="menuTree" :disabled="isView" /> <MenuTree
v-model="checkedKeys"
:defaultCheckedKeys="defaultCheckedKeys"
showMenu
ref="menuTree"
:disabled="isView"
/>
</a-form-model-item> </a-form-model-item>
</a-form-model> </a-form-model>
</template> </template>
<script> <script>
import MenuTree from '@/components/menu_tree/index.vue'; import MenuTree from '@/components/menu_tree/index.vue';
import { addRoleApi } from '@/api'; import { addRoleApi, getRoleApi, updateRoleApi } from '@/api';
export default { export default {
components: { MenuTree }, components: { MenuTree },
...@@ -28,6 +34,7 @@ export default { ...@@ -28,6 +34,7 @@ export default {
form: {}, form: {},
rules: {}, rules: {},
checkedKeys: [], checkedKeys: [],
defaultCheckedKeys: [],
}; };
}, },
computed: { computed: {
...@@ -40,12 +47,19 @@ export default { ...@@ -40,12 +47,19 @@ export default {
}, },
methods: { methods: {
submit() { submit() {
return addRoleApi({ ...this.form, authorityList: this.$refs['menuTree'].get() }); const query = { ...this.form, authorityList: this.$refs['menuTree'].get() };
console.log(query);
return this.isEdit ? updateRoleApi(query) : addRoleApi(query);
}, },
setData(data, type) { setData(data, type) {
this.form = data; this.getData(data.roleId);
this.type = type; this.type = type;
}, },
async getData(id) {
const res = await getRoleApi(id);
this.form = res;
this.defaultCheckedKeys = res.menuComponentKeys.map(i => parseInt(i.split('-')[0]));
},
}, },
}; };
</script> </script>
...@@ -59,10 +59,6 @@ const routerMap = { ...@@ -59,10 +59,6 @@ const routerMap = {
name: '组织管理', name: '组织管理',
component: () => import('@/pages/system/view/organization'), component: () => import('@/pages/system/view/organization'),
}, },
user_management: {
name: '用户管理',
component: () => import('@/pages/system/view/user'),
},
role_management: { role_management: {
name: '角色管理', name: '角色管理',
component: () => import('@/pages/system/view/role'), component: () => import('@/pages/system/view/role'),
......
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