index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col :span="24" class="one">
  6. <search-1 :form="searchForm" @onSubmit="search" @toReset="toClose"></search-1>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <data-btn :fields="btnList" @add="toAdd"></data-btn>
  10. </el-col>
  11. <el-col :span="24" class="thr">
  12. <data-table
  13. :fields="fields"
  14. :opera="opera"
  15. :vOpera="false"
  16. :data="list"
  17. @query="search"
  18. :total="total"
  19. @edit="toEdit"
  20. @del="toDel"
  21. :select="true"
  22. :selected="selected"
  23. @handleSelect="handleSelect"
  24. >
  25. </data-table>
  26. </el-col>
  27. </el-col>
  28. </el-row>
  29. <e-dialog :dialog="dialog" @toClose="toClose">
  30. <template v-slot:info>
  31. <form-1 v-if="dialog.type == '1'" :form="form" @onSubmit="onSubmit" @toReset="toClose" :menuList="menuList" :typeList="typeList"></form-1>
  32. </template>
  33. </e-dialog>
  34. </div>
  35. </template>
  36. <script>
  37. import search1 from './parts/search-1.vue';
  38. import form1 from './parts/form-1.vue';
  39. import { mapState, createNamespacedHelpers } from 'vuex';
  40. const { mapActions } = createNamespacedHelpers('role');
  41. const { mapActions: menu } = createNamespacedHelpers('menus');
  42. export default {
  43. name: 'index',
  44. props: {},
  45. components: {
  46. search1,
  47. form1,
  48. },
  49. data: function () {
  50. return {
  51. btnList: [{ label: '添加', method: 'add' }],
  52. // 列表
  53. opera: [
  54. { label: '修改', method: 'edit' },
  55. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  56. ],
  57. fields: [
  58. { label: '角色名称', model: 'name' },
  59. { label: '角色代码', model: 'code' },
  60. {
  61. label: '角色状态',
  62. model: 'status',
  63. format: (i) => (i === '0' ? '使用' : '停用'),
  64. },
  65. ],
  66. list: [],
  67. total: 0,
  68. // 多选值
  69. selected: [],
  70. // 弹框
  71. dialog: { title: '信息管理', show: false, type: '1' },
  72. // 增加数据
  73. form: {},
  74. // 查詢
  75. searchForm: {},
  76. // 菜单
  77. menuList: [],
  78. // 角色类型
  79. typeList: [],
  80. };
  81. },
  82. async created() {
  83. await this.searchOther();
  84. await this.search();
  85. },
  86. methods: {
  87. ...menu({ menuQuery: 'query' }),
  88. ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
  89. // 查询
  90. async search({ skip = 0, limit = this.$limit, ...info } = {}) {
  91. const condition = _.cloneDeep(this.searchForm);
  92. let res = await this.query({ skip, limit, ...condition, ...info });
  93. if (this.$checkRes(res)) {
  94. this.$set(this, `list`, res.data);
  95. this.$set(this, `total`, res.total);
  96. }
  97. },
  98. // 新增
  99. toAdd() {
  100. this.dialog = { title: '信息管理', show: true, type: '1' };
  101. },
  102. // 修改
  103. async toEdit({ data }) {
  104. let res = await this.fetch(data._id);
  105. if (this.$checkRes(res)) {
  106. this.$set(this, `form`, res.data);
  107. this.dialog = { title: '信息管理', show: true, type: '1' };
  108. }
  109. },
  110. // 提交
  111. async onSubmit({ data }) {
  112. if (data.id) {
  113. let res = await this.update(data);
  114. if (this.$checkRes(res)) {
  115. this.$message({ type: `success`, message: `维护信息成功` });
  116. this.toClose();
  117. }
  118. } else {
  119. let res = await this.create(data);
  120. if (this.$checkRes(res)) {
  121. this.$message({ type: `success`, message: `创建信息成功` });
  122. this.toClose();
  123. }
  124. }
  125. },
  126. // 删除
  127. async toDel({ data }) {
  128. let res = await this.delete(data._id);
  129. if (this.$checkRes(res)) {
  130. this.$message({ type: `success`, message: `刪除信息成功` });
  131. this.search();
  132. }
  133. },
  134. // 关闭
  135. toClose() {
  136. this.form = {};
  137. this.searchForm = {};
  138. this.dialog = { title: '信息管理', show: false, type: '1' };
  139. this.search();
  140. },
  141. // 多选
  142. handleSelect(data) {
  143. this.$set(this, `selected`, data);
  144. },
  145. // 查询其他信息
  146. async searchOther() {
  147. let res = await this.menuQuery({ status: '0' });
  148. if (this.$checkRes(res)) this.$set(this, `menuList`, res.data);
  149. },
  150. },
  151. computed: {
  152. ...mapState(['user']),
  153. },
  154. metaInfo() {
  155. return { title: this.$route.meta.title };
  156. },
  157. watch: {
  158. test: {
  159. deep: true,
  160. immediate: true,
  161. handler(val) {},
  162. },
  163. },
  164. };
  165. </script>
  166. <style lang="less" scoped>
  167. .main {
  168. .one {
  169. margin: 0 0 10px 0;
  170. }
  171. .two {
  172. margin: 0 0 10px 0;
  173. }
  174. }
  175. </style>