|
@@ -0,0 +1,150 @@
|
|
|
+<template>
|
|
|
+ <div id="index">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" class="index">
|
|
|
+ <el-col :span="24" class="top">
|
|
|
+ <topInfo :topTitle="pageTitle"></topInfo>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="main">
|
|
|
+ <data-table
|
|
|
+ :fields="fields"
|
|
|
+ @delete="toDelete"
|
|
|
+ :data="list"
|
|
|
+ :opera="opera"
|
|
|
+ @edit="toEdit"
|
|
|
+ :total="total"
|
|
|
+ @query="search"
|
|
|
+ :usePage="true"
|
|
|
+ ></data-table>
|
|
|
+ </el-col>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-drawer title="权限分配" :visible.sync="drawer" direction="rtl" @closed="handleClose" :destroy-on-close="false">
|
|
|
+ <data-form :fields="formFields" :data="form" :rules="{}" @save="drawerSave" :isNew="drawerIsNew">
|
|
|
+ <template #custom="{item, form}">
|
|
|
+ <el-checkbox-group v-model="form.menus">
|
|
|
+ <el-checkbox v-for="(i, index) in menuList" :key="index" :label="i._id">{{ i.role_name }}</el-checkbox>
|
|
|
+ </el-checkbox-group>
|
|
|
+ </template>
|
|
|
+ </data-form>
|
|
|
+ </el-drawer>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import topInfo from '@/layout/public/top.vue';
|
|
|
+import dataForm from '@/components/form.vue';
|
|
|
+import dataTable from '@/components/data-table.vue';
|
|
|
+import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: authUser } = createNamespacedHelpers('authUser');
|
|
|
+const { mapActions: role } = createNamespacedHelpers('role');
|
|
|
+export default {
|
|
|
+ name: 'index',
|
|
|
+ props: {},
|
|
|
+ components: {
|
|
|
+ topInfo, //头部标题
|
|
|
+ dataTable,
|
|
|
+ dataForm,
|
|
|
+ },
|
|
|
+ data: function() {
|
|
|
+ return {
|
|
|
+ drawer: false,
|
|
|
+ form: {},
|
|
|
+ drawerIsNew: true,
|
|
|
+ opera: [
|
|
|
+ {
|
|
|
+ label: '编辑',
|
|
|
+ icon: 'el-icon-edit',
|
|
|
+ method: 'edit',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '删除',
|
|
|
+ icon: 'el-icon-delete',
|
|
|
+ method: 'delete',
|
|
|
+ confirm: true,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ fields: [
|
|
|
+ { label: '用户名', prop: 'name' },
|
|
|
+ { label: '机构名称', prop: 'deptname' },
|
|
|
+ ],
|
|
|
+ formFields: [
|
|
|
+ { label: '用户名', model: 'name', type: 'text' },
|
|
|
+ { label: '机构名称', model: 'deptname', type: 'text' },
|
|
|
+ { label: '权限', model: 'menus', custom: true },
|
|
|
+ ],
|
|
|
+ list: [],
|
|
|
+ menuList: [],
|
|
|
+ total: 0,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.search();
|
|
|
+ this.getOtherList();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...authUser(['fetch', 'query', 'update']),
|
|
|
+ ...role({ getRoleList: 'query' }),
|
|
|
+ async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
|
+ const res = await this.query({ skip, limit, role: '4', pid: this.user.uid, ...info });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `list`, res.data);
|
|
|
+ this.$set(this, `total`, res.total);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async drawerSave({ data, isNew }) {
|
|
|
+ let res;
|
|
|
+ let msg;
|
|
|
+ let duplicate = JSON.parse(JSON.stringify(data));
|
|
|
+ if (isNew) {
|
|
|
+ res = await this.create(duplicate);
|
|
|
+ msg = '创建成功';
|
|
|
+ } else {
|
|
|
+ res = await this.update(duplicate);
|
|
|
+ msg = '修改成功';
|
|
|
+ }
|
|
|
+ if (this.$checkRes(res, msg, res.errmsg)) {
|
|
|
+ this.handleClose();
|
|
|
+ this.search();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async toEdit({ data }) {
|
|
|
+ const res = await this.fetch({ id: data.id });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ let menus = res.data.menus;
|
|
|
+ this.$set(this, 'form', { ...data, menus: menus.map(i => i.id) });
|
|
|
+ }
|
|
|
+ this.drawer = true;
|
|
|
+ this.drawerIsNew = false;
|
|
|
+ },
|
|
|
+ async toDelete({ data }) {
|
|
|
+ const res = await this.delete(data.id);
|
|
|
+ if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
|
|
|
+ },
|
|
|
+ handleClose() {
|
|
|
+ this.drawer = false;
|
|
|
+ this.form = { menus: [] };
|
|
|
+ this.drawerIsNew = true;
|
|
|
+ },
|
|
|
+ async getOtherList() {
|
|
|
+ const res = await this.getRoleList();
|
|
|
+ if (this.$checkRes(res)) this.$set(this, `menuList`, res.data.reverse());
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
+ pageTitle() {
|
|
|
+ return `${this.$route.meta.title}`;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+.main {
|
|
|
+ padding: 15px 20px;
|
|
|
+}
|
|
|
+</style>
|