guhongwei 4 years ago
parent
commit
27605e9e39
4 changed files with 239 additions and 0 deletions
  1. 11 0
      src/router/index.js
  2. 3 0
      src/store/index.js
  3. 131 0
      src/views/science/detail.vue
  4. 94 0
      src/views/science/index.vue

+ 11 - 0
src/router/index.js

@@ -148,6 +148,17 @@ export default new Router({
           component: () => import('../views/notice/detail.vue'),
           meta: { title: '通知信息管理' },
         },
+        // 科技新闻
+        {
+          path: '/science',
+          component: () => import('../views/science/index.vue'),
+          meta: { title: '科技新闻' },
+        },
+        {
+          path: '/science/detail',
+          component: () => import('../views/science/detail.vue'),
+          meta: { title: '科技新闻信息管理' },
+        },
       ],
     },
     {

+ 3 - 0
src/store/index.js

@@ -27,6 +27,8 @@ import roadShow from '@common/src/store/roadShow';
 import interview from '@common/src/store/interview';
 // 通知管理
 import notice from '@common/src/store/notice';
+// 科技新闻
+import science from '@common/src/store/science';
 // 字典表
 import category from '@common/src/store/category';
 import code from '@common/src/store/code';
@@ -51,6 +53,7 @@ export default new Vuex.Store({
     roadShow,
     interview,
     notice,
+    science,
     category,
     code,
     place,

+ 131 - 0
src/views/science/detail.vue

@@ -0,0 +1,131 @@
+<template>
+  <div id="detail">
+    <el-row>
+      <el-col :span="24" class="main">
+        <el-col :span="24" class="back">
+          <el-button type="primary" size="mini" @click="back">返回</el-button>
+        </el-col>
+        <el-col :span="24" class="detail">
+          <data-form :data="form" :fields="formFields" :rules="rules" @save="toSave">
+            <template #custom="{item,form}">
+              <template v-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 == '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>
+  </div>
+</template>
+
+<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: science } = createNamespacedHelpers('science');
+export default {
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+  name: 'detail',
+  props: {},
+  components: {
+    dataForm,
+    upload,
+  },
+  data: function() {
+    return {
+      formFields: [
+        { label: '信息标题', model: 'title' },
+        { label: '信息来源', model: 'origin' },
+        { label: '发布时间', model: 'publish_time', type: 'date' },
+        { label: '图片文件', model: 'picture', custom: true },
+        { label: '附件', model: 'filepath', custom: true },
+        { label: '信息内容', model: 'content', type: 'editor' },
+      ],
+      form: {},
+      rules: {
+        title: [{ required: true, message: '请输入信息标题' }],
+        origin: [{ required: true, message: '请输入信息来源' }],
+        publish_time: [{ required: true, message: '请输入发布时间' }],
+      },
+    };
+  },
+  async created() {
+    if (this.id) await this.search();
+  },
+  methods: {
+    ...science(['fetch', 'create', 'update']),
+    // 查询详情
+    async search() {
+      let res = await this.fetch(this.id);
+      if (this.$checkRes(res)) {
+        this.$set(this, `form`, res.data);
+      }
+    },
+    // 提交
+    async toSave({ data }) {
+      data.user_id = this.user.id;
+      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();
+        }
+      }
+    },
+    // 返回
+    back() {
+      this.$router.push({ path: '/science' });
+    },
+    // 图片上传
+    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: {},
+};
+</script>
+
+<style lang="less" scoped>
+.main {
+  .back {
+    text-align: right;
+    margin: 0 0 10px 0;
+  }
+}
+</style>

+ 94 - 0
src/views/science/index.vue

@@ -0,0 +1,94 @@
+<template>
+  <div id="index">
+    <el-row>
+      <el-col :span="24" class="main">
+        <el-col :span="24" class="top">
+          <el-button type="primary" size="mini" @click="add">添加</el-button>
+        </el-col>
+        <el-col :span="24" class="down">
+          <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @edit="toEdit" @delete="toDelete"></data-table>
+        </el-col>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import dataTable from '@common/src/components/frame/filter-page-table.vue';
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: science } = createNamespacedHelpers('science');
+export default {
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+  name: 'index',
+  props: {},
+  components: { dataTable },
+  data: function() {
+    return {
+      opera: [
+        {
+          label: '编辑',
+          method: 'edit',
+        },
+        {
+          label: '删除',
+          method: 'delete',
+        },
+      ],
+      fields: [
+        { label: '标题', prop: 'title', filter: 'input' },
+        { label: '来源', prop: 'origin' },
+        { label: '时间', prop: 'publish_time' },
+      ],
+      list: [],
+      total: 0,
+    };
+  },
+  async created() {
+    await this.search();
+  },
+  methods: {
+    ...science(['query', 'fetch', 'create', 'update', 'delete']),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      let res = await this.query({ skip, limit, ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+        this.$set(this, `total`, res.total);
+      }
+    },
+    // 修改
+    toEdit({ data }) {
+      this.$router.push({ path: '/science/detail', query: { id: data.id } });
+    },
+    // 删除
+    async toDelete({ data }) {
+      let res = await this.delete(data.id);
+      if (this.$checkRes(res)) {
+        this.$message({
+          message: '信息删除成功',
+          type: 'success',
+        });
+        this.search();
+      }
+    },
+    // 添加数据
+    add() {
+      this.$router.push({ path: '/science/detail' });
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+  },
+  watch: {},
+};
+</script>
+
+<style lang="less" scoped>
+.main {
+  .top {
+    text-align: right;
+    margin: 0 0 10px 0;
+  }
+}
+</style>