utils.js 2.6 KB
Newer Older
徐立's avatar
徐立 committed
1
/* eslint no-useless-escape:0 import/prefer-default-export:0 */
钟是志's avatar
钟是志 committed
2
import { Modal, Popconfirm, message } from 'antd';
钟是志's avatar
钟是志 committed
3
import { uaaRequest } from '@/webPublic/one_stop_public/utils/request';
4
import { getTime } from '@/webPublic/zyd_public/utils/queryCurrent';
5 6
import { getUrlInfo } from '@/webPublic/one_stop_public/DetailForAudit/utils';
import { getUiaInfo } from '@/webPublic/one_stop_public/2023yunshangguizhou/request2.0';
7 8
import { getToken } from '@/webPublic/one_stop_public/utils/token';

9

徐立's avatar
徐立 committed
10 11
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;

12
const isUrl = (path) => reg.test(path);
徐立's avatar
徐立 committed
13 14

const isAntDesignPro = () => {
钟是志's avatar
1  
钟是志 committed
15 16 17
	if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
		return true;
	}
徐立's avatar
徐立 committed
18

钟是志's avatar
1  
钟是志 committed
19
	return window.location.hostname === 'preview.pro.ant.design';
徐立's avatar
徐立 committed
20 21 22
}; // 给官方演示站点用,用于关闭真实开发环境不需要使用的特性

const isAntDesignProOrDev = () => {
钟是志's avatar
1  
钟是志 committed
23
	const { NODE_ENV } = process.env;
徐立's avatar
徐立 committed
24

钟是志's avatar
1  
钟是志 committed
25 26 27
	if (NODE_ENV === 'development') {
		return true;
	}
徐立's avatar
徐立 committed
28

钟是志's avatar
1  
钟是志 committed
29
	return isAntDesignPro();
徐立's avatar
徐立 committed
30 31
};

32
export { isAntDesignProOrDev, isAntDesignPro, isUrl };
徐立's avatar
徐立 committed
33

34
export const dispatch = (type, payload, callback) => {
钟是志's avatar
1  
钟是志 committed
35 36 37 38 39
	window.g_app._store.dispatch({
		type,
		payload,
		callback,
	});
徐立's avatar
徐立 committed
40
};
钟是志's avatar
钟是志 committed
41

钟是志's avatar
1  
钟是志 committed
42 43 44 45 46 47 48 49
export const isFromIframe = () => {
	// 判断是否来自iframe 嵌入页面 暂时放弃使用
	return false;
	let isFromIframe = window.frames.length !== parent.frames.length;
	if (window.location.origin.indexOf('localhost') > -1) {
		return false;
	}
	return isFromIframe;
钟是志's avatar
钟是志 committed
50
};
51

52
export const getModal = () => {
钟是志's avatar
1  
钟是志 committed
53
	return isFromIframe() ? window?.parent?.iframeParentComponent?.Modal : Modal;
54
};
55 56

export const getPopconfirm = () => {
钟是志's avatar
1  
钟是志 committed
57
	return isFromIframe() ? window?.parent?.iframeParentComponent?.Popconfirm : Popconfirm;
58 59 60
};

export const getMessage = () => {
钟是志's avatar
1  
钟是志 committed
61
	return isFromIframe() ? window?.parent?.iframeParentComponent?.message : message;
62
};
钟是志's avatar
钟是志 committed
63 64

export const getOneStopMyInfo = (params = {}) => {
65 66 67 68 69 70 71 72 73 74 75 76 77 78
  let urlInfo = getUrlInfo();
  if(urlInfo.tenantCode){ // 如果是sass 系统 存在租户 则调用2.0的接口获取
    getUiaInfo({}, '/userApi/getMyInfo').then((res) => {
      if(res){
        localStorage.setItem('user', JSON.stringify(res));
      }
    })
  }else{
    return uaaRequest('/UserApi/getMy', params).then((res) => {
      if (res) {
        if (!res.groupsId) {
          res.groupsId = 'pub';
        }
        res.differenceBetweenServerAndClientTime = -50;
79
        res.token = getToken();
80 81 82 83 84 85 86 87
        localStorage.setItem('user', JSON.stringify(res));
        return res;
      }
    });
  }



钟是志's avatar
钟是志 committed
88
};