Authored by 李奇

开关逻辑优化

... ... @@ -7,6 +7,7 @@ import mta from './vendors/mta_analysis';
import {Event} from '/login/utils/index.js';
import {wxLogin} from '/login/utils/login/login';
import appReport from './libs/appReport';
import iconfSwitch from './libs/switch';
import {isStringEmpty, getYHStorageSync} from './utils/util';
import regeneratorRuntime from '/login/libs/regenerator-runtime/index';
... ... @@ -115,6 +116,13 @@ App({
//当应用程序进入前台显示状态时触发
onShow(options) {
iconfSwitch(this).then(data => {
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> app onshow switch');
this.globalData.hasSetSwitch = true;
if (data['disableJavaApi'] && md5('disableJavaApi') === data['disableJavaApi']) { // TODO 键值确认
this.globalData.switch_javaApiEnable = false;
}
});
let that = this
let params = {};
yasReport(YB_ENTER_FOREGROUND, params, that)
... ... @@ -313,6 +321,8 @@ App({
},
globalData: {
hasSetSwitch: false,
switch_javaApiEnable: true,
selectedChannel: 'boy',
userInfo: {},
systemInfo: null,
... ...
... ... @@ -9,65 +9,88 @@ import md5 from '../../../vendors/md5';
const g_sourceApiArry = [ '/list', '/content', '/list/recommend', '/code/recent', '/list/mine', '/code/gain', '/code/mine' ];
const g_toJavaApiArry = [ 'app.yoluck.activityList', 'app.yoluck.getContent', 'app.yoluck.recommendList', 'app.yoluck.recent', 'app.yoluck.participationList', 'app.yoluck.getCode', 'app.yoluck.userCode' ];
const app = getApp();
class Service {
constructor(url = '') {
this.url = url;
this.g_javaApiEnable = true;
this.hasSetSwitch = false;
if (!this.hasSetSwitch) {
iconfSwitch().then(data => {
this.hasSetSwitch = true;
if (data['disableJavaApi'] && md5('disableJavaApi') === data['disableJavaApi']) { // TODO 键值确认
this.g_javaApiEnable = false;
}
});
}
}
_get(path, data) {
let method = path ? this.url + path : API_HOST;
let pathIndex = g_sourceApiArry.indexOf(path);
//适配服务器更换Java接口,开关控制是否切换
if (this.g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
method = API_HOST;
data.method = g_toJavaApiArry[pathIndex];
}
return GET(method, data).then(result => {
let executeReq = () => {
//适配服务器更换Java接口,开关控制是否切换
if (this.g_javaApiEnable && pathIndex >= 0) {
if (result.data.list) {
let newList = Humps.decamelizeKeys(Object.values(result.data.list));
result.data.list = newList;
} else {
let newData = Humps.decamelizeKeys(result.data);
result.data = newData;
}
if (app.globalData.switch_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
method = API_HOST;
data.method = g_toJavaApiArry[pathIndex];
}
return result
});
return GET(method, data).then(result => {
//适配服务器更换Java接口,开关控制是否切换
if (app.globalData.switch_javaApiEnable && pathIndex >= 0) {
if (result.data.list) {
let newList = Humps.decamelizeKeys(Object.values(result.data.list));
result.data.list = newList;
} else {
let newData = Humps.decamelizeKeys(result.data);
result.data = newData;
}
}
return result
});
};
if (!app.globalData.hasSetSwitch) {
iconfSwitch().then(data => {
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> _get switch');
app.globalData.hasSetSwitch = true;
if (data['disableJavaApi'] && md5('disableJavaApi') === data['disableJavaApi']) { // TODO 键值确认
app.globalData.switch_javaApiEnable = false;
}
return executeReq();
});
} else {
return executeReq();
}
}
_post(path, data) {
let method = path ? this.url + path : API_HOST;
let pathIndex = g_sourceApiArry.indexOf(path);
//适配服务器更换Java接口,开关控制是否切换
if (this.g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
method = API_HOST;
data.method = g_toJavaApiArry[pathIndex];
}
return POST(method, data).then(result => {
let executeReq = () => {
//适配服务器更换Java接口,开关控制是否切换
if (this.g_javaApiEnable && pathIndex >= 0) {
let newData = Humps.decamelizeKeys(result.data);
result.data = newData;
if (app.globalData.switch_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
method = API_HOST;
data.method = g_toJavaApiArry[pathIndex];
}
return result;
});
return POST(method, data).then(result => {
//适配服务器更换Java接口,开关控制是否切换
if (app.globalData.switch_javaApiEnable && pathIndex >= 0) {
let newData = Humps.decamelizeKeys(result.data);
result.data = newData;
}
return result;
});
}
if (!app.globalData.hasSetSwitch) {
iconfSwitch().then(data => {
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> _post switch');
app.globalData.hasSetSwitch = true;
if (data['disableJavaApi'] && md5('disableJavaApi') === data['disableJavaApi']) { // TODO 键值确认
app.globalData.switch_javaApiEnable = false;
}
return executeReq();
});
} else {
return executeReq();
}
}
}
... ...