|
|
@ -1,5 +1,7 @@ |
|
|
|
import store from '@/store' |
|
|
|
import { getToken } from '@/utils/token' |
|
|
|
import { setNodeId, getNodeId } from '@/utils/nodeId' |
|
|
|
import { getLongRandom } from '@/utils/nineTool'; |
|
|
|
import errorCode from '@/utils/errorCode' |
|
|
|
import { getSessionCache, setSessionCache } from '@/utils/cache' |
|
|
|
import { toast, showConfirm, tansParams } from '@/utils/requestTool' |
|
|
@ -16,6 +18,17 @@ const request = config => { |
|
|
|
if (getToken() && !isToken) { |
|
|
|
config.header['Authorization'] = 'Vrapile ' + getToken() |
|
|
|
} |
|
|
|
|
|
|
|
// 节点
|
|
|
|
let nodeId = getNodeId(); |
|
|
|
if(!nodeId){ |
|
|
|
nodeId = getLongRandom(24); |
|
|
|
setNodeId(nodeId); |
|
|
|
} |
|
|
|
config.header["platform"] = getApp().globalData.appId; |
|
|
|
config.header["terminal"] = getApp().globalData.terminal; |
|
|
|
config.header["nodeId"] = nodeId; |
|
|
|
|
|
|
|
// get请求映射params参数
|
|
|
|
if (config.params) { |
|
|
|
let url = config.url + '?' + tansParams(config.params) |
|
|
@ -54,9 +67,14 @@ const request = config => { |
|
|
|
header: config.header, |
|
|
|
dataType: 'json' |
|
|
|
}).then(res => { |
|
|
|
// let [error, res] = response
|
|
|
|
const code = res.data.code || res.data.status || 200 |
|
|
|
const msg = errorCode[code] || res.data.msg || errorCode['default'] |
|
|
|
|
|
|
|
// if (code != 200) {
|
|
|
|
// toast('后端接口连接异常')
|
|
|
|
// reject('后端接口连接异常')
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
if (code === 401) { |
|
|
|
// 密码登录的,实现自动重新登录
|
|
|
|
let loginInfo = store.state.user.loginInfo; |
|
|
@ -80,10 +98,10 @@ const request = config => { |
|
|
|
} |
|
|
|
} else if (code === 500) { |
|
|
|
toast(msg) |
|
|
|
reject('500') |
|
|
|
reject(res) |
|
|
|
} else if (code !== 200) { |
|
|
|
toast(msg) |
|
|
|
reject(code) |
|
|
|
reject(res) |
|
|
|
} |
|
|
|
resolve(res.data) |
|
|
|
}).catch(error => { |
|
|
|