dfws-ve-taro-request 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6719,9 +6719,10 @@ var _default = dist.default = {
6719
6719
  };
6720
6720
 
6721
6721
  // 是否进行接口解密
6722
- var isEncoding = function (url) {
6722
+ var isEncoding = function (url, encode) {
6723
6723
  if (url === void 0) { url = ''; }
6724
- return url.includes('/sso/v1/') || url.includes('/resume/v1/');
6724
+ if (encode === void 0) { encode = false; }
6725
+ return encode || url.includes('/sso/v1/') || url.includes('/resume/v1/') || url.includes('/resume/v2/');
6725
6726
  };
6726
6727
  // 加密
6727
6728
  var encryptByDES = function (params, debug) {
@@ -6774,13 +6775,13 @@ var codeMessage = {
6774
6775
  504: '网关超时。',
6775
6776
  };
6776
6777
  // 错误上报监控系统
6777
- var onErrorMsgRrport = function (response, options, Taro) {
6778
+ var onErrorMsgRrport = function (response, options, Taro, encode) {
6778
6779
  var _a;
6779
6780
  var statusCode = response.statusCode;
6780
6781
  var _b = options.method, method = _b === void 0 ? "get" : _b, url = options.url, data = options.data;
6781
6782
  var errorText = codeMessage[statusCode] || '';
6782
6783
  var statusParams = data;
6783
- var encoding = isEncoding(url) &&
6784
+ var encoding = isEncoding(url, encode) &&
6784
6785
  ((_a = response.data) === null || _a === void 0 ? void 0 : _a.type) !== "application/octet-stream";
6785
6786
  var errorData = {
6786
6787
  'id': '9',
@@ -6806,7 +6807,7 @@ var onErrorMsgRrport = function (response, options, Taro) {
6806
6807
  console.log('error:', err);
6807
6808
  });
6808
6809
  };
6809
- var checkStatus = function (response, options, Taro) {
6810
+ var checkStatus = function (response, options, Taro, encode) {
6810
6811
  var statusCode = response.statusCode, data = response.data;
6811
6812
  if (statusCode >= 200 && statusCode < 300 || statusCode == 406) {
6812
6813
  if (data.code == 400 || statusCode == 406) {
@@ -6840,13 +6841,14 @@ var checkStatus = function (response, options, Taro) {
6840
6841
  icon: 'none',
6841
6842
  });
6842
6843
  // 上报前端监控系统
6843
- return onErrorMsgRrport(response, options, Taro);
6844
+ return onErrorMsgRrport(response, options, Taro, encode);
6844
6845
  }
6845
6846
  };
6846
- var request = (function (url, data, method, header, Taro, debug) {
6847
+ var request = (function (url, data, method, header, Taro, debug, encode) {
6847
6848
  if (method === void 0) { method = 'get'; }
6848
6849
  if (debug === void 0) { debug = false; }
6849
- var isEncode = isEncoding(url); // 判断是否加密
6850
+ if (encode === void 0) { encode = false; }
6851
+ var isEncode = isEncoding(url, encode); // 判断是否加密
6850
6852
  var isMethod = method.toLocaleLowerCase() === 'get' && Object.keys(data).length; // 请求方式get而且加密处理
6851
6853
  if (isMethod) {
6852
6854
  url = "".concat(url, "?").concat(isEncode ? encryptByDES(objectToQueryString(data), debug) : objectToQueryString(data));
@@ -6859,13 +6861,21 @@ var request = (function (url, data, method, header, Taro, debug) {
6859
6861
  header: __assign(__assign({ 'authorization': Taro.getStorageSync('ticket') }, header), { 've-version': header.version || '1.0.0', 'dfws-params': header.params || '', 'content-type': header["content-type"] || 'application/json;charset=utf-8', 'resume-language': header['resume-language'] || 'zh-CN', 'common-params': header['common-params'] || '' })
6860
6862
  }).then(function (res) {
6861
6863
  var response = isEncode ? __assign(__assign({}, res), { data: decryptByDES(unescape(res.data), debug) }) : res;
6862
- return checkStatus(response, { url: url, data: data, method: method }, Taro);
6864
+ return checkStatus(response, { url: url, data: data, method: method }, Taro, encode);
6863
6865
  }).catch(function (err) {
6864
6866
  console.log('error:', err);
6865
- Taro.showToast({
6866
- title: '网络异常,请稍后重试',
6867
- icon: 'none',
6868
- });
6867
+ if (err && err.statusCode == 401) {
6868
+ Taro.removeStorage({ key: 'ticket' });
6869
+ Taro.removeStorage({ key: 'user_id' });
6870
+ Taro.removeStorage({ key: 'openid' });
6871
+ Taro.removeStorage({ key: 'mobile' });
6872
+ }
6873
+ else {
6874
+ Taro.showToast({
6875
+ title: '网络异常,请稍后重试',
6876
+ icon: 'none',
6877
+ });
6878
+ }
6869
6879
  return {
6870
6880
  status: 0,
6871
6881
  errMsg: '',
@@ -6874,10 +6884,11 @@ var request = (function (url, data, method, header, Taro, debug) {
6874
6884
  });
6875
6885
 
6876
6886
  var index = {
6877
- request: function (taro, projectChannel, url, data, method, headers, debug) {
6887
+ request: function (taro, projectChannel, url, data, method, headers, debug, isEncode) {
6878
6888
  if (projectChannel === void 0) { projectChannel = {}; }
6879
6889
  if (headers === void 0) { headers = {}; }
6880
6890
  if (debug === void 0) { debug = false; }
6891
+ if (isEncode === void 0) { isEncode = false; }
6881
6892
  /**
6882
6893
  * 东方网升项目公共 header
6883
6894
  * @param {object} dfws_params
@@ -6887,7 +6898,7 @@ var index = {
6887
6898
  dfws_header.getNetworkType(function (network) {
6888
6899
  channel.network = network;
6889
6900
  });
6890
- return request(url, data, method, __assign({ version: channel.version, params: JSON.stringify(dfws_header.queryChannels()) }, headers), taro, debug);
6901
+ return request(url, data, method, __assign({ version: channel.version, params: JSON.stringify(dfws_header.queryChannels()) }, headers), taro, debug, isEncode);
6891
6902
  },
6892
6903
  // 接口解密
6893
6904
  decryptByDES: decryptByDES,