Sfoglia il codice sorgente

scss=>less&首页请求同步发送

lrf402788946 5 anni fa
parent
commit
ddf610caf2

+ 1 - 1
src/layout/index/weilai.vue

@@ -22,4 +22,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 13 - 0
src/store/column.js

@@ -1,5 +1,6 @@
 import Vue from 'vue';
 import Vuex from 'vuex';
+import axios from 'axios';
 import _ from 'lodash';
 Vue.use(Vuex);
 const api = {
@@ -9,6 +10,18 @@ const api = {
 export const state = () => ({});
 export const mutations = {};
 export const actions = {
+  async getAllColumn({ commit, dispatch }, payload) {
+    let toGet = () => {
+      let res = [];
+      for (const id of payload) {
+        res.push(dispatch('getColumn', { type: 'list', data: { parent_id: id } }));
+      }
+      return res;
+    };
+    let result = await axios.all(toGet());
+    let arr = _.flattenDeep(_.flattenDeep(result).map(item => item.data));
+    return arr;
+  },
   async getColumn({ commit }, { type, data }) {
     let result;
     if (type === `list`) {

+ 24 - 0
src/store/news.js

@@ -1,5 +1,6 @@
 import Vue from 'vue';
 import Vuex from 'vuex';
+import axios from 'axios';
 import _ from 'lodash';
 Vue.use(Vuex);
 const api = {
@@ -10,6 +11,29 @@ const api = {
 export const state = () => ({});
 export const mutations = {};
 export const actions = {
+  async getAllNews({ commit, dispatch }, payload) {
+    let toGet = () => {
+      let res = [];
+      for (const item of payload) {
+        let data = {
+          skip: 0,
+          limit: 8,
+        };
+        if (item.type === 'bugList') {
+          data.news_type = `0`;
+          data.parent_id = item.content_id;
+        } else {
+          data.news_type = `1`;
+          data.parent_id = item.id;
+        }
+        res.push(dispatch('getNews', { type: 'bugList', data }));
+      }
+      return res;
+    };
+    let result = await axios.all(toGet());
+    let arr = _.flattenDeep(_.flattenDeep(result).map(item => item.data));
+    return arr;
+  },
   async getNews({ commit }, { type, data }) {
     let result;
     if (type !== 'fetch') {

+ 0 - 0
src/store/test.js


+ 1 - 1
src/views/detail.vue

@@ -155,4 +155,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 41 - 9
src/views/index.vue

@@ -72,7 +72,7 @@ export default {
   },
   computed: {},
   methods: {
-    ...mapActions(['getSite', `getMenu`, 'getColumn', 'getModule', 'getNews', 'getJobInfo', 'getPosts', 'getLink']),
+    ...mapActions(['getSite', `getMenu`, 'getColumn', 'getAllNews', 'getAllColumn', 'getModule', 'getNews', 'getJobInfo', 'getPosts', 'getLink']),
     //站点信息
     async toGetSite() {
       let site = sessionStorage.getItem('site');
@@ -159,18 +159,21 @@ export default {
     },
     async finishedModule() {
       let modules = JSON.parse(JSON.stringify(this.modules));
-      for (const item of modules) {
-        if (`${item.is_use}` === `0`) {
-          let res = await this.completeModules(item);
-          item.children = res;
-          this.$set(this, `${item.category}List`, item);
-        }
-      }
+      // for (const item of modules) {
+      //   if (`${item.is_use}` === `0`) {
+      //     let res = await this.completeModules(item);
+      //     item.children = res;
+      //     this.$set(this, `${item.category}List`, item);
+      //   }
+      // }
+      //获取了所有栏目
+      let res = await this.completeAllModules(modules);
       // for (const item of modules) {
       //   this.$set(this, `${item.category}List`, item);
       // }
       this.$set(this, `modules`, modules);
     },
+    //弃用
     async completeModules(item) {
       let result = await this.getColumn({
         type: `list`,
@@ -192,6 +195,7 @@ export default {
         return columns;
       }
     },
+    //弃用
     async completeColumn(item) {
       let data = { skip: 0, limit: 8 };
       if (item.type === `bugList`) {
@@ -228,8 +232,36 @@ export default {
       let result = await this.getPosts({ type: 'fetch', data: { id: id } });
       if (result.errcode === 0) return result.data;
     },
+    //合并请求模块
+    async completeAllModules(modules) {
+      let ids = modules.map(item => item.id);
+      let result = await this.getAllColumn(ids);
+      // result = _.flattenDeep(result);
+      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>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 1 - 1
src/views/member.vue

@@ -216,4 +216,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 1 - 1
src/views/memberDetail.vue

@@ -153,4 +153,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 1 - 1
src/views/memberList.vue

@@ -214,4 +214,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 1 - 1
src/views/recruit/corp.vue

@@ -123,4 +123,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 1 - 1
src/views/recruit/jobfair.vue

@@ -158,4 +158,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 1 - 1
src/views/recruit/jobinfo.vue

@@ -129,4 +129,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 1 - 1
src/views/recruit/jobs.vue

@@ -144,4 +144,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>

+ 1 - 1
src/views/recruit/talk.vue

@@ -139,4 +139,4 @@ export default {
 };
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="less" scoped></style>