lrf402788946 5 years ago
parent
commit
2453902370
4 changed files with 102 additions and 26 deletions
  1. 51 24
      src/pages/index/views/home.vue
  2. 20 1
      src/store/column.js
  3. 1 1
      src/store/module.js
  4. 30 0
      src/store/news.js

+ 51 - 24
src/pages/index/views/home.vue

@@ -47,23 +47,27 @@
       </el-col>
       </el-col>
     </el-row>
     </el-row>
     <!-- list部分 -->
     <!-- list部分 -->
-    <div class="list">
+    <div class="list" v-for="(mod, index) in modules" :key="`mod${index}`">
       <el-row class="tip" type="flex">
       <el-row class="tip" type="flex">
         <el-col :span="16">
         <el-col :span="16">
-          {{ news.title }}<b class="tip_en">{{ news.title }}</b>
+          {{ mod.title }}<b class="tip_en">{{ mod.title }}</b>
         </el-col>
         </el-col>
-        <el-col :span="8" class="more" @click.native="toHtml(`newsList.html#/${news.id}?title=${news.title}`)">
+        <el-col :span="8" class="more" @click.native="toHtml(`newsList.html#/${mod.id}?title=${mod.title}`)">
           查看更多
           查看更多
         </el-col>
         </el-col>
       </el-row>
       </el-row>
-      <el-row type="flex" @click.native="toHtml(`news.html#/${item.id}`)" v-for="(item, index) in news.infoList" :key="index" class="data_list">
-        <el-col :span="7"> 【{{ news.title }}】 </el-col>
-        <el-col :span="17">
-          <p class="textOver">{{ item.title }}</p>
-        </el-col>
-      </el-row>
+      <template v-for="(col, colIndex) in mod.children">
+        <template v-for="(news, newsIndex) in col.children">
+          <el-row type="flex" @click.native="toHtml(`news.html#/${news.id}`)" :key="`col${newsIndex}${colIndex}`" class="data_list" :gutter="10">
+            <el-col :span="7" :key="`newsCol${newsIndex}`" style="text-overflow: ellipsis;overflow: hidden;white-space: nowrap;"> 【{{ col.title }}】 </el-col>
+            <el-col :span="17" :key="`newsTitle${newsIndex}`">
+              <p class="textOver">{{ news.title }}</p>
+            </el-col>
+          </el-row>
+        </template>
+      </template>
     </div>
     </div>
-    <div class="list">
+    <!-- <div class="list">
       <el-row class="tip" type="flex">
       <el-row class="tip" type="flex">
         <el-col :span="16">
         <el-col :span="16">
           {{ notice.title }}<b class="tip_en">{{ notice.title }}</b>
           {{ notice.title }}<b class="tip_en">{{ notice.title }}</b>
@@ -78,7 +82,7 @@
           <p class="textOver">{{ item.title }}</p>
           <p class="textOver">{{ item.title }}</p>
         </el-col>
         </el-col>
       </el-row>
       </el-row>
-    </div>
+    </div> -->
     <div class="list">
     <div class="list">
       <el-row class="tip" type="flex">
       <el-row class="tip" type="flex">
         <el-col :span="24"> 联系我们<b class="tip_en">CONTACT</b> </el-col>
         <el-col :span="24"> 联系我们<b class="tip_en">CONTACT</b> </el-col>
@@ -122,8 +126,7 @@ export default {
     drawerJobfair: false,
     drawerJobfair: false,
     drawerCenter: false,
     drawerCenter: false,
     site: {},
     site: {},
-    news: {},
-    notice: {},
+    modules: {},
     siteTitle: '',
     siteTitle: '',
   }),
   }),
   async created() {
   async created() {
@@ -139,7 +142,7 @@ export default {
     }),
     }),
   },
   },
   methods: {
   methods: {
-    ...mapActions(['siteOperation', 'moduleOperation', 'columnOperation', 'newsOperation']),
+    ...mapActions(['siteOperation', 'moduleOperation', 'columnOperation', 'newsOperation', 'getAllColumn', 'getAllNews']),
     toHtml(uri, type) {
     toHtml(uri, type) {
       if (type) {
       if (type) {
         let url = '';
         let url = '';
@@ -172,17 +175,41 @@ export default {
     },
     },
     //获取固定的4个模块
     //获取固定的4个模块
     async getModule() {
     async getModule() {
-      //获取分站所有模块 TODO:site=>_tenant
-      let result = await this.moduleOperation({ type: 'list' });
+      //获取手机可以使用的所有模块
+      let result = await this.moduleOperation({ type: 'list', data: { is_mobile: '0' } });
       if (`${result.errcode}` === '0') {
       if (`${result.errcode}` === '0') {
-        let moduleList = result.data;
-        for (let item of moduleList) {
-          //item为模块信息,拿着模块信息去查该模块下有什么栏目
-          if (`${item.is_use}` === '0') {
-            item = await this.getColumn(item);
-            await this.makeList(item);
-          } // console.log(item);
-        }
+        let modules = result.data;
+        //获取模块下的所有栏目
+        let columns = await this.getAllColumn(modules.map(i => i.id));
+        //获取栏目下的所有信息
+        let news = await this.getAllNews(columns);
+        //合并栏目和信息
+        columns = columns.map(item => {
+          let newsList = news.filter(fil => fil.parent_id === item.id);
+          item.children = newsList;
+          return item;
+        });
+        modules = modules.map(item => {
+          let children = columns.filter(fil => fil.parent_id === item.id);
+          item.children = children;
+          for (const sc of item.children) {
+            let schildren = _.get(sc, `children`, []);
+            sc.children = _.sortBy(schildren, i => {
+              return new Date(_.get(i, `meta.createdA`)).getTime();
+            });
+            sc.children = sc.children.filter(f => f.is_use === '0');
+          }
+          return item;
+        });
+        this.$set(this, `modules`, modules);
+        console.log(modules);
+        // for (let item of moduleList) {
+        //   //item为模块信息,拿着模块信息去查该模块下有什么栏目
+        //   if (`${item.is_use}` === '0') {
+        //     item = await this.getColumn(item);
+        //     await this.makeList(item);
+        //   } // console.log(item);
+        // }
       }
       }
     },
     },
     //根据条件获取栏目
     //根据条件获取栏目

+ 20 - 1
src/store/column.js

@@ -1,5 +1,6 @@
 import Vue from 'vue';
 import Vue from 'vue';
 import Vuex from 'vuex';
 import Vuex from 'vuex';
+import axios from 'axios';
 import _ from 'lodash';
 import _ from 'lodash';
 
 
 Vue.use(Vuex);
 Vue.use(Vuex);
@@ -10,12 +11,30 @@ const api = {
 export const state = () => ({});
 export const state = () => ({});
 export const mutations = {};
 export const mutations = {};
 export const actions = {
 export const actions = {
+  //请求所有的栏目
+  async getAllColumn({ commit, dispatch }, payload) {
+    let toGet = () => {
+      let res = [];
+      for (const id of payload) {
+        res.push(
+          dispatch('columnOperation', {
+            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 columnOperation({ state }, { type, data }) {
   async columnOperation({ state }, { type, data }) {
     let { skip, limit } = data;
     let { skip, limit } = data;
     let result;
     let result;
     if (type === 'list') {
     if (type === 'list') {
-      //TODO
       let { parent_id } = data;
       let { parent_id } = data;
       result = await this.$axios.$get(api.columnQuery, {}, { parent_id: parent_id, is_use: '0' });
       result = await this.$axios.$get(api.columnQuery, {}, { parent_id: parent_id, is_use: '0' });
     }
     }

+ 1 - 1
src/store/module.js

@@ -13,7 +13,7 @@ export const actions = {
   async moduleOperation({ state }, { type, data }) {
   async moduleOperation({ state }, { type, data }) {
     let result;
     let result;
     if (type === 'list') {
     if (type === 'list') {
-      result = await this.$axios.$get(api.moduleQuery, {}, { is_use: '0' });
+      result = await this.$axios.$get(api.moduleQuery, {}, { is_use: '0', ...data });
     }
     }
     return result;
     return result;
   },
   },

+ 30 - 0
src/store/news.js

@@ -1,6 +1,7 @@
 import Vue from 'vue';
 import Vue from 'vue';
 import Vuex from 'vuex';
 import Vuex from 'vuex';
 import _ from 'lodash';
 import _ from 'lodash';
+import axios from 'axios';
 
 
 Vue.use(Vuex);
 Vue.use(Vuex);
 const api = {
 const api = {
@@ -11,6 +12,35 @@ const api = {
 export const state = () => ({});
 export const state = () => ({});
 export const mutations = {};
 export const mutations = {};
 export const actions = {
 export const actions = {
+  async getAllNews({ commit, dispatch }, payload) {
+    let toGet = () => {
+      let res = [];
+      for (const item of payload) {
+        let data = {
+          skip: 0,
+          limit: 4,
+        };
+        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('newsOperation', {
+            type: 'list',
+            data,
+          })
+        );
+      }
+      return res;
+    };
+    let result = await axios.all(toGet());
+    //降维
+    let arr = _.flattenDeep(_.flattenDeep(result).map(item => item.data));
+    return arr;
+  },
   // 信息管理
   // 信息管理
   async newsOperation({ state }, { type, data }) {
   async newsOperation({ state }, { type, data }) {
     let { skip, limit } = data;
     let { skip, limit } = data;