add.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div id="add">
  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_title="true" :is_back="true" @toBack="toBack"></c-search>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <data-form :fields="fields" :form="form" :rules="{}" @save="toSave" :span="24">
  10. <template #type>
  11. <el-option v-for="i in typeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  12. </template>
  13. <template #place>
  14. <el-option v-for="i in placeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  15. </template>
  16. <template #is_use>
  17. <el-option v-for="i in isuseList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  18. </template>
  19. <template #img_url="{ item }">
  20. <c-upload v-model="form[item.model]" url="/files/projectadmin/imgurl/upload" accept="" listType="text" :limit="1"></c-upload>
  21. </template>
  22. <template #file_url="{ item }">
  23. <c-upload v-model="form[item.model]" url="/files/projectadmin/imgurl/upload" accept="" listType="text" :limit="1"></c-upload>
  24. </template>
  25. <template #content="{ item }">
  26. <c-editor v-model="form[item.model]" url="/files/projectadmin/other/upload" />
  27. </template>
  28. </data-form>
  29. </el-col>
  30. </el-col>
  31. </el-row>
  32. </div>
  33. </template>
  34. <script>
  35. import { mapState, createNamespacedHelpers } from 'vuex';
  36. const { mapActions } = createNamespacedHelpers('news');
  37. const { mapActions: dictdata } = createNamespacedHelpers('dictdata');
  38. export default {
  39. name: 'add',
  40. props: {},
  41. components: {},
  42. data: function () {
  43. return {
  44. fields: [
  45. { label: '新闻类型', model: 'type', type: 'select' },
  46. { label: '名称', model: 'title' },
  47. { label: '来源', model: 'origin' },
  48. { label: '发布时间', model: 'create_time', type: 'date' },
  49. { label: '简介', model: 'brief', type: 'textarea' },
  50. { label: '图片', model: 'img_url', custom: true },
  51. { label: '文件', model: 'file_url', custom: true },
  52. { label: '内容', model: 'content', custom: true },
  53. { label: '展示位置', model: 'place', type: 'select' },
  54. { label: '是否启用', model: 'is_use', type: 'select' },
  55. ],
  56. form: {},
  57. // 是否启用
  58. isuseList: [],
  59. // 展示位置
  60. placeList: [],
  61. // 新闻类型
  62. typeList: [],
  63. };
  64. },
  65. async created() {
  66. await this.searchOther();
  67. await this.search();
  68. },
  69. methods: {
  70. ...mapActions(['fetch', 'create', 'update']),
  71. ...dictdata({ dQuery: 'query' }),
  72. async search() {
  73. if (this.id) {
  74. let res = await this.fetch(this.id);
  75. if (this.$checkRes(res)) {
  76. this.$set(this, `form`, res.data);
  77. }
  78. }
  79. },
  80. // 保存信息
  81. async toSave({ data }) {
  82. let res;
  83. if (data.id) res = await this.update(data);
  84. else res = await this.create(data);
  85. if (this.$checkRes(res, `维护信息成功`, res.errmsg)) this.toBack();
  86. },
  87. // 字典
  88. async searchOther() {
  89. let res;
  90. // 是否启用
  91. res = await this.dQuery({ type: 'is_use' });
  92. if (this.$checkRes(res)) {
  93. this.$set(this, `isuseList`, res.data);
  94. }
  95. // 展示位置
  96. res = await this.dQuery({ type: 'banner_place' });
  97. if (this.$checkRes(res)) {
  98. this.$set(this, `placeList`, res.data);
  99. }
  100. // 新闻类型
  101. res = await this.dQuery({ type: 'news_type' });
  102. if (this.$checkRes(res)) {
  103. this.$set(this, `typeList`, res.data);
  104. }
  105. },
  106. // 返回
  107. toBack() {
  108. window.history.go('-1');
  109. },
  110. },
  111. computed: {
  112. ...mapState(['user']),
  113. id() {
  114. return this.$route.query.id;
  115. },
  116. },
  117. metaInfo() {
  118. return { title: this.$route.meta.title };
  119. },
  120. watch: {
  121. test: {
  122. deep: true,
  123. immediate: true,
  124. handler(val) {},
  125. },
  126. },
  127. };
  128. </script>
  129. <style lang="less" scoped></style>