From f6626b05f1275cc2f8ca77f773d4f6a6af1b0a89 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 21 十一月 2022 16:11:55 +0800 Subject: [PATCH] 2022-11-21 --- src/api/index.js | 187 +++++++++++++++++++++++++++++++++++++++------- 1 files changed, 159 insertions(+), 28 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index b320ee1..2a36ed4 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -2,6 +2,7 @@ import qs from 'qs' import { notification } from 'antd' import md5 from 'md5' +import CryptoJS from 'crypto-js' import jsSHA from 'jssha' import moment from 'moment' import Utils from '@/utils/utils.js' @@ -10,6 +11,7 @@ window.GLOB.WebSql = null window.GLOB.IndexDB = null +window.GLOB.OuterToken = {} const systemMenuKeys = `1581067625930haged11ieaivpavv77k,1581734956310scks442ul2d955g9tu5,1583991994144ndddg0bhh0is6shi0v1,1583979633842550imkchl4qt4qppsiv,1578900109100np8aqd0a77q3na46oas, 1585192949946f3et2ts8tn82krmumdf,15855615451212m12ip23vpcm79kloro,1587005717541lov40vg61q7l1rbveon,1590458676585agbbr63t6ihighg2i1g,1602315375262ikd33ii0nii34pt861o,1582771068837vsv54a089lgp45migbg, 1582777675954ifu05upurs465omoth7,158294809668898cklbv6c5bou8e1fpu,1584676379094iktph45fb8imhg96bql,1584695125339vo5g7iqgfn01qmrd6s2,1584699661372vhmpp9dn9foo0eob722,15848421131551gg04ie8sitsd3f7467, @@ -217,7 +219,8 @@ timestamp: moment().format('YYYY-MM-DD HH:mm:ss'), SessionUid: _SessionUid, TypeCharOne: 'pc', - kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)) + kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)), + appkey: window.GLOB.appkey || '' } let url = '/webapi/dologon/s_visitor_login' @@ -251,8 +254,6 @@ param.v_type = param.v_type || 'Y' param.secretkey = md5(param.LText + solt + param.timestamp) - param.appkey = window.GLOB.appkey || '' - return axios({ url: url, method: 'post', @@ -275,10 +276,9 @@ login_city: city, login_id_address: ipAddress, kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)), - device_id: localStorage.getItem('SessionUid') + device_id: localStorage.getItem('SessionUid'), + appkey: window.GLOB.appkey || '' } - - param.appkey = window.GLOB.appkey || '' let url = '/webapi/dologon' if (isCloud) { @@ -312,10 +312,10 @@ login_city: city, login_id_address: ipAddress, kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)), - device_id: localStorage.getItem('SessionUid') + device_id: localStorage.getItem('SessionUid'), + timestamp: moment().format('YYYY-MM-DD HH:mm:ss'), + appkey: window.GLOB.appkey || '' } - - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') let sys_datetime = sessionStorage.getItem('sys_datetime') let app_datetime = sessionStorage.getItem('app_datetime') @@ -345,20 +345,17 @@ param.svccode = 'oms' } - param.appkey = window.GLOB.appkey || '' let url = '/webapi/dologon' if (isCloud) { param.debug = 'Y' if (options.cloudServiceApi) { - // url = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon') param.rduri = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon') } } else if (window.GLOB.mainSystemApi) { if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') { param.linkurl = window.GLOB.linkurl } - // url = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon') param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon') } @@ -402,7 +399,7 @@ /** * @description 鑾峰彇绯荤粺鐗堟湰淇℃伅锛屽惎鐢ㄦ垨鏇存柊websql */ - getAppVersion (_resolve, _reject) { + getAppVersion (reload) { if (!window.GLOB.WebSql && !window.GLOB.IndexDB) { return Promise.reject() } @@ -433,7 +430,7 @@ CacheUtils.updateWebSqlversion('1.00', curTime) resolve() return - } else if (!msg.createDate) { + } else if (!msg.createDate || reload === true) { param.modifydate = curTime param.menuids = window.btoa(msg.menuids) } else if (msg.menuids) { @@ -458,18 +455,25 @@ list.push(...res.menu_del) } + list = list.map(mid => mid.menuid) + + if (typeof(reload) === 'string' && !list.includes(reload)) { + list.push(reload) + } + if (list.length > 0) { let clear = false list.forEach(mid => { - if (systemMenuKeys.indexOf(mid.menuid) > -1) { + if (systemMenuKeys.indexOf(mid) > -1) { clear = true } }) - let keys = list.map(mid => `'${mid.menuid}'`).join(',') if (clear) { - keys = '' + list = '' + } else { + list = list.map(mid => `'${mid}'`).join(',') } - CacheUtils.delWebSqlConfig(keys) + CacheUtils.delWebSqlConfig(list) } CacheUtils.updateWebSqlversion(res.app_version || '1.00', curTime) @@ -495,7 +499,7 @@ CacheUtils.updateIndexDBversion({version: '1.00', createDate: curTime}) resolve() return - } else if (!msg.createDate) { + } else if (!msg.createDate || reload === true) { param.modifydate = curTime param.menuids = window.btoa(msg.menuids) } else if (msg.menuids) { @@ -520,18 +524,23 @@ list.push(...res.menu_del) } + list = list.map(mid => mid.menuid) + + if (typeof(reload) === 'string' && !list.includes(reload)) { + list.push(reload) + } + if (list.length > 0) { let clear = false list.forEach(mid => { - if (systemMenuKeys.indexOf(mid.menuid) > -1) { + if (systemMenuKeys.indexOf(mid) > -1) { clear = true } }) - let keys = list.map(mid => mid.menuid) if (clear) { - keys = '' + list = '' } - CacheUtils.delIndexDBConfig(keys) + CacheUtils.delIndexDBConfig(list) } CacheUtils.updateIndexDBversion({version: res.app_version || '1.00', createDate: curTime}) @@ -562,11 +571,6 @@ deleteMenuStorage (menuId) { if (window.GLOB.IndexDB) { let key = menuId + (sessionStorage.getItem('UserID') || '') - - if (sessionStorage.getItem('isEditState') === 'true' && options.cloudServiceApi) { - key = menuId + (sessionStorage.getItem('CloudUserID') || '') - } - return CacheUtils.delMenuIndexDBConfig(key) } else { return CacheUtils.delMenuWebSqlConfig(menuId) @@ -855,6 +859,117 @@ } } + visitOuterSystem (param, _resolve) { + let token = param.$token + delete param.$token + + try { + token = JSON.parse(token) + token = token.message + + const key = CryptoJS.enc.Utf8.parse(window.GLOB.appkey.slice(-16)) + const iv = CryptoJS.enc.Utf8.parse('mksoft') + + let encryptedHexStr = CryptoJS.enc.Hex.parse(token) + let _srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr) + let decrypt = CryptoJS.AES.decrypt(_srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }) + let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8) + token = decryptedStr.toString() + + token = JSON.parse(window.decodeURIComponent(window.atob(token))) + } catch (e) { + token = null + _resolve({status: false, ErrCode: 'E', message: '鎺ュ彛淇℃伅瑙f瀽澶辫触锛�'}) + } + + if (!token) return + + let userid = '' + let loginUid = '' + let dataM = '' + + if (window.GLOB.OuterToken[token.interface]) { + let msg = window.GLOB.OuterToken[token.interface] + + let seconds = Math.floor((new Date().getTime() - msg.timestamp) / 1000) + if (seconds >= 3600) { + delete window.GLOB.OuterToken[token.interface] + } else { + userid = msg.userid + loginUid = msg.loginUid + dataM = msg.dataM || '' + } + } + + // param.appkey = token.appkey || '' + + if (userid && loginUid) { + param.dataM = dataM + param.userid = userid + param.LoginUID = loginUid + param = this.encryptParam(param) + + axios({ + url: token.interface, + method: 'post', + data: param + }).then(res => { + _resolve(res) + }) + } else { + let _param = { + UserName: token.username, + systemType: options.sysType, + login_city: sessionStorage.getItem('city') || '', + device_id: token.appkey || '', + timestamp: moment().format('YYYY-MM-DD HH:mm:ss'), + Type: token.publicKey, + appkey: token.appkey || '' + } + + let shaObj = new jsSHA('SHA-1', 'TEXT') + shaObj.update(token.password) + _param.Password = shaObj.getHash('HEX').toUpperCase() + _param.Password = md5(token.privateKey + token.username + _param.Password + _param.timestamp) + + let url = token.interface.replace(/\/webapi(.*)/, '/webapi/dologon') + + if (token.ssoInterface) { + _param.rduri = token.ssoInterface.replace(/\/webapi(.*)/, '/webapi/dologon') + } + + axios({ + url, + method: 'post', + data: _param + }).then(result => { + if (result.status) { + window.GLOB.OuterToken[token.interface] = { + userid: result.UserID, + loginUid: result.LoginUID, + timestamp: new Date().getTime(), + dataM: result.dataM ? 'Y' : '' + } + + param.dataM = result.dataM ? 'Y' : '' + param.userid = result.UserID + param.LoginUID = result.LoginUID + param = this.encryptParam(param) + + axios({ + url: token.interface, + method: 'post', + data: param + }).then(res => { + _resolve(res) + }) + } else { + _resolve(result) + } + }) + } + } + /** * @description 鑾峰彇涓氬姟閫氱敤鎺ュ彛 * 璁块棶 'https://sso.mk9h.cn/webapi/dostars'鎴栦簯绔椂锛屼紶鍏serid銆丩oginUID @@ -866,6 +981,22 @@ param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || '' param.appkey = window.GLOB.appkey || '' + if (param.$token === '') { + return Promise.resolve({status: false, ErrCode: 'E', message: '鎺ュ彛鍦板潃灏氭湭璁剧疆锛�'}) + } else if (param.$token) { + return new Promise(resolve => this.visitOuterSystem(param, resolve)) + } + + if (['sPC_Get_TableData', 'sPC_Get_TableData_debug', 'sPC_TableData_InUpDe', 'sPC_TableData_InUpDe_debug', 'sPC_Get_structured_data'].includes(param.func)) { + if (sessionStorage.getItem('isEditState') === 'true') { + param.username = sessionStorage.getItem('CloudUserName') || '' + param.fullname = sessionStorage.getItem('CloudFullName') || '' + } else { + param.username = sessionStorage.getItem('User_Name') || '' + param.fullname = sessionStorage.getItem('Full_Name') || '' + } + } + let login = false let rduri = null -- Gitblit v1.8.0