@conecli/cone-render 0.10.1-shop3.108 → 0.10.1-shop3.109

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 Taro from '@tarojs/taro';
2
1
  'app-activity',
3
2
  'app-rank',
4
3
  'app-seckill',
5
4
  'm-coupon',
6
5
  'scene-buy',
7
6
  'light-details',
8
7
  'member-paid-center',
9
8
  'member-paid-card',
10
9
  'member-paid-bind',
11
10
  'app-introduce',
12
11
  'app-search-result',
13
12
  if (window?.shopGlobalSwitch?.openAccessibilityLanguage) {
14
13
  Taro.nextTick(() => {
15
14
  const htmlRoot = document?.documentElement;
16
15
  htmlRoot && htmlRoot.setAttribute('lang', isLanguageForEn ? 'en' : 'zh-CN');
17
16
  });
18
17
  }
19
18
  const mainConfig = {
20
19
  childList: true,
21
20
  subtree: true,
22
21
  attributes: true,
23
22
  attributeFilter: ['auto-accessible'],
24
23
  };
25
24
  const mainObserver = new MutationObserver(function (mutations) {
26
25
  mutations.forEach(function (mutation) {
27
26
  if (mutation.type === 'childList') {
28
27
  mutation.addedNodes.forEach(function (node) {
29
28
  if (node.nodeType === Node.ELEMENT_NODE) {
30
29
  if (node.hasAttribute && node.getAttribute('auto-accessible') === 'true') {
31
30
  updateAccessibilityLabel(node);
32
31
  }
33
32
  const accessibleElements = node.querySelectorAll
34
33
  ? node.querySelectorAll('[auto-accessible="true"]')
35
34
  : [];
36
35
  accessibleElements.forEach(function (el) {
37
36
  updateAccessibilityLabel(el);
38
37
  });
39
38
  }
40
39
  });
41
40
  }
42
41
  if (mutation.type === 'attributes' && mutation.attributeName === 'auto-accessible') {
43
42
  if (mutation.target.getAttribute('auto-accessible') === 'true') {
44
43
  updateAccessibilityLabel(mutation.target);
45
44
  }
46
45
  }
47
46
  });
48
47
  });
49
48
  mainObserver.observe(document.body, mainConfig);
50
49
  setupGlobalContentObserver();
51
50
  const contentConfig = {
52
51
  characterData: true,
53
52
  childList: true,
54
53
  subtree: true,
55
54
  };
56
55
  const lastUpdateTime = new WeakMap();
57
56
  const THROTTLE_DELAY = 2000;
58
57
 
59
58
  function shouldUpdate(element) {
60
59
  const now = Date.now();
61
60
  const lastTime = lastUpdateTime.get(element);
62
61
  if (!lastTime || now - lastTime >= THROTTLE_DELAY) {
63
62
  lastUpdateTime.set(element, now);
64
63
  return true;
65
64
  }
66
65
  return false;
67
66
  }
68
67
  const globalContentObserver = new MutationObserver(function (mutations) {
69
68
  const affectedElements = new Set();
70
69
  mutations.forEach(function (mutation) {
71
70
  let targetElement = null;
72
71
  if (mutation.type === 'characterData') {
73
72
  targetElement = findClosestAccessibleElement(mutation.target);
74
73
  } else if (mutation.type === 'childList') {
75
74
  targetElement = findClosestAccessibleElement(mutation.target);
76
75
  }
77
76
  if (targetElement && targetElement.getAttribute('auto-accessible') === 'true') {
78
77
  affectedElements.add(targetElement);
79
78
  }
80
79
  });
81
80
  affectedElements.forEach(function (element) {
82
81
  if (shouldUpdate(element)) {
83
82
  updateAccessibilityLabel(element);
84
83
  } else {
85
84
  }
86
85
  });
87
86
  });
88
87
  globalContentObserver.observe(document.body, contentConfig);
89
88
  let current = node;
90
89
  if (current.nodeType === Node.TEXT_NODE) {
91
90
  current = current.parentElement;
92
91
  }
93
92
  while (current && current !== document.body) {
94
93
  if (current.getAttribute && current.getAttribute('auto-accessible') === 'true') {
95
94
  return current;
96
95
  }
97
96
  current = current.parentElement;
98
97
  }
99
98
  return null;
100
99
  if (!element) return;
101
100
  if (element.hasAttribute('aria-label')) {
102
101
  completeA11yAttributes(element);
103
102
  if (!element.getAttribute('data-auto-aria-label')) {
104
103
  return;
105
104
  }
106
105
  }
107
106
  const text = element.innerText;
108
107
  if (text) {
109
108
  const processedText = text.replace(/\r|\n/g, ' ').replace(/¥\s(\d+)(\s(\.\d+))?/, '¥$1$3');
110
109
  element.setAttribute('aria-label', processedText);
111
110
  element.setAttribute('data-auto-aria-label', 'true');
112
111
  completeA11yAttributes(element);
113
112
  }
114
113
  if (!element.hasAttribute('role')) {
115
114
  element.setAttribute('role', 'text');
116
115
  }
117
116
  if (!element.hasAttribute('tabindex')) {
118
117
  element.setAttribute('tabindex', 0);
119
118
  }
120
119
  const routerURL = 'router://JDShopModule/isAccessibilityIsRunning';
121
120
  const callBackName = `nativeGetAccessibilityIsRunning${Date.now()}`;
122
121
  let params: any = {
123
122
  routerURL,
124
123
  routerParam: null,
125
124
  callBackName,
126
125
  };
127
126
  return new Promise((resolve) => {
128
127
  window[callBackName] = (res) => {
129
128
  let data;
130
129
  try {
131
130
  data = typeof res === 'string' ? JSON.parse(res) : res;
132
131
  } catch (e) {
133
132
  console.error('JSON parse error:', e);
134
133
  data = {};
135
134
  }
136
135
  console.log('无障碍router回调成功:', res);
137
136
  const isRunning = data?.data?.isAccessibilityIsRunning || false;
138
137
  resolve(isRunning);
139
138
  };
140
139
  if (isJdAndIosDevice) {
141
140
  callRouterIOS(params);
142
141
  } else if (isJdAndAndroidDevice) {
143
142
  callRouterAndroid(params);
144
143
  }
145
144
  });
146
145
  setPageLanguage();
147
146
  let isRunning;
148
147
  try {
149
148
  isRunning = await getAccessibilityIsRunning();
150
149
  } catch (e) {
151
150
  console.error('getAccessibilityIsRunning() ~~ error:', e);
152
151
  }
153
152
  if (isRunning || autoAccessiblePagesWhitelist.includes(buildType)) {
154
153
  console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
155
154
  setupMainObserver();
156
155
  } else {
157
156
  console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);
158
157
  }
158
+ import Taro from '@tarojs/taro';
159
159
  'app-activity',
160
160
  'app-rank',
161
161
  'app-seckill',
162
162
  'm-coupon',
163
163
  'scene-buy',
164
164
  'light-details',
165
165
  'member-paid-center',
166
166
  'member-paid-card',
167
167
  'member-paid-bind',
168
168
  'app-introduce',
169
169
  'app-search-result',
170
170
  if (window?.shopGlobalSwitch?.openAccessibilityLanguage) {
171
171
  Taro.nextTick(() => {
172
172
  const htmlRoot = document?.documentElement;
173
173
  htmlRoot && htmlRoot.setAttribute('lang', isLanguageForEn ? 'en' : 'zh-CN');
174
174
  });
175
175
  }
176
176
  const mainConfig = {
177
177
  childList: true,
178
178
  subtree: true,
179
179
  attributes: true,
180
180
  attributeFilter: ['auto-accessible'],
181
181
  };
182
182
  const mainObserver = new MutationObserver(function (mutations) {
183
183
  mutations.forEach(function (mutation) {
184
184
  if (mutation.type === 'childList') {
185
185
  mutation.addedNodes.forEach(function (node) {
186
186
  if (node.nodeType === Node.ELEMENT_NODE) {
187
187
  if (node.hasAttribute && node.getAttribute('auto-accessible') === 'true') {
188
188
  updateAccessibilityLabel(node);
189
189
  }
190
190
  const accessibleElements = node.querySelectorAll
191
191
  ? node.querySelectorAll('[auto-accessible="true"]')
192
192
  : [];
193
193
  accessibleElements.forEach(function (el) {
194
194
  updateAccessibilityLabel(el);
195
195
  });
196
196
  }
197
197
  });
198
198
  }
199
199
  if (mutation.type === 'attributes' && mutation.attributeName === 'auto-accessible') {
200
200
  if (mutation.target.getAttribute('auto-accessible') === 'true') {
201
201
  updateAccessibilityLabel(mutation.target);
202
202
  }
203
203
  }
204
204
  });
205
205
  });
206
206
  mainObserver.observe(document.body, mainConfig);
207
207
  setupGlobalContentObserver();
208
208
  const contentConfig = {
209
209
  characterData: true,
210
210
  childList: true,
211
211
  subtree: true,
212
212
  };
213
213
  const lastUpdateTime = new WeakMap();
214
214
  const THROTTLE_DELAY = 2000;
215
215
 
216
216
  function shouldUpdate(element) {
217
217
  const now = Date.now();
218
218
  const lastTime = lastUpdateTime.get(element);
219
219
  if (!lastTime || now - lastTime >= THROTTLE_DELAY) {
220
220
  lastUpdateTime.set(element, now);
221
221
  return true;
222
222
  }
223
223
  return false;
224
224
  }
225
225
  const globalContentObserver = new MutationObserver(function (mutations) {
226
226
  const affectedElements = new Set();
227
227
  mutations.forEach(function (mutation) {
228
228
  let targetElement = null;
229
229
  if (mutation.type === 'characterData') {
230
230
  targetElement = findClosestAccessibleElement(mutation.target);
231
231
  } else if (mutation.type === 'childList') {
232
232
  targetElement = findClosestAccessibleElement(mutation.target);
233
233
  }
234
234
  if (targetElement && targetElement.getAttribute('auto-accessible') === 'true') {
235
235
  affectedElements.add(targetElement);
236
236
  }
237
237
  });
238
238
  affectedElements.forEach(function (element) {
239
239
  if (shouldUpdate(element)) {
240
240
  updateAccessibilityLabel(element);
241
241
  } else {
242
242
  }
243
243
  });
244
244
  });
245
245
  globalContentObserver.observe(document.body, contentConfig);
246
246
  let current = node;
247
247
  if (current.nodeType === Node.TEXT_NODE) {
248
248
  current = current.parentElement;
249
249
  }
250
250
  while (current && current !== document.body) {
251
251
  if (current.getAttribute && current.getAttribute('auto-accessible') === 'true') {
252
252
  return current;
253
253
  }
254
254
  current = current.parentElement;
255
255
  }
256
256
  return null;
257
257
  if (!element) return;
258
258
  if (element.hasAttribute('aria-label')) {
259
259
  completeA11yAttributes(element);
260
260
  if (!element.getAttribute('data-auto-aria-label')) {
261
261
  return;
262
262
  }
263
263
  }
264
264
  const text = element.innerText;
265
265
  if (text) {
266
266
  const processedText = text.replace(/\r|\n/g, ' ').replace(/¥\s(\d+)(\s(\.\d+))?/, '¥$1$3');
267
267
  element.setAttribute('aria-label', processedText);
268
268
  element.setAttribute('data-auto-aria-label', 'true');
269
269
  completeA11yAttributes(element);
270
270
  }
271
271
  if (!element.hasAttribute('role')) {
272
272
  element.setAttribute('role', 'text');
273
273
  }
274
274
  if (!element.hasAttribute('tabindex')) {
275
275
  element.setAttribute('tabindex', 0);
276
276
  }
277
277
  const routerURL = 'router://JDShopModule/isAccessibilityIsRunning';
278
278
  const callBackName = `nativeGetAccessibilityIsRunning${Date.now()}`;
279
279
  let params: any = {
280
280
  routerURL,
281
281
  routerParam: null,
282
282
  callBackName,
283
283
  };
284
284
  return Promise.race([
285
285
  new Promise((resolve) => { setTimeout(() => resolve(false), 1000) }),
286
286
  new Promise((resolve) => {
287
287
  window[callBackName] = (res) => {
288
288
  let data;
289
289
  try {
290
290
  data = typeof res === 'string' ? JSON.parse(res) : res;
291
291
  } catch (e) {
292
292
  console.error('JSON parse error:', e);
293
293
  data = {};
294
294
  }
295
295
  console.log('无障碍router回调成功:', res);
296
296
  const isRunning = data?.data?.isAccessibilityIsRunning || false;
297
297
  resolve(isRunning);
298
298
  };
299
299
  if (isJdAndIosDevice) {
300
300
  callRouterIOS(params);
301
301
  } else if (isJdAndAndroidDevice) {
302
302
  callRouterAndroid(params);
303
303
  } else if (isJdAndHarmonyDevice) {
304
304
  const plugin = 'JdShopPlugin';
305
305
  const action = Message_Type.GET_ACCESSIBILITY_IS_RUNNING;
306
306
  params = {
307
307
  ...params,
308
308
  routerURL: '',
309
309
  routerParam: {
310
310
  type: action,
311
311
  callBackName,
312
312
  },
313
313
  };
314
314
  window.XWebView &&
315
315
  window.XWebView.callNative(
316
316
  plugin,
317
317
  action,
318
318
  JSON.stringify(params),
319
319
  callBackName,
320
320
  `${callBackName}HarmonyOS`,
321
321
  );
322
322
  } else {
323
323
  resolve(false);
324
324
  }
325
325
  })
326
326
  ])
327
327
  setPageLanguage();
328
328
  let isRunning;
329
329
  try {
330
330
  isRunning = await getAccessibilityIsRunning();
331
331
  } catch (e) {
332
332
  console.error('getAccessibilityIsRunning() ~~ error:', e);
333
333
  }
334
334
  if (isRunning || autoAccessiblePagesWhitelist.includes(buildType)) {
335
335
  console.log('🚀 ~~ 页面启用无障碍自动支持方案 ~~ buildType:', buildType);
336
336
  setupMainObserver();
337
337
  } else {
338
338
  console.log('🚀 ~~ 页面不启用无障碍自动支持方案 !! buildType:', buildType);
339
339
  }
@@ -1 +1 @@
1
- import React from 'react';
2
1
  console.warn('🚗 ~~ file: index.tsx:22 ~~ reportException() ~~ {type, detail, text}:', {
3
2
  type,
4
3
  data,
5
4
  text,
6
5
  });
7
6
  draBusinessCustomReport({
8
7
  eventName: 'business',
9
8
  errorName: getSgmCustomCode(`${SgmCustomCode.PRICE_RENDER}_${type}`),
10
9
  errorMessage: '[双价格组件]' + text,
11
10
  extraData: JSON.stringify({
12
11
  type,
13
12
  data,
14
13
  }),
15
14
  });
16
15
  return rest.some((item) => item === undefined || item === '');
17
16
  const numPrice = Number(strPrice);
18
17
  if (isNaN(numPrice)) {
19
18
  reportException({
20
19
  type: 'isNotNumericType',
21
20
  data: props,
22
21
  text: `传入价格字段值“${strPrice}”转换数字报错`,
23
22
  });
24
23
  return false;
25
24
  }
26
25
  else if (numPrice <= 0) {
27
26
  reportException({
28
27
  type: 'isNotPositiveNumber',
29
28
  data: props,
30
29
  text: `传入价格字段值“${strPrice}”不是一个正数`,
31
30
  });
32
31
  return false;
33
32
  }
34
33
  const result = numPrice.toString().match(/(\d+)(\.(\d+))?/);
35
34
  if (result && result[3]?.length > 2) {
36
35
  reportException({
37
36
  type: 'decimalPlaceTooLong',
38
37
  data: props,
39
38
  text: `传入价格字段值“${strPrice}”小数位不能超过2位`,
40
39
  });
41
40
  return false;
42
41
  }
43
42
  if (/^\d+(\.\d+)?[eE][+-]?\d+$/.test(strPrice)) {
44
43
  reportException({
45
44
  type: 'findScientificNotation',
46
45
  data: props,
47
46
  text: `传入价格字段值“${strPrice}”是一个科学计数法格式`,
48
47
  });
49
48
  }
50
49
  return true;
51
50
  const { jdPrice, finalPrice, forceShowFinalPrice } = props;
52
51
  if (jdPrice && finalPrice) {
53
52
  const getLastPassValidateState = forceShowFinalPrice || Number(finalPrice) < Number(jdPrice);
54
53
  !getLastPassValidateState &&
55
54
  reportException({
56
55
  type: 'pricesCompareException',
57
56
  data: props,
58
57
  text: `身份/到手价必须小于松果价`,
59
58
  });
60
59
  return getLastPassValidateState;
61
60
  } else {
62
61
  return true;
63
62
  }
64
63
  const numPrice = Number(strPrice);
65
64
  const result = numPrice.toString().match(/(\d+)(\.(\d+))?/);
66
65
  if (result) {
67
66
  return {
68
67
  integerPrice: result[1],
69
68
  decimalPrice: (result[3] || '').replace(/0+$/, ''),
70
69
  };
71
70
  } else {
72
71
  reportException({
73
72
  type: 'deconstructException',
74
73
  data: props,
75
74
  text: `解构传入价格字段值“${strPrice}”解构发生异常`,
76
75
  });
77
76
  return null;
78
77
  }
79
78
  const {
80
79
  jdPrice,
81
80
  finalPrice,
82
81
  priceText = '',
83
82
  priceTextColor = '',
84
83
  priceUnit = '',
85
84
  priceType,
86
85
  hitUserIdentity = false,
87
86
  forceShowFinalPrice = false,
88
87
  hideSmallPrice = false,
89
88
  fallbackRender = null,
90
89
  className = null,
91
90
  style = {},
92
91
  childrenClassName = null,
93
92
  bigNoPriceClassName = null,
94
93
  bigSymbolClassName = null,
95
94
  bigIntegerClassName = null,
96
95
  bigDecimalClassName = null,
97
96
  priceDescClassName = null,
98
97
  smallPriceClassName = null,
99
98
  smallPriceDescClassName = null,
100
99
  lineNumber = 1,
101
100
  size = 'M',
102
101
  isDefaultRemoveSmallPrice = false,
103
102
  useFontV2 = false,
104
103
  useFontV2Bold = false,
105
104
  useSmallFontV2 = false,
106
105
  useSmallFontV2Bold = false,
107
106
  nativeProps,
108
107
  } = props;
109
108
  let useBackstop = false;
110
109
  const isShowPriceUnit = priceUnit && priceUnit !== '';
111
110
  if (isNull(props.priceType)) {
112
111
  useBackstop = true;
113
112
  reportException({
114
113
  type: 'paramMiss',
115
114
  data: props,
116
115
  text: '缺少必要入参:priceType',
117
116
  });
118
117
  } else if (
119
118
  !allowedNoHitUserIdentityTypes.includes(props.priceType) &&
120
119
  props.hitUserIdentity === undefined
121
120
  ) {
122
121
  useBackstop = true;
123
122
  reportException({
124
123
  type: 'paramMiss',
125
124
  data: props,
126
125
  text: `价格类型${props.priceType}缺少必要入参:hitUserIdentity`,
127
126
  });
128
127
  }
129
128
  const especialHitStyleType = {
130
129
  7: 'plusStyle',
131
130
  9: 'samStyle',
132
131
  };
133
132
  const especialMissStyleType = {
134
133
  7: 'plusStyle',
135
134
  8: 'fansStyle',
136
135
  9: 'samStyle',
137
136
  10: 'studentStyle',
138
137
  12: 'yhdStyle',
139
138
  13: 'memberStyle',
140
139
  };
141
140
  const isUseFinalPriceAsBigPrice = allowedNoHitUserIdentityTypes.includes(priceType);
142
141
  const isEquivalentHit = isUseFinalPriceAsBigPrice || hitUserIdentity;
143
142
  const isOnlyShowBigPrice = priceType === 3 || isNull(finalPrice);
144
143
  const smallPrice = isEquivalentHit ? jdPrice : finalPrice;
145
144
  const isHideSmallPrice =
146
145
  hideSmallPrice || priceType === 14 || isDefaultRemoveSmallPrice || isNaN(Number(smallPrice));
147
146
  const isTextPrice = priceType === 4;
148
147
  if (!isTextPrice && !useBackstop) {
149
148
  if (finalPrice && !numericPriceValidate(finalPrice, props)) {
150
149
  useBackstop = true;
151
150
  } else if (jdPrice && !numericPriceValidate(jdPrice, props)) {
152
151
  useBackstop = true;
153
152
  }
154
153
  if (!useBackstop && !isOnlyShowBigPrice && !isHideSmallPrice && !pricesCompareValidate(props)) {
155
154
  useBackstop = true;
156
155
  }
157
156
  }
158
157
  const bigPriceObj =
159
158
  isTextPrice || useBackstop
160
159
  ? {}
161
160
  : getDeconstructPrice(isEquivalentHit && !isNull(finalPrice) ? finalPrice : jdPrice, props);
162
161
  const { integerPrice = '', decimalPrice = '' } = bigPriceObj || {};
163
162
  const isPriceDescInFront = isEquivalentHit;
164
163
  const hitColorStyle = isEquivalentHit ? styles[especialHitStyleType[priceType]] : null;
165
164
  const missColorStyle = isEquivalentHit ? null : styles[especialMissStyleType[priceType]];
166
165
  const isBigPriceHasDecimal = decimalPrice !== '' && !/^0+$/.test(decimalPrice);
167
166
  const sizeLineHeight = {
168
167
  XS: 28,
169
168
  S: 34,
170
169
  M: 40,
171
170
  L: 46,
172
171
  XL: 52,
173
172
  };
174
173
  const lineHeight = Taro.pxTransform(sizeLineHeight[size] * 1.25);
175
174
  const wrapHeight = Taro.pxTransform(sizeLineHeight[size] * 1.25 * lineNumber);
176
175
  const computedHeightStyle = {
177
176
  height: wrapHeight,
178
177
  };
179
178
  const itemCommonStyle = {
180
179
  height: lineHeight,
181
180
  };
182
181
  const priceTextStyle = priceTextColor ? { color: priceTextColor } : {};
183
182
  const needSizeStyles = [
184
183
  'bigNoPrice',
185
184
  'bigSymbol',
186
185
  'bigInteger',
187
186
  'bigDecimal',
188
187
  'priceDesc',
189
188
  'smallPrice',
190
189
  'priceUnit',
191
190
  ];
192
191
  const sizeStyles = needSizeStyles.reduce((acc, cur) => {
193
192
  acc[cur] = styles[cur + size];
194
193
  return acc;
195
194
  }, {});
196
195
  const finalFallbackText = global?.languageJsonData?.noPriceTip || '暂无报价';
197
196
  const noPriceShowText =
198
197
  priceText || (/^[\u4e00-\u9fa5]+$/.test(jdPrice) ? jdPrice : finalFallbackText);
199
198
  if (useBackstop && fallbackRender) {
200
199
  return fallbackRender;
201
200
  }
202
201
  return (
203
202
  <View
204
203
  className={classNames(styles.wrap, className)}
205
204
  style={{ ...computedHeightStyle, ...style }}
206
205
  {...nativeProps}
207
206
  >
208
207
  {isTextPrice || useBackstop ? (
209
208
  <Text
210
209
  className={classNames(
211
210
  styles.childStyle,
212
211
  styles.bigStyle,
213
212
  styles.bigNoPrice,
214
213
  sizeStyles['bigNoPrice'],
215
214
  childrenClassName,
216
215
  bigNoPriceClassName,
217
216
  )}
218
217
  style={{ ...itemCommonStyle }}
219
218
  >
220
219
  {useBackstop ? finalFallbackText : noPriceShowText}
221
220
  </Text>
222
221
  ) : (
223
222
  [
224
223
  <Text
225
224
  className={classNames(
226
225
  styles.childStyle,
227
226
  styles.bigStyle,
228
227
  styles.bigSymbol,
229
228
  sizeStyles['bigSymbol'],
230
229
  hitColorStyle,
231
230
  childrenClassName,
232
231
  bigSymbolClassName,
233
232
  {
234
233
  [styles.fontV2]: useFontV2,
235
234
  [styles.fontV2Bold]: useFontV2Bold,
236
235
  },
237
236
  )}
238
237
  key="bigSymbol"
239
238
  style={{ ...itemCommonStyle }}
240
239
  >
241
240
  ¥
242
241
  </Text>,
243
242
  <Text
244
243
  className={classNames(
245
244
  styles.childStyle,
246
245
  styles.bigStyle,
247
246
  styles.bigInteger,
248
247
  sizeStyles['bigInteger'],
249
248
  hitColorStyle,
250
249
  !isOnlyShowBigPrice &&
251
250
  !isBigPriceHasDecimal &&
252
251
  !isPriceDescInFront &&
253
252
  !isShowPriceUnit
254
253
  ? styles.rightMargin
255
254
  : null,
256
255
  childrenClassName,
257
256
  bigIntegerClassName,
258
257
  {
259
258
  [styles.fontV2]: useFontV2,
260
259
  [styles.fontV2Bold]: useFontV2Bold,
261
260
  },
262
261
  )}
263
262
  key="bigInteger"
264
263
  style={{ ...itemCommonStyle }}
265
264
  >
266
265
  {integerPrice}
267
266
  </Text>,
268
267
  isBigPriceHasDecimal ? (
269
268
  <Text
270
269
  className={classNames(
271
270
  styles.childStyle,
272
271
  styles.bigStyle,
273
272
  styles.bigDecimal,
274
273
  sizeStyles['bigDecimal'],
275
274
  hitColorStyle,
276
275
  isPriceDescInFront || priceText === '' || isShowPriceUnit
277
276
  ? null
278
277
  : styles.rightMargin,
279
278
  childrenClassName,
280
279
  bigDecimalClassName,
281
280
  {
282
281
  [styles.fontV2]: useFontV2,
283
282
  [styles.fontV2Bold]: useFontV2Bold,
284
283
  },
285
284
  )}
286
285
  key="bigDecimal"
287
286
  style={{ ...itemCommonStyle }}
288
287
  >
289
288
  .{decimalPrice}
290
289
  </Text>
291
290
  ) : null,
292
291
  isShowPriceUnit ? (
293
292
  <Text
294
293
  className={classNames(
295
294
  styles.childStyle,
296
295
  styles.priceUnit,
297
296
  styles.rightMargin,
298
297
  sizeStyles['priceUnit'],
299
298
  styles.bigStyle,
300
299
  hitColorStyle,
301
300
  childrenClassName,
302
301
  priceDescClassName,
303
302
  )}
304
303
  key="descFrontUnit"
305
304
  style={{ ...itemCommonStyle }}
306
305
  >
307
306
  {priceUnit}
308
307
  </Text>
309
308
  ) : null,
310
309
  !isOnlyShowBigPrice && [
311
310
  isPriceDescInFront && (
312
311
  <Text
313
312
  className={classNames(
314
313
  styles.childStyle,
315
314
  styles.priceDesc,
316
315
  {
317
316
  [styles['priceEnDesc']]: isLanguageForEn,
318
317
  },
319
318
  {
320
319
  [styles['priceHiddenDesc']]: priceText === '',
321
320
  },
322
321
  sizeStyles['priceDesc'],
323
322
  styles.bigStyle,
324
323
  hitColorStyle,
325
324
  isPriceDescInFront && !isShowPriceUnit && !isHideSmallPrice
326
325
  ? styles.rightMargin
327
326
  : null,
328
327
  childrenClassName,
329
328
  priceDescClassName,
330
329
  )}
331
330
  key="descFront"
332
331
  style={{ ...itemCommonStyle, ...priceTextStyle }}
333
332
  >
334
333
  {priceText === '' ? '_' : priceText}
335
334
  </Text>
336
335
  ),
337
336
  <View
338
337
  style={{
339
338
  display: 'inline-flex',
340
339
  }}
341
340
  >
342
341
  {smallPrice && !isHideSmallPrice ? (
343
342
  <Text
344
343
  className={classNames(
345
344
  styles.childStyle,
346
345
  styles.smallPrice,
347
346
  sizeStyles['smallPrice'],
348
347
  styles.smallStyle,
349
348
  missColorStyle,
350
349
  childrenClassName,
351
350
  smallPriceClassName,
352
351
  {
353
352
  [styles.fontV2]: useSmallFontV2Bold ? false : useSmallFontV2 || useFontV2,
354
353
  [styles.fontV2Bold]: useSmallFontV2
355
354
  ? false
356
355
  : useSmallFontV2Bold || useFontV2Bold,
357
356
  },
358
357
  )}
359
358
  key="smallPrice"
360
359
  style={{ ...itemCommonStyle }}
361
360
  >
362
361
  ¥{Number(smallPrice)}
363
362
  </Text>
364
363
  ) : null}
365
364
  {isShowPriceUnit && !isHideSmallPrice ? (
366
365
  <Text
367
366
  className={classNames(
368
367
  styles.childStyle,
369
368
  styles.priceUnit,
370
369
  sizeStyles['priceUnit'],
371
370
  styles.smallStyle,
372
371
  styles.missPriceDesc,
373
372
  missColorStyle,
374
373
  childrenClassName,
375
374
  smallPriceDescClassName || priceDescClassName,
376
375
  )}
377
376
  key="descFrontUnit"
378
377
  style={{ ...itemCommonStyle }}
379
378
  >
380
379
  {priceUnit}
381
380
  </Text>
382
381
  ) : null}
383
382
  {!isPriceDescInFront && !isHideSmallPrice && (
384
383
  <Text
385
384
  className={classNames(
386
385
  styles.childStyle,
387
386
  styles.priceDesc,
388
387
  {
389
388
  [styles['priceEnDesc']]: isLanguageForEn,
390
389
  },
391
390
  {
392
391
  [styles['priceHiddenDesc']]: priceText === '',
393
392
  },
394
393
  sizeStyles['priceDesc'],
395
394
  styles.smallStyle,
396
395
  styles.missPriceDesc,
397
396
  missColorStyle,
398
397
  childrenClassName,
399
398
  smallPriceDescClassName || priceDescClassName,
400
399
  )}
401
400
  key="descBack"
402
401
  style={{ ...itemCommonStyle }}
403
402
  >
404
403
  {priceText === '' ? '_' : priceText}
405
404
  </Text>
406
405
  )}
407
406
  </View>,
408
407
  ],
409
408
  ]
410
409
  )}
411
410
  </View>
412
411
  );
412
+ import React from 'react';
413
413
  console.warn('🚗 ~~ file: index.tsx:22 ~~ reportException() ~~ {type, detail, text}:', {
414
414
  type,
415
415
  data,
416
416
  text,
417
417
  });
418
418
  draBusinessCustomReport({
419
419
  eventName: 'business',
420
420
  errorName: getSgmCustomCode(`${SgmCustomCode.PRICE_RENDER}_${type}`),
421
421
  errorMessage: '[双价格组件]' + text,
422
422
  extraData: JSON.stringify({
423
423
  type,
424
424
  data,
425
425
  }),
426
426
  });
427
427
  return rest.some((item) => item === undefined || item === '');
428
428
  const numPrice = Number(strPrice);
429
429
  if (isNaN(numPrice)) {
430
430
  reportException({
431
431
  type: 'isNotNumericType',
432
432
  data: props,
433
433
  text: `传入价格字段值“${strPrice}”转换数字报错`,
434
434
  });
435
435
  return false;
436
436
  }
437
437
  else if (numPrice <= 0) {
438
438
  reportException({
439
439
  type: 'isNotPositiveNumber',
440
440
  data: props,
441
441
  text: `传入价格字段值“${strPrice}”不是一个正数`,
442
442
  });
443
443
  return false;
444
444
  }
445
445
  const result = numPrice.toString().match(/(\d+)(\.(\d+))?/);
446
446
  if (result && result[3]?.length > 2) {
447
447
  reportException({
448
448
  type: 'decimalPlaceTooLong',
449
449
  data: props,
450
450
  text: `传入价格字段值“${strPrice}”小数位不能超过2位`,
451
451
  });
452
452
  return false;
453
453
  }
454
454
  if (/^\d+(\.\d+)?[eE][+-]?\d+$/.test(strPrice)) {
455
455
  reportException({
456
456
  type: 'findScientificNotation',
457
457
  data: props,
458
458
  text: `传入价格字段值“${strPrice}”是一个科学计数法格式`,
459
459
  });
460
460
  }
461
461
  return true;
462
462
  const { jdPrice, finalPrice, forceShowFinalPrice } = props;
463
463
  if (jdPrice && finalPrice) {
464
464
  const getLastPassValidateState = forceShowFinalPrice || Number(finalPrice) < Number(jdPrice);
465
465
  !getLastPassValidateState &&
466
466
  reportException({
467
467
  type: 'pricesCompareException',
468
468
  data: props,
469
469
  text: `身份/到手价必须小于松果价`,
470
470
  });
471
471
  return getLastPassValidateState;
472
472
  } else {
473
473
  return true;
474
474
  }
475
475
  const numPrice = Number(strPrice);
476
476
  const result = numPrice.toString().match(/(\d+)(\.(\d+))?/);
477
477
  if (result) {
478
478
  return {
479
479
  integerPrice: result[1],
480
480
  decimalPrice: (result[3] || '').replace(/0+$/, ''),
481
481
  };
482
482
  } else {
483
483
  reportException({
484
484
  type: 'deconstructException',
485
485
  data: props,
486
486
  text: `解构传入价格字段值“${strPrice}”解构发生异常`,
487
487
  });
488
488
  return null;
489
489
  }
490
490
  const {
491
491
  jdPrice,
492
492
  finalPrice,
493
493
  priceText = '',
494
494
  priceTextColor = '',
495
495
  subPriceTextColor = '',
496
496
  subPriceColor = '',
497
497
  priceUnit = '',
498
498
  priceType,
499
499
  hitUserIdentity = false,
500
500
  forceShowFinalPrice = false,
501
501
  hideSmallPrice = false,
502
502
  fallbackRender = null,
503
503
  className = null,
504
504
  style = {},
505
505
  childrenClassName = null,
506
506
  bigNoPriceClassName = null,
507
507
  bigSymbolClassName = null,
508
508
  bigIntegerClassName = null,
509
509
  bigDecimalClassName = null,
510
510
  priceDescClassName = null,
511
511
  smallPriceClassName = null,
512
512
  smallPriceDescClassName = null,
513
513
  lineNumber = 1,
514
514
  size = 'M',
515
515
  isDefaultRemoveSmallPrice = false,
516
516
  useFontV2 = false,
517
517
  useFontV2Bold = false,
518
518
  useSmallFontV2 = false,
519
519
  useSmallFontV2Bold = false,
520
520
  nativeProps,
521
521
  } = props;
522
522
  let useBackstop = false;
523
523
  const isShowPriceUnit = priceUnit && priceUnit !== '';
524
524
  if (isNull(props.priceType)) {
525
525
  useBackstop = true;
526
526
  reportException({
527
527
  type: 'paramMiss',
528
528
  data: props,
529
529
  text: '缺少必要入参:priceType',
530
530
  });
531
531
  } else if (
532
532
  !allowedNoHitUserIdentityTypes.includes(props.priceType) &&
533
533
  props.hitUserIdentity === undefined
534
534
  ) {
535
535
  useBackstop = true;
536
536
  reportException({
537
537
  type: 'paramMiss',
538
538
  data: props,
539
539
  text: `价格类型${props.priceType}缺少必要入参:hitUserIdentity`,
540
540
  });
541
541
  }
542
542
  const especialHitStyleType = {
543
543
  7: 'plusStyle',
544
544
  9: 'samStyle',
545
545
  };
546
546
  const especialMissStyleType = {
547
547
  7: 'plusStyle',
548
548
  8: 'fansStyle',
549
549
  9: 'samStyle',
550
550
  10: 'studentStyle',
551
551
  12: 'yhdStyle',
552
552
  13: 'memberStyle',
553
553
  };
554
554
  const isUseFinalPriceAsBigPrice = allowedNoHitUserIdentityTypes.includes(priceType);
555
555
  const isEquivalentHit = isUseFinalPriceAsBigPrice || hitUserIdentity;
556
556
  const isOnlyShowBigPrice = priceType === 3 || isNull(finalPrice);
557
557
  const smallPrice = isEquivalentHit ? jdPrice : finalPrice;
558
558
  const isHideSmallPrice =
559
559
  hideSmallPrice || priceType === 14 || isDefaultRemoveSmallPrice || isNaN(Number(smallPrice));
560
560
  const isTextPrice = priceType === 4;
561
561
  if (!isTextPrice && !useBackstop) {
562
562
  if (finalPrice && !numericPriceValidate(finalPrice, props)) {
563
563
  useBackstop = true;
564
564
  } else if (jdPrice && !numericPriceValidate(jdPrice, props)) {
565
565
  useBackstop = true;
566
566
  }
567
567
  if (!useBackstop && !isOnlyShowBigPrice && !isHideSmallPrice && !pricesCompareValidate(props)) {
568
568
  useBackstop = true;
569
569
  }
570
570
  }
571
571
  const bigPriceObj =
572
572
  isTextPrice || useBackstop
573
573
  ? {}
574
574
  : getDeconstructPrice(isEquivalentHit && !isNull(finalPrice) ? finalPrice : jdPrice, props);
575
575
  const { integerPrice = '', decimalPrice = '' } = bigPriceObj || {};
576
576
  const isPriceDescInFront = isEquivalentHit;
577
577
  const hitColorStyle = isEquivalentHit ? styles[especialHitStyleType[priceType]] : null;
578
578
  const missColorStyle = isEquivalentHit ? null : styles[especialMissStyleType[priceType]];
579
579
  const isBigPriceHasDecimal = decimalPrice !== '' && !/^0+$/.test(decimalPrice);
580
580
  const sizeLineHeight = {
581
581
  XS: 28,
582
582
  S: 34,
583
583
  M: 40,
584
584
  L: 46,
585
585
  XL: 52,
586
586
  };
587
587
  const lineHeight = Taro.pxTransform(sizeLineHeight[size] * 1.25);
588
588
  const wrapHeight = Taro.pxTransform(sizeLineHeight[size] * 1.25 * lineNumber);
589
589
  const computedHeightStyle = {
590
590
  height: wrapHeight,
591
591
  };
592
592
  const itemCommonStyle = {
593
593
  height: lineHeight,
594
594
  };
595
595
  const bigPriceTextStyle = priceTextColor ? { color: priceTextColor } : {};
596
596
  const smallPriceTextStyle = subPriceTextColor ? { color: subPriceTextColor } : {};
597
597
  const smallPriceStyle = subPriceColor ? { color: subPriceColor } : {};
598
598
  const needSizeStyles = [
599
599
  'bigNoPrice',
600
600
  'bigSymbol',
601
601
  'bigInteger',
602
602
  'bigDecimal',
603
603
  'priceDesc',
604
604
  'smallPrice',
605
605
  'priceUnit',
606
606
  ];
607
607
  const sizeStyles = needSizeStyles.reduce((acc, cur) => {
608
608
  acc[cur] = styles[cur + size];
609
609
  return acc;
610
610
  }, {});
611
611
  const finalFallbackText = global?.languageJsonData?.noPriceTip || '暂无报价';
612
612
  const noPriceShowText =
613
613
  priceText || (/^[\u4e00-\u9fa5]+$/.test(jdPrice) ? jdPrice : finalFallbackText);
614
614
  if (useBackstop && fallbackRender) {
615
615
  return fallbackRender;
616
616
  }
617
617
  return (
618
618
  <View
619
619
  className={classNames(styles.wrap, className)}
620
620
  style={{ ...computedHeightStyle, ...style }}
621
621
  {...nativeProps}
622
622
  >
623
623
  {isTextPrice || useBackstop ? (
624
624
  <Text
625
625
  className={classNames(
626
626
  styles.childStyle,
627
627
  styles.bigStyle,
628
628
  styles.bigNoPrice,
629
629
  sizeStyles['bigNoPrice'],
630
630
  childrenClassName,
631
631
  bigNoPriceClassName,
632
632
  )}
633
633
  style={{ ...itemCommonStyle }}
634
634
  >
635
635
  {useBackstop ? finalFallbackText : noPriceShowText}
636
636
  </Text>
637
637
  ) : (
638
638
  [
639
639
  <Text
640
640
  className={classNames(
641
641
  styles.childStyle,
642
642
  styles.bigStyle,
643
643
  styles.bigSymbol,
644
644
  sizeStyles['bigSymbol'],
645
645
  hitColorStyle,
646
646
  childrenClassName,
647
647
  bigSymbolClassName,
648
648
  {
649
649
  [styles.fontV2]: useFontV2,
650
650
  [styles.fontV2Bold]: useFontV2Bold,
651
651
  },
652
652
  )}
653
653
  key="bigSymbol"
654
654
  style={{ ...itemCommonStyle }}
655
655
  >
656
656
  ¥
657
657
  </Text>,
658
658
  <Text
659
659
  className={classNames(
660
660
  styles.childStyle,
661
661
  styles.bigStyle,
662
662
  styles.bigInteger,
663
663
  sizeStyles['bigInteger'],
664
664
  hitColorStyle,
665
665
  !isOnlyShowBigPrice &&
666
666
  !isBigPriceHasDecimal &&
667
667
  !isPriceDescInFront &&
668
668
  !isShowPriceUnit
669
669
  ? styles.rightMargin
670
670
  : null,
671
671
  childrenClassName,
672
672
  bigIntegerClassName,
673
673
  {
674
674
  [styles.fontV2]: useFontV2,
675
675
  [styles.fontV2Bold]: useFontV2Bold,
676
676
  },
677
677
  )}
678
678
  key="bigInteger"
679
679
  style={{ ...itemCommonStyle }}
680
680
  >
681
681
  {integerPrice}
682
682
  </Text>,
683
683
  isBigPriceHasDecimal ? (
684
684
  <Text
685
685
  className={classNames(
686
686
  styles.childStyle,
687
687
  styles.bigStyle,
688
688
  styles.bigDecimal,
689
689
  sizeStyles['bigDecimal'],
690
690
  hitColorStyle,
691
691
  isPriceDescInFront || priceText === '' || isShowPriceUnit
692
692
  ? null
693
693
  : styles.rightMargin,
694
694
  childrenClassName,
695
695
  bigDecimalClassName,
696
696
  {
697
697
  [styles.fontV2]: useFontV2,
698
698
  [styles.fontV2Bold]: useFontV2Bold,
699
699
  },
700
700
  )}
701
701
  key="bigDecimal"
702
702
  style={{ ...itemCommonStyle }}
703
703
  >
704
704
  .{decimalPrice}
705
705
  </Text>
706
706
  ) : null,
707
707
  isShowPriceUnit ? (
708
708
  <Text
709
709
  className={classNames(
710
710
  styles.childStyle,
711
711
  styles.priceUnit,
712
712
  styles.rightMargin,
713
713
  sizeStyles['priceUnit'],
714
714
  styles.bigStyle,
715
715
  hitColorStyle,
716
716
  childrenClassName,
717
717
  priceDescClassName,
718
718
  )}
719
719
  key="descFrontUnit"
720
720
  style={{ ...itemCommonStyle }}
721
721
  >
722
722
  {priceUnit}
723
723
  </Text>
724
724
  ) : null,
725
725
  !isOnlyShowBigPrice && [
726
726
  isPriceDescInFront && (
727
727
  <Text
728
728
  className={classNames(
729
729
  styles.childStyle,
730
730
  styles.priceDesc,
731
731
  {
732
732
  [styles['priceEnDesc']]: isLanguageForEn,
733
733
  },
734
734
  {
735
735
  [styles['priceHiddenDesc']]: priceText === '',
736
736
  },
737
737
  sizeStyles['priceDesc'],
738
738
  styles.bigStyle,
739
739
  hitColorStyle,
740
740
  isPriceDescInFront && !isShowPriceUnit && !isHideSmallPrice
741
741
  ? styles.rightMargin
742
742
  : null,
743
743
  childrenClassName,
744
744
  priceDescClassName,
745
745
  )}
746
746
  key="descFront"
747
747
  style={{ ...itemCommonStyle, ...bigPriceTextStyle }}
748
748
  >
749
749
  {priceText === '' ? '_' : priceText}
750
750
  </Text>
751
751
  ),
752
752
  <View
753
753
  style={{
754
754
  display: 'inline-flex',
755
755
  }}
756
756
  >
757
757
  {smallPrice && !isHideSmallPrice ? (
758
758
  <Text
759
759
  className={classNames(
760
760
  styles.childStyle,
761
761
  styles.smallPrice,
762
762
  sizeStyles['smallPrice'],
763
763
  styles.smallStyle,
764
764
  missColorStyle,
765
765
  childrenClassName,
766
766
  smallPriceClassName,
767
767
  {
768
768
  [styles.fontV2]: useSmallFontV2Bold ? false : useSmallFontV2 || useFontV2,
769
769
  [styles.fontV2Bold]: useSmallFontV2
770
770
  ? false
771
771
  : useSmallFontV2Bold || useFontV2Bold,
772
772
  },
773
773
  )}
774
774
  key="smallPrice"
775
775
  style={{ ...itemCommonStyle, ...smallPriceStyle }}
776
776
  >
777
777
  ¥{Number(smallPrice)}
778
778
  </Text>
779
779
  ) : null}
780
780
  {isShowPriceUnit && !isHideSmallPrice ? (
781
781
  <Text
782
782
  className={classNames(
783
783
  styles.childStyle,
784
784
  styles.priceUnit,
785
785
  sizeStyles['priceUnit'],
786
786
  styles.smallStyle,
787
787
  styles.missPriceDesc,
788
788
  missColorStyle,
789
789
  childrenClassName,
790
790
  smallPriceDescClassName || priceDescClassName,
791
791
  )}
792
792
  key="descFrontUnit"
793
793
  style={{ ...itemCommonStyle, ...smallPriceStyle }}
794
794
  >
795
795
  {priceUnit}
796
796
  </Text>
797
797
  ) : null}
798
798
  {!isPriceDescInFront && !isHideSmallPrice && (
799
799
  <Text
800
800
  className={classNames(
801
801
  styles.childStyle,
802
802
  styles.priceDesc,
803
803
  {
804
804
  [styles['priceEnDesc']]: isLanguageForEn,
805
805
  },
806
806
  {
807
807
  [styles['priceHiddenDesc']]: priceText === '',
808
808
  },
809
809
  sizeStyles['priceDesc'],
810
810
  styles.smallStyle,
811
811
  styles.missPriceDesc,
812
812
  missColorStyle,
813
813
  childrenClassName,
814
814
  smallPriceDescClassName || priceDescClassName,
815
815
  )}
816
816
  key="descBack"
817
817
  style={{ ...itemCommonStyle, ...smallPriceTextStyle }}
818
818
  >
819
819
  {priceText === '' ? '_' : priceText}
820
820
  </Text>
821
821
  )}
822
822
  </View>,
823
823
  ],
824
824
  ]
825
825
  )}
826
826
  </View>
827
827
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conecli/cone-render",
3
- "version": "0.10.1-shop3.108",
3
+ "version": "0.10.1-shop3.109",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist/"