فهرست منبع

Merge branch 'master' of http://git.cc-lotus.info/echoFan/web-test

echoFan 4 سال پیش
والد
کامیت
f084117a8c
5فایلهای تغییر یافته به همراه142 افزوده شده و 5 حذف شده
  1. 38 0
      src/store/column.js
  2. 8 2
      src/store/index.js
  3. 15 0
      src/store/module.js
  4. 55 0
      src/store/news.js
  5. 26 3
      src/views/index0.vue

+ 38 - 0
src/store/column.js

@@ -0,0 +1,38 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import axios from 'axios';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  list: `/api/cms/column/list`,
+  fetch: id => `/api/cms/column/fetch/${id}`,
+};
+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`) {
+      result = await this.$axios.$get(api.list, { ...data, is_use: '0' });
+    } else {
+      let { id } = data;
+      result = await this.$axios.$get(api.fetch(id));
+    }
+
+    return result;
+  },
+};

+ 8 - 2
src/store/index.js

@@ -1,11 +1,17 @@
 import Vue from 'vue';
 import Vuex from 'vuex';
-
+import * as news from './news';
+import * as column from './column';
+import * as module from './module';
 Vue.use(Vuex);
 
 export default new Vuex.Store({
   state: {},
   mutations: {},
   actions: {},
-  modules: {},
+  modules: {
+    news,
+    column,
+    module,
+  },
 });

+ 15 - 0
src/store/module.js

@@ -0,0 +1,15 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  list: `/api/cms/modules/list`,
+};
+export const state = () => ({});
+export const mutations = {};
+export const actions = {
+  async getModule({ commit }, { type, data }) {
+    let result = await this.$axios.$get(_.get(api, type), { ...data, is_use: '0' });
+    return result;
+  },
+};

+ 55 - 0
src/store/news.js

@@ -0,0 +1,55 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import axios from 'axios';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  list: `/api/cms/news/list`,
+  fetch: id => `/api/cms/news/fetch/${id}`,
+  bugList: `/api/cms/newscreeper/list`,
+};
+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,
+        };
+        if (item.parent != '图片新闻') data.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') {
+      result = await this.$axios.$get(api.bugList, { ...data, is_use: '0' });
+    } else {
+      let { id } = data;
+      result = await this.$axios.$get(api.fetch(id));
+    }
+
+    return result;
+  },
+};

+ 26 - 3
src/views/index0.vue

@@ -159,7 +159,7 @@
 </template>
 
 <script>
-import { mapState, createNamespacedHelpers } from 'vuex';
+import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
 export default {
   name: 'index',
   props: {},
@@ -272,10 +272,33 @@ export default {
         content: '办公地址:长春市经济技术开发区金川街151号,吉林省高等学校毕业生就业指导中心2楼一站式办公大厅,邮编:130033。',
         sydw: require('@a/sydw.png'),
       },
+      modules: [],
     };
   },
-  created() {},
-  methods: {},
+  created() {
+    this.searchinfo();
+  },
+  methods: {
+    ...mapActions(['getAllNews', 'getAllColumn', 'getModule']),
+    async searchinfo() {
+      let arr = await this.getModule({ type: `list` });
+      sessionStorage.setItem('modules', JSON.stringify(arr.data));
+      this.$set(this, `modules`, arr.data);
+      let ids = this.modules.map(item => item.id);
+      let result = await this.getAllColumn(ids);
+      console.log(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 val = await this.getAllNews(result);
+        console.log(val);
+      }
+    },
+  },
   computed: {
     ...mapState(['user']),
     pageTitle() {