Browse Source

修改分站接口请求方式

lrf402788946 5 years ago
parent
commit
d3f12c67b7
7 changed files with 197 additions and 1751 deletions
  1. 1 0
      src/layout/layout-part/top-menu.vue
  2. 2 2
      src/plugins/var.js
  3. 96 6
      src/store.js
  4. 94 139
      src/views/index/index.vue
  5. 0 1597
      src/views/index/page-one.vue
  6. 1 7
      src/views/jobs/list.vue
  7. 3 0
      vue.config.js

+ 1 - 0
src/layout/layout-part/top-menu.vue

@@ -63,6 +63,7 @@ export default {
     async getMenu() {
       //获取菜单
       let result = await this.menuOperation({ type: 'list', data: { site: this.$site } });
+      console.log(result);
       if (`${result.errcode}` === '0') {
         //获取菜单的栏目
         let allMenu = result.data;

+ 2 - 2
src/plugins/var.js

@@ -9,8 +9,8 @@ const getSiteId = () => {
   if (arr.length > 0) {
     schId = arr[0];
     if (schId === 'smart') schId = 'master';
-    else `${schId}`.includes('localhost') || `${schId}`.includes('127.0.0.1') ? (schId = 'master') : '';
-    sessionStorage.setItem('schId', `${schId}`.includes('localhost') || `${schId}`.includes('127.0.0.1') ? 'master' : schId);
+    else `${schId}`.includes('localhost') || `${schId}`.includes('127.0.0.1') ? (schId = '99991') : '';
+    sessionStorage.setItem('schId', `${schId}`.includes('localhost') || `${schId}`.includes('127.0.0.1') ? '99991' : schId);
   }
   return schId;
 };

+ 96 - 6
src/store.js

@@ -1,6 +1,7 @@
 import Vue from 'vue';
 import Vuex from 'vuex';
 import _ from 'lodash';
+import axios from 'axios';
 
 Vue.use(Vuex);
 const api = {
@@ -113,7 +114,18 @@ export default new Vuex.Store({
       let { skip, limit } = data;
       if (type === 'searchCorp') {
         let { schid, fairid, corpid, status } = data;
-        result = this.$axios.$get(api.fairCorp, {}, { schid: schid, fairid: fairid, corpid: corpid, status: status, skip: skip, limit: limit });
+        result = this.$axios.$get(
+          api.fairCorp,
+          {},
+          {
+            schid: schid,
+            fairid: fairid,
+            corpid: corpid,
+            status: status,
+            skip: skip,
+            limit: limit,
+          }
+        );
       }
       if (type === 'searchJobs') {
         let { id } = data;
@@ -220,7 +232,9 @@ export default new Vuex.Store({
         let { corpid } = data;
         let base = await this.$axios.$get(api.corpBase, { corpid: corpid });
         let info = await this.$axios.$get(api.corpInfo, { corpid: corpid });
-        let identity = await this.$axios.$get(api.corpIdentity, { corpid: corpid });
+        let identity = await this.$axios.$get(api.corpIdentity, {
+          corpid: corpid,
+        });
         result = {
           data: { ...info.data, ...identity.data, ...base.data },
           errcode: `${info.errcode}` === '0' && `${identity.errcode}` === '0' && `${base.errcode}` === '0' ? '0' : '1',
@@ -238,7 +252,17 @@ export default new Vuex.Store({
       }
       if (type === 'list') {
         let { schid, fairid, studid } = data;
-        result = await this.$axios.$get(api.tickets, {}, { schid: schid, fairid: fairid, studid: studid, skip: skip, limit: limit });
+        result = await this.$axios.$get(
+          api.tickets,
+          {},
+          {
+            schid: schid,
+            fairid: fairid,
+            studid: studid,
+            skip: skip,
+            limit: limit,
+          }
+        );
       }
       if (type === 'search') {
         let { id } = data;
@@ -276,7 +300,15 @@ export default new Vuex.Store({
         result = await this.$axios.$get(
           api.letters,
           {},
-          { post_id: post_id, resume_id: resume_id, status: status, corpname: corpname, studname: studname, skip: skip, limit: limit }
+          {
+            post_id: post_id,
+            resume_id: resume_id,
+            status: status,
+            corpname: corpname,
+            studname: studname,
+            skip: skip,
+            limit: limit,
+          }
         );
       }
       if (type === 'apply') {
@@ -381,7 +413,6 @@ export default new Vuex.Store({
       let { skip, limit } = data;
       let result;
       if (type === 'list') {
-        //TODO
         let { parent_id, site } = data;
         result = await this.$axios.$get(api.columnQuery, {}, { parent_id: parent_id, is_use: '0' });
       }
@@ -404,7 +435,15 @@ export default new Vuex.Store({
         result = await this.$axios.$get(
           api.stucorplist,
           {},
-          { corpid: corpid, corpname: corpname, studid: studid, studname: studname, studschool: studschool, skip: skip, limit: limit }
+          {
+            corpid: corpid,
+            corpname: corpname,
+            studid: studid,
+            studname: studname,
+            studschool: studschool,
+            skip: skip,
+            limit: limit,
+          }
         );
       }
       if (type === 'search') {
@@ -435,6 +474,57 @@ export default new Vuex.Store({
       let result = await this.$axios.$get(api.getCorps, {}, { status: '已认证', skip: 0, limit: 8 });
       return result;
     },
+
+    //批量查询栏目
+    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 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('newsOperation', {
+              type: 'list',
+              data,
+            })
+          );
+        }
+        return res;
+      };
+      console.log('in function:');
+      let result = await axios.all(toGet());
+      //降维
+      let arr = _.flattenDeep(_.flattenDeep(result).map(item => item.data));
+      return arr;
+    },
   },
 });
 

+ 94 - 139
src/views/index/index.vue

@@ -1,7 +1,6 @@
 <template>
   <div id="request">
     <el-row>
-      <!-- v-if="user !== 'master'" -->
       <pages-one
         v-if="!loading"
         :topInfo="site"
@@ -25,39 +24,6 @@
         </template>
       </pages-one>
     </el-row>
-    <!-- <el-row v-else>
-      <master
-        v-if="!loading"
-        :topinfo="site"
-        :menulist="menu"
-        :bannerinfo="master.bannerinfo"
-        :newsList="news.infoList"
-        :noticeinfo="master.noticeinfo"
-        :noticelist="notice.infoList"
-        :huodonginfo="master.jobsinfo"
-        :fairsList="jobfairList"
-        :talksList="talksOutList"
-        :infoList="jobinfoList"
-        :recruitList="self1List"
-        :otherList="self2List"
-        :fasttop="master.fasttop"
-        :fastlist="master.fastlist"
-        :contactinfo="master.contactinfo"
-        :content="site.content"
-        :companytop="master.companytop"
-        :companylist="corpList"
-        :unittop="master.unittop"
-        :unitlist="coopList"
-        :footinfo="site"
-        :floating="floating"
-        :rilitop="master.rilitop"
-        :rightInfo="master.rightInfo"
-      >
-        <template #rili>
-          <self-calendars></self-calendars>
-        </template>
-      </master>
-    </el-row> -->
   </div>
 </template>
 
@@ -69,8 +35,6 @@ import topMenu from '@/layout/layout-part/top-menu.vue';
 import selfCalendar from '@/components/self-calendar.vue';
 import selfCalendars from '@/components/self-calendars.vue';
 import pagesOne from '@publics/src/views/index.vue';
-//master部分
-import { masterInfo } from '@/config/master-info';
 import { mapActions, mapState } from 'vuex';
 export default {
   name: 'request',
@@ -80,7 +44,6 @@ export default {
     topMenu,
     selfCalendar,
     // selfCalendars,
-    // master,
   },
   data: () => ({
     user: 'master',
@@ -90,7 +53,6 @@ export default {
     jobs: jobMenu,
     loading: true,
     limit: 4,
-    newList: [],
     talksList: [],
     jobfairList: [],
     talksOutList: [],
@@ -103,10 +65,9 @@ export default {
     self2List: [],
     coopList: [],
     linkList: [],
-    //master数据
-    master: { ...masterInfo },
-    corpList: [],
     siteTitle: '',
+    // 重写逻辑
+    modules: [],
   }),
   metaInfo() {
     return {
@@ -117,10 +78,9 @@ export default {
     await this.checkUser();
     await this.getSite();
     this.search();
-    this.getModule();
     this.getLink();
-    if (this.user === 'master') this.masterData();
     await this.getMenu();
+    this.loadModule();
     this.$set(this, `loading`, false);
   },
   computed: {},
@@ -135,7 +95,8 @@ export default {
       'columnOperation',
       'linkOperation',
       'menuOperation',
-      'corpListOperation',
+      'getAllColumn',
+      'getAllNews',
     ]),
     //检查用户身份
     checkUser() {
@@ -165,7 +126,6 @@ export default {
           this.$set(this, `siteTitle`, this.site.name);
         }
       } else {
-        console.log(JSON.parse(site));
         this.$set(this, `site`, JSON.parse(site));
         this.$set(this, `siteTitle`, this.site.name);
         let arr = this.site;
@@ -215,92 +175,6 @@ export default {
         this.$message.error(result.errmsg ? result.errmsg : 'error');
       }
     },
-    //获取固定的4个模块
-    async getModule() {
-      //获取分站所有模块 TODO:site=>_tenant
-      let result = await this.moduleOperation({ type: 'list' });
-      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);
-        }
-      }
-    },
-    //根据条件获取栏目
-    async getColumn(item) {
-      let res = await this.columnOperation({ type: 'list', data: { parent_id: item.id } });
-      //查詢模块下所有的栏目(因为修改关联方是:抓取栏目和正常栏目关联,栏目类型(type)为bugList.所以bugList需要用content_id再去查下面关联的信息
-      if (`${res.errcode}` === '0') {
-        for (const col of res.data) {
-          if (col.type === 'bugList') {
-            col.path = `/info/list/${col.content_id}`;
-            col.children = await this.getNewsList(col, '0');
-          } else if (col.type === 'column') {
-            col.path = `/info/list/${col.id}`;
-            col.children = await this.getNewsList(col, '1');
-          } else if (col.type === 'content') {
-            col.path = `/info/detail?id=${col.content_id}`;
-          }
-        }
-        item.children = res.data;
-      }
-      return item;
-    },
-    //根据条件获取信息
-    async getNewsList(item, news_type) {
-      let data = { skip: 0, limit: 6, news_type: news_type };
-      data.parent_id = item.type === 'bugList' ? item.content_id : item.id;
-      let res = await this.newsOperation({ type: 'list', data: data });
-      if (`${res.errcode}` === '0') {
-        for (const val of res.data) {
-          let result = await this.newsOperation({ type: 'search', data: { id: val.id } });
-          if (`${result.errcode}` === '0') {
-            val.content = result.data.content;
-          } else {
-            this.$message.error(result.errmsg ? result.errmsg : 'error');
-          }
-        }
-        return res.data;
-      } else {
-        this.$message.error(res.errmsg ? res.errmsg : 'error');
-      }
-    },
-    //组合数据
-    makeList(item) {
-      if (!item) return;
-      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 };
-        this.$set(this, `news`, 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 };
-        // console.log(object);
-        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);
-      }
-    },
     //友情链接/合作单位
     async getLink() {
       //合作单位
@@ -314,6 +188,7 @@ export default {
         this.$set(this, `linkList`, link.data);
       }
     },
+
     //检查+读取菜单
     async loadMenu() {
       let menu = sessionStorage.getItem('menu');
@@ -364,14 +239,94 @@ export default {
         return res.data;
       }
     },
-    //主站信息组合
-    async masterData() {
-      this.$set(this.master, `bannerinfo`, { banner: this.site.banner });
-      //获取入驻企业
-      let result = await this.corpListOperation();
-      // console.log(result);
-      if (`${result.errcode}` === '0') {
-        this.$set(this, `corpList`, result.data);
+
+    //模块
+    async loadModule() {
+      let modules = sessionStorage.getItem('modules');
+      if (modules) this.finishedModule(JSON.parse(modules));
+      else this.toGetModule();
+    },
+    async toGetModule() {
+      let result = await this.moduleOperation({ type: `list` });
+      if (result.errcode === 0) {
+        sessionStorage.setItem('modules', JSON.stringify(result.data));
+        this.finishedModule(result.data);
+      }
+    },
+    async finishedModule(mods) {
+      let modules = JSON.parse(JSON.stringify(mods));
+      //获取了所有栏目
+      let res = await this.completeAllModules(modules);
+    },
+    //合并请求模块
+    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 = `/info/list/${item.id}`;
+          else if (item.type === 'bugList') {
+            item.path = `/info/list/${item.content_id}`;
+          } else if (item.type === 'content') {
+            item.path = `/info/detail?id=${item.content_id}`;
+          }
+          return item;
+        });
+        //请求信息
+        let res = await this.getAllNews(result);
+        //合并栏目和信息
+        result = result.map(item => {
+          let newsList = res.filter(fil => {
+            let fid = item.type === 'bugList' ? item.content_id : item.id;
+            return fil.parent_id === fid;
+          });
+          item.children = newsList;
+          return item;
+        });
+        modules = modules.map(item => {
+          let children = result.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');
+          }
+          this.makeList(item);
+          return item;
+        });
+      }
+    },
+    makeList(mod) {
+      console.log(mod);
+      if (mod.category === 'news') {
+        let arr = [];
+        let colObject = {};
+        for (const col of mod.children) {
+          if (!colObject.id) colObject = col;
+          for (const news of col.children) {
+            arr.push(news);
+          }
+        }
+        let object = { ...JSON.parse(JSON.stringify(mod)), infoList: arr, column: colObject };
+        this.$set(this, `news`, object);
+      } else if (mod.category === 'notice') {
+        let arr = [];
+        let colObject = {};
+        for (const col of mod.children) {
+          if (!colObject.id) colObject = col;
+          for (const news of col.children) {
+            arr.push(news);
+          }
+        }
+        let object = { ...JSON.parse(JSON.stringify(mod)), infoList: arr, column: colObject };
+        this.$set(this, `notice`, object);
+      } else if (mod.category === 'self1') {
+        this.$set(this, `self1List`, mod.children);
+      } else if (mod.category === 'self2') {
+        this.$set(this, `self2List`, mod.children);
       }
     },
   },

File diff suppressed because it is too large
+ 0 - 1597
src/views/index/page-one.vue


+ 1 - 7
src/views/jobs/list.vue

@@ -95,13 +95,7 @@ export default {
     currentPage: 1,
     totalRow: 0,
     list: [],
-    filter: [
-      
-     ,
-    
-      { label: '职位名称', name: 'job_name' },
-      { label: '企业名称', name: 'corpname' },
-    ],
+    filter: [{ label: '职位名称', name: 'job_name' }, { label: '企业名称', name: 'corpname' }],
     loading: false,
   }),
   created() {

+ 3 - 0
vue.config.js

@@ -22,6 +22,9 @@ module.exports = {
       '/api': {
         target: 'http://smart.cc-lotus.info',
         ws: true,
+        onProxyReq(proxyReq, req, res) {
+          proxyReq.setHeader('x-tenant', '99991');
+        },
       },
       '/test': {
         target: 'http://10.16.11.186:8103',