From a26f13ee999e84fc49cc3545e6e5d3daf9c6c41f Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 07 十月 2024 00:15:39 +0800 Subject: [PATCH] 2024-10-07 --- src/api/index.js | 313 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 225 insertions(+), 88 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index 50f5937..e508205 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -100,37 +100,15 @@ /** * @description 寰俊涓氬姟璇锋眰 鍘熸帴鍙� 'wxpay/getaccesstoken' */ - wxAccessToken (domain = '') { - let _url = domain || window.GLOB.baseurl + // wxAccessToken (appId, domain = '') { + // let _url = domain || window.GLOB.baseurl - if (/qingqiumarket.cn|cloud.mk9h.cn/.test(_url)) { - _url = _url.replace('http://qingqiumarket.cn', 'http://qingqiumarket.cn:8080') - _url = _url.replace('http://cloud.mk9h.cn', 'http://cloud.mk9h.cn:8080') - _url = _url.replace('https://qingqiumarket.cn', 'https://qingqiumarket.cn:8443') - _url = _url.replace('https://cloud.mk9h.cn', 'https://cloud.mk9h.cn:8443') - } - - return new Promise(resolve => { - if (window.GLOB.accessToken.domain === domain && window.GLOB.accessToken.accessTime && (parseInt(new Date().getTime() / 1000) - window.GLOB.accessToken.accessTime < 30)) { - resolve(window.GLOB.accessToken) - } else { - window.GLOB.accessToken = {domain} - axios({ - url: _url + 'wechat/jsapi/getaccesstoken', - method: 'post', - headers: { 'Content-Type': 'application/json' }, - data: JSON.stringify({appId: 'wx4d8a34c8d4494872'}) - }).then(res => { - if (res.oa_access_token) { - window.GLOB.accessToken.accessTime = parseInt(new Date().getTime() / 1000) - window.GLOB.accessToken.oa_access_token = res.oa_access_token - // window.GLOB.accessToken.mini_access_token = res.mini_access_token - } - resolve(res) - }) - } - }) - } + // return axios({ + // url: _url + 'wechat/getaccesstoken', + // method: 'post', + // data: JSON.stringify({app_id: appId}) + // }) + // } /** * @description 寰俊涓氬姟璇锋眰 @@ -144,12 +122,12 @@ if (process.env.NODE_ENV === 'production') { _url = document.location.origin + '/' + url } - if (/qingqiumarket.cn|cloud.mk9h.cn/.test(_url)) { - _url = _url.replace('http://qingqiumarket.cn', 'http://qingqiumarket.cn:8080') - _url = _url.replace('http://cloud.mk9h.cn', 'http://cloud.mk9h.cn:8080') - _url = _url.replace('https://qingqiumarket.cn', 'https://qingqiumarket.cn:8443') - _url = _url.replace('https://cloud.mk9h.cn', 'https://cloud.mk9h.cn:8443') - } + } + if (/qingqiumarket.cn|cloud.mk9h.cn/.test(_url)) { + _url = _url.replace('http://qingqiumarket.cn/', 'http://qingqiumarket.cn:8080/') + _url = _url.replace('http://cloud.mk9h.cn/', 'http://cloud.mk9h.cn:8080/') + _url = _url.replace('https://qingqiumarket.cn/', 'https://qingqiumarket.cn:8443/') + _url = _url.replace('https://cloud.mk9h.cn/', 'https://cloud.mk9h.cn:8443/') } if (param) { @@ -169,7 +147,27 @@ /** * @description 鐩存帴璇锋眰 */ - directRequest (params) { + directRequest (params, script, position) { + if (script) { + try { + // eslint-disable-next-line + let func = new Function('axios', 'Api', 'param', 'position', 'systemType', 'notification', script) + let promise = func(axios, this, params, position, window.GLOB.systemType, notification) + + if (promise instanceof Promise) { + return promise + } + } catch (e) { + console.warn(e) + } + + return Promise.resolve({ + status: false, + message: '鑷畾涔夎剼鏈墽琛岄敊璇�', + ErrCode: 'E' + }) + } + return axios(params) } @@ -494,26 +492,26 @@ /** * @description 鑾峰彇鎴栦慨鏀圭郴缁熼厤缃紝澧炲姞appkey */ - getSystemFuncs (time) { - let param = { - func: 's_get_func_base_sso', - update_date: time, - userid: sessionStorage.getItem('UserID') || '', - lang: sessionStorage.getItem('lang') || '', - SessionUid: localStorage.getItem('SessionUid') || '', - LoginUID: sessionStorage.getItem('LoginUID') || '', - appkey: window.GLOB.appkey - } + // getSystemFuncs (time) { + // let param = { + // func: 's_get_func_base_sso', + // update_date: time, + // userid: sessionStorage.getItem('UserID') || '', + // lang: sessionStorage.getItem('lang') || '', + // SessionUid: localStorage.getItem('SessionUid') || '', + // LoginUID: sessionStorage.getItem('LoginUID') || '', + // appkey: window.GLOB.appkey + // } - let url = window.GLOB.mainSystemApi || '/webapi/dostars' - param = this.encryptParam(param) + // let url = window.GLOB.mainSystemApi || '/webapi/dostars' + // param = this.encryptParam(param) - return axios({ - url: `${url}/${param.func}`, - method: 'post', - data: JSON.stringify(param) - }) - } + // return axios({ + // url: `${url}/${param.func}`, + // method: 'post', + // data: JSON.stringify(param) + // }) + // } /** * @description 鑾峰彇鎴栦慨鏀圭郴缁熼厤缃紝澧炲姞appkey @@ -672,6 +670,65 @@ param.SessionUid = localStorage.getItem('SessionUid') || '' param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || '' param.appkey = window.GLOB.appkey || '' + + if (param.$backend) { + delete param.$backend + + let id = '' + if (cache) { + id = param.data[0].id + + if (window.GLOB.CacheMap.has(id)) { + return Promise.resolve(window.GLOB.CacheMap.get(id)) + } + } + + param.username = sessionStorage.getItem('User_Name') || '' + param.fullname = sessionStorage.getItem('Full_Name') || '' + param.s_debug = window.GLOB.debugger ? 'Y' : '' + param.data_md5 = param.data_md5 || '' + param.time_limit = param.time_limit || 0 + + let url = '/webapi/exstars' + if (param.rduri) { + param.rduri = param.rduri.replace(/dostars/ig, 'exstars') + if (!window.GLOB.transfer) { + url = param.rduri + delete param.rduri + } + } + + if (param.$type) { + url += '/' + param.$type + } + + delete param.$type + + param = this.encryptParam(param) + + return new Promise((resolve) => { + axios({ + url: url, + method: 'post', + data: JSON.stringify(param) + }).then(res => { + if (res.mksqls) { + res.mksqls.forEach(n => { + n = n.replace(/(UNION ALL\s+)?SELECT obj_name='[\S\s]+sub_field=''\s+/ig, '') + window.mkInfo(n) + }) + } + if (res.ErrCode === 'version_error') { + res.ErrCode = '-2' + MKEmitter.emit('reloadTabs') + } + if (res.status && id) { + window.GLOB.CacheMap.set(id, res) + } + resolve(res) + }) + }) + } let url = '/webapi/dostars' if (param.rduri && !window.GLOB.transfer) { @@ -940,9 +997,55 @@ } }) }) + } else if (param.$backend) { + delete param.$backend + + let url = '/webapi/exstars' + if (param.rduri) { + param.rduri = param.rduri.replace(/dostars/ig, 'exstars') + if (!window.GLOB.transfer) { + url = param.rduri + delete param.rduri + } + } + + if (param.$type) { + url += '/' + param.$type + } + + delete param.$type + + param.username = sessionStorage.getItem('User_Name') || '' + param.fullname = sessionStorage.getItem('Full_Name') || '' + param.s_debug = window.GLOB.debugger ? 'Y' : '' + param.data_md5 = param.data_md5 || '' + param.time_limit = param.time_limit || 0 + + param = this.encryptParam(param) + + return new Promise((resolve) => { + axios({ + url: url, + method: 'post', + data: JSON.stringify(param), + requestId + }).then(res => { + if (res.mksqls) { + res.mksqls.forEach(n => { + n = n.replace(/(UNION ALL\s+)?SELECT obj_name='[\S\s]+sub_field=''\s+/ig, '') + window.mkInfo(n) + }) + } + if (res.ErrCode === 'version_error') { + res.ErrCode = '-2' + MKEmitter.emit('reloadTabs') + } + resolve(res) + }) + }) } else { let url = '/webapi/dostars' - if (param.rduri && !window.GLOB.transfer && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') { + if (param.rduri && (!window.GLOB.transfer || /https:\/\/sso.mk9h.cn/.test(param.rduri)) && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') { url = param.rduri delete param.rduri } @@ -956,6 +1059,27 @@ requestId }) } + } + + /** + * @description 娓呯┖鍚庣缂撳瓨 + */ + cacheInterface (param) { + param.appkey = window.GLOB.appkey || '' + + let url = '/webapi/excache' + if (param.rduri && !window.GLOB.transfer) { + url = param.rduri + delete param.rduri + } + + param = this.encryptParam(param) + + return axios({ + url: url, + method: 'post', + data: JSON.stringify(param), + }) } /** @@ -1001,26 +1125,45 @@ /** * @description 澶ф枃浠朵笂浼� */ - getLargeFileUpload (param) { - return axios({ - url: '/webapi/doupload', - method: 'post', - headers: { 'Content-Type': 'multipart/form-data' }, - data: param + getFileUpload (param) { + param.append('shardingCnt', 1) + param.append('LoginUID', sessionStorage.getItem('LoginUID') || '') + param.append('UserID', sessionStorage.getItem('UserID') || '') + + return new Promise((resolve, reject) => { + axios({ + url: '/webapi/doupload', + method: 'post', + headers: { 'Content-Type': 'multipart/form-data' }, + data: param + }).then(res => { + if (res.status && res.urlPath) { + if (!/Content\/images/.test(res.urlPath)) { + let key = CryptoJS.enc.Utf8.parse('D1185ED7B32568C9') + let wordArray = CryptoJS.enc.Base64.parse(res.urlPath) + let decryptedWordArray = CryptoJS.AES.decrypt({ ciphertext: wordArray }, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }) + res.urlPath = CryptoJS.enc.Utf8.stringify(decryptedWordArray) + } + if (!/^http/.test(res.urlPath)) { + res.urlPath = window.GLOB.baseurl + res.urlPath + } + } + resolve(res) + }) }) } /** * @description 鏌ヨ鏂囦欢鏄惁宸蹭笂浼� */ - getFilePreUpload (param) { - return axios({ - url: '/webapi/dopreload', - method: 'post', - headers: { 'Content-Type': 'multipart/form-data' }, - data: param - }) - } + // getFilePreUpload (param) { + // return axios({ + // url: '/webapi/dopreload', + // method: 'post', + // headers: { 'Content-Type': 'multipart/form-data' }, + // data: param + // }) + // } /** * @description oss鏂囦欢涓婁紶 @@ -1031,10 +1174,10 @@ _url = document.location.origin + '/file/oss/upload' } if (/qingqiumarket.cn|cloud.mk9h.cn/.test(_url)) { - _url = _url.replace('http://qingqiumarket.cn', 'http://qingqiumarket.cn:8080') - _url = _url.replace('http://cloud.mk9h.cn', 'http://cloud.mk9h.cn:8080') - _url = _url.replace('https://qingqiumarket.cn', 'https://qingqiumarket.cn:8443') - _url = _url.replace('https://cloud.mk9h.cn', 'https://cloud.mk9h.cn:8443') + _url = _url.replace('http://qingqiumarket.cn/', 'http://qingqiumarket.cn:8080/') + _url = _url.replace('http://cloud.mk9h.cn/', 'http://cloud.mk9h.cn:8080/') + _url = _url.replace('https://qingqiumarket.cn/', 'https://qingqiumarket.cn:8443/') + _url = _url.replace('https://cloud.mk9h.cn/', 'https://cloud.mk9h.cn:8443/') } return axios({ @@ -1046,30 +1189,24 @@ } /** - * @description 鑾峰彇寰俊鏀粯浜岀淮鐮� + * @description 鑾峰彇寰俊鏀粯浜岀淮鐮� 鍘熸帴鍙xpay/wxNativePay */ getWxNativePay (param) { - let _url = window.GLOB.baseurl + 'wxpay/wxNativePay' - return axios({ - url: _url, + url: window.GLOB.baseurl + 'wechat/native', method: 'post', - data: qs.stringify(param) + data: JSON.stringify(param) }) } /** - * @description 寰俊鏀粯閫�娆� + * @description 寰俊鏀粯閫�娆� 鍘熸帴鍙xpay/wxRefund */ - setRefund (orderId) { - let _param = new FormData() - _param.append('out_biz_no', orderId) - + setRefund (param) { return axios({ - url: '/wxpay/wxRefund', - headers: { 'Content-Type': 'multipart/form-data' }, + url: window.GLOB.baseurl + 'wechat/wxRefund', method: 'post', - data: _param + data: JSON.stringify(param) }) } @@ -1110,7 +1247,7 @@ sql = sql.replace(/@db@/ig, window.GLOB.externalDatabase) } - console.info(`/* sql 楠岃瘉 */\n${sql.replace(/\n\s{6,20}/ig, '\n')}`) + window.mkInfo(`/* sql 楠岃瘉 */\n${sql.replace(/\n\s{6,20}/ig, '\n')}`) sql = sql.replace(/\n/ig, ' ') -- Gitblit v1.8.0