channel.js 1.36 KB
import * as Types from './types';
import { get, set } from 'lodash';
import { getImgUrl } from '../../common/utils';

export default function() {
  return {
    namespaced: true,
    state: {
      channelData: [],
    },
    mutations: {
      [Types.FETCH_CHANNEL](state, { list }) {
        state.channelData = list;
      },
    },
    actions: {
      async fetchChannelList({ commit }) {
        const result = await this.$api.get('/api/ufo/channel/channelList', {
          content_code: '9cb6138be8e60c96f48107da481816c3',
          uid: '64668089',
        });
        if (result.code === 200) {
          result.data.map(res => {
            // 焦点图
            if(res.template_name === 'focus') {
              for (let i = 0; i < res.data.length; i++) {
                let url = "https:" + getImgUrl(get(res.data[i], "src") || '', 750, 200);
                set(res.data[i], "src", url);
              }
            }
            // 热门系列
            if(res.template_name === 'hotSeries') {
              for (let i = 0; i < res.data.length; i++) {
                let url = "https:" + getImgUrl(get(res.data[i], "image_url") || '', 100, 80);
                set(res.data[i], "image_url", url);
              }
            }
          })
          console.log(result.data);
          commit(Types.FETCH_CHANNEL, { list: result.data });
        }
      }
    },
  };
}