@conecli/cone-render 0.8.19-beta.2 → 0.8.19-beta.3

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.
@@ -1 +1 @@
1
- import { isApp, getUrlQuery } from '../utils/jm-common'
1
+ import { isApp, getUrlQuery } from '../utils/jm-common'
@@ -1 +1 @@
1
- import * as device from './device'
1
+ import * as device from './device'
@@ -1 +1 @@
1
- var splitOnFirst = function splitOnFirst(string, separator) {
2
1
  return Object.prototype.toString.call(obj);
3
2
  return typeof obj === 'function';
4
3
  return '[object Object]' === getType(obj);
5
4
  return '[object Array]' == getType(obj);
6
5
  return '[object Undefined]' === getType(obj);
7
6
  return '[object Null]' == getType(obj);
8
7
  return typeof obj === 'string';
9
8
  return typeof obj === 'boolean';
10
9
  return '[object Number]' === getType(num);
11
10
  ua = ua || navigator.userAgent;
12
11
  if (name === 'wx') return (/micromessenger/i.test(ua)
13
12
  );
14
13
  if (name === 'qq') return (/qq\//i.test(ua)
15
14
  );
16
15
  if (name === 'weibo') return (/weibo/i.test(ua)
17
16
  );
18
17
  if (name === 'jd') return (/^jdapp/i.test(ua)
19
18
  );
20
19
  if (name === 'jdlittle') return (/^jdltapp/i.test(ua)
21
20
  );
22
21
  if (name === 'mp') return navigator.userAgent.match(/micromessenger/i) && navigator.userAgent.match(/miniprogram/i) || window.__wxjs_environment === 'miniprogram';
23
22
  if (name === 'jdb') return (/JDBmall/i.test(ua)
24
23
  );
25
24
  return false;
26
25
  ua = ua || navigator.userAgent;
27
26
  return (/android/i.test(ua) && !isIOS()
28
27
  );
29
28
  ua = ua || navigator.userAgent;
30
29
  return (/ip(hone|od)|ipad/i.test(ua)
31
30
  );
32
31
  ua = ua || navigator.userAgent;
33
32
  return (/ipad/i.test(ua) || /android/i.test(ua) && !/mobi|mini|fennec/i.test(ua)
34
33
  );
35
34
  ua = ua || navigator.userAgent;
36
35
  return !!ua.match(/ip(hone|od)|android.+mobile|windows (ce|phone)|blackberry|bb10|symbian|webos|firefox.+fennec|opera m(ob|in)i|polaris|iemobile|lgtelecom|nokia|sonyericsson|dolfin|uzard|natebrowser|ktf;|skt;/i);
37
36
  ua = ua || navigator.userAgent;
38
37
  return !!ua.match(/iphone/i);
39
38
  ua = ua || navigator.userAgent;
40
39
  return !!ua.match(/ipad/i);
41
40
  ua = ua || navigator.userAgent;
42
41
  if (name === 'xview') return typeof window.XView !== 'undefined';
43
42
  if (name === 'wk') return !!ua.match(/supportjdshwk/i) || window._is_jdsh_wkwebview == 1;
44
43
  return false;
45
44
  ua = ua || navigator.userAgent;
46
45
  var re = /nettype\/([\S]*)/i;
47
46
  if (isApp('jd', ua)) re = /network\/([^;]*)/i;
48
47
  return re.test(ua) ? RegExp.$1.toLowerCase() : 'unknown';
49
48
  ua = ua || navigator.userAgent;
50
49
  if (!isApp('jd', ua)) return null;
51
50
  return ua.split(';')[4];
52
51
  ua = ua || navigator.userAgent;
53
52
  if (appName === 'jd') return ua.split(';')[2] || null;
54
53
  if (appName === 'wx') return (/micromessenger\/([\S]*)/i.test(ua) ? RegExp.$1 : null
55
54
  );
56
55
  if (appName === 'qq') return (/qq\/([\S]*)/i.test(ua) ? RegExp.$1 : null
57
56
  );
58
57
  return null;
59
58
  ua = ua || navigator.userAgent;
60
59
  var match = ua.match(/android\s([0-9\.]*)/i);
61
60
  return match ? match[1] : 'unknown';
62
61
  ua = ua || navigator.userAgent;
63
62
  var match = ua.match(/OS ((\d+_?){2,3})\s/i);
64
63
  return match ? match[1].replace(/_/g, '.') : 'unknown';
64
+ var splitOnFirst = function splitOnFirst(string, separator) {
65
65
  return Object.prototype.toString.call(obj);
66
66
  return typeof obj === 'function';
67
67
  return '[object Object]' === getType(obj);
68
68
  return '[object Array]' == getType(obj);
69
69
  return '[object Undefined]' === getType(obj);
70
70
  return '[object Null]' == getType(obj);
71
71
  return typeof obj === 'string';
72
72
  return typeof obj === 'boolean';
73
73
  return '[object Number]' === getType(num);
74
74
  ua = ua || navigator.userAgent;
75
75
  if (name === 'wx') return (/micromessenger/i.test(ua)
76
76
  );
77
77
  if (name === 'qq') return (/qq\//i.test(ua)
78
78
  );
79
79
  if (name === 'weibo') return (/weibo/i.test(ua)
80
80
  );
81
81
  if (name === 'jd') return (/^jdapp/i.test(ua)
82
82
  );
83
83
  if (name === 'jdlittle') return (/^jdltapp/i.test(ua)
84
84
  );
85
85
  if (name === 'mp') return navigator.userAgent.match(/micromessenger/i) && navigator.userAgent.match(/miniprogram/i) || window.__wxjs_environment === 'miniprogram';
86
86
  return false;
87
87
  ua = ua || navigator.userAgent;
88
88
  return (/android/i.test(ua) && !isIOS()
89
89
  );
90
90
  ua = ua || navigator.userAgent;
91
91
  return (/ip(hone|od)|ipad/i.test(ua)
92
92
  );
93
93
  ua = ua || navigator.userAgent;
94
94
  return (/ipad/i.test(ua) || /android/i.test(ua) && !/mobi|mini|fennec/i.test(ua)
95
95
  );
96
96
  ua = ua || navigator.userAgent;
97
97
  return !!ua.match(/ip(hone|od)|android.+mobile|windows (ce|phone)|blackberry|bb10|symbian|webos|firefox.+fennec|opera m(ob|in)i|polaris|iemobile|lgtelecom|nokia|sonyericsson|dolfin|uzard|natebrowser|ktf;|skt;/i);
98
98
  ua = ua || navigator.userAgent;
99
99
  return !!ua.match(/iphone/i);
100
100
  ua = ua || navigator.userAgent;
101
101
  return !!ua.match(/ipad/i);
102
102
  ua = ua || navigator.userAgent;
103
103
  if (name === 'xview') return typeof window.XView !== 'undefined';
104
104
  if (name === 'wk') return !!ua.match(/supportjdshwk/i) || window._is_jdsh_wkwebview == 1;
105
105
  return false;
106
106
  ua = ua || navigator.userAgent;
107
107
  var re = /nettype\/([\S]*)/i;
108
108
  if (isApp('jd', ua)) re = /network\/([^;]*)/i;
109
109
  return re.test(ua) ? RegExp.$1.toLowerCase() : 'unknown';
110
110
  ua = ua || navigator.userAgent;
111
111
  if (!isApp('jd', ua)) return null;
112
112
  return ua.split(';')[4];
113
113
  ua = ua || navigator.userAgent;
114
114
  if (appName === 'jd') return ua.split(';')[2] || null;
115
115
  if (appName === 'wx') return (/micromessenger\/([\S]*)/i.test(ua) ? RegExp.$1 : null
116
116
  );
117
117
  if (appName === 'qq') return (/qq\/([\S]*)/i.test(ua) ? RegExp.$1 : null
118
118
  );
119
119
  return null;
120
120
  ua = ua || navigator.userAgent;
121
121
  var match = ua.match(/android\s([0-9\.]*)/i);
122
122
  return match ? match[1] : 'unknown';
123
123
  ua = ua || navigator.userAgent;
124
124
  var match = ua.match(/OS ((\d+_?){2,3})\s/i);
125
125
  return match ? match[1].replace(/_/g, '.') : 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conecli/cone-render",
3
- "version": "0.8.19-beta.2",
3
+ "version": "0.8.19-beta.3",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist/"
@@ -1 +0,0 @@
1
- import { JdJumpJdApp } from './jdJumpJdApp'
2
  reportClick,
3
1
  reportToCart,
4
2
  routerInfo: {
5
3
  params: {},
6
4
  },
7
5
  nativeEvent: null,
8
6
  jumpConfig: {
9
7
  venderId: null,
10
8
  shopId: null,
11
9
  sourceValue: '',
12
10
  sourceType: 'App-H5',
13
11
  activityType: 'shopx',
14
12
  moduleId: 'none',
15
13
  entrance: 'none',
16
14
  },
17
15
  logPageParamStr: '',
18
16
  public logPageId: string
19
17
  public jumpConfig: JumpEventReportInterFace.JumpH5ReportConfig
20
18
  constructor(opt = {}) {
21
19
  console.log("jdb加载==========")
22
20
  super(opt)
23
21
  this.getConfig(opt)
24
22
  }
25
23
 
26
24
  jdJumpToProduct(skuParams, logEventInfo) {
27
25
  if(typeof skuParams !== 'object') {
28
26
  console.error('万商app跳转商品详情参数需要对象,详情请查看文档')
29
27
  return
30
28
  }
31
29
 
32
30
  let { skuId, bMallTag, skuUniformBizInfo } = skuParams
33
31
  skuId = skuId.toString().trim()
34
32
  this.jdNavigateToNative({
35
33
  category: 'jump',
36
34
  des: 'skudetail',
37
35
  param: {
38
36
  skuId: skuId,
39
37
  bMallTag: bMallTag,
40
38
  skuUniformBizInfo
41
39
  },
42
40
  logEventInfo,
43
41
  })
44
42
  }
45
43
  jdNavigateToNative(
46
44
  console.log("otherParams", otherParams)
47
45
  const paramsStr = JSON.stringify(otherParams)
48
46
  console.log(
49
47
  '跳转web jd open协议',
50
48
  `${url}?params=${paramsStr}`,
51
49
  )
52
50
  console.log('catch', e)
53
51
  clickEventLog(
54
52
  getConfig(opt = {}) {
55
53
  return Object.assign(this, {}, defaultConfig, opt)
56
54
  }
@@ -1 +0,0 @@
1
- const userInfo =
2
  (window.WebViewCommon && window.WebViewCommon.getUserInfo()) || {}
3
1
  buId: userInfo.buId,
4
2
  process.env.NODE_ENV === 'development'
5
3
  ? {
6
4
  apolloId: '48ee955b0fb04d19b9f9fe8cb73d387f',
7
5
  apolloSecret: '0d9c76ee66b0487da4e17d3cf1d7af7a',
8
6
  }
9
7
  : {
10
8
  apolloId: '80c46fd06e4442998609d9f6a4ab96f0',
11
9
  apolloSecret: 'f36bef08bcba4683b409732095793fb2',
12
10
  }
13
11
  if (typeof window.crypto === 'object') {
14
12
  if (typeof (window.crypto as any).randomUUID === 'function') {
15
13
  return (window.crypto as any).randomUUID()
16
14
  }
17
15
  if (
18
16
  typeof (window.crypto as any).getRandomValues === 'function' &&
19
17
  typeof Uint8Array === 'function'
20
18
  ) {
21
19
  const callback = (c) => {
22
20
  const num = Number(c)
23
21
  return (
24
22
  num ^
25
23
  ((window.crypto as any).getRandomValues(new Uint8Array(1))[0] &
26
24
  (15 >> (num / 4)))
27
25
  ).toString(16)
28
26
  }
29
27
  return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, callback)
30
28
  }
31
29
  }
32
30
  let timestamp = new Date().getTime()
33
31
  let perforNow =
34
32
  (typeof window.performance !== 'undefined' &&
35
33
  window.performance.now &&
36
34
  window.performance.now() * 1000) ||
37
35
  0
38
36
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
39
37
  let random = Math.random() * 16
40
38
  if (timestamp > 0) {
41
39
  random = (timestamp + random) % 16 | 0
42
40
  timestamp = Math.floor(timestamp / 16)
43
41
  } else {
44
42
  random = (perforNow + random) % 16 | 0
45
43
  perforNow = Math.floor(perforNow / 16)
46
44
  }
47
45
  return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
48
46
  })
49
47
  let params = {
50
48
  uniformBizInfo: {
51
49
  tenantId: 1024,
52
50
  ua: 1,
53
51
  buId: commonParam.buId || 377,
54
52
  bMallTag: bMallTag,
55
53
  },
56
54
  commonParam: {
57
55
  pid: 100,
58
56
  verticalCode: 'cn_retail_bmall',
59
57
  ua: 1,
60
58
  language: 'zh',
61
59
  },
62
60
  operations: [{ TheSkus: [{ Id: skuId, num: num || 1 }] }],
63
61
  apolloId: APOLLO.apolloId,
64
62
  apolloSecret: APOLLO.apolloSecret,
65
63
  client: 'H5',
66
64
  verticalTag: 'cn_retail_bmall',
67
65
  carttype: bMallTag == 1 ? 21 : 22,
68
66
  bMallTag: bMallTag,
69
67
  traceId: getUuid(),
70
68
  noResponse: true,
71
69
  }
72
70
  if (skuUuid) {
73
71
  params.operations[0].TheSkus[0].skuUuid = skuUuid
74
72
  }
75
73
  if (window?.siteTransResult?.gridInfoList) {
76
74
  params = {
77
75
  ...params,
78
76
  cartLocationList: [
79
77
  {
80
78
  gridInfos:
81
79
  window?.siteTransResult?.gridInfoList &&
82
80
  JSON.parse(window?.siteTransResult?.gridInfoList),
83
81
  areaIdSet:
84
82
  window?.siteTransResult?.area &&
85
83
  window?.siteTransResult?.area?.split('-'),
86
84
  },
87
85
  ],
88
86
  }
89
87
  }
90
88
  return params
@@ -1 +0,0 @@
1
- export const HttpStatus = {
2
  SUCCESS: 200,
3
1
  CREATED: 201,
4
2
  ACCEPTED: 202,
5
3
  CLIENT_ERROR: 400,
6
4
  AUTHENTICATE: 401,
7
5
  FORBIDDEN: 403,
8
6
  NOT_FOUND: 404,
9
7
  SERVER_ERROR: 500,
10
8
  BAD_GATEWAY: 502,
11
9
  SERVICE_UNAVAILABLE: 503,
12
10
  GATEWAY_TIMEOUT: 504
13
11
  [HttpStatus.NOT_FOUND]: "请求资源不存在",
14
12
  [HttpStatus.BAD_GATEWAY]: "服务端异常,请稍后重试",
15
13
  [HttpStatus.FORBIDDEN]: "没有权限访问",
16
14
  [HttpStatus.AUTHENTICATE]: "需要鉴权",
17
15
  [HttpStatus.SUCCESS]: "成功"
18
16
  "getPagePreview"
19
17
  "getShopHomeFloorInfo",
20
18
  "getShopCategory",
21
19
  "getShopNavigationCategory",
22
20
  "receiveShopCoupon",
23
21
  "getShopHomePromotionWebPage",
24
22
  "shopGuessYouLike",
25
23
  "addRemind",
26
24
  "cancelRemind",
27
25
  "getVipDetail",
28
26
  "shopDetail",
29
27
  "address_queryAddress",
30
28
  "shopMemberSprintJoinActivity",
31
29
  "shopMemberSprintReceivePrize"
@@ -1 +0,0 @@
1
- import Taro, { RequestTask } from '@tarojs/taro'
2
  jsonHeader = 'application/json;charset=utf-8',
3
1
  formDataHeader = 'application/x-www-form-urlencoded',
4
2
  public fmInfo: {
5
3
  eid?: string
6
4
  fp?: string
7
5
  jsToken?: string
8
6
  sdkToken?: string
9
7
  }
10
8
  public api: ServiceInterFace.HttpApi
11
9
  constructor() {
12
10
  this._init()
13
11
  this.api = api
14
12
  this.fmInfo = {}
15
13
  }
16
14
  _init(): void {
17
15
  httpInterceptors.forEach((item) => {
18
16
  Taro.addInterceptor((chain) => item(chain))
19
17
  })
20
18
  }
21
19
 
22
20
  get(url: string, data: any = null, otherOptions = {}): Taro.RequestTask<any> {
23
21
  return this.request({ url, data, method: 'GET', ...otherOptions })
24
22
  }
25
23
 
26
24
  post(
27
25
  url: string,
28
26
  data: any = null,
29
27
  otherOptions = {},
30
28
  ): Taro.RequestTask<any> {
31
29
  return this.request({ url, data, method: 'POST', ...otherOptions })
32
30
  }
33
31
 
34
32
  _getMobileJsToken(): Promise<{
35
33
  ok: boolean
36
34
  data?: any
37
35
  error?: any
38
36
  }> {
39
37
  return new Promise((resolve, reject) => {
40
38
  try {
41
39
  if (window?.getJsToken) {
42
40
  window.getJsToken(function (res) {
43
41
  console.log('JS token 获取结果:', res)
44
42
  resolve({
45
43
  ok: true,
46
44
  data: res,
47
45
  })
48
46
  }, 600)
49
47
  } else {
50
48
  reject({
51
49
  ok: false,
52
50
  error: '没有识别到getJsToken全局方法',
53
51
  })
54
52
  }
55
53
  } catch (e) {
56
54
  console.log('获取指纹JS token 异常', e)
57
55
  reject({
58
56
  ok: false,
59
57
  error: e,
60
58
  })
61
59
  }
62
60
  })
63
61
  }
64
62
 
65
63
  async _getFmInfo() {
66
64
  try {
67
65
  const { ok, data } = await this._getMobileJsToken()
68
66
  this.fmInfo = ok && data ? data : this.fmInfo
69
67
  return this.fmInfo
70
68
  } catch (e) {
71
69
  console.log('获取指纹信息异常', e)
72
70
  return this.fmInfo
73
71
  }
74
72
  }
75
73
 
76
74
  async request({
77
75
  url,
78
76
  method = 'POST',
79
77
  timeout = 7000,
80
78
  ...otherOptions
81
79
  }): RequestTask<any> {
82
80
  const header = {
83
81
  'content-type':
84
82
  method === 'POST'
85
83
  ? RequestHeaderContentType.formDataHeader
86
84
  : RequestHeaderContentType.jsonHeader,
87
85
  }
88
86
  const getReqData = otherOptions.data
89
87
  if (url === this.api.apiFunc && typeof getReqData === 'object') {
90
88
  const { jsToken } = await this._getFmInfo()
91
89
  jsToken && (getReqData['x-api-eid-token'] = jsToken)
92
90
  }
93
91
  const requestTask = Taro.request({
94
92
  url,
95
93
  method,
96
94
  timeout,
97
95
  header,
98
96
  credentials: 'include',
99
97
  ...otherOptions,
100
98
  })
101
99
  const requestTimeoutPromise =
102
100
  new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
103
101
  setTimeout(() => {
104
102
  resolve({
105
103
  statusCode: 500,
106
104
  resTimeoutState: true,
107
105
  errMsg: 'request timeout',
108
106
  })
109
107
  }, timeout)
110
108
  })
111
109
  return Promise.race([requestTask, requestTimeoutPromise]).then(
112
110
  (res: any) => {
113
111
  if (res && res.statusCode === 500 && res.resTimeoutState) {
114
112
  console.log('request 请求超时 url:' + url)
115
113
  requestTask.abort && requestTask.abort()
116
114
  }
117
115
  return res
118
116
  },
119
117
  )
120
118
  }
@@ -1 +0,0 @@
1
- import Taro from '@tarojs/taro'
@@ -1 +0,0 @@
1
- import Taro from '@tarojs/taro'
@@ -1 +0,0 @@
1
- import Http from './http'
@@ -1 +0,0 @@
1
- import Taro, { RequestTask } from '@tarojs/taro'
2
  SHOP_COLOR_APPID,
3
1
  JshopxColorFunctionIdList,
4
2
  PagesColorFunctionIdList,
5
3
  JSHOPX_COLOR_APPID,
6
4
  PAGES_COLOR_APPID,
7
5
  PAGES_DOMAIN,
8
6
  B2BColorFunctionIdList,
9
7
  B2B_COLOR_APPID,
10
8
  cookiesStr: '',
11
9
  requestHeaderContentType: {
12
10
  jsonHeader: {
13
11
  'content-type': 'application/json;charset=utf-8',
14
12
  },
15
13
  formDataHeader: {
16
14
  'content-type': 'application/x-www-form-urlencoded',
17
15
  },
18
16
  },
19
17
  requestBaseParam: {
20
18
  data: null,
21
19
  header: {
22
20
  'content-type': 'application/json;charset=utf-8',
23
21
  },
24
22
  },
25
23
  timeOut: 7000,
26
24
  apiClientParams: {
27
25
  appid: SHOP_COLOR_APPID,
28
26
  clientVersion:
29
27
  isH5AndJdShopView && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
30
28
  client: isH5AndJdShopView ? (isIosDevice ? 'apple' : 'android') : 'wh5',
31
29
  area: '1_72_2799_0',
32
30
  uuid: UUID,
33
31
  },
34
32
  public addressFetchInfo: {
35
33
  reqState: boolean
36
34
  promiseInstance: null | Promise<any>
37
35
  }
38
36
  public getPromotionConfig: {
39
37
  projectId: null | string | number
40
38
  pageId: null | string | number
41
39
  }
42
40
  public resInfo: ServiceInterFace.HttpRequestInfo
43
41
  public api: ServiceInterFace.HttpApi
44
42
  public isPageDomain: boolean
45
43
  constructor(opt) {
46
44
  this._init()
47
45
  this.addressFetchInfo = {
48
46
  reqState: false,
49
47
  promiseInstance: null,
50
48
  }
51
49
  this.getPromotionConfig = {
52
50
  projectId: null,
53
51
  pageId: null,
54
52
  }
55
53
  this._userAreaUpdateListen()
56
54
  this.resInfo = this._getResConfig(opt)
57
55
  this.api = api
58
56
  this.isPageDomain = window.location.hostname === PAGES_DOMAIN
59
57
  }
60
58
  _init(): void {
61
59
  httpInterceptors.forEach((item) => {
62
60
  Taro.addInterceptor((chain) => item(chain))
63
61
  })
64
62
  }
65
63
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
66
64
  return Object.assign({}, DefaultConfig, opt)
67
65
  }
68
66
 
69
67
  _userAreaUpdateListen() {
70
68
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
71
69
  this.updateApiClientParamsResInfo({
72
70
  area,
73
71
  })
74
72
  })
75
73
  }
76
74
  updateApiClientParamsResInfo(opt = {}) {
77
75
  this.resInfo.apiClientParams = {
78
76
  ...this.resInfo.apiClientParams,
79
77
  ...opt,
80
78
  }
81
79
  }
82
80
 
83
81
  _paramsSign(data) {
84
82
  return Promise.resolve(data)
85
83
  }
86
84
 
87
85
  checkFunctionIdToReturnAppId(functionId) {
88
86
  if (JshopxColorFunctionIdList.includes(functionId)) {
89
87
  return JSHOPX_COLOR_APPID
90
88
  } else if (
91
89
  this.isPageDomain &&
92
90
  PagesColorFunctionIdList.includes(functionId)
93
91
  ) {
94
92
  return PAGES_COLOR_APPID
95
93
  } else if (B2BColorFunctionIdList.includes(functionId)) {
96
94
  return B2B_COLOR_APPID
97
95
  } else {
98
96
  return SHOP_COLOR_APPID
99
97
  }
100
98
  }
101
99
 
102
100
  gatewayReq(
103
101
  functionId: string,
104
102
  bodyParams = {},
105
103
  clientParams = {},
106
104
  ): Promise<any> {
107
105
  if (
108
106
  functionId === 'receiveShopCoupon' &&
109
107
  ((isH5 && window.isJingGouMiniViewState) || isWxMinAndWxapp)
110
108
  ) {
111
109
  clientParams = Object.assign(
112
110
  {},
113
111
  {
114
112
  loginType: '1',
115
113
  loginWQBiz: WXAPP_BIZ_KEY,
116
114
  },
117
115
  clientParams,
118
116
  )
119
117
  }
120
118
  const apiClientParams = Object.assign(
121
119
  {},
122
120
  this.resInfo.apiClientParams,
123
121
  clientParams,
124
122
  )
125
123
  apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId)
126
124
  const getReqData = {
127
125
  functionId: functionId,
128
126
  body: JSON.stringify(bodyParams),
129
127
  t: Date.now(),
130
128
  ...apiClientParams,
131
129
  }
132
130
  console.log(`gatewayReq:${this.api.apiFunc}`)
133
131
  return http
134
132
  .request({
135
133
  url: this.api.apiFunc,
136
134
  data: getReqData,
137
135
  method: 'GET',
138
136
  })
139
137
  .then((res: ServiceInterFace.RequestPromiseRes) => {
140
138
  const { statusCode, data } = res
141
139
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
142
140
  ok: true,
143
141
  }
144
142
  if (statusCode === 200 && data) {
145
143
  const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
146
144
  ? Number(res.data.code)
147
145
  : -1
148
146
  const subCode = Object.prototype.hasOwnProperty.call(
149
147
  res.data,
150
148
  'subCode',
151
149
  )
152
150
  ? Number(res.data.subCode)
153
151
  : -1
154
152
  if (
155
153
  data.success === true ||
156
154
  data.isSuccess ||
157
155
  resCode === 0 ||
158
156
  resCode === 200 ||
159
157
  subCode === 0
160
158
  ) {
161
159
  changeRes = {
162
160
  result: Object.prototype.hasOwnProperty.call(data, 'result')
163
161
  ? data.result
164
162
  : Object.prototype.hasOwnProperty.call(data, 'data')
165
163
  ? data.data
166
164
  : data,
167
165
  code: data.code || 200,
168
166
  ok: true,
169
167
  source: data,
170
168
  }
171
169
  return changeRes
172
170
  } else {
173
171
  changeRes = {
174
172
  ...data,
175
173
  ok: false,
176
174
  statusCode: res.statusCode,
177
175
  }
178
176
  return changeRes
179
177
  }
180
178
  } else {
181
179
  changeRes = {
182
180
  ...data,
183
181
  ok: false,
184
182
  statusCode: res.statusCode,
185
183
  }
186
184
  return changeRes
187
185
  }
188
186
  })
189
187
  .catch((res) => {
190
188
  return {
191
189
  ...res,
192
190
  ok: false,
193
191
  } as ServiceInterFace.RequestResponseFormatRes
194
192
  })
195
193
  }
196
194
 
197
195
  async receiveCoupon(param = {}, clientParams) {
198
196
  return await this.gatewayReq(
199
197
  'receiveShopCoupon',
200
198
  {
201
199
  operation: '3',
202
200
  ...param,
203
201
  },
204
202
  clientParams,
205
203
  )
206
204
  }
207
205
  async bMallAddCart(params = {}) {
208
206
  return await this.gatewayReq('bmall_cartAdd', params, {
209
207
  client: 'H5',
210
208
  })
211
209
  }
212
210
  async bMallChangeCart(params = {}) {
213
211
  return await this.gatewayReq('bmall_cartChange', params, {
214
212
  client: 'H5',
215
213
  })
216
214
  }
217
215
  async bMallRemoveCart(params = {}) {
218
216
  return await this.gatewayReq(
219
217
  'bmall_cartRemove',
220
218
  params,
221
219
  {
222
220
  client: 'H5',
223
221
  },
224
222
  )
225
223
  }
226
224
  async bMallGetOmittedProduct(params = {}) {
227
225
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
228
226
  client: 'H5',
229
227
  })
230
228
  }
231
229
  async bMallAddCartService({ skuId, bMallTag, num }) {
232
230
  const params = getParams({ skuId, bMallTag, num })
233
231
  return await this.addCart(params)
234
232
  }
235
233
  async bMallGetSkuNumService(bMallTag = 1) {
236
234
  const params = getParams({ bMallTag })
237
235
  delete params.operations
238
236
  return await this.getOmittedProduct(params)
239
237
  }
240
238
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid }) {
241
239
  let params = getParams({ skuId, bMallTag, num, skuUuid })
242
240
  return await this.removeCart(params)
243
241
  }
244
242
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid }) {
245
243
  let params = getParams({ skuId, bMallTag, num, skuUuid })
246
244
  return await this.changeCart(params)
247
245
  }
248
246
 
249
247
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
250
248
  if (!needRequest && window.bMallCartData) {
251
249
  return window.bMallCartData
252
250
  }
253
251
  const cartData = await this.getSkuNumService(bMallTag)
254
252
  let items
255
253
  if (cartData.ok && cartData.result) {
256
254
  items = cartData?.result?.items || {}
257
255
  }
258
256
  window.bMallCartData = items
259
257
  return items
260
258
  }
261
259
 
262
260
  async bMallCartHandle(goodItem, num) {
263
261
  try {
264
262
  const {
265
263
  skuUuid,
266
264
  limitUpper,
267
265
  limitLower,
268
266
  } = goodItem
269
267
  let cartNum = Number(num)
270
268
  if (limitLower && cartNum && cartNum < limitLower) {
271
269
  cartNum = limitLower
272
270
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
273
271
  cartNum = limitUpper
274
272
  }
275
273
  if (skuUuid && cartNum > 0) {
276
274
  return this.changeCartService({
277
275
  ...goodItem,
278
276
  skuUuid,
279
277
  num: cartNum,
280
278
  })
281
279
  } else if (!skuUuid && cartNum > 0) {
282
280
  return this.addCartService({ ...goodItem, num: cartNum })
283
281
  } else if (skuUuid && !cartNum) {
284
282
  return this.removeCartService({
285
283
  ...goodItem,
286
284
  skuUuid,
287
285
  num: cartNum,
288
286
  })
289
287
  } else {
290
288
  console.error('参数不全')
291
289
  return false
292
290
  }
293
291
  } catch (e) {
294
292
  console.error(e)
295
293
  }
296
294
  }