| | |
| | | import axios from 'axios' |
| | | import qs from 'qs' |
| | | import { notification } from 'antd' |
| | | import { notification, Modal } 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' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import CacheUtils from './cacheutils' |
| | | import options from '@/store/options.js' |
| | | |
| | | window.GLOB.IndexDB = null |
| | | window.GLOB.OuterToken = {} |
| | | window.GLOB.$error = false |
| | | |
| | | let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : '' |
| | | let db = `mkdb${service}` |
| | |
| | | axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' |
| | | axios.defaults.withCredentials = false |
| | | |
| | | // axios.interceptors.request.use((config) => { |
| | | // return config |
| | | // }, (error) => { |
| | | // return Promise.reject(error) |
| | | // }) |
| | | |
| | | const setCurrentUrl = (res) => { |
| | | if (!!(window.history && window.history.pushState)) { |
| | | sessionStorage.clear() |
| | | 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() |
| | | } |
| | | } |
| | | |
| | | axios.interceptors.response.use((response) => { |
| | | if (response.data.ErrCode === 'LoginError') { |
| | | if (window.debugger === true) { |
| | | response.data.ErrCode = 'E' |
| | | return Promise.resolve(response.data) |
| | | } else if (window.GLOB.developing) { |
| | | if (window.GLOB.developing) { |
| | | sessionStorage.setItem('devError', 'true') |
| | | response.data.ErrCode = 'E' |
| | | return Promise.resolve(response.data) |
| | | } else if (!sessionStorage.getItem('loginError')) { |
| | | setCurrentUrl(response) |
| | | } else if (response.config.url.indexOf('https://sso.mk9h.cn/webapi/dostars') > -1) { |
| | | return Promise.reject(response.data) |
| | | } else if (response.config.url.indexOf('https://epc.mk9h.cn/webapi/dostars') > -1) { |
| | | return Promise.reject(response.data) |
| | | } |
| | | |
| | | if (!window.GLOB.$error) { |
| | | window.GLOB.$error = true |
| | | |
| | | Modal.destroyAll() |
| | | Modal.error({ |
| | | title: response.data.message, |
| | | okText: '知道了', |
| | | onOk: () => { |
| | | window.GLOB.$error = false |
| | | sessionStorage.clear() |
| | | if (!!(window.history && window.history.pushState)) { |
| | | window.history.replaceState(null, null, window.location.href.split('#')[0] + '#/login') |
| | | window.location.reload() |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | return Promise.reject(response.data) |
| | | } else { |
| | | return Promise.resolve(response.data) |
| | | } |
| | | }, (error) => { |
| | | let response = error.response |
| | | 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() |
| | | if (response && response.status) { |
| | | notification.error({ |
| | | className: 'notification-custom-error', |
| | | bottom: 0, |
| | | message: '状态码-' + response.status + ',请联系管理员', |
| | | placement: 'bottomRight', |
| | | duration: 15 |
| | | }) |
| | | } |
| | | |
| | | return Promise.reject(response) |
| | | }) |
| | | |
| | | class Api { |
| | |
| | | param.thd_party_openid = openid |
| | | param.thd_party_appid = appid |
| | | param.id = scanId |
| | | } else if (binding_type === 'login_check') { // appid 此时为目标 |
| | | } 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') |
| | | |
| | | |
| | | if (!param.rduri) { |
| | | param.rduri = window.GLOB.baseurl + 'webapi/dologon/s_visitor_login' |
| | | } |
| | | |
| | | param.linkurl = appid.replace(/\/webapi(.*)/, '/index.html') |
| | | |
| | | if (appid) { |
| | | url = appid.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login') |
| | | param.linkurl = appid.replace(/\/webapi(.*)/, '/index.html') |
| | | } else { |
| | | param.linkurl = window.GLOB.linkurl |
| | | } |
| | | } |
| | | |
| | | param.LText = md5(window.btoa(_SessionUid + param.timestamp + (param.linkurl || ''))) |
| | |
| | | Password: '', |
| | | check_code: checkcode, |
| | | way_no: 'sms_vcode', |
| | | systemType: options.sysType, |
| | | systemType: window.GLOB.sysType, |
| | | login_city: sessionStorage.getItem('city') || '', |
| | | login_id_address: sessionStorage.getItem('ipAddress') || '', |
| | | kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)), |
| | |
| | | let url = '/webapi/dologon' |
| | | if (isCloud) { |
| | | param.debug = 'Y' |
| | | if (options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon') |
| | | if (window.GLOB.cloudServiceApi) { |
| | | param.rduri = window.GLOB.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon') |
| | | } |
| | | } else if (window.GLOB.mainSystemApi) { |
| | | if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') { |
| | | if (window.GLOB.sysType !== 'cloud' && window.GLOB.systemType !== 'production') { |
| | | param.linkurl = window.GLOB.linkurl |
| | | } |
| | | param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon') |
| | |
| | | let param = { |
| | | // func: 'webapi_login', |
| | | UserName: username, |
| | | systemType: options.sysType, |
| | | systemType: window.GLOB.sysType, |
| | | Type: 'S', |
| | | login_city: sessionStorage.getItem('city') || '', |
| | | login_id_address: sessionStorage.getItem('ipAddress') || '', |
| | |
| | | |
| | | if (isCloud) { |
| | | param.debug = 'Y' |
| | | if (options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon') |
| | | if (window.GLOB.cloudServiceApi) { |
| | | param.rduri = window.GLOB.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon') |
| | | } |
| | | } else if (window.GLOB.mainSystemApi) { |
| | | if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') { |
| | | if (window.GLOB.sysType !== 'cloud' && window.GLOB.systemType !== 'production') { |
| | | param.linkurl = window.GLOB.linkurl |
| | | } |
| | | param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon') |
| | |
| | | } |
| | | |
| | | delCacheConfig (type = '') { |
| | | let date = moment().subtract(7, 'days').format('YYYY-MM-DD') |
| | | let date = moment().subtract(7, 'days').format('YYYY-MM-DD HH:mm:ss') |
| | | CacheUtils.delIndexDBCacheConfig(date, type) |
| | | } |
| | | |
| | | writeCacheConfig (menuid, data) { |
| | | writeCacheConfig (menuid, data, BID = '', id = '') { |
| | | if (!menuid) return |
| | | let date = moment().format('YYYY-MM-DD') |
| | | let date = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | let _data = data ? JSON.stringify(data) : '' |
| | | let userid = sessionStorage.getItem('UserID') || '' |
| | | |
| | | CacheUtils.writeCacheInIndexDB({menuid, CreateDate: date, LongParam: _data}) |
| | | CacheUtils.writeCacheInIndexDB({menuid: md5(menuid + userid + BID + id), BID: BID, id: id, CreateDate: date, LongParam: _data}) |
| | | } |
| | | |
| | | getLCacheConfig (menuid) { |
| | | getLCacheConfig (menuid, minutes, BID = '', id = '') { |
| | | return new Promise((resolve, reject) => { |
| | | if (window.GLOB.IndexDB) { |
| | | CacheUtils.getIndexDBCacheConfig(menuid).then(res => { |
| | | if (res && res.LongParam) { |
| | | let _data = JSON.parse(res.LongParam) |
| | | if (_data.length === 0) { |
| | | resolve() |
| | | } else { |
| | | resolve(_data) |
| | | } |
| | | } else { |
| | | resolve() |
| | | } |
| | | }) |
| | | } else { |
| | | resolve() |
| | | } |
| | | let limit = minutes ? moment().subtract(minutes, 'minutes').format('YYYY-MM-DD HH:mm:ss') : '' |
| | | let userid = sessionStorage.getItem('UserID') || '' |
| | | |
| | | CacheUtils.getIndexDBCacheConfig(md5(menuid + userid + BID + id)).then(res => { |
| | | if (res && res.LongParam) { |
| | | resolve({data: JSON.parse(res.LongParam), valid: !limit || res.CreateDate > limit}) |
| | | } else { |
| | | resolve({data: null, valid: false}) |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | |
| | | modifydate: msg.createDate |
| | | } |
| | | |
| | | if (window.GLOB.initVersion && sessionStorage.getItem('visitorUserID')) { |
| | | param.userid = sessionStorage.getItem('visitorUserID') |
| | | param.LoginUID = sessionStorage.getItem('visitorLoginUID') |
| | | } |
| | | |
| | | param.TypeCharOne = '' |
| | | param.typename = '' |
| | | |
| | |
| | | if (list.length > 0) { |
| | | let clear = false |
| | | let _appkey = window.GLOB.appkey.substr(-10) |
| | | let reg = new RegExp(_appkey + '$', 'ig') |
| | | let reg = new RegExp(_appkey + '$', 'i') |
| | | let reHome = list.includes('home_page_id') |
| | | |
| | | list.forEach(mid => { |
| | | if (reg.test(mid)) { |
| | |
| | | list = '' |
| | | } |
| | | CacheUtils.delIndexDBConfig(list) |
| | | this.delCacheConfig('all') |
| | | |
| | | if (reHome) { |
| | | MKEmitter.emit('reloadMenuView', 'home_page_id') |
| | | } |
| | | } |
| | | |
| | | CacheUtils.updateIndexDBversion({version: res.app_version || '1.00', createDate: curTime}) |
| | |
| | | */ |
| | | getCloudConfig (param) { |
| | | param.lang = param.lang || sessionStorage.getItem('lang') || '' |
| | | param.appkey = window.GLOB.appkey || '' |
| | | param.appkey = param.appkey || window.GLOB.appkey || '' |
| | | param.SessionUid = localStorage.getItem('SessionUid') || '' |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | param.userid = param.userid || sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = param.LoginUID || sessionStorage.getItem('CloudLoginUID') || '' |
| | | |
| | | param = this.encryptParam(param) |
| | | |
| | | let url = options.cloudServiceApi ? options.cloudServiceApi : '/webapi/dostars' |
| | | let url = window.GLOB.cloudServiceApi ? window.GLOB.cloudServiceApi : '/webapi/dostars' |
| | | if (param.func) { |
| | | url = url + '/' + param.func |
| | | } |
| | |
| | | param.appkey = param.appkey || window.GLOB.appkey |
| | | |
| | | let url = '/webapi/dostars' |
| | | if (sessionStorage.getItem('isEditState') === 'true' && options.cloudServiceApi) { // 编辑状态,且存在云端地址 |
| | | url = options.cloudServiceApi |
| | | if (window.GLOB.mkHS && window.GLOB.cloudServiceApi) { // HS下,且存在云端地址 |
| | | url = window.GLOB.cloudServiceApi |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } else if (window.GLOB.mainSystemApi) { |
| | |
| | | param.lang = param.lang || sessionStorage.getItem('lang') || '' |
| | | param.SessionUid = localStorage.getItem('SessionUid') || '' |
| | | param.LoginUID = sessionStorage.getItem('LoginUID') || '' |
| | | param.appkey = window.GLOB.appkey || '' |
| | | param.appkey = param.appkey || window.GLOB.appkey || '' |
| | | |
| | | let url = '/webapi/dostars' |
| | | if (sessionStorage.getItem('isEditState') === 'true') { // 编辑状态,单点登录服务器为云端 |
| | | if (options.cloudServiceApi) { // 存在云端地址时,使用云端系统参数 |
| | | url = options.cloudServiceApi |
| | | if (window.GLOB.mkHS) { // HS下,单点登录服务器为云端 |
| | | if (window.GLOB.cloudServiceApi) { // 存在云端地址时,使用云端系统参数 |
| | | url = window.GLOB.cloudServiceApi |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } |
| | |
| | | if (window.GLOB.CacheMap.has(_param)) { |
| | | return Promise.resolve(window.GLOB.CacheMap.get(_param)) |
| | | } else { |
| | | return Promise.resolve({ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false}) |
| | | return Promise.resolve({ErrCode: 'S', LongParam: '', message: '', status: false}) |
| | | } |
| | | } |
| | | |
| | |
| | | token = JSON.parse(window.decodeURIComponent(window.atob(token))) |
| | | } catch (e) { |
| | | token = null |
| | | _resolve({status: false, ErrCode: 'E', message: '接口信息解析失败!', ErrMesg: 'token_error'}) |
| | | _resolve({status: false, ErrCode: 'token_error', message: '接口信息解析失败!'}) |
| | | } |
| | | |
| | | if (!token) return |
| | |
| | | } else { |
| | | let _param = { |
| | | UserName: token.username, |
| | | systemType: options.sysType, |
| | | systemType: window.GLOB.sysType, |
| | | login_city: sessionStorage.getItem('city') || '', |
| | | device_id: token.appkey || '', |
| | | timestamp: moment().format('YYYY-MM-DD HH:mm:ss'), |
| | |
| | | param.appkey = window.GLOB.appkey || '' |
| | | |
| | | if (param.$token === '') { |
| | | return Promise.resolve({status: false, ErrCode: 'E', message: '接口地址尚未设置!', ErrMesg: 'token_error'}) |
| | | return Promise.resolve({status: false, ErrCode: 'token_error', 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') || '' |
| | | } |
| | | if (['sPC_TableData_InUpDe', 'sPC_TableData_InUpDe_debug'].includes(param.func)) { |
| | | param.username = sessionStorage.getItem('User_Name') || '' |
| | | param.fullname = sessionStorage.getItem('Full_Name') || '' |
| | | } |
| | | |
| | | let login = false |