|
@@ -5,32 +5,44 @@
|
|
<el-col :span="24" class="top">
|
|
<el-col :span="24" class="top">
|
|
<topInfo :topTitle="topTitle"></topInfo>
|
|
<topInfo :topTitle="topTitle"></topInfo>
|
|
</el-col>
|
|
</el-col>
|
|
- <el-col :span="24" class="search" style="text-align:right">
|
|
|
|
- <el-button size="mini" type="primary" @click="$router.push({ path: './detail' })" icon="el-icon-plus">分配权限</el-button>
|
|
|
|
- </el-col>
|
|
|
|
<el-col :span="24" class="main">
|
|
<el-col :span="24" class="main">
|
|
<!-- <mainData :tableData="tableData" :total="total" @delete="deleteData"></mainData> -->
|
|
<!-- <mainData :tableData="tableData" :total="total" @delete="deleteData"></mainData> -->
|
|
- <data-table :fields="fields" @delete="toDelete" :data="list" :opera="opera" @edit="toEdit" :total="total" @query="search"></data-table>
|
|
|
|
|
|
+ <data-table :fields="fields" @delete="toDelete" :data="list" :opera="opera" @edit="toEdit" :usePage="false"></data-table>
|
|
</el-col>
|
|
</el-col>
|
|
</el-col>
|
|
</el-col>
|
|
</el-row>
|
|
</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>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
import topInfo from '@/layout/public/top.vue';
|
|
import topInfo from '@/layout/public/top.vue';
|
|
|
|
+import dataForm from '@/components/form.vue';
|
|
import dataTable from '@/components/data-table.vue';
|
|
import dataTable from '@/components/data-table.vue';
|
|
import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
|
|
import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
|
|
-const { mapActions: users } = createNamespacedHelpers('users');
|
|
|
|
|
|
+const { mapActions: authUser } = createNamespacedHelpers('authUser');
|
|
|
|
+const { mapActions: role } = createNamespacedHelpers('role');
|
|
export default {
|
|
export default {
|
|
name: 'index',
|
|
name: 'index',
|
|
props: {},
|
|
props: {},
|
|
components: {
|
|
components: {
|
|
topInfo, //头部标题
|
|
topInfo, //头部标题
|
|
dataTable,
|
|
dataTable,
|
|
|
|
+ dataForm,
|
|
},
|
|
},
|
|
data: () => ({
|
|
data: () => ({
|
|
topTitle: '权限管理',
|
|
topTitle: '权限管理',
|
|
|
|
+ drawer: false,
|
|
|
|
+ form: {},
|
|
|
|
+ drawerIsNew: true,
|
|
opera: [
|
|
opera: [
|
|
{
|
|
{
|
|
label: '编辑',
|
|
label: '编辑',
|
|
@@ -45,30 +57,67 @@ export default {
|
|
},
|
|
},
|
|
],
|
|
],
|
|
fields: [{ label: '用户名', prop: 'name' }],
|
|
fields: [{ label: '用户名', prop: 'name' }],
|
|
|
|
+ formFields: [
|
|
|
|
+ { label: '用户名', model: 'name', type: 'text' },
|
|
|
|
+ { label: '权限', model: 'menus', custom: true },
|
|
|
|
+ ],
|
|
list: [],
|
|
list: [],
|
|
|
|
+ menuList: [],
|
|
total: 0,
|
|
total: 0,
|
|
}),
|
|
}),
|
|
created() {
|
|
created() {
|
|
this.search();
|
|
this.search();
|
|
|
|
+ this.getOtherList();
|
|
},
|
|
},
|
|
computed: {},
|
|
computed: {},
|
|
methods: {
|
|
methods: {
|
|
- ...users(['query', 'delete', 'update']),
|
|
|
|
|
|
+ ...authUser(['fetch', 'query', 'update']),
|
|
|
|
+ ...role({ getRoleList: 'query' }),
|
|
async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
const res = await this.query({ skip, limit, ...info });
|
|
const res = await this.query({ skip, limit, ...info });
|
|
if (this.$checkRes(res)) {
|
|
if (this.$checkRes(res)) {
|
|
this.$set(this, `list`, res.data);
|
|
this.$set(this, `list`, res.data);
|
|
- console.log(res.data);
|
|
|
|
this.$set(this, `total`, res.total);
|
|
this.$set(this, `total`, res.total);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- toEdit({ data }) {
|
|
|
|
- this.$router.push({ path: './detail', query: { id: data.id } });
|
|
|
|
|
|
+ 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 }) {
|
|
async toDelete({ data }) {
|
|
const res = await this.delete(data.id);
|
|
const res = await this.delete(data.id);
|
|
if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
|
|
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);
|
|
|
|
+ },
|
|
},
|
|
},
|
|
};
|
|
};
|
|
</script>
|
|
</script>
|