|
@@ -1,4 +1,4 @@
|
|
-import { APPID,SOURCE_KEY } from '@/constants.js'
|
|
|
|
|
|
+import { APPID, SOURCE_KEY } from '@/constants.js'
|
|
import CacheTool from '@/utils/cache-tool.js'
|
|
import CacheTool from '@/utils/cache-tool.js'
|
|
import log from './log.js'
|
|
import log from './log.js'
|
|
import { getUTMSource } from '@/utils/utils.js'
|
|
import { getUTMSource } from '@/utils/utils.js'
|
|
@@ -9,59 +9,59 @@ const CONTENT_TYPE_ARRAY = {
|
|
'form': 'application/x-www-form-urlencoded'
|
|
'form': 'application/x-www-form-urlencoded'
|
|
}
|
|
}
|
|
|
|
|
|
-function getHeaders( config = {} ) {
|
|
|
|
- const {contentType = 'json'} = config;
|
|
|
|
|
|
+function getHeaders(config = {}) {
|
|
|
|
+ const { contentType = 'json' } = config;
|
|
const ct = CONTENT_TYPE_ARRAY[contentType];
|
|
const ct = CONTENT_TYPE_ARRAY[contentType];
|
|
let header = {
|
|
let header = {
|
|
'appId': APPID,
|
|
'appId': APPID,
|
|
'Content-Type': ct
|
|
'Content-Type': ct
|
|
};
|
|
};
|
|
const token = getToken()
|
|
const token = getToken()
|
|
- if ( token ) {
|
|
|
|
- header['Authorization'] = `Bearer ${ token }`;
|
|
|
|
|
|
+ if (token) {
|
|
|
|
+ header['Authorization'] = `Bearer ${token}`;
|
|
}
|
|
}
|
|
|
|
|
|
const groupId = uni.getStorageSync("groupId");
|
|
const groupId = uni.getStorageSync("groupId");
|
|
const mallId = uni.getStorageSync("mallid");
|
|
const mallId = uni.getStorageSync("mallid");
|
|
- if ( groupId ) {
|
|
|
|
|
|
+ if (groupId) {
|
|
header['brandId'] = groupId
|
|
header['brandId'] = groupId
|
|
}
|
|
}
|
|
- if ( mallId ) {
|
|
|
|
|
|
+ if (mallId) {
|
|
header['lbsId'] = mallId
|
|
header['lbsId'] = mallId
|
|
}
|
|
}
|
|
const sourceObj = getUTMSource();
|
|
const sourceObj = getUTMSource();
|
|
- return Object.assign(header,sourceObj);
|
|
|
|
|
|
+ return Object.assign(header, sourceObj);
|
|
}
|
|
}
|
|
|
|
|
|
-function handleConfig( config = {} ) {
|
|
|
|
|
|
+function handleConfig(config = {}) {
|
|
const header = getHeaders(config)
|
|
const header = getHeaders(config)
|
|
const noToken = config.noToken
|
|
const noToken = config.noToken
|
|
- if ( noToken ) {
|
|
|
|
|
|
+ if (noToken) {
|
|
delete header.Authorization;
|
|
delete header.Authorization;
|
|
}
|
|
}
|
|
- return {header,...config};
|
|
|
|
|
|
+ return { header, ...config };
|
|
}
|
|
}
|
|
|
|
|
|
function getToken() {
|
|
function getToken() {
|
|
const token = uni.getStorageSync('kipAccessToken')
|
|
const token = uni.getStorageSync('kipAccessToken')
|
|
// if (!token || token?.trim() == '' || token == 'null' || token == 'undefined') {
|
|
// if (!token || token?.trim() == '' || token == 'null' || token == 'undefined') {
|
|
- if ( !token || token == 'null' || token == 'undefined' ) {
|
|
|
|
|
|
+ if (!token || token == 'null' || token == 'undefined') {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
return token
|
|
return token
|
|
}
|
|
}
|
|
|
|
|
|
-function getUrl( path ) {
|
|
|
|
|
|
+function getUrl(path) {
|
|
console.log(555555555, path);
|
|
console.log(555555555, path);
|
|
// 如果是dev、qa、prod环境
|
|
// 如果是dev、qa、prod环境
|
|
if (window.ininjectConfig) {
|
|
if (window.ininjectConfig) {
|
|
- if(path.indexOf('/profileApi') > -1) {
|
|
|
|
|
|
+ if (path.indexOf('/profileApi') > -1) {
|
|
return `${window.ininjectConfig.profileApi}${path}`
|
|
return `${window.ininjectConfig.profileApi}${path}`
|
|
}
|
|
}
|
|
if (/weixinApi/g.test(path)) {
|
|
if (/weixinApi/g.test(path)) {
|
|
return path;
|
|
return path;
|
|
}
|
|
}
|
|
- if(/\/qaPayment/g.test(path)) {
|
|
|
|
|
|
+ if (/\/qaPayment/g.test(path)) {
|
|
return `${window.ininjectConfig.qaPayment}${path}`
|
|
return `${window.ininjectConfig.qaPayment}${path}`
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -92,25 +92,25 @@ function cleanCacheAndGoLogin() {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-function handleKipResponse( resp,request ) {
|
|
|
|
- if ( resp && resp.data ) {
|
|
|
|
- const {status} = resp;
|
|
|
|
- console.log(`kip request resp => errMsg ${ status }`)
|
|
|
|
- const {path} = request.detail;
|
|
|
|
|
|
+function handleKipResponse(resp, request) {
|
|
|
|
+ if (resp && resp.data) {
|
|
|
|
+ const { status } = resp;
|
|
|
|
+ console.log(`kip request resp => errMsg ${status}`)
|
|
|
|
+ const { path } = request.detail;
|
|
let isLogout = false;
|
|
let isLogout = false;
|
|
- if ( path.indexOf("/logout") > -1 ) {
|
|
|
|
|
|
+ if (path.indexOf("/logout") > -1) {
|
|
isLogout = true;
|
|
isLogout = true;
|
|
}
|
|
}
|
|
- if ( !resp || !resp.data ) {
|
|
|
|
|
|
+ if (!resp || !resp.data) {
|
|
return resp;
|
|
return resp;
|
|
}
|
|
}
|
|
const result = resp.data;
|
|
const result = resp.data;
|
|
- if ( result ) {
|
|
|
|
- const {message,code} = result || {}
|
|
|
|
- console.log(`kip api resul => message: ${ message } code: ${ code }`)
|
|
|
|
- if ( result.code == '300000' && !isLogout ) {
|
|
|
|
|
|
+ if (result) {
|
|
|
|
+ const { message, code } = result || {}
|
|
|
|
+ console.log(`kip api resul => message: ${message} code: ${code}`)
|
|
|
|
+ if (result.code == '300000' && !isLogout) {
|
|
console.warn('===> kip的access_token已过期')
|
|
console.warn('===> kip的access_token已过期')
|
|
- log.info(`kip的access_token已过期`,result)
|
|
|
|
|
|
+ log.info(`kip的access_token已过期`, result)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -119,7 +119,7 @@ function handleKipResponse( resp,request ) {
|
|
|
|
|
|
export default {
|
|
export default {
|
|
detail: null,
|
|
detail: null,
|
|
- base( method,path,param = {},config ) {
|
|
|
|
|
|
+ base(method, path, param = {}, config) {
|
|
const _this = this;
|
|
const _this = this;
|
|
_this.detail = {
|
|
_this.detail = {
|
|
method,
|
|
method,
|
|
@@ -127,44 +127,44 @@ export default {
|
|
param,
|
|
param,
|
|
config
|
|
config
|
|
}
|
|
}
|
|
- return new Promise(( resolve,reject ) => {
|
|
|
|
- const url = getUrl(`/profileApi${path}`);
|
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ const url = getUrl(/weixinApi/.test(path) ? path : `/profileApi${path}`);
|
|
console.log(130, url);
|
|
console.log(130, url);
|
|
- const {header} = handleConfig(config)
|
|
|
|
- log.info(`===>request-kip url: ${ url }`)
|
|
|
|
- log.info(`===>request-kip header: ${ JSON.stringify(header) }`)
|
|
|
|
|
|
+ const { header } = handleConfig(config)
|
|
|
|
+ log.info(`===>request-kip url: ${url}`)
|
|
|
|
+ log.info(`===>request-kip header: ${JSON.stringify(header)}`)
|
|
uni.request({
|
|
uni.request({
|
|
header: header,
|
|
header: header,
|
|
method: method,
|
|
method: method,
|
|
url: url,
|
|
url: url,
|
|
data: param,
|
|
data: param,
|
|
}).then(res => {
|
|
}).then(res => {
|
|
- log.info(`===>request-kip response: ${ JSON.stringify(res.data) }`)
|
|
|
|
|
|
+ log.info(`===>request-kip response: ${JSON.stringify(res.data)}`)
|
|
resolve(handleKipResponse(res, _this))
|
|
resolve(handleKipResponse(res, _this))
|
|
- if ( res.status == 581 ) {
|
|
|
|
|
|
+ if (res.status == 581) {
|
|
uni.navigateTo({
|
|
uni.navigateTo({
|
|
url: '/pages/errorPage/errorLimit?msg=当前访问太火爆了,稍后试试吧~'
|
|
url: '/pages/errorPage/errorLimit?msg=当前访问太火爆了,稍后试试吧~'
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- }).catch(( response ) => {
|
|
|
|
- log.error(`===>request-kip error: ${ JSON.stringify(response) }`)
|
|
|
|
|
|
+ }).catch((response) => {
|
|
|
|
+ log.error(`===>request-kip error: ${JSON.stringify(response)}`)
|
|
reject(response)
|
|
reject(response)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- get( path,param = {},config ) {
|
|
|
|
- return this.base('GET',path,param,config)
|
|
|
|
|
|
+ get(path, param = {}, config) {
|
|
|
|
+ return this.base('GET', path, param, config)
|
|
},
|
|
},
|
|
- post( path,param = {},config ) {
|
|
|
|
- return this.base('POST',path,param,config)
|
|
|
|
|
|
+ post(path, param = {}, config) {
|
|
|
|
+ return this.base('POST', path, param, config)
|
|
},
|
|
},
|
|
- put( path,param = {},config ) {
|
|
|
|
- return this.base('PUT',path,param,config)
|
|
|
|
|
|
+ put(path, param = {}, config) {
|
|
|
|
+ return this.base('PUT', path, param, config)
|
|
},
|
|
},
|
|
- delete( path,param = {},config ) {
|
|
|
|
- return this.base('DELETE',path,param,config)
|
|
|
|
|
|
+ delete(path, param = {}, config) {
|
|
|
|
+ return this.base('DELETE', path, param, config)
|
|
},
|
|
},
|
|
- uploadFile( path,param = {},config ) {
|
|
|
|
|
|
+ uploadFile(path, param = {}, config) {
|
|
const _this = this;
|
|
const _this = this;
|
|
_this.detail = {
|
|
_this.detail = {
|
|
method: 'POST',
|
|
method: 'POST',
|
|
@@ -172,9 +172,9 @@ export default {
|
|
param,
|
|
param,
|
|
config
|
|
config
|
|
}
|
|
}
|
|
- return new Promise(( resolve,reject ) => {
|
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
const url = getUrl(path);
|
|
const url = getUrl(path);
|
|
- const {fileType,file,formData} = param
|
|
|
|
|
|
+ const { fileType, file, formData } = param
|
|
let header = getHeaders(config)
|
|
let header = getHeaders(config)
|
|
header["Content-Type"] = "multipart/form-data"
|
|
header["Content-Type"] = "multipart/form-data"
|
|
uni.uploadFile({
|
|
uni.uploadFile({
|
|
@@ -187,14 +187,14 @@ export default {
|
|
file: file,
|
|
file: file,
|
|
formData: formData
|
|
formData: formData
|
|
}).then(res => {
|
|
}).then(res => {
|
|
- resolve(handleKipResponse(res[1],_this))
|
|
|
|
- }).catch(( response ) => {
|
|
|
|
|
|
+ resolve(handleKipResponse(res[1], _this))
|
|
|
|
+ }).catch((response) => {
|
|
reject(response)
|
|
reject(response)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- refreshToken( path ) {
|
|
|
|
- return new Promise(( resolve,reject ) => {
|
|
|
|
|
|
+ refreshToken(path) {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
const url = getUrl(path);
|
|
const url = getUrl(path);
|
|
const header = getHeaders()
|
|
const header = getHeaders()
|
|
delete header.Authorization;
|
|
delete header.Authorization;
|
|
@@ -204,7 +204,7 @@ export default {
|
|
url: url,
|
|
url: url,
|
|
}).then(res => {
|
|
}).then(res => {
|
|
resolve(res[1])
|
|
resolve(res[1])
|
|
- }).catch(( response ) => {
|
|
|
|
|
|
+ }).catch((response) => {
|
|
reject(response)
|
|
reject(response)
|
|
})
|
|
})
|
|
})
|
|
})
|