add.vue 3.2 KB

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