@conecli/cone-render 0.9.1-shop2.31 → 0.9.1-shop2.33

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.
@@ -93,6 +93,14 @@
93
93
  .priceDesc {
94
94
  margin-left: 4px;
95
95
  font-family: PingFang SC;
96
+ &.priceHiddenDesc {
97
+ width: 0;
98
+ visibility: hidden;
99
+ }
100
+ &.priceEnDesc {
101
+ width: 0;
102
+ visibility: hidden;
103
+ }
96
104
  }
97
105
  .priceDescXL {
98
106
  font-size: 28px;
@@ -1 +1 @@
1
- import React from 'react';
2
1
  console.warn("🚗 ~~ file: index.tsx:22 ~~ reportException() ~~ {type, detail, text}:", {type, data, text})
3
2
  sgmCustomReport({
4
3
  code: getSgmCustomCode(`${SgmCustomCode.PRICE_RENDER}_${type}`),
5
4
  msg: {
6
5
  type,
7
6
  data,
8
7
  text: '[双价格组件]' + text
9
8
  },
10
9
  })
11
10
  return rest.some(item => item === undefined || item === '')
12
11
  const numPrice = Number(strPrice)
13
12
  if(isNaN(numPrice)){
14
13
  reportException({
15
14
  type: 'isNotNumericType',
16
15
  data: props,
17
16
  text: `传入价格字段值“${strPrice}”转换数字报错`
18
17
  })
19
18
  return false
20
19
  }
21
20
  else if(numPrice <= 0){
22
21
  reportException({
23
22
  type: 'isNotPositiveNumber',
24
23
  data: props,
25
24
  text: `传入价格字段值“${strPrice}”不是一个正数`
26
25
  })
27
26
  return false
28
27
  }
29
28
  const result = numPrice.toString().match(/(\d+)(\.(\d+))?/)
30
29
  if(result && result[3]?.length > 2){
31
30
  reportException({
32
31
  type: 'decimalPlaceTooLong',
33
32
  data: props,
34
33
  text: `传入价格字段值“${strPrice}”小数位不能超过2位`
35
34
  })
36
35
  return false
37
36
  }
38
37
  if(/^\d+(\.\d+)?[eE][+-]?\d+$/.test(strPrice)){
39
38
  reportException({
40
39
  type: 'findScientificNotation',
41
40
  data: props,
42
41
  text: `传入价格字段值“${strPrice}”是一个科学计数法格式`
43
42
  })
44
43
  }
45
44
  return true
46
45
  const {jdPrice, finalPrice} = props
47
46
  if(jdPrice && finalPrice && Number(jdPrice) <= Number(finalPrice)){
48
47
  reportException({
49
48
  type: 'pricesCompareException',
50
49
  data: props,
51
50
  text: `身份/到手价必须小于松果价`
52
51
  })
53
52
  return false
54
53
  }else{
55
54
  return true
56
55
  }
57
56
  const numPrice = Number(strPrice)
58
57
  const result = numPrice.toString().match(/(\d+)(\.(\d+))?/)
59
58
  if(result){
60
59
  return {
61
60
  integerPrice: result[1],
62
61
  decimalPrice: (result[3] || '').replace(/0+$/, '')
63
62
  }
64
63
  }else{
65
64
  reportException({
66
65
  type: 'deconstructException',
67
66
  data: props,
68
67
  text: `解构传入价格字段值“${strPrice}”解构发生异常`
69
68
  })
70
69
  return null
71
70
  }
72
71
  const {
73
72
  jdPrice,
74
73
  finalPrice,
75
74
  priceText = '',
76
75
  priceType,
77
76
  hitUserIdentity = false,
78
77
  fallbackRender = null,
79
78
  className = null,
80
79
  style = {},
81
80
  childrenClassName = null,
82
81
  bigNoPriceClassName = null,
83
82
  bigSymbolClassName = null,
84
83
  bigIntegerClassName = null,
85
84
  bigDecimalClassName = null,
86
85
  priceDescClassName = null,
87
86
  smallPriceClassName = null,
88
87
  lineNumber = 1,
89
88
  size = 'M',
90
89
  isDefaultRemoveSmallPrice = false
91
90
  } = props
92
91
  let useBackstop = false
93
92
  if(isNull(props.jdPrice, props.priceType)){
94
93
  useBackstop = true
95
94
  reportException({
96
95
  type: 'paramMiss',
97
96
  data: props,
98
97
  text: '缺少必要入参:jdPrice、priceType'
99
98
  })
100
99
  }else if(!allowedNoHitUserIdentityTypes.includes(props.priceType) && props.hitUserIdentity === undefined){
101
100
  useBackstop = true
102
101
  reportException({
103
102
  type: 'paramMiss',
104
103
  data: props,
105
104
  text: `价格类型${props.priceType}缺少必要入参:hitUserIdentity`
106
105
  })
107
106
  }
108
107
  const especialHitStyleType = {
109
108
  7: 'plusStyle',
110
109
  9: 'samStyle'
111
110
  }
112
111
  const especialMissStyleType = {
113
112
  7: 'plusStyle',
114
113
  8: 'fansStyle',
115
114
  9: 'samStyle',
116
115
  10: 'studentStyle',
117
116
  12: 'yhdStyle',
118
117
  13: 'memberStyle'
119
118
  }
120
119
  const isTextPrice = priceType === 4
121
120
  if(!isTextPrice && !useBackstop){
122
121
  if(finalPrice && !numericPriceValidate(finalPrice, props)){
123
122
  useBackstop = true
124
123
  }else if(!numericPriceValidate(jdPrice, props)){
125
124
  useBackstop = true
126
125
  }
127
126
  if(!useBackstop && !pricesCompareValidate(props)){
128
127
  useBackstop = true
129
128
  }
130
129
  }
131
130
  const isUseFinalPriceAsBigPrice = allowedNoHitUserIdentityTypes.includes(priceType)
132
131
  const isEquivalentHit = isUseFinalPriceAsBigPrice || hitUserIdentity
133
132
  const bigPriceObj = (isTextPrice || useBackstop)? {}: getDeconstructPrice(isEquivalentHit && !isNull(finalPrice)? finalPrice: jdPrice, props)
134
133
  const {integerPrice = '', decimalPrice = ''} = bigPriceObj || {}
135
134
  const isOnlyShowBigPrice = priceType === 3 || isNull(finalPrice)
136
135
  const smallPrice = isEquivalentHit? jdPrice: finalPrice
137
136
  const isHideSmallPrice = priceType === 14 || isDefaultRemoveSmallPrice || isNaN(Number(smallPrice))
138
137
  const isPriceDescInFront = isEquivalentHit
139
138
  const hitColorStyle = isEquivalentHit? styles[especialHitStyleType[priceType]]: null
140
139
  const missColorStyle = isEquivalentHit? null: styles[especialMissStyleType[priceType]]
141
140
  const isBigPriceHasDecimal = decimalPrice !== '' && !/^0+$/.test(decimalPrice)
142
141
  const sizeLineHeight = {
143
142
  'XS': 28,
144
143
  'S': 34,
145
144
  'M': 40,
146
145
  'L': 46,
147
146
  'XL': 52
148
147
  }
149
148
  const lineHeight = Taro.pxTransform(sizeLineHeight[size] * 1.25)
150
149
  const wrapHeight = Taro.pxTransform(sizeLineHeight[size] * 1.25 * lineNumber)
151
150
  const computedHeightStyle = {
152
151
  height: wrapHeight
153
152
  }
154
153
  const itemCommonStyle = {
155
154
  height: lineHeight
156
155
  }
157
156
  const needSizeStyles = ['bigNoPrice', 'bigSymbol', 'bigInteger', 'bigDecimal', 'priceDesc', 'smallPrice']
158
157
  const sizeStyles = needSizeStyles.reduce((acc, cur) => {
159
158
  acc[cur] = styles[cur + size]
160
159
  return acc
161
160
  }, {})
162
161
  const finalFallbackText = '暂无报价'
163
162
  const noPriceShowText = priceText || (/^[\u4e00-\u9fa5]+$/.test(jdPrice)? jdPrice: finalFallbackText)
164
163
  if(useBackstop && fallbackRender){
165
164
  return fallbackRender
166
165
  }
167
166
  return (
168
167
  <View className={classNames(styles.wrap, className)} style={{...computedHeightStyle, ...style}}>
169
168
  {isTextPrice || useBackstop?
170
169
  <Text className={classNames(styles.childStyle, styles.bigStyle, styles.bigNoPrice, sizeStyles['bigNoPrice'], childrenClassName, bigNoPriceClassName)} style={{...itemCommonStyle}}>{useBackstop? finalFallbackText: noPriceShowText}</Text>
171
170
  :
172
171
  [
173
172
  <Text className={classNames(styles.childStyle, styles.bigStyle, styles.bigSymbol, sizeStyles['bigSymbol'], hitColorStyle, childrenClassName, bigSymbolClassName)} key="bigSymbol" style={{...itemCommonStyle}}>¥</Text>,
174
173
  <Text className={classNames(styles.childStyle, styles.bigStyle, styles.bigInteger, sizeStyles['bigInteger'], hitColorStyle, !isOnlyShowBigPrice && !isBigPriceHasDecimal && !isPriceDescInFront ? styles.rightMargin : null, childrenClassName, bigIntegerClassName)} key="bigInteger" style={{...itemCommonStyle}}>{integerPrice}</Text>,
175
174
  isBigPriceHasDecimal?
176
175
  <Text className={classNames(styles.childStyle, styles.bigStyle, styles.bigDecimal, sizeStyles['bigDecimal'], hitColorStyle, isPriceDescInFront ? null : styles.rightMargin, childrenClassName, bigDecimalClassName)} key="bigDecimal" style={{...itemCommonStyle}}>.{decimalPrice}</Text>
177
176
  :
178
177
  null
179
178
  ,
180
179
  !isOnlyShowBigPrice && [
181
180
  isPriceDescInFront && <Text className={classNames(styles.childStyle, styles.priceDesc, sizeStyles['priceDesc'], styles.bigStyle, hitColorStyle, isPriceDescInFront ? styles.rightMargin : null, childrenClassName, priceDescClassName)} key="descFront" style={{...itemCommonStyle}}>{priceText}</Text>,
182
181
  <view style={{
183
182
  display: 'inline-flex'
184
183
  }}>
185
184
  {smallPrice && !isHideSmallPrice ? <Text className={classNames(styles.childStyle, styles.smallPrice, sizeStyles['smallPrice'], styles.smallStyle, missColorStyle, childrenClassName, smallPriceClassName)} key="smallPrice" style={{...itemCommonStyle}}>¥{Number(smallPrice)}</Text> : null}
186
185
  {!isPriceDescInFront && !isHideSmallPrice && <Text className={classNames(styles.childStyle, styles.priceDesc, sizeStyles['priceDesc'], styles.smallStyle, styles.missPriceDesc, missColorStyle, childrenClassName, priceDescClassName)} key="descBack" style={{...itemCommonStyle}}>{priceText}</Text>}
187
186
  </view>
188
187
  ]
189
188
  ]
190
189
  }
191
190
  </View>
192
191
  )
192
+ import React from 'react';
193
193
  console.warn('🚗 ~~ file: index.tsx:22 ~~ reportException() ~~ {type, detail, text}:', {
194
194
  type,
195
195
  data,
196
196
  text,
197
197
  });
198
198
  sgmCustomReport({
199
199
  code: getSgmCustomCode(`${SgmCustomCode.PRICE_RENDER}_${type}`),
200
200
  msg: {
201
201
  type,
202
202
  data,
203
203
  text: '[双价格组件]' + text,
204
204
  },
205
205
  });
206
206
  return rest.some((item) => item === undefined || item === '');
207
207
  const numPrice = Number(strPrice);
208
208
  if (isNaN(numPrice)) {
209
209
  reportException({
210
210
  type: 'isNotNumericType',
211
211
  data: props,
212
212
  text: `传入价格字段值“${strPrice}”转换数字报错`,
213
213
  });
214
214
  return false;
215
215
  }
216
216
  else if (numPrice <= 0) {
217
217
  reportException({
218
218
  type: 'isNotPositiveNumber',
219
219
  data: props,
220
220
  text: `传入价格字段值“${strPrice}”不是一个正数`,
221
221
  });
222
222
  return false;
223
223
  }
224
224
  const result = numPrice.toString().match(/(\d+)(\.(\d+))?/);
225
225
  if (result && result[3]?.length > 2) {
226
226
  reportException({
227
227
  type: 'decimalPlaceTooLong',
228
228
  data: props,
229
229
  text: `传入价格字段值“${strPrice}”小数位不能超过2位`,
230
230
  });
231
231
  return false;
232
232
  }
233
233
  if (/^\d+(\.\d+)?[eE][+-]?\d+$/.test(strPrice)) {
234
234
  reportException({
235
235
  type: 'findScientificNotation',
236
236
  data: props,
237
237
  text: `传入价格字段值“${strPrice}”是一个科学计数法格式`,
238
238
  });
239
239
  }
240
240
  return true;
241
241
  const { jdPrice, finalPrice } = props;
242
242
  if (jdPrice && finalPrice && Number(jdPrice) <= Number(finalPrice)) {
243
243
  reportException({
244
244
  type: 'pricesCompareException',
245
245
  data: props,
246
246
  text: `身份/到手价必须小于松果价`,
247
247
  });
248
248
  return false;
249
249
  } else {
250
250
  return true;
251
251
  }
252
252
  const numPrice = Number(strPrice);
253
253
  const result = numPrice.toString().match(/(\d+)(\.(\d+))?/);
254
254
  if (result) {
255
255
  return {
256
256
  integerPrice: result[1],
257
257
  decimalPrice: (result[3] || '').replace(/0+$/, ''),
258
258
  };
259
259
  } else {
260
260
  reportException({
261
261
  type: 'deconstructException',
262
262
  data: props,
263
263
  text: `解构传入价格字段值“${strPrice}”解构发生异常`,
264
264
  });
265
265
  return null;
266
266
  }
267
267
  const {
268
268
  jdPrice,
269
269
  finalPrice,
270
270
  priceText = '',
271
271
  priceType,
272
272
  hitUserIdentity = false,
273
273
  fallbackRender = null,
274
274
  className = null,
275
275
  style = {},
276
276
  childrenClassName = null,
277
277
  bigNoPriceClassName = null,
278
278
  bigSymbolClassName = null,
279
279
  bigIntegerClassName = null,
280
280
  bigDecimalClassName = null,
281
281
  priceDescClassName = null,
282
282
  smallPriceClassName = null,
283
283
  lineNumber = 1,
284
284
  size = 'M',
285
285
  isDefaultRemoveSmallPrice = false,
286
286
  } = props;
287
287
  let useBackstop = false;
288
288
  if (isNull(props.jdPrice, props.priceType)) {
289
289
  useBackstop = true;
290
290
  reportException({
291
291
  type: 'paramMiss',
292
292
  data: props,
293
293
  text: '缺少必要入参:jdPrice、priceType',
294
294
  });
295
295
  } else if (
296
296
  !allowedNoHitUserIdentityTypes.includes(props.priceType) &&
297
297
  props.hitUserIdentity === undefined
298
298
  ) {
299
299
  useBackstop = true;
300
300
  reportException({
301
301
  type: 'paramMiss',
302
302
  data: props,
303
303
  text: `价格类型${props.priceType}缺少必要入参:hitUserIdentity`,
304
304
  });
305
305
  }
306
306
  const especialHitStyleType = {
307
307
  7: 'plusStyle',
308
308
  9: 'samStyle',
309
309
  };
310
310
  const especialMissStyleType = {
311
311
  7: 'plusStyle',
312
312
  8: 'fansStyle',
313
313
  9: 'samStyle',
314
314
  10: 'studentStyle',
315
315
  12: 'yhdStyle',
316
316
  13: 'memberStyle',
317
317
  };
318
318
  const isUseFinalPriceAsBigPrice = allowedNoHitUserIdentityTypes.includes(priceType);
319
319
  const isEquivalentHit = isUseFinalPriceAsBigPrice || hitUserIdentity;
320
320
  const isOnlyShowBigPrice = priceType === 3 || isNull(finalPrice);
321
321
  const smallPrice = isEquivalentHit ? jdPrice : finalPrice;
322
322
  const isHideSmallPrice =
323
323
  priceType === 14 || isDefaultRemoveSmallPrice || isNaN(Number(smallPrice));
324
324
  const isTextPrice = priceType === 4;
325
325
  if (!isTextPrice && !useBackstop) {
326
326
  if (finalPrice && !numericPriceValidate(finalPrice, props)) {
327
327
  useBackstop = true;
328
328
  } else if (!numericPriceValidate(jdPrice, props)) {
329
329
  useBackstop = true;
330
330
  }
331
331
  if (!useBackstop && !isOnlyShowBigPrice && !isHideSmallPrice && !pricesCompareValidate(props)) {
332
332
  useBackstop = true;
333
333
  }
334
334
  }
335
335
  const bigPriceObj =
336
336
  isTextPrice || useBackstop
337
337
  ? {}
338
338
  : getDeconstructPrice(isEquivalentHit && !isNull(finalPrice) ? finalPrice : jdPrice, props);
339
339
  const { integerPrice = '', decimalPrice = '' } = bigPriceObj || {};
340
340
  const isPriceDescInFront = isEquivalentHit;
341
341
  const hitColorStyle = isEquivalentHit ? styles[especialHitStyleType[priceType]] : null;
342
342
  const missColorStyle = isEquivalentHit ? null : styles[especialMissStyleType[priceType]];
343
343
  const isBigPriceHasDecimal = decimalPrice !== '' && !/^0+$/.test(decimalPrice);
344
344
  const sizeLineHeight = {
345
345
  XS: 28,
346
346
  S: 34,
347
347
  M: 40,
348
348
  L: 46,
349
349
  XL: 52,
350
350
  };
351
351
  const lineHeight = Taro.pxTransform(sizeLineHeight[size] * 1.25);
352
352
  const wrapHeight = Taro.pxTransform(sizeLineHeight[size] * 1.25 * lineNumber);
353
353
  const computedHeightStyle = {
354
354
  height: wrapHeight,
355
355
  };
356
356
  const itemCommonStyle = {
357
357
  height: lineHeight,
358
358
  };
359
359
  const needSizeStyles = [
360
360
  'bigNoPrice',
361
361
  'bigSymbol',
362
362
  'bigInteger',
363
363
  'bigDecimal',
364
364
  'priceDesc',
365
365
  'smallPrice',
366
366
  ];
367
367
  const sizeStyles = needSizeStyles.reduce((acc, cur) => {
368
368
  acc[cur] = styles[cur + size];
369
369
  return acc;
370
370
  }, {});
371
371
  const finalFallbackText = !isLanguageForEn ? '暂无报价' : 'Unpriced';
372
372
  const noPriceShowText =
373
373
  priceText || (/^[\u4e00-\u9fa5]+$/.test(jdPrice) ? jdPrice : finalFallbackText);
374
374
  if (useBackstop && fallbackRender) {
375
375
  return fallbackRender;
376
376
  }
377
377
  return (
378
378
  <View
379
379
  className={classNames(styles.wrap, className)}
380
380
  style={{ ...computedHeightStyle, ...style }}
381
381
  >
382
382
  {isTextPrice || useBackstop ? (
383
383
  <Text
384
384
  className={classNames(
385
385
  styles.childStyle,
386
386
  styles.bigStyle,
387
387
  styles.bigNoPrice,
388
388
  sizeStyles['bigNoPrice'],
389
389
  childrenClassName,
390
390
  bigNoPriceClassName,
391
391
  )}
392
392
  style={{ ...itemCommonStyle }}
393
393
  >
394
394
  {useBackstop ? finalFallbackText : noPriceShowText}
395
395
  </Text>
396
396
  ) : (
397
397
  [
398
398
  <Text
399
399
  className={classNames(
400
400
  styles.childStyle,
401
401
  styles.bigStyle,
402
402
  styles.bigSymbol,
403
403
  sizeStyles['bigSymbol'],
404
404
  hitColorStyle,
405
405
  childrenClassName,
406
406
  bigSymbolClassName,
407
407
  )}
408
408
  key="bigSymbol"
409
409
  style={{ ...itemCommonStyle }}
410
410
  >
411
411
  ¥
412
412
  </Text>,
413
413
  <Text
414
414
  className={classNames(
415
415
  styles.childStyle,
416
416
  styles.bigStyle,
417
417
  styles.bigInteger,
418
418
  sizeStyles['bigInteger'],
419
419
  hitColorStyle,
420
420
  !isOnlyShowBigPrice && !isBigPriceHasDecimal && !isPriceDescInFront
421
421
  ? styles.rightMargin
422
422
  : null,
423
423
  childrenClassName,
424
424
  bigIntegerClassName,
425
425
  )}
426
426
  key="bigInteger"
427
427
  style={{ ...itemCommonStyle }}
428
428
  >
429
429
  {integerPrice}
430
430
  </Text>,
431
431
  isBigPriceHasDecimal ? (
432
432
  <Text
433
433
  className={classNames(
434
434
  styles.childStyle,
435
435
  styles.bigStyle,
436
436
  styles.bigDecimal,
437
437
  sizeStyles['bigDecimal'],
438
438
  hitColorStyle,
439
439
  isPriceDescInFront ? null : styles.rightMargin,
440
440
  childrenClassName,
441
441
  bigDecimalClassName,
442
442
  )}
443
443
  key="bigDecimal"
444
444
  style={{ ...itemCommonStyle }}
445
445
  >
446
446
  .{decimalPrice}
447
447
  </Text>
448
448
  ) : null,
449
449
  !isOnlyShowBigPrice && [
450
450
  isPriceDescInFront && (
451
451
  <Text
452
452
  className={classNames(
453
453
  styles.childStyle,
454
454
  styles.priceDesc,
455
455
  {
456
456
  [styles['priceEnDesc']]: isLanguageForEn,
457
457
  },
458
458
  {
459
459
  [styles['priceHiddenDesc']]: priceText === '',
460
460
  },
461
461
  sizeStyles['priceDesc'],
462
462
  styles.bigStyle,
463
463
  hitColorStyle,
464
464
  isPriceDescInFront ? styles.rightMargin : null,
465
465
  childrenClassName,
466
466
  priceDescClassName,
467
467
  )}
468
468
  key="descFront"
469
469
  style={{ ...itemCommonStyle }}
470
470
  >
471
471
  {priceText === '' ? '_' : priceText}
472
472
  </Text>
473
473
  ),
474
474
  <View
475
475
  style={{
476
476
  display: 'inline-flex',
477
477
  }}
478
478
  >
479
479
  {smallPrice && !isHideSmallPrice ? (
480
480
  <Text
481
481
  className={classNames(
482
482
  styles.childStyle,
483
483
  styles.smallPrice,
484
484
  sizeStyles['smallPrice'],
485
485
  styles.smallStyle,
486
486
  missColorStyle,
487
487
  childrenClassName,
488
488
  smallPriceClassName,
489
489
  )}
490
490
  key="smallPrice"
491
491
  style={{ ...itemCommonStyle }}
492
492
  >
493
493
  ¥{Number(smallPrice)}
494
494
  </Text>
495
495
  ) : null}
496
496
  {!isPriceDescInFront && !isHideSmallPrice && (
497
497
  <Text
498
498
  className={classNames(
499
499
  styles.childStyle,
500
500
  styles.priceDesc,
501
501
  {
502
502
  [styles['priceEnDesc']]: isLanguageForEn,
503
503
  },
504
504
  {
505
505
  [styles['priceHiddenDesc']]: priceText === '',
506
506
  },
507
507
  sizeStyles['priceDesc'],
508
508
  styles.smallStyle,
509
509
  styles.missPriceDesc,
510
510
  missColorStyle,
511
511
  childrenClassName,
512
512
  priceDescClassName,
513
513
  )}
514
514
  key="descBack"
515
515
  style={{ ...itemCommonStyle }}
516
516
  >
517
517
  {priceText === '' ? '_' : priceText}
518
518
  </Text>
519
519
  )}
520
520
  </View>,
521
521
  ],
522
522
  ]
523
523
  )}
524
524
  </View>
525
525
  );