1070 lines
38 KiB
JavaScript
1070 lines
38 KiB
JavaScript
|
|
window.onerror = function (msg, url, line, col, error) {
|
|||
|
|
if (/webpackJsonp/.test(msg) || /ERR_CONTENT_LENGTH_MISMATCH/.test(msg)) {
|
|||
|
|
if ((parseInt(window.localStorage['reloadTimes']) || 0) >= 3) {
|
|||
|
|
window.localStorage['reloadTimes'] = 0
|
|||
|
|
window.console && window.console.error('reload fail over 3 times');
|
|||
|
|
} else {
|
|||
|
|
window.localStorage['reloadTimes'] = (parseInt(window.localStorage['reloadTimes']) || 0) + 1;
|
|||
|
|
window.location.reload(true);
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
window.localStorage['emDebug'] && alert(JSON.stringify(arguments))
|
|||
|
|
}
|
|||
|
|
if (window.em && (typeof window.em.checkJsApi === 'function') && (typeof window.em.invoke === 'function') && window.em.checkJsApi('saveLog')) {
|
|||
|
|
const jsErrorInfo = {
|
|||
|
|
type: 'js',
|
|||
|
|
message: msg, // 报错信息
|
|||
|
|
fileName: url || '', // 文件名
|
|||
|
|
lineNumber: line || 0, // js报错文件的行号
|
|||
|
|
colNumber: col || 0, // js报错文件的列好
|
|||
|
|
stack: error && error.stack ? error.stack : '', // 堆栈
|
|||
|
|
}
|
|||
|
|
window.em.invoke('saveLog', {
|
|||
|
|
message: JSON.stringify(jsErrorInfo)
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
(function () {
|
|||
|
|
var getJSONObj = function (key) {
|
|||
|
|
if (!window.localStorage[key]) {
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
try {
|
|||
|
|
return JSON.parse(window.localStorage[key]);
|
|||
|
|
} catch (e) {
|
|||
|
|
return {};
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
var getFd = function (values) {
|
|||
|
|
var fd = '';
|
|||
|
|
for (var p in values) {
|
|||
|
|
if (values.hasOwnProperty(p)) {
|
|||
|
|
var target = values[p];
|
|||
|
|
target = target === void 0 ? '' : target;
|
|||
|
|
var item = encodeURIComponent(target);
|
|||
|
|
fd += p + '=' + item + '&';
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return fd;
|
|||
|
|
}.bind(this);
|
|||
|
|
|
|||
|
|
var checkReject = function (obj) {
|
|||
|
|
var isFalse = false;
|
|||
|
|
if (obj.errorCode && obj.errorCode === '001') { // session异常
|
|||
|
|
console && console.log('session过期');
|
|||
|
|
isFalse = true;
|
|||
|
|
} else if (obj.errorCode && obj.errorCode === '002') { // session异常
|
|||
|
|
console && console.log('登陆超时');
|
|||
|
|
isFalse = true;
|
|||
|
|
} else if (typeof obj.status !== 'undefined' && (!obj.status || obj.status === 'false')) {
|
|||
|
|
console && console.log(JSON.stringify(obj));
|
|||
|
|
isFalse = true;
|
|||
|
|
}
|
|||
|
|
return isFalse;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
var callApi = function (options) {
|
|||
|
|
var url = options.url || '';
|
|||
|
|
var method = options.method || 'GET';
|
|||
|
|
var params = options.params || {};
|
|||
|
|
var type = options.type || 'json';
|
|||
|
|
var includeCredentials = options.includeCredentials !== false ? true : false;
|
|||
|
|
var useJson = options.useJson || false;
|
|||
|
|
var _url = url;
|
|||
|
|
var server = window.server || '';
|
|||
|
|
|
|||
|
|
var ua = window.navigator.userAgent;
|
|||
|
|
var inMobile = (/.*E-Mobile7.*/.test(ua) ||
|
|||
|
|
/.*E-Mobile\/7.*/.test(ua) ||
|
|||
|
|
/.*e-mobile\/7.*/.test(ua) ||
|
|||
|
|
/.*wxwork.*/.test(ua) ||
|
|||
|
|
/.*DingTalk.*/.test(ua) ||
|
|||
|
|
/.*TaurusApp.*/.test(ua) ||
|
|||
|
|
/Qing\/.*;(iOS|iPhone|Android).*/.test(ua) ||
|
|||
|
|
/.*e-mobile-xp.*/.test(ua) ||
|
|||
|
|
/.*HuaWei-AnyOffice.*/.test(ua) ||
|
|||
|
|
/.*Lark.*/.test(ua) ||
|
|||
|
|
/.*QYZone_.*/.test(ua)
|
|||
|
|
)
|
|||
|
|
var uajugde = ua.indexOf('Mobi') > -1 || ua.indexOf('iPh') > -1 || ua.indexOf('480') > -1
|
|||
|
|
if (inMobile || uajugde) {
|
|||
|
|
params._ec_ismobile = true;
|
|||
|
|
// params._ec_browser = ua.browser;
|
|||
|
|
// params._ec_browserVersion = ua.version;
|
|||
|
|
// params._ec_os = ua.os;
|
|||
|
|
// params._ec_osVersion = ua.osVersion;
|
|||
|
|
params.ismobile = 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (/\?/.test(_url)) {
|
|||
|
|
var urlParams = getFrameParams(_url);
|
|||
|
|
_url = _url.slice(0, _url.indexOf('?'))
|
|||
|
|
// params = Object.assign({}, params, urlParams);
|
|||
|
|
for (var key in urlParams) {
|
|||
|
|
if (urlParams.hasOwnProperty(key)) {
|
|||
|
|
var element = urlParams[key];
|
|||
|
|
params[key] = element;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (getJSONObj('customSessionKey')) {
|
|||
|
|
var customSessionKey = getJSONObj('customSessionKey');
|
|||
|
|
params[customSessionKey.keyName] = customSessionKey.keyValue;
|
|||
|
|
}
|
|||
|
|
if (window.wm_test_accesskey) {
|
|||
|
|
params['wm_test_accesskey'] = window.wm_test_accesskey;
|
|||
|
|
}
|
|||
|
|
_url = server + _url;
|
|||
|
|
|
|||
|
|
var reg = new RegExp("^" + window.ecologyContentPath + "");
|
|||
|
|
_url = reg.test(_url) ? _url : (window.ecologyContentPath || "") + _url;
|
|||
|
|
|
|||
|
|
if (method.toUpperCase() === 'GET' && Object.keys(params).length > 0) {
|
|||
|
|
var c = '?';
|
|||
|
|
if (/\?/.test(_url)) {
|
|||
|
|
c = '&';
|
|||
|
|
}
|
|||
|
|
_url = _url + c + getFd(params);
|
|||
|
|
}
|
|||
|
|
if (method.toUpperCase() === 'GET' && !/__random__/.test(_url)) {
|
|||
|
|
var c = '?';
|
|||
|
|
if (/\?/.test(_url)) {
|
|||
|
|
c = '&';
|
|||
|
|
}
|
|||
|
|
_url += c + '__random__=' + new Date().getTime();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function evil(fn) {
|
|||
|
|
var Fn = Function; // 一个变量指向Function,防止有些前端编译工具报错
|
|||
|
|
return new Fn('return ' + fn)();
|
|||
|
|
}
|
|||
|
|
var fetchParams = {};
|
|||
|
|
if (window.e9ssoMobileConfig && window.e9ssoMobileConfig.inUse && window.e9ssoMobileConfig.callapi_params_handler) {
|
|||
|
|
var res = window.e9ssoMobileConfig.callapi_params_handler(_url, method, params, includeCredentials, useJson, fetchParams);
|
|||
|
|
_url = res.url;
|
|||
|
|
method = res.method;
|
|||
|
|
params = res.params;
|
|||
|
|
includeCredentials = res.includeCredentials;
|
|||
|
|
useJson = res.useJson;
|
|||
|
|
fetchParams = res.fetchParams || {}
|
|||
|
|
}
|
|||
|
|
return new Promise(function (resolve, reject) {
|
|||
|
|
var xhr = new XMLHttpRequest();
|
|||
|
|
xhr.open(method.toUpperCase(), _url, true);
|
|||
|
|
if (useJson === true) {
|
|||
|
|
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
|
|||
|
|
} else {
|
|||
|
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
|
|||
|
|
}
|
|||
|
|
if (fetchParams.headers && fetchParams.headers.encryptKey) {
|
|||
|
|
xhr.setRequestHeader("encryptKey", fetchParams.headers.encryptKey);
|
|||
|
|
}
|
|||
|
|
if (window.localStorage['m_access_token'] &&
|
|||
|
|
(
|
|||
|
|
!/\/api\/system\/info\/getOSinfo/.test(_url) &&
|
|||
|
|
!/\/api\/hrm\/classifiedProtection\/getClassificationInfo4Component/.test(_url)
|
|||
|
|
)
|
|||
|
|
) {
|
|||
|
|
if (!/\/spa\/portal\/static4mobilelogin\/index\.html#\/login/.test(window.location.href)) {
|
|||
|
|
if (window.localStorage['mobileTokenName']) {
|
|||
|
|
xhr.setRequestHeader(window.localStorage['mobileTokenName'], window.localStorage['m_access_token']);
|
|||
|
|
params[window.localStorage['mobileTokenName']] = window.localStorage['m_access_token']
|
|||
|
|
} else {
|
|||
|
|
xhr.setRequestHeader("mobiletoken", window.localStorage['m_access_token']);
|
|||
|
|
params['mobiletoken'] = window.localStorage['m_access_token']
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (window.localStorage.emToken) {
|
|||
|
|
window.localStorage.removeItem('ecemtoken')
|
|||
|
|
}
|
|||
|
|
xhr.withCredentials = includeCredentials;
|
|||
|
|
xhr.onreadystatechange = function () {
|
|||
|
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
|||
|
|
var data = xhr.responseText;
|
|||
|
|
if (window.e9ssoMobileConfig && window.e9ssoMobileConfig.inUse && window.e9ssoMobileConfig.callapi_response_handler) {
|
|||
|
|
data = window.e9ssoMobileConfig.callapi_response_handler(data, reject, xhr.response);
|
|||
|
|
}
|
|||
|
|
if (type === 'json' && typeof (data) === 'string') {
|
|||
|
|
try {
|
|||
|
|
data = JSON.parse(data);
|
|||
|
|
} catch (error) {
|
|||
|
|
data = data || '{}';
|
|||
|
|
data = evil('(' + data + ')'); // JSON.parse 解析反斜杠报错处理
|
|||
|
|
// alert('fetch 数据处理异常: ' + error);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (data.code == 10002) {
|
|||
|
|
resolve(data)
|
|||
|
|
}
|
|||
|
|
if (data.code == 401 && window.localStorage['m_refresh_token']) {
|
|||
|
|
callApi({
|
|||
|
|
url: '/api/ec/dev/app/refreshToken',
|
|||
|
|
method: 'POST',
|
|||
|
|
params: {
|
|||
|
|
m_refresh_token: window.localStorage['m_refresh_token']
|
|||
|
|
},
|
|||
|
|
type: 'json',
|
|||
|
|
}).then(function (res) {
|
|||
|
|
if (!res.status && res.code == 10002) {
|
|||
|
|
window.localStorage['m_access_token'] = ''
|
|||
|
|
window.localStorage['m_refresh_token'] = ''
|
|||
|
|
// alert('10002 登录超时,请重新登录')
|
|||
|
|
reinitEm(true);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (res.m_access_token) {
|
|||
|
|
window.localStorage['m_access_token'] = res.m_access_token
|
|||
|
|
window.location.reload();
|
|||
|
|
} else {
|
|||
|
|
// alert('m_access_token 不存在,重登陆失败')
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
resolve({
|
|||
|
|
status: true
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (data.em_url_open) {
|
|||
|
|
window.em_url_open = data.em_url_open;
|
|||
|
|
}
|
|||
|
|
if (/wxExternalAddressEnable=1/.test(window.location.href) || window.localStorage['wxExternalAddressEnable'] == '1') {
|
|||
|
|
window.em_url_open = window.location.protocol + '//' + window.location.host
|
|||
|
|
window.localStorage['wxExternalAddressEnable'] = '1'
|
|||
|
|
}
|
|||
|
|
if (data.ec_id) {
|
|||
|
|
window.localStorage.emobile_ec_id = data.ec_id
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// // 单点登录接口返回 code无效单独处理
|
|||
|
|
if (
|
|||
|
|
(data.status === "false" || !data.status) &&
|
|||
|
|
data.msg &&
|
|||
|
|
/\"errcode\"\:9101[1|2]/.test(data.msg)
|
|||
|
|
) {
|
|||
|
|
reinitEm();
|
|||
|
|
resolve({
|
|||
|
|
status: true
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (window.rewriteApiData) {
|
|||
|
|
data = window.rewriteApiData(_url, params, data);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (type === 'json' && data && data.status === 'false') {
|
|||
|
|
resolve(data);
|
|||
|
|
console && console.log('数据异常:' + JSON.stringify(data));
|
|||
|
|
} else if (!data.status && (data.showMsg || data.showType === 'msg')) {
|
|||
|
|
resolve(data);
|
|||
|
|
alert('数据异常:' + JSON.stringify(data));
|
|||
|
|
} else if (!data.status && (data.showModal || data.showType === 'modal')) {
|
|||
|
|
resolve(data);
|
|||
|
|
alert('数据异常:' + JSON.stringify(data));
|
|||
|
|
} else if (type === 'json' && checkReject(data)) {
|
|||
|
|
console && console.log('数据异常:' + JSON.stringify(data));
|
|||
|
|
var urlParamsT = getFrameParams() || '';
|
|||
|
|
if (/\/api\/ecode\/sync/.test(url) ||
|
|||
|
|
urlParamsT['em_no_login'] == '1'
|
|||
|
|
) {
|
|||
|
|
resolve({
|
|||
|
|
status: true
|
|||
|
|
});
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var ua = window.navigator.userAgent;
|
|||
|
|
if ((
|
|||
|
|
/.*wxwork.*/.test(ua) ||
|
|||
|
|
/.*DingTalk.*/.test(ua) ||
|
|||
|
|
/.*TaurusApp.*/.test(ua) ||
|
|||
|
|
/.*Lark.*/.test(ua)
|
|||
|
|
) && window.em_url_open &&
|
|||
|
|
window.localStorage.emobile_ec_id
|
|||
|
|
&& !window.stopredirect
|
|||
|
|
) {
|
|||
|
|
window.location.href = window.em_url_open + '/wxapi/wxclienturl/redirect?em_sys_id=' + window.localStorage.emobile_ec_id + '&redirect_url=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + window.location.pathname + '?_random=' + new Date().getTime() + window.location.search.replace('?', '&') + window.location.hash)
|
|||
|
|
resolve();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
reject(data.msg);
|
|||
|
|
} else {
|
|||
|
|
resolve(data);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
xhr.send(getFd(params));
|
|||
|
|
}.bind(this));
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
var loadEmFile = function (res, rs, rj, emUrl) {
|
|||
|
|
loadjs.isDefined('em') ?
|
|||
|
|
loadjs.ready('em', function () {
|
|||
|
|
initEM(res, rs, rj, false, emUrl);
|
|||
|
|
}.bind(this)) :
|
|||
|
|
loadjs(emUrl, 'em', {
|
|||
|
|
success: function () {
|
|||
|
|
window.wm_test_sso_em_loaded_end = new Date().getTime();
|
|||
|
|
initEM(res, rs, rj, false, emUrl);
|
|||
|
|
}.bind(this),
|
|||
|
|
error: function (res) {
|
|||
|
|
if (/^https/.test(location.href) !== /^https/.test(emUrl)) {
|
|||
|
|
rj({
|
|||
|
|
msg: 'jem.js 加载失败:em与ec协议不一致'
|
|||
|
|
});
|
|||
|
|
} else {
|
|||
|
|
throw('em not reach');
|
|||
|
|
}
|
|||
|
|
}.bind(this),
|
|||
|
|
numRetries: 2
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var ssoInit = function (emCode) {
|
|||
|
|
if (emCode === undefined) {
|
|||
|
|
emCode = '';
|
|||
|
|
}
|
|||
|
|
return new Promise(function (rs, rj) {
|
|||
|
|
var params = getFrameParams();
|
|||
|
|
var ua = window.navigator.userAgent;
|
|||
|
|
var loadJem = (/.*E-Mobile7.*/.test(ua) ||
|
|||
|
|
/.*E-Mobile\/7.*/.test(ua) ||
|
|||
|
|
/.*e-mobile\/7.*/.test(ua) ||
|
|||
|
|
/.*wxwork.*/.test(ua) ||
|
|||
|
|
/.*DingTalk.*/.test(ua) ||
|
|||
|
|
/.*TaurusApp.*/.test(ua) ||
|
|||
|
|
/Qing\/.*;(iOS|iPhone|Android).*/.test(ua) ||
|
|||
|
|
/.*e-mobile-xp.*/.test(ua) ||
|
|||
|
|
/.*HuaWei-AnyOffice.*/.test(ua) ||
|
|||
|
|
/.*Lark.*/.test(ua) ||
|
|||
|
|
/.*QYZone_.*/.test(ua)
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
if ((params.em_auth_code && params.em_auth_code != 'undefined') || loadJem) {
|
|||
|
|
try {
|
|||
|
|
var tempParams = params;
|
|||
|
|
var code = emCode || params.em_auth_code
|
|||
|
|
// tempParams = Object.assign(tempParams, { em_auth_code: code });
|
|||
|
|
tempParams.em_auth_code = code
|
|||
|
|
var codeList = window.emCodeList || [];
|
|||
|
|
if (codeList.some(function (codeUsed) {
|
|||
|
|
code == codeUsed
|
|||
|
|
})) {
|
|||
|
|
tempParams = {};
|
|||
|
|
}
|
|||
|
|
tempParams.em_auth_userid = params.em_auth_userid
|
|||
|
|
tempParams.timeZoneOffset = new Date().getTimezoneOffset();
|
|||
|
|
codeList.push(code);
|
|||
|
|
window.emCodeList = codeList;
|
|||
|
|
if (params.em_no_login == '1') {
|
|||
|
|
delete(tempParams.em_auth_code)
|
|||
|
|
window.localStorage['m_access_token'] = '';
|
|||
|
|
window.localStorage['m_refresh_token'] = '';
|
|||
|
|
}
|
|||
|
|
callApi({
|
|||
|
|
url: '/api/ec/dev/app/test',
|
|||
|
|
method: 'GET',
|
|||
|
|
params: tempParams,
|
|||
|
|
type: 'json',
|
|||
|
|
}).then(function (res) {
|
|||
|
|
window.wm_test_sso_api_end = new Date().getTime();
|
|||
|
|
window.localStorage['em_retry_time'] = 0;
|
|||
|
|
window.em_url_open = res.em_url_open;
|
|||
|
|
if (/wxExternalAddressEnable=1/.test(window.location.href) || window.localStorage['wxExternalAddressEnable'] == '1') {
|
|||
|
|
window.em_url_open = window.location.protocol + '//' + window.location.host
|
|||
|
|
window.localStorage['wxExternalAddressEnable'] = '1'
|
|||
|
|
}
|
|||
|
|
if (res.emaccesstk) {
|
|||
|
|
window.localStorage['emaccesstk'] = res.emaccesstk;
|
|||
|
|
}
|
|||
|
|
if (res.languageType) {
|
|||
|
|
window.localStorage['languageidweaver'] = res.languageType
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (res.status === true || res.status === '1') {
|
|||
|
|
|
|||
|
|
if (!res.em_url_open) {
|
|||
|
|
rs();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
setToken(res.mobileTokenName, res.m_access_token, res.m_refresh_token)
|
|||
|
|
//if (res.jemUrl) {
|
|||
|
|
// emUrl = res.jemUrl
|
|||
|
|
//}
|
|||
|
|
try {
|
|||
|
|
var emUrl = window.em_url_open + '/open/js/jem.js';
|
|||
|
|
loadEmFile(res, rs, rj, emUrl);
|
|||
|
|
} catch (error) {
|
|||
|
|
try{
|
|||
|
|
loadEmFile(res, rs, rj, '/mobile/jem.js?=' + new Date().getTime());
|
|||
|
|
} catch (error) {
|
|||
|
|
rj({
|
|||
|
|
msg: 'ec地址jem.js加载异常,请在em后台ecology集成操作中重新编辑保存'
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
rj({
|
|||
|
|
msg: '认证失败,em地址:' + res.em_url,
|
|||
|
|
res: res
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}.bind(this)).catch(function (error) {
|
|||
|
|
var ua = window.navigator.userAgent;
|
|||
|
|
if ((
|
|||
|
|
/.*wxwork.*/.test(ua) ||
|
|||
|
|
/.*DingTalk.*/.test(ua) ||
|
|||
|
|
/.*TaurusApp.*/.test(ua) ||
|
|||
|
|
/.*Lark.*/.test(ua)
|
|||
|
|
) && window.em_url_open &&
|
|||
|
|
window.localStorage.emobile_ec_id
|
|||
|
|
&& !window.stopredirect
|
|||
|
|
) {
|
|||
|
|
window.location.href = window.em_url_open + '/wxapi/wxclienturl/redirect?em_sys_id=' + window.localStorage.emobile_ec_id + '&redirect_url=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + window.location.pathname + '?_random=' + new Date().getTime() + window.location.search.replace('?', '&') + window.location.hash)
|
|||
|
|
rs();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (window.em && window.em.checkJsApi("getEmAuthCode")) {
|
|||
|
|
|
|||
|
|
window.em.getEmAuthCode({
|
|||
|
|
sysId: window.localStorage.emobile_ec_id, // 集成系统ID
|
|||
|
|
success: function (emres) {
|
|||
|
|
// 如:{"em_auth_code":"abc123","errMsg":"getEmAuthCode:ok"}
|
|||
|
|
if (emres.em_auth_code) {
|
|||
|
|
ssoInit(emres.em_auth_code)
|
|||
|
|
} else {
|
|||
|
|
alert('重新获取em_auth_code失败');
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
error: function (error) {
|
|||
|
|
alert('重新获取em_auth_code失败: ' + JSON.stringify(error));
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
} else {
|
|||
|
|
// reinitEm()
|
|||
|
|
if (error.res) {
|
|||
|
|
rj(error.res.msg || error.res);
|
|||
|
|
} else if (error.msg) {
|
|||
|
|
rj(error.msg);
|
|||
|
|
} else {
|
|||
|
|
rj(error);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}.bind(this));
|
|||
|
|
} catch (error) {
|
|||
|
|
window.localStorage['emDebug'] == '1' && alert(error);
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
try {
|
|||
|
|
checkCustomSSO(rs, rj)
|
|||
|
|
} catch (error) {
|
|||
|
|
rj({
|
|||
|
|
msg: '自定义配置 加载异常' + error
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}.bind(this));
|
|||
|
|
}.bind(this);
|
|||
|
|
var checkCustomSSO = function (rs, rj) {
|
|||
|
|
// 移动端单点登录自定义配置
|
|||
|
|
if (window.e9ssoMobileConfig && window.e9ssoMobileConfig.inUse) {
|
|||
|
|
// 移动端单点登录自定义初始化方法
|
|||
|
|
window.e9ssoMobileConfig.customInit().then(function () {
|
|||
|
|
if (!window.ssoCustomChecked && !window.localStorage.ssoCustomChecked) {
|
|||
|
|
window.ssoCustomChecked = true;
|
|||
|
|
if (window.customSsoConfig) {
|
|||
|
|
// 移动端自定义单点登录接口
|
|||
|
|
if (window.customSsoConfig.inUseMobile) {
|
|||
|
|
var params = getFrameParams();
|
|||
|
|
var checkSessionParams = [];
|
|||
|
|
if (window.customSsoConfig.sessionCheckApiParamsMobile) {
|
|||
|
|
var sessionParams = window.customSsoConfig.sessionCheckApiParamsMobile.split(',');
|
|||
|
|
sessionParams.forEach(function (element) {
|
|||
|
|
checkSessionParams[element] = params[element];
|
|||
|
|
}.bind(this));
|
|||
|
|
}
|
|||
|
|
callApi({
|
|||
|
|
url: window.customSsoConfig.sessionCheckApiMobile,
|
|||
|
|
method: window.customSsoConfig.sessionCheckApiMobileType,
|
|||
|
|
params: checkSessionParams,
|
|||
|
|
type: 'json',
|
|||
|
|
}).then(function (res) {
|
|||
|
|
if ((res.status === '1' || res.status === true) && !res.hasSession) {
|
|||
|
|
var service = escape(window.location.href);
|
|||
|
|
var paramsMark = '?';
|
|||
|
|
if (window.customSsoConfig.serverLoginUrlMobile.indexOf('?') !== -1) {
|
|||
|
|
paramsMark = '&';
|
|||
|
|
}
|
|||
|
|
window.location.href = window.customSsoConfig.serverLoginUrlMobile + paramsMark + 'service=' + service;
|
|||
|
|
rs();
|
|||
|
|
} else {
|
|||
|
|
rj('sessionCheckApiMobile');
|
|||
|
|
}
|
|||
|
|
}.bind(this));
|
|||
|
|
} else {
|
|||
|
|
rs();
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
rs();
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
if (window.localStorage.ssoCustomChecked) {
|
|||
|
|
window.localStorage.ssoCustomChecked = false;
|
|||
|
|
}
|
|||
|
|
rs();
|
|||
|
|
}
|
|||
|
|
}.bind(this)).catch(function (res) {
|
|||
|
|
rj('customInit' + JSON.stringify(res));
|
|||
|
|
}.bind(this));
|
|||
|
|
} else {
|
|||
|
|
if (!window.ssoCustomChecked && !window.localStorage.ssoCustomChecked) {
|
|||
|
|
window.ssoCustomChecked = true;
|
|||
|
|
if (window.customSsoConfig) {
|
|||
|
|
// 移动端自定义单点登录接口
|
|||
|
|
if (window.customSsoConfig.inUseMobile) {
|
|||
|
|
var params = getFrameParams();
|
|||
|
|
var checkSessionParams = [];
|
|||
|
|
if (window.customSsoConfig.sessionCheckApiParamsMobile) {
|
|||
|
|
var sessionParams = window.customSsoConfig.sessionCheckApiParamsMobile.split(',');
|
|||
|
|
sessionParams.forEach(function (element) {
|
|||
|
|
checkSessionParams[element] = params[element];
|
|||
|
|
}.bind(this));
|
|||
|
|
}
|
|||
|
|
callApi({
|
|||
|
|
url: window.customSsoConfig.sessionCheckApiMobile,
|
|||
|
|
method: window.customSsoConfig.sessionCheckApiMobileType,
|
|||
|
|
params: checkSessionParams,
|
|||
|
|
type: 'json',
|
|||
|
|
}).then(function (res) {
|
|||
|
|
if ((res.status === '1' || res.status === true) && !res.hasSession) {
|
|||
|
|
var service = escape(window.location.href);
|
|||
|
|
var paramsMark = '?';
|
|||
|
|
if (window.customSsoConfig.serverLoginUrlMobile.indexOf('?') !== -1) {
|
|||
|
|
paramsMark = '&';
|
|||
|
|
}
|
|||
|
|
window.location.href = window.customSsoConfig.serverLoginUrlMobile + paramsMark + 'service=' + service;
|
|||
|
|
rs();
|
|||
|
|
} else {
|
|||
|
|
rj('sessionCheckApiMobile');
|
|||
|
|
}
|
|||
|
|
}.bind(this));
|
|||
|
|
} else {
|
|||
|
|
rs();
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
rs();
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
if (window.localStorage.ssoCustomChecked) {
|
|||
|
|
window.localStorage.ssoCustomChecked = false;
|
|||
|
|
}
|
|||
|
|
rs();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}.bind(this);
|
|||
|
|
var getFrameParams = function (urlStr) {
|
|||
|
|
var url = urlStr || window.location.href;
|
|||
|
|
var params = {};
|
|||
|
|
var urlParams = [];
|
|||
|
|
if (url.indexOf('#') !== -1) {
|
|||
|
|
var paramsArr = url.split('#');
|
|||
|
|
paramsArr.forEach(function (item) {
|
|||
|
|
if (item.indexOf('?') !== -1) {
|
|||
|
|
var urlItem = item.slice(item.indexOf('?') + 1).split('&');
|
|||
|
|
urlItem.forEach(function (element) {
|
|||
|
|
var datas = element.split('=');
|
|||
|
|
params[datas[0]] = datas[1];
|
|||
|
|
}.bind(this));
|
|||
|
|
}
|
|||
|
|
}.bind(this))
|
|||
|
|
} else {
|
|||
|
|
urlParams = url.slice(url.indexOf('?') + 1).split('&');
|
|||
|
|
urlParams.forEach(function (element) {
|
|||
|
|
var datas = element.split('=');
|
|||
|
|
params[datas[0]] = datas[1];
|
|||
|
|
}.bind(this));
|
|||
|
|
}
|
|||
|
|
return params;
|
|||
|
|
}.bind(this);
|
|||
|
|
|
|||
|
|
var initEM = function (res, rs, rj, isReload, emUrl) {
|
|||
|
|
try {
|
|||
|
|
var loadEm = function (retryTimes) {
|
|||
|
|
var retryDelay = 100;
|
|||
|
|
if (retryTimes === 0) {
|
|||
|
|
retryDelay = 0;
|
|||
|
|
}
|
|||
|
|
setTimeout(function () {
|
|||
|
|
// init emobile config
|
|||
|
|
if (window.em) {
|
|||
|
|
window.em.config({
|
|||
|
|
corpId: res.em_corpid,
|
|||
|
|
appId: '',
|
|||
|
|
});
|
|||
|
|
if (window.afterLoadEmApi) {
|
|||
|
|
var getClientInfo = window.em.getClientInfo.bind(window.em)
|
|||
|
|
window.em.getClientInfo = function (func) {
|
|||
|
|
var failFunc = func.fail
|
|||
|
|
var successFunc = func.success
|
|||
|
|
var failOrigin = func.failOrigin
|
|||
|
|
getClientInfo({
|
|||
|
|
success: function (res) {
|
|||
|
|
window.wm_test_em_getClientInfo_end = (new Date).getTime();
|
|||
|
|
var colorReg = /^(#|%23)([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
|
|||
|
|
if (colorReg.test(res.clientTheme)) {
|
|||
|
|
window.localStorage && (window.localStorage["theme-color"] = /^(#|%23)((f|F){3}){1,2}$/.test(res.clientTheme) ? "#55b1f9" : res.clientTheme)
|
|||
|
|
}
|
|||
|
|
try {
|
|||
|
|
if (res.clientFont) {
|
|||
|
|
window.localStorage && (window.localStorage["theme"] = res.clientFont === "3" ? "theme-large" : res.clientFont === "2" ? "theme-big" : "theme-default")
|
|||
|
|
}
|
|||
|
|
window.changeTheme && window.changeTheme();
|
|||
|
|
} catch (error) {
|
|||
|
|
console && console.log(error)
|
|||
|
|
}
|
|||
|
|
successFunc && successFunc(res)
|
|||
|
|
},
|
|||
|
|
fail: function (err) {
|
|||
|
|
failOrigin && failOrigin()
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
// return failFunc && failFunc()
|
|||
|
|
}
|
|||
|
|
window.afterLoadEmApi();
|
|||
|
|
// window.localStorage["theme-color"] = '#393f9d';
|
|||
|
|
// window.changeTheme && window.changeTheme();
|
|||
|
|
}
|
|||
|
|
window.localStorage.emobile_ec_id = res.ec_id;
|
|||
|
|
var params = getFrameParams();
|
|||
|
|
if (/\/mobilemode\/mobile\/view\.html\?appid\=11/.test(window.location.href) && !params.em_auth_code) {
|
|||
|
|
rj('重新获取em_auth_code')
|
|||
|
|
}
|
|||
|
|
rs(res);
|
|||
|
|
} else {
|
|||
|
|
if (retryTimes < 2) {
|
|||
|
|
loadEm(retryTimes + 1);
|
|||
|
|
} else {
|
|||
|
|
if (isReload) {
|
|||
|
|
// loadEm(0);
|
|||
|
|
rj({
|
|||
|
|
msg: 'em对象不存在,重新加载无效'
|
|||
|
|
});
|
|||
|
|
} else {
|
|||
|
|
reloadEm(res, rs, rj, emUrl);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}.bind(this), retryDelay);
|
|||
|
|
}.bind(this);
|
|||
|
|
loadEm(0);
|
|||
|
|
} catch (error) {
|
|||
|
|
window.localStorage['emDebug'] == '1' && alert(error);
|
|||
|
|
}
|
|||
|
|
}.bind(this);
|
|||
|
|
|
|||
|
|
var reinitEm = function (tokenFail) {
|
|||
|
|
window.localStorage['m_access_token'] = ''
|
|||
|
|
window.localStorage['m_refresh_token'] = ''
|
|||
|
|
callApi({
|
|||
|
|
url: '/api/ec/dev/app/test',
|
|||
|
|
method: 'GET',
|
|||
|
|
params: {},
|
|||
|
|
type: 'json',
|
|||
|
|
}).then(function (res) {
|
|||
|
|
if (res.languageType) {
|
|||
|
|
window.localStorage['languageidweaver'] = res.languageType
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (res.ec_id) {
|
|||
|
|
window.localStorage.emobile_ec_id = res.ec_id
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (res.status === true || res.status === '1') {
|
|||
|
|
if (!res.em_url_open) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
var emUrl = window.em_url_open + '/open/js/jem.js';
|
|||
|
|
var rj = function (params) {
|
|||
|
|
alert('reload em fail' + JSON.stringify(params))
|
|||
|
|
}.bind(this)
|
|||
|
|
|
|||
|
|
var rs = function () {
|
|||
|
|
var ua = window.navigator.userAgent;
|
|||
|
|
// if (tokenFail) {
|
|||
|
|
// window.em && window.em.checkJsApi('pushToLogin') && window.em.pushToLogin();
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
if ((
|
|||
|
|
/.*wxwork.*/.test(ua) ||
|
|||
|
|
/.*DingTalk.*/.test(ua) ||
|
|||
|
|
/.*TaurusApp.*/.test(ua) ||
|
|||
|
|
/.*Lark.*/.test(ua)
|
|||
|
|
) && window.em_url_open &&
|
|||
|
|
window.localStorage.emobile_ec_id
|
|||
|
|
) {
|
|||
|
|
window.location.href = window.em_url_open + '/wxapi/wxclienturl/redirect?em_sys_id=' + window.localStorage.emobile_ec_id + '&redirect_url=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + window.location.pathname + '?_random=' + new Date().getTime() + window.location.search.replace('?', '&') + window.location.hash)
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (window.em && window.em.checkJsApi("getEmAuthCode")) {
|
|||
|
|
window.em.getEmAuthCode({
|
|||
|
|
sysId: window.localStorage.emobile_ec_id, // 集成系统ID
|
|||
|
|
success: function (emres) {
|
|||
|
|
// 如:{"em_auth_code":"abc123","errMsg":"getEmAuthCode:ok"}
|
|||
|
|
if (emres.em_auth_code) {
|
|||
|
|
ssoInit(emres.em_auth_code).then(function () {
|
|||
|
|
window.location.reload();
|
|||
|
|
})
|
|||
|
|
} else {
|
|||
|
|
alert('重新获取em_auth_code失败');
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
error: function (error) {
|
|||
|
|
alert('重新获取em_auth_code失败: ' + JSON.stringify(error));
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
var emUrl = window.em_url_open + '/open/js/jem.js';
|
|||
|
|
loadEmFile(res, rs, rj, emUrl);
|
|||
|
|
} catch (error) {
|
|||
|
|
try{
|
|||
|
|
loadEmFile(res, rs, rj, '/mobile/jem.js?=' + new Date().getTime());
|
|||
|
|
} catch (error) {
|
|||
|
|
rj({
|
|||
|
|
msg: 'ec地址jem.js加载异常,请在em后台ecology集成操作中重新编辑保存'
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
// alert({ msg: '重认证失败,' + res.errmsg, res: res });
|
|||
|
|
alert('重认证失败:' + res.em_url)
|
|||
|
|
}
|
|||
|
|
}.bind(this)).catch(function (error) {
|
|||
|
|
alert('重认证失败 ' + JSON.stringify(error))
|
|||
|
|
});
|
|||
|
|
}.bind(this)
|
|||
|
|
|
|||
|
|
var reloadEm = function (res, rs, rj, emUrl) {
|
|||
|
|
loadjs((emUrl), 'em', {
|
|||
|
|
success: function () {
|
|||
|
|
window.wm_test_sso_em_loaded_end = new Date().getTime();
|
|||
|
|
initEM(res, rs, rj, true, emUrl);
|
|||
|
|
}.bind(this),
|
|||
|
|
error: function (res) {
|
|||
|
|
rj({
|
|||
|
|
msg: (('jem.js 重载失败:' + res.em_url_open) || 'jem.js 重载失败,emUrl:' + emUrl)
|
|||
|
|
});
|
|||
|
|
}.bind(this)
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
var getToken = function () {
|
|||
|
|
if (window.localStorage['m_access_token']) {
|
|||
|
|
if (window.localStorage.mobileTokenName) {
|
|||
|
|
return {
|
|||
|
|
mobiletokenname: window.localStorage.mobileTokenName,
|
|||
|
|
mobiletoken: window.localStorage.m_access_token,
|
|||
|
|
refreshtoken: window.localStorage.m_refresh_token
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
return {
|
|||
|
|
mobiletokenname: 'mobiletoken',
|
|||
|
|
mobiletoken: window.localStorage.m_access_token,
|
|||
|
|
refreshtoken: window.localStorage.m_refresh_token
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
window.em && window.em.checkJsApi('getItem') && window.em.getItem({
|
|||
|
|
'key': 'm_access_token',
|
|||
|
|
'success': function (res) {
|
|||
|
|
window.localStorage['m_access_token'] = res.value || '';
|
|||
|
|
},
|
|||
|
|
'fail': function () {}
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
window.em && window.em.checkJsApi('getItem') && window.em.getItem({
|
|||
|
|
'key': 'mobiletokenname',
|
|||
|
|
'success': function (namesuccess) {
|
|||
|
|
window.localStorage['mobileTokenName'] = namesuccess.value || '';
|
|||
|
|
},
|
|||
|
|
'fail': function () {
|
|||
|
|
window.localStorage['mobileTokenName'] = 'mobiletoken';
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
return {
|
|||
|
|
mobiletokenname: window.localStorage.mobileTokenName || 'mobiletoken',
|
|||
|
|
mobiletoken: window.localStorage.m_access_token || '',
|
|||
|
|
refreshtoken: window.localStorage.m_refresh_token || ''
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
var setToken = function (tokenName, token, refreshToken) {
|
|||
|
|
if (tokenName) {
|
|||
|
|
window.localStorage['mobileTokenName'] = tokenName
|
|||
|
|
if (window.em && window.em.checkJsApi('setItem')) {
|
|||
|
|
window.em.setItem({
|
|||
|
|
key: 'mobileTokenName',
|
|||
|
|
value: tokenName
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (token) {
|
|||
|
|
window.localStorage['m_access_token'] = token
|
|||
|
|
if (window.em && window.em.checkJsApi('setItem')) {
|
|||
|
|
window.em.setItem({
|
|||
|
|
key: 'm_access_token',
|
|||
|
|
value: token
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (refreshToken) {
|
|||
|
|
window.localStorage['m_refresh_token'] = refreshToken
|
|||
|
|
if (window.em && window.em.checkJsApi('setItem')) {
|
|||
|
|
window.em.setItem({
|
|||
|
|
key: 'm_refresh_token',
|
|||
|
|
value: refreshToken
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
window.em_ssoInit = ssoInit;
|
|||
|
|
window.sso_callApi = callApi;
|
|||
|
|
window.sso_getJSONObj = getJSONObj;
|
|||
|
|
window.get_token = getToken;
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
var loadDevFile = function () {
|
|||
|
|
var defaultDevFiles = [
|
|||
|
|
"/cloudstore/config/devStatic/devModuleCustomMobile.js?v=" + new Date().getTime(),
|
|||
|
|
"css!/cloudstore/config/devStatic/devModuleStyleMobile.css?v=" + new Date().getTime()
|
|||
|
|
];
|
|||
|
|
if (window.ecDevFileConfig && window.ecDevFileConfig.mobile) {
|
|||
|
|
if (window.ecDevFileConfig.mobile.global) {
|
|||
|
|
defaultDevFiles = window.ecDevFileConfig.mobile.global;
|
|||
|
|
}
|
|||
|
|
if (window.ecDevFileConfig.mobile.moduleConfig && window.ecDevFileConfig.mobile.moduleConfig.length) {
|
|||
|
|
var moduleConfigList = window.ecDevFileConfig.mobile.moduleConfig
|
|||
|
|
for (var index = 0; index < moduleConfigList.length; index++) {
|
|||
|
|
var element = moduleConfigList[index];
|
|||
|
|
if (window.location.href.search(element.hrefRegex) > 0) {
|
|||
|
|
defaultDevFiles = defaultDevFiles.concat(element.files);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
loadjs.isDefined('customDevFiles') ? '' : loadjs(defaultDevFiles, 'customDevFiles');
|
|||
|
|
}
|
|||
|
|
loadDevFile();
|
|||
|
|
} catch (error) {
|
|||
|
|
window.localStorage['emDebug'] == '1' && alert('customDevFiles error')
|
|||
|
|
console && console.log(error)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (/\/signal/.test(location.href) ||
|
|||
|
|
/\/mapSign/.test(location.href) ||
|
|||
|
|
/\/outSign/.test(location.href) ||
|
|||
|
|
/\/signalV2/.test(location.href) ||
|
|||
|
|
/\/mapSignV2/.test(location.href) ||
|
|||
|
|
/\/outSignV2/.test(location.href) ||
|
|||
|
|
/\/myAttendance/.test(location.href) ||
|
|||
|
|
/\/subAttendance/.test(location.href) ||
|
|||
|
|
/\/sign/.test(location.href) ||
|
|||
|
|
/\/subAttendanceCopy/.test(location.href)
|
|||
|
|
) {
|
|||
|
|
window.afterLoadEmApi = null;
|
|||
|
|
} else {
|
|||
|
|
window.afterLoadEmApi = function () {
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (window.ecodeSDK && window.e9ssoMobileConfig) {
|
|||
|
|
window.e9ssoMobileConfig.callapi_response_handler = function callapi_response_handler(data, reject, response, type) {
|
|||
|
|
if (type === 'json') {
|
|||
|
|
try {
|
|||
|
|
var dataTemp = JSON.parse(data);
|
|||
|
|
|
|||
|
|
if (dataTemp.needResponse) {
|
|||
|
|
dataTemp.response = response;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((dataTemp.status === "false" || !dataTemp.status) && dataTemp.msg && /\"errcode\"\:9101[1|2]/.test(dataTemp.msg)) {
|
|||
|
|
reinitEm();
|
|||
|
|
resolve({
|
|||
|
|
status: true
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
if (dataTemp.code === 3) {
|
|||
|
|
window.stopredirect = true;
|
|||
|
|
alert(dataTemp.msg || '账号已被锁定,请联系系统管理员');
|
|||
|
|
resolve({
|
|||
|
|
status: true
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (dataTemp.errorCode && dataTemp.errorCode === '002' && !window.stopredirect) {
|
|||
|
|
reinitEm();
|
|||
|
|
resolve({
|
|||
|
|
status: true
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (dataTemp.code === 10002) {
|
|||
|
|
return {
|
|||
|
|
stauts: true,
|
|||
|
|
code: 10002
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (dataTemp.code === 401) {
|
|||
|
|
if (window.localStorage.m_refresh_token) {
|
|||
|
|
callApi({
|
|||
|
|
url: '/api/ec/dev/app/refreshToken',
|
|||
|
|
method: 'POST',
|
|||
|
|
params: {
|
|||
|
|
m_refresh_token: window.localStorage.m_refresh_token
|
|||
|
|
},
|
|||
|
|
type: 'json'
|
|||
|
|
}).then(function (res) {
|
|||
|
|
if (res.code == 10002) {
|
|||
|
|
// alert('10002 登录超时,请重新登录');
|
|||
|
|
reinitEm();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (res.m_access_token) {
|
|||
|
|
window.localStorage.m_access_token = res.m_access_token;
|
|||
|
|
window.location.reload();
|
|||
|
|
} else {
|
|||
|
|
// alert('m_access_token 不存在,重登陆失败');
|
|||
|
|
reinitEm();
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
} else {
|
|||
|
|
// alert('m_refresh_token 不存在,重登陆失败');
|
|||
|
|
reinitEm();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
status: true
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return dataTemp;
|
|||
|
|
} catch (error) {
|
|||
|
|
var evil = function evil(fn) {
|
|||
|
|
var Fn = Function; // 一个变量指向Function,防止有些前端编译工具报错
|
|||
|
|
|
|||
|
|
return new Fn('return ' + fn)();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
data = data || '{}';
|
|||
|
|
return evil('(' + data + ')'); // JSON.parse 解析反斜杠报错处理
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
return data;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
window.e9ssoMobileConfig = {
|
|||
|
|
inUse: true,
|
|||
|
|
callapi_response_handler: function callapi_response_handler(data, reject, response, type) {
|
|||
|
|
if (type === 'json') {
|
|||
|
|
try {
|
|||
|
|
var dataTemp = JSON.parse(data);
|
|||
|
|
|
|||
|
|
if (dataTemp.needResponse) {
|
|||
|
|
dataTemp.response = response;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ((dataTemp.status === "false" || !dataTemp.status) && dataTemp.msg && /\"errcode\"\:9101[1|2]/.test(dataTemp.msg)) {
|
|||
|
|
reinitEm();
|
|||
|
|
resolve({
|
|||
|
|
status: true
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (dataTemp.code === 3) {
|
|||
|
|
window.stopredirect = true;
|
|||
|
|
alert(dataTemp.msg || '账号已被锁定,请联系系统管理员');
|
|||
|
|
resolve({
|
|||
|
|
status: true
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (dataTemp.errorCode && dataTemp.errorCode === '002' && !window.stopredirect) {
|
|||
|
|
reinitEm();
|
|||
|
|
resolve({
|
|||
|
|
status: true
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (dataTemp.code === 10002) {
|
|||
|
|
return {
|
|||
|
|
stauts: true,
|
|||
|
|
code: 10002
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (dataTemp.code === 401) {
|
|||
|
|
if (window.localStorage.m_refresh_token) {
|
|||
|
|
callApi({
|
|||
|
|
url: '/api/ec/dev/app/refreshToken',
|
|||
|
|
method: 'POST',
|
|||
|
|
params: {
|
|||
|
|
m_refresh_token: window.localStorage.m_refresh_token
|
|||
|
|
},
|
|||
|
|
type: 'json'
|
|||
|
|
}).then(function (res) {
|
|||
|
|
if (res.code == 10002) {
|
|||
|
|
// alert('10002 登录超时,请重新登录');
|
|||
|
|
reinitEm();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (res.m_access_token) {
|
|||
|
|
window.localStorage.m_access_token = res.m_access_token;
|
|||
|
|
window.location.reload();
|
|||
|
|
} else {
|
|||
|
|
// alert('m_access_token 不存在,重登陆失败');
|
|||
|
|
reinitEm();
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
} else {
|
|||
|
|
// alert('m_refresh_token 不存在,重登陆失败');
|
|||
|
|
reinitEm();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
status: true
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return dataTemp;
|
|||
|
|
} catch (error) {
|
|||
|
|
var evil = function evil(fn) {
|
|||
|
|
var Fn = Function; // 一个变量指向Function,防止有些前端编译工具报错
|
|||
|
|
|
|||
|
|
return new Fn('return ' + fn)();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
data = data || '{}';
|
|||
|
|
return evil('(' + data + ')'); // JSON.parse 解析反斜杠报错处理
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
return data;
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
customInit: function customInit() {
|
|||
|
|
return new Promise(function (rs, rj) {
|
|||
|
|
rs();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
})()
|