index.vue 4.8 KB

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