index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. <c-search :is_search="true" :fields="fields" @search="btSearch">
  7. <template #type>
  8. <el-option v-for="i in typeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  9. </template>
  10. <template #place>
  11. <el-option v-for="i in placeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  12. </template>
  13. </c-search>
  14. </el-col>
  15. <el-col :span="24" class="two">
  16. <c-button @toAdd="toAdd"></c-button>
  17. </el-col>
  18. <el-col :span="24" class="thr">
  19. <data-table :fields="fields" :opera="opera" @query="search" :data="list" :total="total" @edit="toEdit" @del="toDel"> </data-table>
  20. </el-col>
  21. </el-col>
  22. </el-row>
  23. </div>
  24. </template>
  25. <script>
  26. import { mapState, createNamespacedHelpers } from 'vuex';
  27. const { mapActions } = createNamespacedHelpers('news');
  28. const { mapActions: dictdata } = createNamespacedHelpers('dictdata');
  29. export default {
  30. name: 'index',
  31. props: {},
  32. components: {},
  33. data: function () {
  34. return {
  35. // 查询
  36. searchInfo: {},
  37. fields: [
  38. { label: '序号', options: { type: 'index' } },
  39. {
  40. label: '新闻类型',
  41. model: 'type',
  42. type: 'select',
  43. format: (i) => {
  44. let data = this.typeList.find((r) => r.value == i);
  45. if (data) return data.label;
  46. else return '暂无';
  47. },
  48. isSearch: true,
  49. },
  50. { label: '名称', model: 'title', isSearch: true },
  51. { label: '来源', model: 'origin' },
  52. { label: '发布时间', model: 'create_time' },
  53. {
  54. label: '展示位置',
  55. model: 'place',
  56. type: 'select',
  57. format: (i) => {
  58. let data = this.placeList.find((r) => r.value == i);
  59. if (data) return data.label;
  60. else return '暂无';
  61. },
  62. isSearch: true,
  63. },
  64. {
  65. label: '是否启用',
  66. model: 'is_use',
  67. format: (i) => {
  68. let data = this.isuseList.find((r) => r.value == i);
  69. if (data) return data.label;
  70. else return '暂无';
  71. },
  72. },
  73. ],
  74. opera: [
  75. { label: '修改', method: 'edit' },
  76. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  77. ],
  78. list: [],
  79. total: 0,
  80. // 字典
  81. // 是否启用
  82. isuseList: [],
  83. // 展示位置
  84. placeList: [],
  85. // 新闻类型
  86. typeList: [],
  87. };
  88. },
  89. async created() {
  90. await this.searchOther();
  91. await this.search();
  92. },
  93. methods: {
  94. ...mapActions(['query', 'delete']),
  95. ...dictdata({ dQuery: 'query' }),
  96. async search({ skip = 0, limit = 10, ...info } = {}) {
  97. let res = await this.query({ skip, limit, ...info, ...this.searchInfo });
  98. if (this.$checkRes(res)) {
  99. this.$set(this, `list`, res.data);
  100. this.$set(this, `total`, res.total);
  101. }
  102. },
  103. btSearch(query) {
  104. this.$set(this, `searchInfo`, query);
  105. this.search();
  106. },
  107. // 新增
  108. toAdd() {
  109. this.$router.push({ path: '/web/news/add' });
  110. },
  111. // 修改
  112. toEdit({ data }) {
  113. this.$router.push({ path: '/web/news/add', query: { id: data._id } });
  114. },
  115. async toDel({ data }) {
  116. let res = await this.delete(data._id);
  117. if (this.$checkRes(res, '删除信息成功', res.errmsg)) this.search();
  118. },
  119. // 字典表
  120. async searchOther() {
  121. let res;
  122. // 是否启用
  123. res = await this.dQuery({ type: 'is_use' });
  124. if (this.$checkRes(res)) {
  125. this.$set(this, `isuseList`, res.data);
  126. }
  127. // 展示位置
  128. res = await this.dQuery({ type: 'banner_place' });
  129. if (this.$checkRes(res)) {
  130. this.$set(this, `placeList`, res.data);
  131. }
  132. // 新闻类型
  133. res = await this.dQuery({ type: 'news_type' });
  134. if (this.$checkRes(res)) {
  135. this.$set(this, `typeList`, res.data);
  136. }
  137. },
  138. },
  139. computed: {
  140. ...mapState(['user']),
  141. },
  142. metaInfo() {
  143. return { title: this.$route.meta.title };
  144. },
  145. watch: {
  146. test: {
  147. deep: true,
  148. immediate: true,
  149. handler(val) {},
  150. },
  151. },
  152. };
  153. </script>
  154. <style lang="less" scoped></style>