Authored by 李奇

开关修改

@@ -4,6 +4,7 @@ import {encrypt, decrypt} from '../utils/icfg-aes'; @@ -4,6 +4,7 @@ import {encrypt, decrypt} from '../utils/icfg-aes';
4 import {stringify} from '../vendors/query-string'; 4 import {stringify} from '../vendors/query-string';
5 5
6 let iconfSwitch = function (app) { 6 let iconfSwitch = function (app) {
  7 + app = app || getApp();
7 let data = {}; 8 let data = {};
8 let device = app.globalData.systemInfo; 9 let device = app.globalData.systemInfo;
9 10
@@ -2,23 +2,34 @@ @@ -2,23 +2,34 @@
2 import { GET, POST } from '../../../libs/request'; 2 import { GET, POST } from '../../../libs/request';
3 import { API_HOST } from '../../../libs/config'; 3 import { API_HOST } from '../../../libs/config';
4 import Humps from './humps.js'; 4 import Humps from './humps.js';
  5 +import iconfSwitch from '../../../libs/switch';
  6 +import md5 from '../../../vendors/md5';
5 7
6 //注:g_sourceApiArry与g_toJavaApiArry的length要相等,且一一对应 8 //注:g_sourceApiArry与g_toJavaApiArry的length要相等,且一一对应
7 const g_sourceApiArry = [ '/list', '/content', '/list/recommend', '/code/recent', '/list/mine', '/code/gain', '/code/mine' ]; 9 const g_sourceApiArry = [ '/list', '/content', '/list/recommend', '/code/recent', '/list/mine', '/code/gain', '/code/mine' ];
8 const g_toJavaApiArry = [ 'app.yoluck.activityList', 'app.yoluck.getContent', 'app.yoluck.recommendList', 'app.yoluck.recent', 'app.yoluck.participationList', 'app.yoluck.getCode', 'app.yoluck.userCode' ]; 10 const g_toJavaApiArry = [ 'app.yoluck.activityList', 'app.yoluck.getContent', 'app.yoluck.recommendList', 'app.yoluck.recent', 'app.yoluck.participationList', 'app.yoluck.getCode', 'app.yoluck.userCode' ];
9 11
10 -const g_javaApiEnable = true;  
11 -  
12 class Service { 12 class Service {
13 constructor(url = '') { 13 constructor(url = '') {
14 this.url = url; 14 this.url = url;
  15 + this.g_javaApiEnable = true;
  16 + this.hasSetSwitch = false;
  17 +
  18 + if (!this.hasSetSwitch) {
  19 + iconfSwitch().then(data => {
  20 + this.hasSetSwitch = true;
  21 + if (data['disableJavaApi'] && md5('disableJavaApi') === data['disableJavaApi']) { // TODO 键值确认
  22 + this.g_javaApiEnable = false;
  23 + }
  24 + });
  25 + }
15 } 26 }
16 27
17 _get(path, data) { 28 _get(path, data) {
18 let method = path ? this.url + path : API_HOST; 29 let method = path ? this.url + path : API_HOST;
19 let pathIndex = g_sourceApiArry.indexOf(path); 30 let pathIndex = g_sourceApiArry.indexOf(path);
20 //适配服务器更换Java接口,开关控制是否切换 31 //适配服务器更换Java接口,开关控制是否切换
21 - if (g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) { 32 + if (this.g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
22 method = API_HOST; 33 method = API_HOST;
23 data.method = g_toJavaApiArry[pathIndex]; 34 data.method = g_toJavaApiArry[pathIndex];
24 } 35 }
@@ -26,7 +37,7 @@ class Service { @@ -26,7 +37,7 @@ class Service {
26 return GET(method, data).then(result => { 37 return GET(method, data).then(result => {
27 38
28 //适配服务器更换Java接口,开关控制是否切换 39 //适配服务器更换Java接口,开关控制是否切换
29 - if (g_javaApiEnable && pathIndex >= 0) { 40 + if (this.g_javaApiEnable && pathIndex >= 0) {
30 if (result.data.list) { 41 if (result.data.list) {
31 let newList = Humps.decamelizeKeys(Object.values(result.data.list)); 42 let newList = Humps.decamelizeKeys(Object.values(result.data.list));
32 result.data.list = newList; 43 result.data.list = newList;
@@ -44,14 +55,14 @@ class Service { @@ -44,14 +55,14 @@ class Service {
44 let pathIndex = g_sourceApiArry.indexOf(path); 55 let pathIndex = g_sourceApiArry.indexOf(path);
45 56
46 //适配服务器更换Java接口,开关控制是否切换 57 //适配服务器更换Java接口,开关控制是否切换
47 - if (g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) { 58 + if (this.g_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) {
48 method = API_HOST; 59 method = API_HOST;
49 data.method = g_toJavaApiArry[pathIndex]; 60 data.method = g_toJavaApiArry[pathIndex];
50 } 61 }
51 return POST(method, data).then(result => { 62 return POST(method, data).then(result => {
52 63
53 //适配服务器更换Java接口,开关控制是否切换 64 //适配服务器更换Java接口,开关控制是否切换
54 - if (g_javaApiEnable && pathIndex >= 0) { 65 + if (this.g_javaApiEnable && pathIndex >= 0) {
55 let newData = Humps.decamelizeKeys(result.data); 66 let newData = Humps.decamelizeKeys(result.data);
56 result.data = newData; 67 result.data = newData;
57 } 68 }