Authored by 李奇

开关修改

... ... @@ -4,6 +4,7 @@ import {encrypt, decrypt} from '../utils/icfg-aes';
import {stringify} from '../vendors/query-string';
let iconfSwitch = function (app) {
app = app || getApp();
let data = {};
let device = app.globalData.systemInfo;
... ...
... ... @@ -2,23 +2,34 @@
import { GET, POST } from '../../../libs/request';
import { API_HOST } from '../../../libs/config';
import Humps from './humps.js';
import iconfSwitch from '../../../libs/switch';
import md5 from '../../../vendors/md5';
//注:g_sourceApiArry与g_toJavaApiArry的length要相等,且一一对应
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 g_javaApiEnable = true;
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 (g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
if (this.g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
method = API_HOST;
data.method = g_toJavaApiArry[pathIndex];
}
... ... @@ -26,7 +37,7 @@ class Service {
return GET(method, data).then(result => {
//适配服务器更换Java接口,开关控制是否切换
if (g_javaApiEnable && pathIndex >= 0) {
if (this.g_javaApiEnable && pathIndex >= 0) {
if (result.data.list) {
let newList = Humps.decamelizeKeys(Object.values(result.data.list));
result.data.list = newList;
... ... @@ -44,14 +55,14 @@ class Service {
let pathIndex = g_sourceApiArry.indexOf(path);
//适配服务器更换Java接口,开关控制是否切换
if (g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
if (this.g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
method = API_HOST;
data.method = g_toJavaApiArry[pathIndex];
}
return POST(method, data).then(result => {
//适配服务器更换Java接口,开关控制是否切换
if (g_javaApiEnable && pathIndex >= 0) {
if (this.g_javaApiEnable && pathIndex >= 0) {
let newData = Humps.decamelizeKeys(result.data);
result.data = newData;
}
... ...