|
@@ -0,0 +1,142 @@
|
|
|
|
+<template>
|
|
|
|
+ <div id="adminUser">
|
|
|
|
+ <el-row>
|
|
|
|
+ <el-col :span="24" class="add" style="text-align:right;padding: 10px 20px;">
|
|
|
|
+ <!-- <el-button size="mini" type="primary" @click="toAdd" icon="el-icon-plus">添加{{ theme }}</el-button> -->
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-col :span="24" class="main">
|
|
|
|
+ <data-table :fields="fields" @delete="toDelete" :data="list" :opera="opera" @edit="toEdit" :total="total" @query="search"></data-table>
|
|
|
|
+ </el-col>
|
|
|
|
+ <el-dialog :title="theme" width="60%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
|
|
|
|
+ <data-form :fields="formFields" :data="form" :rules="{}" @save="toSave" :isNew="dialogIsNew">
|
|
|
|
+ <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-dialog>
|
|
|
|
+ </el-row>
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import dataForm from '@/components/form.vue';
|
|
|
|
+import dataTable from '@/components/data-table.vue';
|
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
|
+const { mapActions: authUser } = createNamespacedHelpers('authUser');
|
|
|
|
+const { mapActions: role } = createNamespacedHelpers('role');
|
|
|
|
+const { mapActions: loginMenu } = createNamespacedHelpers('login');
|
|
|
|
+export default {
|
|
|
|
+ name: 'permission',
|
|
|
|
+ props: {},
|
|
|
|
+ components: { dataTable, dataForm },
|
|
|
|
+ data: function() {
|
|
|
|
+ return {
|
|
|
|
+ theme: '权限',
|
|
|
|
+ dialog: false,
|
|
|
|
+ form: {},
|
|
|
|
+ dialogIsNew: 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' }),
|
|
|
|
+ ...loginMenu(['toGetMenu']),
|
|
|
|
+ async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
|
|
+ const res = await this.query({ skip, limit, role: '1', pid: this.user.uid, ...info });
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.$set(this, `list`, res.data);
|
|
|
|
+ this.$set(this, `total`, res.total);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 添加
|
|
|
|
+ toAdd() {
|
|
|
|
+ this.dialog = true;
|
|
|
|
+ },
|
|
|
|
+ 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.dialog = true;
|
|
|
|
+ this.dialogIsNew = false;
|
|
|
|
+ },
|
|
|
|
+ async toSave({ isNew, data }) {
|
|
|
|
+ let res;
|
|
|
|
+ let msg;
|
|
|
|
+ data.type = 1;
|
|
|
|
+ if (isNew) {
|
|
|
|
+ res = await this.create(data);
|
|
|
|
+ msg = '创建成功';
|
|
|
|
+ } else {
|
|
|
|
+ res = await this.update(data);
|
|
|
|
+ msg = '修改成功';
|
|
|
|
+ }
|
|
|
|
+ if (this.$checkRes(res, msg, res.errmsg)) {
|
|
|
|
+ this.handleClose();
|
|
|
|
+ this.search();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ async toDelete({ data }) {
|
|
|
|
+ const res = await this.delete(data.id);
|
|
|
|
+ if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
|
|
|
|
+ },
|
|
|
|
+ handleClose() {
|
|
|
|
+ this.dialog = false;
|
|
|
|
+ this.form = { menus: [] };
|
|
|
|
+ this.dialogIsNew = true;
|
|
|
|
+ },
|
|
|
|
+ async getOtherList() {
|
|
|
|
+ if (this.user.role == '0') {
|
|
|
|
+ const res = await this.getRoleList({ id: this.user.uid });
|
|
|
|
+ if (this.$checkRes(res)) this.$set(this, `menuList`, res.data.reverse());
|
|
|
|
+ } else if (this.user.role == '1') {
|
|
|
|
+ const res = await this.toGetMenu({ id: this.user.uid });
|
|
|
|
+ if (this.$checkRes(res)) this.$set(this, `menuList`, res.data.menus.reverse());
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ computed: {
|
|
|
|
+ ...mapState(['user']),
|
|
|
|
+ pageTitle() {
|
|
|
|
+ return `${this.$route.meta.title}`;
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ metaInfo() {
|
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style lang="less" scoped></style>
|