Browse Source

修改党员之家

lrf402788946 5 years ago
parent
commit
77de58a6fd
3 changed files with 32 additions and 16 deletions
  1. 1 0
      src/store/column.js
  2. 1 0
      src/store/news.js
  3. 30 16
      src/views/member.vue

+ 1 - 0
src/store/column.js

@@ -10,6 +10,7 @@ const api = {
 export const state = () => ({});
 export const mutations = {};
 export const actions = {
+  //请求所有的栏目
   async getAllColumn({ commit, dispatch }, payload) {
     let toGet = () => {
       let res = [];

+ 1 - 0
src/store/news.js

@@ -11,6 +11,7 @@ const api = {
 export const state = () => ({});
 export const mutations = {};
 export const actions = {
+  //请求所有新闻
   async getAllNews({ commit, dispatch }, payload) {
     let toGet = () => {
       let res = [];

+ 30 - 16
src/views/member.vue

@@ -160,23 +160,9 @@ export default {
     },
     async finishedModule() {
       let modules = JSON.parse(JSON.stringify(this.modules));
-      let object = {};
-      for (const item of modules) {
-        if (item.category === 'member') {
-          if (`${item.is_use}` === `0`) {
-            let res = await this.completeModules(item);
-            item.children = res;
-            // object = item;
-            for (const items of item.children) {
-              this.$set(this, `${items.category}List`, items);
-            }
-          }
-        }
-      }
-      // for (const item of object.children) {
-      //   this.$set(this, `${item.category}List`, item);
-      // }
+      let res = await this.completeAllModules(modules);
     },
+    //弃用
     async completeModules(item) {
       let result = await this.getColumn({
         type: `list`,
@@ -198,6 +184,7 @@ export default {
         return columns;
       }
     },
+    //弃用
     async completeColumn(item) {
       let data = { skip: 0, limit: 8 };
       if (item.type === `bugList`) {
@@ -212,6 +199,33 @@ export default {
         return result.data;
       }
     },
+    //合并请求模块
+    async completeAllModules(modules) {
+      let ids = modules.map(item => item.id);
+      let result = await this.getAllColumn(ids);
+      if (result.length > 0) {
+        //整理栏目
+        result = result.map(item => {
+          if (item.type === 'column') item.path = `/newsList/module/${item.id}`;
+          else item.path = `/newsList/module/${item.content_id}`;
+          return item;
+        });
+        //请求信息
+        let res = await this.getAllNews(result);
+        //合并栏目和信息
+        result = result.map(item => {
+          let newsList = res.filter(fil => fil.parent_id === item.id);
+          item.children = newsList;
+          return item;
+        });
+        modules = modules.map(item => {
+          let children = result.filter(fil => fil.parent_id === item.id);
+          item.children = children;
+          this.$set(this, `${item.category}List`, item);
+          return item;
+        });
+      }
+    },
   },
 };
 </script>