فهرست منبع

新闻动态更新

guhongwei 5 سال پیش
والد
کامیت
245e0a77f2
4فایلهای تغییر یافته به همراه74 افزوده شده و 8 حذف شده
  1. 5 0
      package-lock.json
  2. 1 0
      package.json
  3. 2 1
      src/util/var.js
  4. 66 7
      src/views/index/index.vue

+ 5 - 0
package-lock.json

@@ -6843,6 +6843,11 @@
         }
       }
     },
+    "loadsh": {
+      "version": "0.0.4",
+      "resolved": "https://registry.npm.taobao.org/loadsh/download/loadsh-0.0.4.tgz",
+      "integrity": "sha1-UxS6vRK7EzFd3gJKTKcHWMVInS0="
+    },
     "locate-path": {
       "version": "2.0.0",
       "resolved": "https://registry.npm.taobao.org/locate-path/download/locate-path-2.0.0.tgz",

+ 1 - 0
package.json

@@ -13,6 +13,7 @@
     "element-ui": "^2.12.0",
     "less": "^3.10.3",
     "less-loader": "^5.0.0",
+    "loadsh": "0.0.4",
     "lodash": "^4.17.15",
     "naf-core": "^0.1.2",
     "vue": "^2.6.10",

+ 2 - 1
src/util/var.js

@@ -1,3 +1,4 @@
+/* eslint-disable no-unused-vars */
 import Vue from 'vue';
 import _ from 'lodash';
 
@@ -13,7 +14,7 @@ const getSiteId = () => {
   return schId;
 };
 const Plugin = {
-  install(vue, options) {
+  install(vue) {
     // 4. 添加实例方法
     vue.prototype.$limit = 10;
     vue.prototype.$site = getSiteId();

+ 66 - 7
src/views/index/index.vue

@@ -20,12 +20,7 @@ export default {
     logolist:{
       logo: require('@/assets/logo.png'),
     },
-    newslist:[
-      {
-       title:'新闻动态',
-        time:'2019-10-28',
-      }
-    ],
+    newslist:[],
      noticelist:[
       {
        title:'通知公告',
@@ -50,10 +45,11 @@ export default {
   }),
   created() {
     this.getSite();
+    this.getModule();
   },
   computed: {},
   methods: {
-    ...mapActions(['siteOperation','moduleOperation']),
+    ...mapActions(['siteOperation','moduleOperation','columnOperation','newsOperation']),
     async getSite() {
       let site = sessionStorage.getItem('site');
       if (!site) {
@@ -67,6 +63,69 @@ export default {
       }
       this.$set(this, `loading`, false);
     },
+    async getModule() {
+      //获取分站所有模块
+      let result = await this.moduleOperation({ type: 'list', data: { site: this.$site } });
+      if (`${result.errcode}` === '0') {
+        let moduleList = result.data;
+        for (let item of moduleList) {
+          //item为模块信息,拿着模块信息去查该模块下有什么栏目
+          item = await this.getColumn(item);
+          this.makeList(item);
+        }
+      }
+    },
+    async getColumn(item) {
+      let res = await this.columnOperation({ type: 'list', data: { parent_id: item.id, site: item.site } });
+      if (`${res.errcode}` === '0') {
+        //组合path:res.data内容都为栏目.所以,点击这些栏目显示的列表应该是信息列表,需要用栏目的id作为查询信息的parten_id查出不同栏目的信息
+        for (const col of res.data) {
+          col.path = `/info/list/${col.id}`;
+          //再将栏目下的前几条数据查出来(暂定limit=6)
+          col.children = await this.getNews(col);
+        }
+        item.children = res.data;
+        return item;
+      }
+    },
+    async getNews(item) {
+      //这个item是栏目列表,循环查每个栏目6条信息
+      let res = await this.newsOperation({ type: 'list', data: { parent_id: item.id, site: item.site, skip: 0, limit: 6 } });
+      if (`${res.errcode}` === '0') {
+        return res.data;
+      }
+    },
+    makeList(item) {
+      if (item.category === 'news') {
+        let arr = [];
+        let colObject = {};
+        for (const col of item.children) {
+          if (!colObject.id) colObject = col;
+          for (const news of col.children) {
+            arr.push(news);
+          }
+        }
+        let object = { ...JSON.parse(JSON.stringify(item)), infoList: arr, column: colObject };
+        // eslint-disable-next-line no-console
+        console.log(object);
+        this.$set(this, `newslist`, object);
+      } else if (item.category === 'notice') {
+        let arr = [];
+        let colObject = {};
+        for (const col of item.children) {
+          if (!colObject.id) colObject = col;
+          for (const news of col.children) {
+            arr.push(news);
+          }
+        }
+        let object = { ...JSON.parse(JSON.stringify(item)), infoList: arr, column: colObject };
+        this.$set(this, `notice`, object);
+      } else if (item.category === 'self1') {
+        this.$set(this, `self1List`, item.children);
+      } else if (item.category === 'self2') {
+        this.$set(this, `self2List`, item.children);
+      }
+    },
   },
 };
 </script>