Authored by 于良

逛详情设置背景色为白色,网络请求增加使用Native请求的方式

  1 +'use strict';
  2 +
  3 +import ReactNative, {Platform, Dimensions} from 'react-native';
  4 +import CONFIG from '../config/config';
  5 +import DeviceInfo from 'react-native-device-info';
  6 +import queryString from 'query-string';
  7 +import md5 from 'md5';
  8 +import timeoutPromise from '../utils/timeoutPromise';
  9 +import trimObject from '../utils/trimObject';
  10 +import RNNativeConfig from './RNNativeConfig';
  11 +
  12 +export default class NativeRequest {
  13 +
  14 + constructor(baseURL, timeout) {
  15 + if (baseURL) {
  16 + this.baseUrl = baseURL;
  17 + }
  18 +
  19 + if (timeout) {
  20 + this.timeout = timeout;
  21 + }
  22 + }
  23 +
  24 +
  25 +
  26 + /**
  27 + * GET
  28 + *
  29 + * @param {[object]} opts
  30 + *
  31 + * {
  32 + * url: '/operations/api/v6/category/getCategory', //接口地址
  33 + * timeout: 30, //毫秒
  34 + * }
  35 + *
  36 + * @return {[promise]}
  37 + */
  38 + async get(opts) {
  39 + try {
  40 + let host = this.baseUrl;
  41 + let url = opts && opts.url ? opts.url : '';
  42 + let body = opts && opts.body ? opts.body : {};
  43 + let timeout = this.timeout;
  44 + if (!timeout) {
  45 + timeout = opts && opts.timeout ? opts.timeout : 0;
  46 + }
  47 +
  48 + let params = {
  49 + host,
  50 + timeout,
  51 + url,
  52 + body,
  53 + };
  54 + let response = await ReactNative.NativeModules.YH_CouponHelper.get(params);
  55 + let data = await this._parseResponse(response);
  56 + return data;
  57 +
  58 + } catch(error) {
  59 + throw(error);
  60 + }
  61 + }
  62 +
  63 + /**
  64 + * POST
  65 + *
  66 + * @param {[object]} opts
  67 + *
  68 + * {
  69 + * url: '/operations/api/v6/category/getCategory', //接口地址
  70 + * body: {
  71 + * user: 'Lily',
  72 + * password: '111111',
  73 + * },
  74 + * timeout: 30, //毫秒
  75 + * }
  76 + *
  77 + * @return {[promise]}
  78 + */
  79 + async post(opts) {
  80 + try {
  81 + let host = this.baseUrl;
  82 + let url = opts && opts.url ? opts.url : '';
  83 + let body = opts && opts.body ? opts.body : {};
  84 + let timeout = this.timeout;
  85 + if (!timeout) {
  86 + timeout = opts && opts.timeout ? opts.timeout : 0;
  87 + }
  88 +
  89 + let params = {
  90 + host,
  91 + timeout,
  92 + url,
  93 + body,
  94 + };
  95 + let response = await ReactNative.NativeModules.YH_CouponHelper.post(params);
  96 + let data = await this._parseResponse(response);
  97 + return data;
  98 +
  99 + } catch(error) {
  100 + throw(error);
  101 + }
  102 + }
  103 +
  104 + async _parseResponse(response) {
  105 + let code = response && response.code ? response.code : 0;
  106 + if (code == 200) {
  107 + return response.data;
  108 + } else {
  109 + let message = response && response.message ? response.message : '';
  110 + throw({code, message});
  111 + }
  112 + }
  113 +}
@@ -179,7 +179,7 @@ let styles = StyleSheet.create({ @@ -179,7 +179,7 @@ let styles = StyleSheet.create({
179 backgroundColor: '#f0f0f0', 179 backgroundColor: '#f0f0f0',
180 }, 180 },
181 contentContainer:{ 181 contentContainer:{
182 - 182 + backgroundColor: 'white',
183 }, 183 },
184 GoodsGroupHeader: { 184 GoodsGroupHeader: {
185 flex: 1, 185 flex: 1,