index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <span v-show="view === 'list'">
  6. <el-col :span="24" class="one"> <span>首页广告图标设置</span> </el-col>
  7. <el-col :span="24" class="two">
  8. <search-1 :form="searchForm" :typeList="typeList" @onSubmit="search" @toReset="toClose"></search-1>
  9. </el-col>
  10. <el-col :span="24" class="thr">
  11. <el-button type="primary" size="mini" @click="toAdd()">新增</el-button>
  12. </el-col>
  13. <el-col :span="24" class="four">
  14. <data-table
  15. :select="true"
  16. :selected="selected"
  17. @handleSelect="handleSelect"
  18. :fields="fields"
  19. :opera="opera"
  20. @query="search"
  21. :data="list"
  22. :total="total"
  23. @edit="toEdit"
  24. @del="toDel"
  25. >
  26. </data-table>
  27. </el-col>
  28. </span>
  29. <detail v-if="view === 'info'" :id="id" @toBack="toBack"></detail>
  30. </el-col>
  31. </el-row>
  32. </div>
  33. </template>
  34. <script>
  35. const _ = require('lodash');
  36. import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
  37. const { mapActions } = createNamespacedHelpers('indexModule');
  38. const { mapActions: dictData } = createNamespacedHelpers('dictData');
  39. export default {
  40. name: 'index',
  41. props: {},
  42. components: {
  43. search1: () => import('./parts/search-1.vue'),
  44. detail: () => import('./detail.vue'),
  45. },
  46. data: function () {
  47. const that = this;
  48. return {
  49. view: 'list',
  50. // 列表
  51. opera: [
  52. { label: '修改', method: 'edit' },
  53. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  54. ],
  55. fields: [
  56. { label: '名称', model: 'name' },
  57. {
  58. label: '跳转类型',
  59. model: 'to_type',
  60. format: (i) => {
  61. let data = that.typeList.find((f) => f.value == i);
  62. if (data) return data.label;
  63. else return '暂无';
  64. },
  65. },
  66. { label: '跳转到', model: 'to' },
  67. {
  68. label: '是否正在使用',
  69. model: 'status',
  70. format: (i) => {
  71. let data = that.statusList.find((f) => f.value == i);
  72. if (data) return data.label;
  73. else return '暂无';
  74. },
  75. },
  76. ],
  77. list: [],
  78. total: 0,
  79. // 查询
  80. searchForm: {},
  81. // 多选值
  82. selected: [],
  83. // 类型列表
  84. typeList: [],
  85. // 是否使用
  86. statusList: [],
  87. id: '',
  88. };
  89. },
  90. async created() {
  91. await this.searchOther();
  92. await this.search();
  93. },
  94. methods: {
  95. ...dictData({ dictQuery: 'query' }),
  96. ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
  97. // 查询
  98. async search({ skip = 0, limit = this.$limit, ...info } = {}) {
  99. const condition = _.cloneDeep(this.searchForm);
  100. let res = await this.query({ skip, limit, ...condition, ...info });
  101. if (this.$checkRes(res)) {
  102. this.$set(this, 'list', res.data);
  103. this.$set(this, 'total', res.total);
  104. }
  105. },
  106. // 新增
  107. toAdd() {
  108. let id = '';
  109. this.$set(this, `id`, id);
  110. this.$set(this, `view`, 'info');
  111. },
  112. // 修改
  113. async toEdit({ data }) {
  114. this.$set(this, `id`, data.id);
  115. this.$set(this, `view`, 'info');
  116. },
  117. toBack() {
  118. this.view = 'list';
  119. },
  120. // 删除
  121. async toDel({ data }) {
  122. let res = await this.delete(data._id);
  123. if (this.$checkRes(res)) {
  124. this.$message({ type: `success`, message: `刪除信息成功` });
  125. this.search();
  126. }
  127. },
  128. // 重置
  129. toClose() {
  130. this.searchForm = {};
  131. this.search();
  132. },
  133. // 多选
  134. handleSelect(data) {
  135. this.$set(this, `selected`, data);
  136. },
  137. // 查询其他信息
  138. async searchOther() {
  139. let res;
  140. // 类型
  141. res = await this.dictQuery({ code: 'to_type' });
  142. if (this.$checkRes(res)) {
  143. this.$set(this, `typeList`, res.data);
  144. }
  145. res = await this.dictQuery({ code: 'status' });
  146. if (this.$checkRes(res)) {
  147. this.$set(this, `statusList`, res.data);
  148. }
  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. span:nth-child(1) {
  171. font-size: 20px;
  172. font-weight: 700;
  173. margin-right: 10px;
  174. }
  175. }
  176. .two {
  177. margin: 0 0 10px 0;
  178. }
  179. .thr {
  180. margin: 0 0 10px 0;
  181. }
  182. }
  183. </style>