import { getToken } from '@/webPublic/one_stop_public/utils/getToken';
import { getUserInfo } from '@/webPublic/one_stop_public/utils/token';

export function isJSON(str) {
	if (typeof str == 'string') {
		try {
			JSON.parse(str);
			if (typeof JSON.parse(str) === 'number') {
				return false;
			}
			return true;
		} catch (e) {
			return false;
		}
	}
}

export const getSysCode = () => {
  return getYunShangGuiZhouSyStemConfig().sysCode;
};

// 查询系统配置
export const getYunShangGuiZhouSyStemConfig = () => {
	const localStorageData = localStorage.getItem('antd-pro-systemConfig');
	if (localStorageData && isJSON(localStorageData)) {
		let d = JSON.parse(localStorageData);
		return {
			sysCode: d.code,
			logo: '',
			name: d.name,
			siteId: '5',
			siteUrl: '',
		};
	} else {
		return {
			sysCode: undefined,
			name: '',
		};
	}
};

export const getSassApiHeader = () => {
  // 解决禅道 34246 在学工、素质测评、宿管、离校的所有接口中增加请求头
  return {
    Authorization: `bearer ${getToken()}`,
    sysCode: getSysCode(),
    tenant: getUserInfo().tenantCode || null,
  };
};
