actions.js 5.63 KB
import * as Types from './types';

export default {
  async fetchEshops({commit}) {
    commit(Types.FETCH_ESHOPS_REQUEST);
    const result = await this.$api.get('/getAuthAppList', {
      page: 1,
      limit: 100
    });

    if (result && result.code === 200) {
      commit(Types.FETCH_ESHOPS_SUCCESS, result);
    } else {
      commit(Types.FETCH_ESHOPS_FAILD, { message: result && result.message });
    }
  },
  async fetchAuthUrl() {
    return await this.$api.get('/getAuthUrl?appId=123&type=1');
  },
  async fetchToken() {
    const result = await this.$api.get('/getComponentAccessToken');

    if (result && result.code === 200) {
      return result.data;
    }
  },
  async fetchShopToken(action, {appid}) {
    const result = await this.$api.get('/getAuthorizerAccessToken', {
      authAppId: appid
    });

    if (result && result.code === 200) {
      return result.data;
    }
  },
  async fetchWxGetDraftList({dispatch}) {
    const token = await dispatch('fetchToken');

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/gettemplatedraftlist?access_token=${token}`
    });
  },
  async fetchWxAddToTemplate({dispatch}, {draft_id}) {
    const token = await dispatch('fetchToken');

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/addtotemplate?access_token=${token}`,
      method: 'post',
      params: {
        draft_id
      }
    });
  },
  async fetchWxCommit({dispatch}, payload) {
    const token = await dispatch('fetchShopToken', {appid: payload.authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/commit?access_token=${token}`,
      method: 'post',
      params: {
        template_id: payload.template,
        ext_json: JSON.stringify({
          extAppid: payload.authAppId,
          ext: {
            extAppid: payload.authAppId,
            miniappType: payload.miniappType,
            miniappName: payload.authAppName
          }
        }),
        user_version: payload.version,
        user_desc: payload.desc,
      }
    });
  },
  async fetchWxSend({dispatch}, {authAppId}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/get_category?access_token=${token}`
    });
  },
  async fetchWxAuditStatus({dispatch}, {authAppId}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/get_latest_auditstatus?access_token=${token}`
    });
  },
  async fetchWxGetVersion({dispatch}, {authAppId}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      method: 'post',
      url: `/cgi-bin/wxopen/getweappsupportversion?access_token=${token}`,
      params: {}
    });
  },
  async fetchWxGetCategory({dispatch}, {authAppId}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/get_category?access_token=${token}`
    });
  },
  async fetchWxGetQrcode({dispatch}, {authAppId}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/get_qrcode?access_token=${token}`
    }, {
      responseType: 'blob'
    });
  },
  async fetchWxGetPage({dispatch}, {authAppId}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/get_page?access_token=${token}`
    });
  },
  async fetchWxGetTemplateList({dispatch}) {
    const token = await dispatch('fetchToken');

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/gettemplatelist?access_token=${token}`
    });
  },
  async fetchWxBindTester({dispatch}, {authAppId, wechatid}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/bind_tester?access_token=${token}`,
      method: 'post',
      params: {
        wechatid
      }
    });
  },
  async fetchWxSubmitAudit({dispatch}, {authAppId, item}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/submit_audit?access_token=${token}`,
      method: 'post',
      params: {
        item_list: [item]
      }
    });
  },
  async modifyDomains({dispatch}, {authAppId}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/modify_domain?access_token=${token}`,
      method: 'post',
      params: {
        action: 'set',
        requestdomain: [
          'https://api.yoho.cn',
          'https://analysis.yohobuy.com'
        ],
        downloaddomain: [
          'https://api.yoho.cn',
          'https://cdn.yoho.cn',
          'https://www.fapiao.com'
        ]
      }
    });
  },
  async setWebviewDomains({dispatch}, {authAppId}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/setwebviewdomain?access_token=${token}`,
      method: 'post',
      params: {
        action: 'set',
        webviewdomain: [
          'https://m.yohobuy.com',
          'https://union.yoho.cn',
          'https://ad.yoho.cn',
          'https://activity.yoho.cn',
          'https://action.yoho.cn',
          'https://feature.yoho.cn'
        ]
      }
    });
  },
  async fetchWxRelease({dispatch}, {authAppId}) {
    const token = await dispatch('fetchShopToken', {appid: authAppId});

    return await this.$nodeApi.post('/wx', {
      url: `/wxa/release?access_token=${token}`,
      method: 'post',
      params: {}
    });
  }
};