Commit f5b76818 authored by shuiluo's avatar shuiluo

feat: 优化代码

parent 0a73a4bb
<template> <template>
<my-table url="/api/v1/roles" rowKey="roleId" :addBtn="addBtn" ref="table" noPage> <Table url="/api/v1/roles" rowKey="roleId" addBtn ref="table" noPage :buttons="buttons">
<template #drawer> <template #drawer="drawer">
<Form ref="form" /> <Form v-bind="drawer" />
</template> </template>
<a-table-column title="角色名称" data-index="roleName" /> <a-table-column title="角色名称" data-index="roleName" />
<a-table-column title="角色编码" data-index="roleCode" /> <a-table-column title="角色编码" data-index="roleCode" />
<a-table-column title="角色说明" data-index="remark" /> <a-table-column title="角色说明" data-index="remark" />
<a-table-column title="操作"> </Table>
<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>
<script> <script>
import Form from './form.vue'; import Form from './form.vue';
import PopconfirmDelete from '@/components/popconfirm_delete/index.vue'; import { Table } from '@/components/table';
export default { export default {
components: { Form, PopconfirmDelete }, components: { Form, Table },
data() { data() {
return { return {
addBtn: { onOk: () => this.$refs['form']?.submit() }, buttons: [
{
label: this.$t('table.edit'),
click: this.edit,
},
{ type: 'confirm', url: (row) => `/api/v1/roles/${row.roleId}`, after: this.refreshTable },
],
}; };
}, },
methods: { methods: {
refreshTable() { refreshTable() {
this.$refs['table']?.getData(); this.$refs['table']?.getData();
}, },
view(data, type) { edit(row) {
this.$refs['table']?.show({ type, noFooter: type === 2 }); this.$refs.table.show({ row, title: this.$t('table.edit'), type: 'edit' });
this.$nextTick(() => {
this.$refs['form'].setData({ ...data }, type);
});
}, },
}, },
}; };
......
<template> <template>
<a-form-model layout="vertical" :model="form" :rules="rules" ref="DrawerForm"> <Wraper :hidden="hidden" :refresh="refresh" :onOk="sumit">
<a-form-model-item label="角色名称"> <a-form-model layout="vertical" :model="form" :rules="rules" ref="DrawerForm">
<a-input v-model="form.roleName" :disabled="isView" /> <a-form-model-item label="角色名称">
</a-form-model-item> <a-input v-model="form.roleName" :disabled="isView" />
<a-form-model-item label="角色编码"> </a-form-model-item>
<a-input v-model="form.roleCode" :disabled="isView" /> <a-form-model-item label="角色编码">
</a-form-model-item> <a-input v-model="form.roleCode" :disabled="isView" />
<a-form-model-item label="角色说明" prop="remark"> </a-form-model-item>
<a-input v-model="form.remark" :disabled="isView" /> <a-form-model-item label="角色说明" prop="remark">
</a-form-model-item> <a-input v-model="form.remark" :disabled="isView" />
</a-form-model-item>
<a-form-model-item label="菜单权限"> <a-form-model-item label="菜单权限">
<MenuTree <MenuTree
v-model="checkedKeys" v-model="checkedKeys"
:defaultCheckedKeys="defaultCheckedKeys" :defaultCheckedKeys="defaultCheckedKeys"
showMenu showMenu
ref="menuTree" ref="menuTree"
:disabled="isView" :disabled="isView"
/> />
</a-form-model-item> </a-form-model-item>
</a-form-model> </a-form-model>
</Wraper>
</template> </template>
<script> <script>
import MenuTree from '@/components/menu_tree/index.vue'; import MenuTree from '@/components/menu_tree/index.vue';
import { addRoleApi, getRoleApi, updateRoleApi } from '@/api'; import { addRoleApi, getRoleApi, updateRoleApi } from '@/api';
import FormMixin from '@/components/FormMixin'; import FormMixin from '@/components/FormMixin';
import { WraperMixins } from '@/components/table';
export default { export default {
mixins: [FormMixin], mixins: [FormMixin, WraperMixins],
components: { MenuTree }, components: { MenuTree },
data() { data() {
return { return {
...@@ -38,11 +41,22 @@ export default { ...@@ -38,11 +41,22 @@ export default {
defaultCheckedKeys: [], defaultCheckedKeys: [],
}; };
}, },
computed: {
isEdit() {
return this.type === 'edit';
},
},
mounted() {
if (this.type) {
this.getData(this.row.rowId);
}
},
methods: { methods: {
submit() { submit() {
const query = { const query = {
...this.form, ...this.form,
authorityList: this.$refs['menuTree'].get().map(i => ({ authorityList: this.$refs['menuTree'].get().map((i) => ({
...i, ...i,
nodeId: i.menuId, nodeId: i.menuId,
parentNodeId: i.parentMenuId, parentNodeId: i.parentMenuId,
...@@ -51,14 +65,11 @@ export default { ...@@ -51,14 +65,11 @@ export default {
}; };
return this.isEdit ? updateRoleApi(query) : addRoleApi(query); return this.isEdit ? updateRoleApi(query) : addRoleApi(query);
}, },
setData(data, type) {
this.getData(data.roleId);
this.type = type;
},
async getData(id) { async getData(id) {
const res = await getRoleApi(id); const res = await getRoleApi(id);
this.form = res; this.form = res;
this.defaultCheckedKeys = res.menuComponentKeys.map(i => parseInt(i.split('-')[0])); this.defaultCheckedKeys = res.menuComponentKeys.map((i) => parseInt(i.split('-')[0]));
}, },
}, },
}; };
......
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