index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <breadcrumb :breadcrumbTitle="this.$route.meta.title"></breadcrumb>
  6. <el-col :span="24" class="container info">
  7. <el-col :span="24" class="list">
  8. <data-table :fields="fields" :opera="opera" :data="list" :total="total" @edit="toEdit" @query="search"></data-table>
  9. </el-col>
  10. </el-col>
  11. </el-col>
  12. </el-row>
  13. <el-dialog title="增加权限" :visible.sync="dialog" width="50%" @close="toClose" :destroy-on-close="true">
  14. <data-form :data="form" :fields="formFields" @save="turnSave">
  15. <template #custom="{item, form}">
  16. <el-checkbox-group v-model="form.menus">
  17. <el-checkbox v-for="(i, index) in menuList" :key="index" :label="i.id">{{ i.role_name }}</el-checkbox>
  18. </el-checkbox-group>
  19. </template>
  20. </data-form>
  21. </el-dialog>
  22. </div>
  23. </template>
  24. <script>
  25. import breadcrumb from '@c/common/breadcrumb.vue';
  26. import dataTable from '@/components/frame/filter-page-table.vue';
  27. import dataForm from '@/components/frame/form.vue';
  28. import { mapState, createNamespacedHelpers } from 'vuex';
  29. const { mapActions: authUser } = createNamespacedHelpers('authUser');
  30. const { mapActions: role } = createNamespacedHelpers('role');
  31. const { mapActions: loginMenu } = createNamespacedHelpers('login');
  32. export default {
  33. metaInfo() {
  34. return { title: this.$route.meta.title };
  35. },
  36. name: 'index',
  37. props: {},
  38. components: {
  39. breadcrumb,
  40. dataTable,
  41. dataForm,
  42. },
  43. data: function() {
  44. return {
  45. opera: [
  46. {
  47. label: '修改',
  48. method: 'edit',
  49. },
  50. ],
  51. fields: [
  52. { label: '用户名', prop: 'name' },
  53. { label: '机构名称', prop: 'deptname' },
  54. ],
  55. list: [],
  56. total: 0,
  57. dialog: false,
  58. formFields: [
  59. { label: '用户名', model: 'name', type: 'text' },
  60. { label: '机构名称', model: 'deptname', type: 'text' },
  61. { label: '权限', model: 'menus', custom: true },
  62. ],
  63. form: {},
  64. menuList: [],
  65. };
  66. },
  67. async created() {
  68. await this.getOtherList();
  69. await this.search();
  70. },
  71. methods: {
  72. ...authUser(['fetch', 'query', 'update']),
  73. ...role({ getRoleList: 'query' }),
  74. ...loginMenu(['toGetMenu']),
  75. // 查询列表
  76. async search({ skip = 0, limit = 10, ...info } = {}) {
  77. const res = await this.query({ skip, limit, pid: this.user.uid, ...info });
  78. if (this.$checkRes(res)) {
  79. this.$set(this, `list`, res.data);
  80. this.$set(this, `total`, res.total);
  81. }
  82. },
  83. // 修改
  84. async toEdit({ data }) {
  85. const res = await this.fetch({ id: data.id });
  86. if (this.$checkRes(res)) {
  87. let menus = res.data.menus;
  88. this.$set(this, 'form', { ...data, menus: menus.map(i => i.id) });
  89. }
  90. this.dialog = true;
  91. },
  92. // 保存
  93. async turnSave({ data }) {
  94. let res;
  95. let msg;
  96. if (data.id) {
  97. res = await this.update(data);
  98. msg = '修改成功';
  99. } else {
  100. res = await this.create(data);
  101. msg = '创建成功';
  102. }
  103. if (this.$checkRes(res, msg, res.errmsg)) {
  104. this.toClose();
  105. this.search();
  106. }
  107. },
  108. // 取消增加
  109. toClose() {
  110. this.form = {};
  111. this.dialog = false;
  112. },
  113. async getOtherList() {
  114. if (this.user.role == '0') {
  115. const res = await this.getRoleList({ id: this.user.uid });
  116. if (this.$checkRes(res)) this.$set(this, `menuList`, res.data.reverse());
  117. } else if (this.user.role == '1') {
  118. const res = await this.toGetMenu({ id: this.user.uid });
  119. if (this.$checkRes(res)) this.$set(this, `menuList`, res.data.menus.reverse());
  120. }
  121. },
  122. },
  123. computed: {
  124. ...mapState(['user']),
  125. },
  126. };
  127. </script>
  128. <style lang="less" scoped>
  129. .main {
  130. .info {
  131. .top {
  132. text-align: right;
  133. margin: 15px 0;
  134. }
  135. }
  136. }
  137. </style>