import { getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils';
import { getToken } from '@/webPublic/one_stop_public/utils/token';
import config from '@/config/config';
import { getInfo, transformApi } from '@/highOrderComponent/Service';
import urlTransform from '@/webPublic/zyd_public/request/urlTransform';
export function hrefWithToken(url) {
  if (!getIsBei_Dian()) {
    if (url.indexOf('?') > -1) {
      url = `${url}&token=${getToken()}`;
    } else {
      url = `${url}?token=${getToken()}`;
    }
  }
  const hrefUrl = transformApi(url);
  let u = `${hrefUrl}${url}`;
  u = urlTransform(u);
  if(u && u.indexOf('v1/api/zydsgWeb')){
    getInfo({}, u, {
      method: 'GET',
    });
    return;
  }
  console.log('hrefWithToken', u);

  getInfo({}, '/InstructorConfigApi/getCurrentDate')
    .then((response) => {
      // const hrefUrl = transformApi(url);
      // let u = `${hrefUrl}${url}`;
      // u = urlTransform(u);
      if (response) {
        window.open(`${u}`); // 存在问题 浏览器会自动切换内核到IE 内核导致 文件名称乱码.
        return true;
      } else {
        return false;
      }
    });
}

export function hrefWithTokenSg(url) {
  if (!getIsBei_Dian()) {
    if (url.indexOf('?') > -1) {
      url = `${url}&token=${getToken()}`;
    } else {
      url = `${url}?token=${getToken()}`;
    }
  }

  getInfo({}, '/InstructorConfigApi/getCurrentDate')
    .then((response) => {
      const hrefUrl = `${config.mockServer}/${config.gateWayUrl.zydsg}`;
      if (response) {
        let u = `${hrefUrl}${url}`;
        u = urlTransform(u);
        window.open(u); // 存在问题 浏览器会自动切换内核到IE 内核导致 文件名称乱码.
        return true;
      } else {
        return false;
      }
    });
}
