/*
 * @Description: axios 封装网络请求
 * @Author: ZY
 * @Date: 2020-12-28 14:45:32
 * @LastEditors: ZY
 * @LastEditTime: 2021-01-25 20:01:32
 */

import {useStore} from '@/store';
import HttpClient, {HttpClientConfig} from 'axios-mapper';
import networkConfig from '@/config/default/net.config';
// @ts-ignore
import {walletSign} from '@/apis/wallet';

const https = async (hasToken: Boolean = true, hasSign: Boolean = false) => {
  var signInfo: any;
  if (hasSign) {
    signInfo = await walletSign();
  }
  const config: HttpClientConfig = {
    baseURL: networkConfig.host,
    headers: {
      token: hasToken ? useStore().state.user.token : '',
      data: hasSign ? signInfo.raw : '',
      sign: hasSign ? signInfo.sign : '',
    }
  };
  return new HttpClient(config);
};

export default https;
