guhongwei 4 gadi atpakaļ
vecāks
revīzija
2ca5722962
2 mainītis faili ar 122 papildinājumiem un 9 dzēšanām
  1. 119 8
      src/views/news/detail.vue
  2. 3 1
      src/views/news/index.vue

+ 119 - 8
src/views/news/detail.vue

@@ -5,8 +5,47 @@
         <el-col :span="24" class="top">
           <el-button type="primary" size="mini" @click="back">返回</el-button>
         </el-col>
-        <el-col :span="24" class="down">
-          <data-form :data="form" :fields="fields" :rules="{}" @save="toSave"> </data-form>
+        <el-col :span="24" class="down" v-loading="loading">
+          <data-form :data="form" :fields="fields" :rules="{}" @save="toSave">
+            <template #custom="{item,form}">
+              <template v-if="item.model === 'column_id'">
+                <el-select v-model="form.column_id" placeholder="请选择所属栏目" @change="changeColumn">
+                  <el-option v-for="(i, index) in columnList" :key="index" :label="i.name" :value="i.id"></el-option>
+                </el-select>
+              </template>
+              <template v-else-if="item.model == 'type'">
+                <el-radio-group v-model="form.type" :disabled="form.site == 'kjzx' ? false : true">
+                  <el-radio label="国家"></el-radio>
+                  <el-radio label="科学院"></el-radio>
+                </el-radio-group>
+              </template>
+              <template v-else-if="item.model == 'picture'">
+                <upload :limit="1" :data="form.picture" type="picture" :url="'/files/picture/upload'" @upload="uploadSuccess" @delete="uploadDelete"></upload>
+              </template>
+              <template v-else-if="item.model == 'video'">
+                <upload
+                  :limit="1"
+                  :data="form.video"
+                  listType=""
+                  type="video"
+                  :url="'/files/video/upload'"
+                  @upload="uploadSuccess"
+                  @delete="uploadDelete"
+                ></upload>
+              </template>
+              <template v-else-if="item.model == 'filepath'">
+                <upload
+                  :limit="1"
+                  :data="form.filepath"
+                  listType=""
+                  type="filepath"
+                  :url="'/files/filepath/upload'"
+                  @upload="uploadSuccess"
+                  @delete="uploadDelete"
+                ></upload>
+              </template>
+            </template>
+          </data-form>
         </el-col>
       </el-col>
     </el-row>
@@ -15,6 +54,7 @@
 
 <script>
 import dataForm from '@common/src/components/frame/form.vue';
+import upload from '@common/src/components/frame/upload.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
 const { mapActions: column } = createNamespacedHelpers('column');
 const { mapActions: news } = createNamespacedHelpers('news');
@@ -24,26 +64,97 @@ export default {
   },
   name: 'detail',
   props: {},
-  components: { dataForm },
+  components: { dataForm, upload },
   data: function() {
     return {
       fields: [
-        { label: '所属栏目', model: 'column_id', type: 'select' },
+        { label: '所属栏目', model: 'column_id', custom: true },
         { label: '信息标题', model: 'title' },
+        { label: '信息类型', model: 'type', custom: true },
+        { label: '发布时间', model: 'publish_time', type: 'date' },
+        { label: '信息来源', model: 'origin' },
+        { label: '信息简介', model: 'brief', type: 'textarea' },
+        { label: '图片文件', model: 'picture', custom: true },
+        { label: '视频文件', model: 'video', custom: true },
+        { label: '附件文件', model: 'filepath', custom: true },
+        { label: '内容', model: 'content', type: 'editor' },
       ],
       form: {},
+      // 栏目列表
+      columnList: [],
+      loading: false,
     };
   },
-  created() {},
+  async created() {
+    await this.searchColumn();
+    if (this.id) {
+      await this.search();
+    }
+  },
   methods: {
     ...column({ columnQuery: 'query' }),
-    ...news(['']),
-    toSave({ data }) {
-      console.log(data);
+    ...news(['fetch', 'update', 'create']),
+    async search() {
+      this.loading = true;
+      let res = await this.fetch(this.id);
+      if (this.$checkRes(res)) {
+        this.$set(this, `form`, res.data);
+        console.log(this.form);
+        this.loading = false;
+      }
+    },
+    async toSave({ data }) {
+      if (data.id) {
+        let res = await this.update(data);
+        if (this.$checkRes(res)) {
+          this.$message({
+            message: '信息修改成功',
+            type: 'success',
+          });
+          this.back();
+        }
+      } else {
+        let res = await this.create(data);
+        if (this.$checkRes(res)) {
+          this.$message({
+            message: '信息创建成功',
+            type: 'success',
+          });
+          this.back();
+        }
+      }
+    },
+    // 选择栏目
+    changeColumn(index) {
+      let column = this.columnList.find(i => i.id == index);
+      if (column) this.$set(this.form, `column_name`, column.name);
+      this.$set(this.form, `site`, column.site);
+    },
+    // 返回列表
+    back() {
+      this.$router.push({ path: '/news' });
+    },
+    // 查询栏目
+    async searchColumn() {
+      let res = await this.columnQuery();
+      if (this.$checkRes(res)) {
+        this.$set(this, `columnList`, res.data);
+      }
+    },
+    // 图片上传
+    uploadSuccess({ type, data }) {
+      this.$set(this.form, `${type}`, data.uri);
+    },
+    // 删除图片
+    uploadDelete(data) {
+      this.$set(this.form, `${data.type}`, null);
     },
   },
   computed: {
     ...mapState(['user']),
+    id() {
+      return this.$route.query.id;
+    },
   },
   watch: {},
 };

+ 3 - 1
src/views/news/index.vue

@@ -198,7 +198,9 @@ export default {
       }
     },
     // 修改
-    newsEdit({ data }) {},
+    newsEdit({ data }) {
+      this.$router.push({ path: '/news/detail', query: { id: data.id } });
+    },
     // 删除
     async newsDelete({ data }) {
       let res = await this.delete(data.id);