From c33ac9ddcdbed91bd2267bed2a96199441806a04 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 22 九月 2022 17:00:15 +0800 Subject: [PATCH] 2022-09-22 --- src/api/index.js | 424 ++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 288 insertions(+), 136 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index 01fda72..c5353f8 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -29,7 +29,7 @@ axios.interceptors.request.use((config) => { if (config.url.includes('LoginAndRedirect') || config.url.includes('getjsonresult') || config.url.includes('wxNativePay')) { config.data = qs.stringify(config.data) - } else if (config.url.includes('Upload') || config.url.includes('doupload') || config.url.includes('dopreload')) { + } else if (/\/doupload|\/dopreload|\/upload/.test(config.url)) { config.headers = { 'Content-Type': 'multipart/form-data' } } else if (config.method === 'post' && config.data) { config.data = JSON.stringify(config.data) @@ -42,13 +42,8 @@ const setCurrentUrl = (res) => { if (!!(window.history && window.history.pushState)) { - if (window.location.href.indexOf('paramsmain') > -1) { - let _href = window.location.href.split('#') - localStorage.setItem(_href[0] + 'paramsmain', _href[1]) - } - sessionStorage.clear() - sessionStorage.setItem('loginError', JSON.stringify({request: res.config ? res.config.data : '', response: JSON.stringify(res.data)})) + sessionStorage.setItem('loginError', JSON.stringify({url: res.config ? res.config.url : '', request: res.config ? res.config.data : '', response: JSON.stringify(res.data)})) window.history.replaceState(null, null, window.location.href.split('#')[0] + '#/login') window.location.reload() } @@ -59,32 +54,34 @@ if (window.debugger === true) { response.data.ErrCode = 'E' return Promise.resolve(response.data) - } else { + } else if (!sessionStorage.getItem('loginError')) { setCurrentUrl(response) } } else { return Promise.resolve(response.data) } }, (error) => { - if (error && error.response) { - notification.error({ - className: 'notification-custom-error', - bottom: 0, - message: '鐘舵�佺爜-' + error.response.status + '锛岃鑱旂郴绠$悊鍛�', - placement: 'bottomRight', - duration: 15 - }) + let response = error.response + + if (response) { + if (!response.data || !response.data.errors) { // 杩囨护鏃疯鎶ラ敊淇℃伅 + notification.error({ + className: 'notification-custom-error', + bottom: 0, + message: '鐘舵�佺爜-' + response.status + '锛岃鑱旂郴绠$悊鍛�', + placement: 'bottomRight', + duration: 15 + }) + } + return Promise.reject(response) + } else { + return Promise.reject() } - return Promise.reject(error.response) }) class Api { constructor() { - if (process.env.NODE_ENV === 'production') { - axios.defaults.baseURL = document.location.origin + '/' + window.GLOB.service - } else { - axios.defaults.baseURL = window.GLOB.location + '/' + window.GLOB.service - } + axios.defaults.baseURL = window.GLOB.baseurl } /** @@ -95,9 +92,72 @@ param.userid = param.userid || '' return axios({ - url: '/webapi/dostar', + url: `/webapi/dostar${param.func ? '/' + param.func : ''}`, method: 'post', data: param + }) + } + + /** + * @description 寰俊涓氬姟璇锋眰 + */ + wxAccessToken () { + let _url = window.GLOB.baseurl + 'wxpay/getaccesstoken' + if (process.env.NODE_ENV !== 'production') { + _url = document.location.origin + '/wxpay/getaccesstoken' + } + + return new Promise(resolve => { + if (window.GLOB.accessToken.accessTime && (parseInt(new Date().getTime() / 1000) - window.GLOB.accessToken.accessTime < 30)) { + resolve(window.GLOB.accessToken) + } else { + window.GLOB.accessToken = {} + axios({ + url: _url, + method: 'get' + }).then(res => { + if (res.oa_access_token || res.mini_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) + }) + } + }) + } + + /** + * @description 寰俊涓氬姟璇锋眰 + */ + wxNginxRequest (url, method, param) { + let _url = window.GLOB.location + '/' + url + if (process.env.NODE_ENV === 'production') { + _url = document.location.origin + '/' + url + } + if (/^http:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) { + _url = window.GLOB.location + ':8080/' + url + if (process.env.NODE_ENV === 'production') { + _url = document.location.origin + ':8080/' + url + } + } else if (/^https:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) { + _url = window.GLOB.location + ':8443/' + url + if (process.env.NODE_ENV === 'production') { + _url = document.location.origin + ':8443/' + url + } + } + + if (param) { + return axios({ + url: _url, + method, + data: param + }) + } + + return axios({ + url: _url, + method }) } @@ -141,7 +201,7 @@ /** * @description 娓稿鐧诲綍 */ - getTouristMsg (appid, openid, memberid, scanId) { + getTouristMsg (binding_type, appid, openid, memberid, scanId) { let _SessionUid = localStorage.getItem('SessionUid') if (!_SessionUid) { // 鎵嬪姩娓呴櫎SessionUid鏃讹紝瀹炴椂鐢熸垚 @@ -153,27 +213,42 @@ func: 's_visitor_login', timestamp: moment().format('YYYY-MM-DD HH:mm:ss'), SessionUid: _SessionUid, - TypeCharOne: 'pc' + TypeCharOne: 'pc', + kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)) } - - param.LText = md5(window.btoa(_SessionUid + param.timestamp)) - param.secretkey = md5(param.LText + 'mingke' + param.timestamp) - param.appkey = window.GLOB.appkey || '' + let url = '/webapi/dologon/s_visitor_login' + if (window.GLOB.mainSystemApi) { + param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login') + } - if (appid) { + if (binding_type === 'mk') { param.binding_type = 'mk' param.thd_party_member_id = memberid param.thd_party_openid = openid param.thd_party_appid = appid param.id = scanId - } + } else if (binding_type === 'login_check') { // appid 姝ゆ椂涓虹洰鏍� + param.v_type = 'login_check' + param.LoginUID = sessionStorage.getItem('LoginUID') || '' + url = appid.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login') - let url = '/webapi/dologon/s_visitor_login' - if (window.GLOB.mainSystemApi) { - // url = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login') - param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login') + if (!param.rduri) { + param.rduri = window.GLOB.baseurl + 'webapi/dologon/s_visitor_login' + } + + param.linkurl = appid.replace(/\/webapi(.*)/, '/index.html') } + + param.LText = md5(window.btoa(_SessionUid + param.timestamp + (param.linkurl || ''))) + + // param.secretkey = md5(param.LText + 'mingke' + param.timestamp) // v_type 涓虹┖鏃� + let solt = md5((window.GLOB.appkey + window.btoa(window.GLOB.appkey + 'mingke') + 'mingke').toLowerCase()).slice(-6).toUpperCase() + + param.v_type = param.v_type || 'Y' + param.secretkey = md5(param.LText + solt + param.timestamp) + + param.appkey = window.GLOB.appkey || '' return axios({ url: url, @@ -195,7 +270,9 @@ way_no: 'sms_vcode', systemType: options.sysType, login_city: city, - login_id_address: ipAddress + login_id_address: ipAddress, + kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)), + device_id: localStorage.getItem('SessionUid') } param.appkey = window.GLOB.appkey || '' @@ -204,14 +281,12 @@ 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') } @@ -232,7 +307,9 @@ systemType: options.sysType, Type: 'S', login_city: city, - login_id_address: ipAddress + login_id_address: ipAddress, + kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)), + device_id: localStorage.getItem('SessionUid') } param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') @@ -487,32 +564,11 @@ param.userid = sessionStorage.getItem('CloudUserID') || '' param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' } else if (window.GLOB.mainSystemApi) { - url = window.GLOB.mainSystemApi - } - - param = this.encryptParam(param) - - return axios({ - url: `${url}${param.func ? '/' + param.func : ''}`, - method: 'post', - data: param - }) - } - - /** - * @description 鑾峰彇鎴栦慨鏀规湰鍦伴厤缃紝澧炲姞appkey - */ - getLocalConfig (param) { - param.userid = param.userid || sessionStorage.getItem('UserID') || '' - param.lang = param.lang || sessionStorage.getItem('lang') || '' - param.SessionUid = localStorage.getItem('SessionUid') || '' - param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || '' - param.appkey = window.GLOB.appkey || '' - - let url = '/webapi/dostars' - if (param.rduri) { - url = param.rduri - delete param.rduri + if (!window.GLOB.transfer) { + url = window.GLOB.mainSystemApi + } else { + param.rduri = window.GLOB.mainSystemApi + } } param = this.encryptParam(param) @@ -526,7 +582,6 @@ /** * @description 鑾峰彇绯荤粺閰嶇疆锛屽彇鍊间紭鍏堢瓑绾ebsql銆佺紦瀛樸�佹湇鍔″櫒 - * @param {Object} param 璇锋眰鍙傛暟 */ getCacheConfig (param) { param.userid = sessionStorage.getItem('UserID') || '' @@ -543,7 +598,11 @@ param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' } } else if (window.GLOB.mainSystemApi) { - url = window.GLOB.mainSystemApi + if (!window.GLOB.transfer) { + url = window.GLOB.mainSystemApi + } else { + param.rduri = window.GLOB.mainSystemApi + } } let _param = JSON.parse(JSON.stringify(param)) // 缂撳瓨鏍¢獙锛屽幓闄ゆ椂闂村拰鍔犲瘑瀛楃 @@ -621,11 +680,10 @@ /** * @description 鑾峰彇鏈湴绯荤粺閰嶇疆 - * @param {Object} param 璇锋眰鍙傛暟 */ getLocalCacheConfig (param) { param.userid = sessionStorage.getItem('UserID') || '' - param.lang = param.lang || sessionStorage.getItem('lang') || '' + param.lang = sessionStorage.getItem('lang') || '' param.SessionUid = localStorage.getItem('SessionUid') || '' param.LoginUID = sessionStorage.getItem('LoginUID') || '' param.appkey = window.GLOB.appkey || '' @@ -666,7 +724,15 @@ } }) param.sign = md5(values) - param.t = new Date().getTime() + param.t = new Date().getTime(); + + ['arr_field', 'LText_field', 'custom_script', 'LText1', 'LText', 'LText2', 'DateCount'].forEach(key => { + if (param[key]) { + let val = param[key] + delete param[key] + param[key] = val + } + }) return param } @@ -684,7 +750,7 @@ param.appkey = window.GLOB.appkey || '' let url = '/webapi/dostars' - if (param.rduri) { + if (param.rduri && !window.GLOB.transfer) { url = param.rduri delete param.rduri } @@ -718,85 +784,128 @@ /** * @description 鑾峰彇涓氬姟閫氱敤鎺ュ彛 + * 璁块棶 'https://sso.mk9h.cn/webapi/dostars'鎴栦簯绔椂锛屼紶鍏serid銆丩oginUID */ genericInterface (param) { - param.userid = sessionStorage.getItem('UserID') || '' - param.lang = sessionStorage.getItem('lang') || '' + param.userid = param.userid || sessionStorage.getItem('UserID') || '' + param.lang = param.lang || sessionStorage.getItem('lang') || '' param.SessionUid = localStorage.getItem('SessionUid') || '' - param.LoginUID = sessionStorage.getItem('LoginUID') || '' + param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || '' param.appkey = window.GLOB.appkey || '' - if (options.cloudServiceApi && param.rduri === options.cloudServiceApi) { // HS涓嬭彍鍗� - param.userid = sessionStorage.getItem('CloudUserID') || param.userid || '' - param.LoginUID = sessionStorage.getItem('CloudLoginUID') || param.LoginUID || '' + let login = false + let rduri = null + + if (param.rduri && /\s|\n/.test(param.rduri)) { + param.rduri = param.rduri.replace(/\s|\n/g, '') + if (!param.rduri) { + delete param.rduri + } } - // 寰呬紭鍖栵紝澧炲姞鏄惁鏀寔璺ㄥ煙璇锋眰 - // let url = '/webapi/dostars' - // if (param.rduri) { - // url = param.rduri - // delete param.rduri - // } + if (param.$login && !window.GLOB.transfer) { + login = true + rduri = param.rduri || '' + } + delete param.$login + + let url = '/webapi/dostars' + + if (param.rduri && !window.GLOB.transfer && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') { + url = param.rduri + delete param.rduri + } param = this.encryptParam(param) - return axios({ - url: `/webapi/dostars${param.func ? '/' + param.func : ''}`, - method: 'post', - data: param - }) + if (login) { + let time = +sessionStorage.getItem(rduri) + let c_time = Math.round(new Date().getTime() / 1000) + + if (time && c_time - time <= 60) { + sessionStorage.setItem(rduri, c_time) + return axios({ + url: `${url}${param.func ? '/' + param.func : ''}`, + method: 'post', + data: param + }) + } + + return new Promise((resolve, reject) => { + this.getTouristMsg('login_check', rduri).then(res => { + if (res.status) { + sessionStorage.setItem(rduri, c_time) + axios({ + url: `${url}${param.func ? '/' + param.func : ''}`, + method: 'post', + data: param + }).then(result => { + resolve(result) + }) + } else { + resolve(res) + } + }) + }) + } else { + return axios({ + url: `${url}${param.func ? '/' + param.func : ''}`, + method: 'post', + data: param + }) + } } /** - * @description 瀵煎嚭Excel + * @description 瀵煎嚭Excel锛屽悗鍙扮敓鎴愭枃浠� */ - getExcelOut (param, name) { - param.userid = sessionStorage.getItem('UserID') - param.lang = sessionStorage.getItem('lang') || '' - param.SessionUid = localStorage.getItem('SessionUid') || '' - param.LoginUID = sessionStorage.getItem('LoginUID') || '' - param.appkey = window.GLOB.appkey || '' + // getExcelOut (param, name) { + // param.userid = sessionStorage.getItem('UserID') + // param.lang = sessionStorage.getItem('lang') || '' + // param.SessionUid = localStorage.getItem('SessionUid') || '' + // param.LoginUID = sessionStorage.getItem('LoginUID') || '' + // param.appkey = window.GLOB.appkey || '' - return new Promise(resolve => { - axios({ - url: '/webapi/doexcel', - responseType: 'blob', - method: 'post', - data: param - }).then(res => { - try { - const blob = new Blob([res]) + // return new Promise(resolve => { + // axios({ + // url: '/webapi/doexcel', + // responseType: 'blob', + // method: 'post', + // data: param + // }).then(res => { + // try { + // const blob = new Blob([res]) - if (res.type === 'application/json') { - const reader = new FileReader() - reader.onload = e => resolve(JSON.parse(e.target.result)) - reader.readAsText(blob) - } else { - if ('download' in document.createElement('a')) { // 闈濱E涓嬭浇 - const elink = document.createElement('a') - elink.download = name - elink.style.display = 'none' - elink.href = URL.createObjectURL(blob) - document.body.appendChild(elink) - elink.click() - URL.revokeObjectURL(elink.href) // 閲婃斁URL 瀵硅薄 - document.body.removeChild(elink) - } else { // IE10+涓嬭浇 - navigator.msSaveBlob(blob, name) - } - resolve() - } - } catch (e) { - resolve({ - ErrCode: 'E', - ErrMesg: '鏂囦欢瑙f瀽閿欒', - message: '', - status: false - }) - } - }) - }) - } + // if (res.type === 'application/json') { + // const reader = new FileReader() + // reader.onload = e => resolve(JSON.parse(e.target.result)) + // reader.readAsText(blob) + // } else { + // if ('download' in document.createElement('a')) { // 闈濱E涓嬭浇 + // const elink = document.createElement('a') + // elink.download = name + // elink.style.display = 'none' + // elink.href = URL.createObjectURL(blob) + // document.body.appendChild(elink) + // elink.click() + // URL.revokeObjectURL(elink.href) // 閲婃斁URL 瀵硅薄 + // document.body.removeChild(elink) + // } else { // IE10+涓嬭浇 + // navigator.msSaveBlob(blob, name) + // } + // resolve() + // } + // } catch (e) { + // resolve({ + // ErrCode: 'E', + // ErrMesg: '鏂囦欢瑙f瀽閿欒', + // message: '', + // status: false + // }) + // } + // }) + // }) + // } /** * @description 涓婁紶base64 @@ -815,8 +924,19 @@ param = this.encryptParam(param) let url = '/webapi/SaveBase64Image' + if (param.rduri) { - url = param.rduri.replace(/webapi(.*)$/, 'webapi/SaveBase64Image') + param.rduri = param.rduri.replace(/webapi(.*)$/, 'webapi/SaveBase64Image') + if (/\s|\n/.test(param.rduri)) { + param.rduri = param.rduri.replace(/\s|\n/g, '') + if (!param.rduri) { + delete param.rduri + } + } + } + + if (param.rduri && !window.GLOB.transfer) { + url = param.rduri delete param.rduri } @@ -850,11 +970,43 @@ } /** + * @description oss鏂囦欢涓婁紶 + */ + fileOssUpload (param) { + let _url = window.GLOB.location + '/file/oss/upload' + if (process.env.NODE_ENV === 'production') { + _url = document.location.origin + '/file/oss/upload' + } + if (/^http:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) { + _url = window.GLOB.location + ':8080/file/oss/upload' + if (process.env.NODE_ENV === 'production') { + _url = document.location.origin + ':8080/file/oss/upload' + } + } else if (/^https:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) { + _url = window.GLOB.location + ':8443/file/oss/upload' + if (process.env.NODE_ENV === 'production') { + _url = document.location.origin + ':8443/file/oss/upload' + } + } + + return axios({ + url: _url, + method: 'post', + data: param + }) + } + + /** * @description 鑾峰彇寰俊鏀粯浜岀淮鐮� */ getWxNativePay (param) { + let _url = window.GLOB.baseurl + 'wxpay/wxNativePay' + if (process.env.NODE_ENV !== 'production') { + _url = document.location.origin + '/wxpay/wxNativePay' + } + return axios({ - url: '/wxpay/wxNativePay', + url: _url, method: 'post', data: param }) -- Gitblit v1.8.0