123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import regeneratorRuntime from '@/common/static/lib/runtime';
- var settimelist = [];
- const SUCCESS_CODE = 200;
- const request = (requestConfig, isHideLoading) => new Promise((resolve, reject) => {
- const success = async ({
- data,
- header,
- statusCode
- }) => {
- if (requestConfig.url.lastIndexOf("elab-marketing-system/behavior/brandMiniWeb/upload") == -1
- && requestConfig.url.lastIndexOf("/elab-marketing-user/userMerge/queryUserMobileAuth") == -1) {
- var app = getApp(); //获取应用实例
- if (requestConfig.time) {
- var setTimeItem = settimelist.find(item => item.key == requestConfig.time);
- if (setTimeItem) {
- clearTimeout(setTimeItem.value); //不在弹出loading
- settimelist.splice(settimelist.findIndex(item => item.key == requestConfig.time), 1);
- }
- }
- app && app.hideLoading();
- }
- if(header.xcx_token){
- app.globalData.xcx_token = header.xcx_token;
- console.log('收到token',app.globalData.xcx_token)
- }
- // #ifdef H5
- if(header.xcx_token){
- app.globalData.xcx_token = header.xcx_token;
- uni.setStorageSync('xcx_token', header.xcx_token);
- console.log('H5收到token',app.globalData.xcx_token);
- }
- // #endif
- if (statusCode === SUCCESS_CODE) {
- resolve(data);
- }
- const error = `http status code ${statusCode}`;
- if(requestConfig.url.lastIndexOf("elab-marketing-user/applet/enter_house")!=-1
- || requestConfig.url.lastIndexOf("elab-marketing-user/applet/auth_mobile")!=-1){
- if(data.errorCode && data.errorCode == "USER_MERGE"){ //认为是需要去做用户合并操作
- app && app.userMerge();
- }
- }
- resolve({
- message: data.message || error,
- responseData: data,
- requestData: requestConfig
- });
- };
- const fail = (e) => {
- try {
- if (requestConfig.url.lastIndexOf("elab-marketing-system/behavior/brandMiniWeb/upload") == -1
- && requestConfig.url.lastIndexOf("/elab-marketing-user/userMerge/queryUserMobileAuth") == -1) {
- var app = getApp(); //获取应用实例
- if (requestConfig.time) {
- var setTimeItem = settimelist.find(item => item.key == requestConfig.time);
- if (setTimeItem) {
- clearTimeout(setTimeItem.value); //不在弹出loading
- settimelist.splice(settimelist.findIndex(item => item.key == requestConfig.time), 1);
- }
- }
- app && app.hideLoading();
- }
- wx.showToast({
- title: '网络连接异常...',
- icon: "error"
- })
- resolve({
- message: "网络连接异常",
- error: e
- });
- console.log("***fail-Error***", e);
- } catch (e) {
- console.log("***reject-Error***", e);
- }
- };
- const config = { ...requestConfig,
- success,
- fail
- };
- if (requestConfig.url.lastIndexOf("elab-marketing-system/behavior/brandMiniWeb/upload") == -1
- && requestConfig.url.lastIndexOf("/elab-marketing-user/userMerge/queryUserMobileAuth") == -1) {
- if (!isHideLoading) {
- var app = getApp(); //获取应用实例
- var _value = setTimeout(() => {
- app && app.showLoading();
- }, 2000); //两秒后执行弹出loading动作
- var _data = {
- key: requestConfig.time,
- value: _value
- };
- settimelist.push(_data);
- }
- }
- uni.request(config);
- });
- export default request;
|