| | |
| | | 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) |
| | |
| | | |
| | | 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() |
| | | } |
| | |
| | | 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 |
| | | } |
| | | |
| | | /** |
| | |
| | | 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 |
| | | }) |
| | | } |
| | | |
| | |
| | | /** |
| | | * @description 游客登录 |
| | | */ |
| | | getTouristMsg (appid, openid, memberid, scanId) { |
| | | getTouristMsg (binding_type, appid, openid, memberid, scanId) { |
| | | let _SessionUid = localStorage.getItem('SessionUid') |
| | | |
| | | if (!_SessionUid) { // 手动清除SessionUid时,实时生成 |
| | |
| | | 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, |
| | |
| | | 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 || '' |
| | |
| | | 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') |
| | | } |
| | | |
| | |
| | | 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') |
| | |
| | | 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) |
| | |
| | | |
| | | /** |
| | | * @description 获取系统配置,取值优先等级websql、缓存、服务器 |
| | | * @param {Object} param 请求参数 |
| | | */ |
| | | getCacheConfig (param) { |
| | | param.userid = sessionStorage.getItem('UserID') || '' |
| | |
| | | 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)) // 缓存校验,去除时间和加密字符 |
| | |
| | | |
| | | /** |
| | | * @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 || '' |
| | |
| | | } |
| | | }) |
| | | 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 |
| | | } |
| | |
| | | param.appkey = window.GLOB.appkey || '' |
| | | |
| | | let url = '/webapi/dostars' |
| | | if (param.rduri) { |
| | | if (param.rduri && !window.GLOB.transfer) { |
| | | url = param.rduri |
| | | delete param.rduri |
| | | } |
| | |
| | | |
| | | /** |
| | | * @description 获取业务通用接口 |
| | | * 访问 'https://sso.mk9h.cn/webapi/dostars'或云端时,传入userid、LoginUID |
| | | */ |
| | | 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')) { // 非IE下载 |
| | | 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: '文件解析错误', |
| | | 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')) { // 非IE下载 |
| | | // 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: '文件解析错误', |
| | | // message: '', |
| | | // status: false |
| | | // }) |
| | | // } |
| | | // }) |
| | | // }) |
| | | // } |
| | | |
| | | /** |
| | | * @description 上传base64 |
| | |
| | | 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 |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * @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 |
| | | }) |