@conecli/cone-render 0.10.1-shop3.5 → 0.10.1-shop3.51

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.
Files changed (99) hide show
  1. package/README.md +1 -1
  2. package/dist/common/accessibility.h5.ts +1 -0
  3. package/dist/common/accessibility.ts +0 -0
  4. package/dist/common/const.ts +1 -1
  5. package/dist/common/index.h5.ts +1 -1
  6. package/dist/common/index.jd.ts +1 -1
  7. package/dist/common/index.ts +1 -1
  8. package/dist/common/index.weapp.ts +1 -1
  9. package/dist/common/jdplayerSdk.weapp.tsx +1 -0
  10. package/dist/common/jssdk.ts +1 -1
  11. package/dist/common/jssdk.weapp.ts +1 -0
  12. package/dist/common/pageType.ts +1 -1
  13. package/dist/common/token/index.h5.ts +1 -1
  14. package/dist/common/token/token.jd.ts +1 -1
  15. package/dist/common/wxappApi.ts +1 -1
  16. package/dist/components/ErrorBoundary.tsx +1 -1
  17. package/dist/components/base/CommonFloorHead/index.module.scss +126 -111
  18. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  19. package/dist/components/base/CountDown/index.tsx +1 -1
  20. package/dist/components/base/CustomScrollView/index-back.tsx +1 -0
  21. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  22. package/dist/components/base/CustomVideo/index.tsx +1 -1
  23. package/dist/components/base/CustomVideo/index.weapp.tsx +1 -0
  24. package/dist/components/base/Dialog/index.module.scss +11 -0
  25. package/dist/components/base/InOrOutViewObserver/index.weapp.tsx +1 -0
  26. package/dist/components/base/InViewRender/index.tsx +1 -1
  27. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  28. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  29. package/dist/components/base/MobileCommonHeader/index.weapp.tsx +1 -0
  30. package/dist/components/base/NetworkDataError/const.ts +1 -1
  31. package/dist/components/base/NetworkDataError/index.module.scss +118 -72
  32. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  33. package/dist/components/base/Price/Base/index.module.scss +12 -0
  34. package/dist/components/base/Price/Base/index.tsx +1 -1
  35. package/dist/components/base/Price/Double/index.module.scss +24 -0
  36. package/dist/components/base/Price/Double/index.tsx +1 -1
  37. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  38. package/dist/components/floorItem.weapp.tsx +1 -1
  39. package/dist/interface/common.ts +1 -1
  40. package/dist/interface/component.ts +1 -1
  41. package/dist/interface/jumpEventReport.ts +1 -1
  42. package/dist/jumpEventReport/base.ts +1 -1
  43. package/dist/jumpEventReport/const.ts +1 -1
  44. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  45. package/dist/jumpEventReport/index.h5.ts +1 -1
  46. package/dist/jumpEventReport/index.jd.ts +1 -1
  47. package/dist/jumpEventReport/index.weapp.ts +1 -1
  48. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  49. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  50. package/dist/jumpEventReport/logEventConfig.h5.ts +1 -0
  51. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  52. package/dist/jumpEventReport/web/report.ts +1 -1
  53. package/dist/jumpEventReport/web.base.ts +1 -1
  54. package/dist/jumpEventReport/web.jd.ts +1 -1
  55. package/dist/jumpEventReport/web.pc.ts +1 -1
  56. package/dist/jumpEventReport/web.tjm.ts +1 -1
  57. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  58. package/dist/language/en_US.json +231 -0
  59. package/dist/language/zh_CN.json +231 -0
  60. package/dist/language/zh_HK.json +231 -0
  61. package/dist/libs/taroAppReport.js +2 -2
  62. package/dist/modules/ContainerFloorList/index.h5.module.scss +66 -56
  63. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  64. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  65. package/dist/modules/DecorateContainerFloorList/index.weapp.tsx +1 -0
  66. package/dist/open/api/environment.ts +1 -1
  67. package/dist/open/api/shopMember.ts +1 -1
  68. package/dist/open/api/shopMember.weapp.ts +1 -0
  69. package/dist/open/api/util.ts +1 -1
  70. package/dist/open/index.ts +1 -1
  71. package/dist/sass/app.h5.scss +278 -224
  72. package/dist/service/fetchGateway.ts +1 -1
  73. package/dist/service/fetchGateway.weapp.ts +1 -0
  74. package/dist/service/fetchJsonp.weapp.ts +1 -0
  75. package/dist/service/http/colorSign.ts +1 -1
  76. package/dist/service/http/const.ts +1 -1
  77. package/dist/service/http/h5Http.ts +1 -1
  78. package/dist/service/http/httpInterceptors.weapp.ts +1 -0
  79. package/dist/service/requestServer.h5.ts +1 -1
  80. package/dist/service/requestServer.ts +1 -1
  81. package/dist/service/requestServer.weapp.ts +1 -0
  82. package/dist/utils/connectNativeJsBridge.ts +1 -1
  83. package/dist/utils/h5Utils.ts +1 -1
  84. package/dist/utils/harmonyCallRouter.h5.ts +1 -0
  85. package/dist/utils/harmonyCallRouter.ts +0 -0
  86. package/dist/utils/index.h5.ts +1 -1
  87. package/dist/utils/index.ts +1 -1
  88. package/dist/utils/index.weapp.ts +1 -1
  89. package/dist/utils/jumpExtMapUtil.h5.ts +1 -0
  90. package/dist/utils/jumpExtMapUtil.ts +1 -0
  91. package/dist/utils/log.ts +1 -0
  92. package/dist/utils/{sColor.js → sColor.ts} +1 -1
  93. package/dist/utils/sColor.weapp.ts +1 -0
  94. package/dist/utils/utils.ts +1 -1
  95. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  96. package/dist/wxapp/common/user_info.js +1 -1
  97. package/package.json +160 -141
  98. package/dist/jumpEventReport/web/wqshop.report.ts +0 -1
  99. package/dist/utils/priceUtils.js +0 -1
@@ -1 +1 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react'
2
1
  isH5,
3
2
  addHttps,
4
3
  isH5AndJdShopView,
5
4
  draBusinessCustomReport,
6
5
  (props: ComponentInterFace.CustomVideoProps, ref: any) => {
7
6
  const {
8
7
  isSystemVideo,
9
8
  style,
10
9
  videoStyle,
11
10
  src,
12
11
  width,
13
12
  height,
14
13
  controls,
15
14
  id,
16
15
  poster,
17
16
  autoplay: isvAutoplay,
18
17
  loop,
19
18
  showMuteBtn: isvShowMuteBtn,
20
19
  muteButtonPostion,
21
20
  showFullscreenBtn,
22
21
  muteBtnPicSrcObj,
23
22
  muteBtnClassName,
24
23
  muteBtnStyle,
25
24
  objectFit,
26
25
  mockAutoplay,
27
26
  threshold,
28
27
  onPlayCallback,
29
28
  onPauseCallback,
30
29
  onVideoApiCall,
31
30
  inViewCallback,
32
31
  outViewCallback,
33
32
  } = props
34
33
  const { wifiVideoAutoPlay } = global.info.sysInfo
35
34
  const isFollowAppVideoPlayStatus = global.getDynamicConfig(
36
35
  'isFollowAppVideoPlayStatus',
37
36
  )
38
37
  let showMuteBtn = isvShowMuteBtn
39
38
  let autoplay = isvAutoplay
40
39
  if (isSystemVideo) {
41
40
  showMuteBtn = false
42
41
  autoplay = wifiVideoAutoPlay
43
42
  } else {
44
43
  if (isvAutoplay && isFollowAppVideoPlayStatus) {
45
44
  autoplay = wifiVideoAutoPlay
46
45
  }
47
46
  }
48
47
  console.log(
49
48
  'CustomVideo',
50
49
  'isSystemVideo:',
51
50
  isSystemVideo,
52
51
  'wifiVideoAutoPlay:',
53
52
  wifiVideoAutoPlay,
54
53
  ',isvAutoplay:',
55
54
  isvAutoplay,
56
55
  ',isFollowAppVideoPlayStatus:',
57
56
  isFollowAppVideoPlayStatus,
58
57
  ',autoplay:',
59
58
  autoplay,
60
59
  ',id:',
61
60
  id,
62
61
  )
63
62
  const [videoMutedState, setVideoMutedState] = useState(MUTED)
64
63
  const lastPlayStatusRef = useRef(-1)
65
64
  const manualPauseStateRef = useRef(false)
66
65
  const initPlayStatusRef = useRef(false)
67
66
  const isInViewStateRef = useRef(false)
68
67
  const disposeRef = useRef<Function | null>()
69
68
  ref === null && (ref = useRef<HTMLVideoElement | null>())
70
69
 
71
70
  const playVideo = useCallback(() => {
72
71
  if (ref && ref.current) {
73
72
  console.log(`CustomVideo id:${id} 开始播放视频`)
74
73
  const result = ref.current.play()
75
74
  result &&
76
75
  result
77
76
  .then(() => {
78
77
  console.log(`播放视频成功`)
79
78
  })
80
79
  .catch(e => {
81
80
  console.log('CustomVideo playVideo ', e.name, ':', e.message)
82
81
  })
83
82
  }
84
83
  }, [])
85
84
 
86
85
  const pauseVideo = useCallback(() => {
87
86
  if (ref && ref.current) {
88
87
  console.log(`CustomVideo id:${id} 暂停视频`)
89
88
  ref.current.pause()
90
89
  }
91
90
  }, [])
92
91
 
93
92
  useEffect(() => {
94
93
  if (!isH5 || !ref.current) return
95
94
  if (autoplay && mockAutoplay) {
96
95
 
97
96
  const callInitAutoplay = () => {
98
97
  console.log(
99
98
  `CustomVideo id:${id} 触发初始化autoplay callInitAutoplay`,
100
99
  )
101
100
  if (
102
101
  autoplay &&
103
102
  mockAutoplay &&
104
103
  !initPlayStatusRef.current &&
105
104
  isInViewStateRef.current &&
106
105
  ref.current.paused
107
106
  ) {
108
107
  playVideo()
109
108
  }
110
109
  }
111
110
  const onWeixinJSBridgeReady = e => {
112
111
  callInitAutoplay()
113
112
  }
114
113
  const onTouchstart = e => {
115
114
  callInitAutoplay()
116
115
  }
117
116
  const onScroll = e => {
118
117
  callInitAutoplay()
119
118
  }
120
119
  const onPlay = e => {
121
120
  if (!initPlayStatusRef.current) {
122
121
  const dispose = disposeRef.current
123
122
  dispose && dispose()
124
123
  disposeRef.current = null
125
124
  }
126
125
  initPlayStatusRef.current = true
127
126
  }
128
127
  document?.addEventListener('WeixinJSBridgeReady', onWeixinJSBridgeReady)
129
128
  document?.addEventListener('touchstart', onTouchstart)
130
129
  document?.addEventListener('scroll', onScroll)
131
130
  ref.current.addEventListener('play', onPlay)
132
131
  const dispose = () => {
133
132
  console.log('调用dispose')
134
133
  document?.removeEventListener(
135
134
  'WeixinJSBridgeReady',
136
135
  onWeixinJSBridgeReady,
137
136
  )
138
137
  document?.removeEventListener('touchstart', onTouchstart)
139
138
  document?.removeEventListener('scroll', onScroll)
140
139
  ref?.current?.removeEventListener('play', onPlay)
141
140
  }
142
141
  disposeRef.current = dispose
143
142
  }
144
143
  const handleVideoPlayApiCall = () => {
145
144
  if (!isH5 || !ref.current) return
146
145
  playVideo()
147
146
  manualPauseStateRef.current = false
148
147
  }
149
148
  const handleVideoPauseApiCall = () => {
150
149
  if (!isH5 || !ref.current) return
151
150
  manualPauseStateRef.current = true
152
151
  pauseVideo()
153
152
  }
154
153
 
155
154
  const handleVideoSeekApiCall = (position: number) => {
156
155
  if (!isH5 || !ref.current) return
157
156
  if (typeof position === 'undefined' || typeof position !== 'number')
158
157
  return
159
158
  ref.current.currentTime = position
160
159
  }
161
160
 
162
161
  if (onVideoApiCall) {
163
162
  onVideoApiCall({
164
163
  play: handleVideoPlayApiCall,
165
164
  pause: handleVideoPauseApiCall,
166
165
  seek: handleVideoSeekApiCall,
167
166
  })
168
167
  }
169
168
  return () => {
170
169
  const dispose = disposeRef.current
171
170
  dispose && dispose()
172
171
  disposeRef.current = null
173
172
  }
174
173
  }, [])
175
174
 
176
175
  const handleMuted = useCallback(() => {
177
176
  if (!isH5 || !ref.current) return
178
177
  const handleMutedState = ref.current.muted
179
178
  if (handleMutedState === true) {
180
179
  ref.current.muted = false
181
180
  setVideoMutedState(false)
182
181
  } else {
183
182
  ref.current.muted = true
184
183
  setVideoMutedState(true)
185
184
  }
186
185
  }, [videoMutedState])
187
186
 
188
187
  const handleVideoInViewCallback = useCallback(() => {
189
188
  if (!isH5 || !ref.current) return
190
189
  console.log(
191
190
  `
192
191
  )} CustomVideo handleVideoInViewCallback id:${id} 进入可视区域 lastPlayStatusRef.current:${lastPlayStatusRef.current},paused:${ref.current.paused}`,
193
192
  )
194
193
  isInViewStateRef.current = true
195
194
  if (
196
195
  autoplay &&
197
196
  ((mockAutoplay && !initPlayStatusRef.current) ||
198
197
  lastPlayStatusRef.current === -1) &&
199
198
  ref.current.paused
200
199
  ) {
201
200
  console.log(`CustomVideo id:${id} 首次进入可视区域`)
202
201
  playVideo()
203
202
  } else if (lastPlayStatusRef.current === 1 && ref.current.paused) {
204
203
  console.log(`CustomVideo id:${id} 非首次进入可视区域`)
205
204
  playVideo()
206
205
  }
207
206
  typeof inViewCallback === 'function' && inViewCallback()
208
207
  }, [])
209
208
 
210
209
  const handleVideoOutViewCallback = useCallback(() => {
211
210
  if (!isH5 || !ref.current) return
212
211
  isInViewStateRef.current = false
213
212
  console.log(
214
213
  `CustomVideo handleVideoOutViewCallback id:${id} 不在可视区域,视频暂停,lastPlayStatusRef:${lastPlayStatusRef.current}`,
215
214
  )
216
215
  pauseVideo()
217
216
  typeof outViewCallback === 'function' && outViewCallback()
218
217
  }, [])
219
218
 
220
219
  const getVideoWidthAndHeightStyle = () => {
221
220
  const style = {}
222
221
  width && (style['width'] = width)
223
222
  height && (style['height'] = height)
224
223
  return style
225
224
  }
226
225
 
227
226
  const getMuteBtnBackgroundImageStyle = useCallback(() => {
228
227
  const isMutedPicSrc = muteBtnPicSrcObj?.IS_MUTED
229
228
  const notMutedPicSrc = muteBtnPicSrcObj?.NOT_MUTED
230
229
  const finalIsMutedPicSrc =
231
230
  typeof isMutedPicSrc !== 'undefined' && isMutedPicSrc !== ''
232
231
  ? isMutedPicSrc
233
232
  : DEFAULT_MUTE_BTN_PIC.IS_MUTED
234
233
  const finalNotMutedPicSrc =
235
234
  typeof notMutedPicSrc !== 'undefined' && notMutedPicSrc !== ''
236
235
  ? notMutedPicSrc
237
236
  : DEFAULT_MUTE_BTN_PIC.NOT_MUTED
238
237
  return {
239
238
  backgroundImage: `url(${
240
239
  videoMutedState ? finalIsMutedPicSrc : finalNotMutedPicSrc
241
240
  })`,
242
241
  }
243
242
  }, [videoMutedState])
244
243
  return src ? (
245
244
  <InOrOutViewObserver
246
245
  inViewCallback={handleVideoInViewCallback}
247
246
  outViewCallback={handleVideoOutViewCallback}
248
247
  threshold={threshold}
249
248
  >
250
249
  {isH5 ? (
251
250
  <View
252
251
  className={customVideoStyle['d-video-wrap']}
253
252
  style={{ ...style, ...getVideoWidthAndHeightStyle() }}
254
253
  >
255
254
  <video
256
255
  style={{ ...videoStyle }}
257
256
  className={classNames(customVideoStyle['d-video-play'], {
258
257
  'd-video-forbid-fullscreen-button': isSystemVideo,
259
258
  })}
260
259
  id={id}
261
260
  data-jd-video={true}
262
261
  src={src}
263
262
  controls={controls}
264
263
  poster={poster ? addHttps(poster) : ''}
265
264
  ref={ref}
266
265
  loop={loop}
267
266
  autoPlay={autoplay}
268
267
  muted={MUTED}
269
268
  x5-playsinline="true"
270
269
  playsInline
271
270
  webkit-playsinline="true"
272
271
  controlsList={
273
272
  isH5AndJdShopView
274
273
  ? 'nodownload nofullscreen noremoteplayback'
275
274
  : ''
276
275
  }
277
276
  onError={e => {
278
277
  const errMsg = formatVedioErrorMsg(e.target?.error)
279
278
  const data = {
280
279
  type: 'video',
281
280
  subType: 'CustomVideo',
282
281
  isSystemVideo,
283
282
  src,
284
283
  autoplay,
285
284
  errMsg,
286
285
  isH5,
287
286
  }
288
287
  console.log('CustomVideo error 1:', data)
289
288
  draBusinessCustomReport(data)
290
289
  }}
291
290
  onPlay={e => {
292
291
  lastPlayStatusRef.current = 1
293
292
  onPlayCallback && onPlayCallback(e)
294
293
  }}
295
294
  onPause={e => {
296
295
  if (isInViewStateRef.current) {
297
296
  lastPlayStatusRef.current = 0
298
297
  }
299
298
  onPauseCallback && onPauseCallback(e)
300
299
  }}
301
300
  />
302
301
  {!controls && showMuteBtn && (
303
302
  <View
304
303
  className={classNames(
305
304
  customVideoStyle['d-video-mute-btn'],
306
305
  customVideoStyle[`d-mute-btn-${muteButtonPostion}`],
307
306
  `${muteBtnClassName}`,
308
307
  )}
309
308
  style={{ ...getMuteBtnBackgroundImageStyle(), ...muteBtnStyle }}
310
309
  onClick={handleMuted}
311
310
  ></View>
312
311
  )}
313
312
  </View>
314
313
  ) : (
315
314
  <Video
316
315
  style={{ ...videoStyle }}
317
316
  ref={ref}
318
317
  className={customVideoStyle['d-video-play']}
319
318
  src={src}
320
319
  id={id}
321
320
  controls={controls}
322
321
  poster={poster ? addHttps(poster) : ''}
323
322
  loop={loop}
324
323
  data-jd-video={true}
325
324
  autoplay={autoplay}
326
325
  muted={MUTED}
327
326
  showMuteBtn={showMuteBtn}
328
327
  showFullscreenBtn={showFullscreenBtn}
329
328
  objectFit={objectFit}
330
329
  onError={e => {
331
330
  const errMsg = formatVedioErrorMsg(e.target?.error)
332
331
  const data = {
333
332
  type: 'video',
334
333
  subType: 'CustomVideo',
335
334
  isSystemVideo,
336
335
  src,
337
336
  autoplay,
338
337
  errMsg,
339
338
  isH5,
340
339
  }
341
340
  console.log('CustomVideo error 2:', data)
342
341
  draBusinessCustomReport(data)
343
342
  }}
344
343
  onPlay={e => {
345
344
  lastPlayStatusRef.current = 1
346
345
  onPlayCallback && onPlayCallback(e)
347
346
  }}
348
347
  onPause={e => {
349
348
  if (isInViewStateRef.current) {
350
349
  lastPlayStatusRef.current = 0
351
350
  }
352
351
  onPauseCallback && onPauseCallback(e)
353
352
  }}
354
353
  />
355
354
  )}
356
355
  </InOrOutViewObserver>
357
356
  ) : null
358
357
  },
359
358
  return process.env.BUILD_TYPE !== BUILD_TYPE.DECORATE
360
359
  isSystemVideo: false,
361
360
  id: '',
362
361
  style: {},
363
362
  videoStyle: {},
364
363
  className: '',
365
364
  src: '',
366
365
  width: '100%',
367
366
  height: '100%',
368
367
  controls: false,
369
368
  poster: '',
370
369
  autoplay: true,
371
370
  mockAutoplay: getDefaultMockAutoplay(),
372
371
  loop: true,
373
372
  showMuteBtn: true,
374
373
  muteButtonPostion: 'topLeft',
375
374
  muteBtnPicSrcObj: DEFAULT_MUTE_BTN_PIC,
376
375
  muteBtnClassName: '',
377
376
  muteBtnStyle: {},
378
377
  showFullscreenBtn: false,
379
378
  objectFit: 'cover',
380
379
  threshold: 0.6,
380
+ import Taro from '@tarojs/taro';
381
381
  isH5,
382
382
  addHttps,
383
383
  isH5AndJdShopView,
384
384
  draBusinessCustomReport,
385
385
  isJdAndIosDevice,
386
386
  const {
387
387
  isSystemVideo,
388
388
  floorData,
389
389
  style,
390
390
  videoStyle,
391
391
  src,
392
392
  width,
393
393
  height,
394
394
  controls,
395
395
  id,
396
396
  poster,
397
397
  autoplay: isvAutoplay,
398
398
  loop,
399
399
  showMuteBtn: isvShowMuteBtn,
400
400
  muteButtonPostion,
401
401
  showFullscreenBtn,
402
402
  muteBtnPicSrcObj,
403
403
  muteBtnClassName,
404
404
  muteBtnStyle,
405
405
  objectFit,
406
406
  mockAutoplay,
407
407
  threshold = 0.6,
408
408
  onPlayCallback,
409
409
  onPauseCallback,
410
410
  onVideoApiCall,
411
411
  inViewCallback,
412
412
  outViewCallback,
413
413
  } = props;
414
414
  const { wifiVideoAutoPlay } = global.info.sysInfo;
415
415
  const isFollowAppVideoPlayStatus = global.getDynamicConfig('isFollowAppVideoPlayStatus');
416
416
  let showMuteBtn = isvShowMuteBtn;
417
417
  let autoplay = isvAutoplay;
418
418
  if (isSystemVideo) {
419
419
  showMuteBtn = false;
420
420
  autoplay = wifiVideoAutoPlay;
421
421
  } else {
422
422
  if (isvAutoplay && isFollowAppVideoPlayStatus) {
423
423
  autoplay = wifiVideoAutoPlay;
424
424
  }
425
425
  }
426
426
  console.log(
427
427
  'CustomVideo',
428
428
  'isSystemVideo:',
429
429
  isSystemVideo,
430
430
  'wifiVideoAutoPlay:',
431
431
  wifiVideoAutoPlay,
432
432
  ',isvAutoplay:',
433
433
  isvAutoplay,
434
434
  ',isFollowAppVideoPlayStatus:',
435
435
  isFollowAppVideoPlayStatus,
436
436
  ',autoplay:',
437
437
  autoplay,
438
438
  ',id:',
439
439
  id,
440
440
  );
441
441
  const [videoMutedState, setVideoMutedState] = useState(MUTED);
442
442
  const lastPlayStatusRef = useRef(-1);
443
443
  const manualPauseStateRef = useRef(false);
444
444
  const initPlayStatusRef = useRef(false);
445
445
  const isInViewStateRef = useRef(false);
446
446
  const disposeRef = useRef<Function | null>();
447
447
  const initFloorIndexRef = useRef(-1);
448
448
  ref === null && (ref = useRef<HTMLVideoElement | null>());
449
449
 
450
450
  const playVideo = useCallback(() => {
451
451
  if (ref && ref.current) {
452
452
  console.log(`CustomVideo id:${id} 开始播放视频`);
453
453
  const result = ref.current.play();
454
454
  result &&
455
455
  result
456
456
  .then(() => {
457
457
  console.log(`播放视频成功`);
458
458
  })
459
459
  .catch((e) => {
460
460
  console.log('CustomVideo playVideo ', e.name, ':', e.message);
461
461
  });
462
462
  }
463
463
  }, []);
464
464
 
465
465
  const pauseVideo = useCallback(() => {
466
466
  if (ref && ref.current) {
467
467
  console.log(`CustomVideo id:${id} 暂停视频`);
468
468
  ref.current.pause();
469
469
  }
470
470
  }, []);
471
471
 
472
472
  const handleIosFirstScreenVideoPause = useCallback(() => {
473
473
  const floorIndex = initFloorIndexRef.current;
474
474
  if (ref.current && floorIndex >= 0 && floorIndex < 4) {
475
475
  ref.current.setAttribute('data-init-pause', true);
476
476
  if (!ref.current.paused) {
477
477
  ref.current.pause();
478
478
  } else {
479
479
  setTimeout(() => {
480
480
  !ref.current.paused && ref.current.pause();
481
481
  }, 1500);
482
482
  }
483
483
  }
484
484
  }, []);
485
485
 
486
486
  useEffect(() => {
487
487
  isJdAndIosDevice &&
488
488
  autoplay &&
489
489
  mockAutoplay &&
490
490
  Taro.eventCenter.on(TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE_INIT_NOW_TIME, (res) => {
491
491
  console.log('app初始化可见性变化=>', res, '如果是0,表示不可见');
492
492
  res === 0 && handleIosFirstScreenVideoPause();
493
493
  });
494
494
  }, []);
495
495
 
496
496
  useEffect(() => {
497
497
  if (!isH5 || !ref.current) return;
498
498
  if (floorData && floorData.hasOwnProperty('containerIndex')) {
499
499
  initFloorIndexRef.current = floorData.containerIndex;
500
500
  } else {
501
501
  const containerNode = ref.current.closest('[data-container-id]');
502
502
  if (containerNode) {
503
503
  initFloorIndexRef.current = Number(containerNode.getAttribute('data-container-index'));
504
504
  }
505
505
  }
506
506
  if (autoplay && mockAutoplay) {
507
507
 
508
508
  const callInitAutoplay = () => {
509
509
  console.log(`CustomVideo id:${id} 触发初始化autoplay callInitAutoplay`);
510
510
  if (
511
511
  autoplay &&
512
512
  mockAutoplay &&
513
513
  !initPlayStatusRef.current &&
514
514
  isInViewStateRef.current &&
515
515
  ref.current.paused
516
516
  ) {
517
517
  playVideo();
518
518
  }
519
519
  };
520
520
  const onWeixinJSBridgeReady = () => {
521
521
  callInitAutoplay();
522
522
  };
523
523
  const onTouchstart = () => {
524
524
  callInitAutoplay();
525
525
  };
526
526
  const onScroll = () => {
527
527
  callInitAutoplay();
528
528
  };
529
529
  const onPlay = () => {
530
530
  if (!initPlayStatusRef.current) {
531
531
  const dispose = disposeRef.current;
532
532
  dispose && dispose();
533
533
  disposeRef.current = null;
534
534
  }
535
535
  initPlayStatusRef.current = true;
536
536
  };
537
537
  document?.addEventListener('WeixinJSBridgeReady', onWeixinJSBridgeReady);
538
538
  document?.addEventListener('touchstart', onTouchstart);
539
539
  document?.addEventListener('scroll', onScroll);
540
540
  ref.current.addEventListener('play', onPlay);
541
541
  const dispose = () => {
542
542
  console.log('调用dispose');
543
543
  document?.removeEventListener('WeixinJSBridgeReady', onWeixinJSBridgeReady);
544
544
  document?.removeEventListener('touchstart', onTouchstart);
545
545
  document?.removeEventListener('scroll', onScroll);
546
546
  ref?.current?.removeEventListener('play', onPlay);
547
547
  };
548
548
  disposeRef.current = dispose;
549
549
  }
550
550
  const handleVideoPlayApiCall = () => {
551
551
  if (!isH5 || !ref.current) return;
552
552
  playVideo();
553
553
  manualPauseStateRef.current = false;
554
554
  };
555
555
  const handleVideoPauseApiCall = () => {
556
556
  if (!isH5 || !ref.current) return;
557
557
  manualPauseStateRef.current = true;
558
558
  pauseVideo();
559
559
  };
560
560
 
561
561
  const handleVideoSeekApiCall = (position: number) => {
562
562
  if (!isH5 || !ref.current) return;
563
563
  if (typeof position === 'undefined' || typeof position !== 'number') return;
564
564
  ref.current.currentTime = position;
565
565
  };
566
566
 
567
567
  if (onVideoApiCall) {
568
568
  onVideoApiCall({
569
569
  play: handleVideoPlayApiCall,
570
570
  pause: handleVideoPauseApiCall,
571
571
  seek: handleVideoSeekApiCall,
572
572
  });
573
573
  }
574
574
  return () => {
575
575
  const dispose = disposeRef.current;
576
576
  dispose && dispose();
577
577
  disposeRef.current = null;
578
578
  };
579
579
  }, []);
580
580
 
581
581
  const handleMuted = useCallback(() => {
582
582
  if (!isH5 || !ref.current) return;
583
583
  const handleMutedState = ref.current.muted;
584
584
  if (handleMutedState === true) {
585
585
  ref.current.muted = false;
586
586
  setVideoMutedState(false);
587
587
  } else {
588
588
  ref.current.muted = true;
589
589
  setVideoMutedState(true);
590
590
  }
591
591
  }, [videoMutedState]);
592
592
 
593
593
  const handleVideoInViewCallback = useCallback(() => {
594
594
  if (!isH5 || !ref.current) return;
595
595
  console.log(
596
596
  `
597
597
  )} CustomVideo handleVideoInViewCallback id:${id} 进入可视区域 lastPlayStatusRef.current:${lastPlayStatusRef.current},paused:${ref.current.paused}`,
598
598
  );
599
599
  isInViewStateRef.current = true;
600
600
  if (
601
601
  autoplay &&
602
602
  ((mockAutoplay && !initPlayStatusRef.current) || lastPlayStatusRef.current === -1) &&
603
603
  ref.current.paused
604
604
  ) {
605
605
  console.log(`CustomVideo id:${id} 首次进入可视区域`);
606
606
  playVideo();
607
607
  } else if (lastPlayStatusRef.current === 1 && ref.current.paused) {
608
608
  console.log(`CustomVideo id:${id} 非首次进入可视区域`);
609
609
  playVideo();
610
610
  }
611
611
  typeof inViewCallback === 'function' && inViewCallback();
612
612
  }, []);
613
613
 
614
614
  const handleVideoOutViewCallback = useCallback(() => {
615
615
  if (!isH5 || !ref.current) return;
616
616
  isInViewStateRef.current = false;
617
617
  console.log(
618
618
  `CustomVideo handleVideoOutViewCallback id:${id} 不在可视区域,视频暂停,lastPlayStatusRef:${lastPlayStatusRef.current}`,
619
619
  );
620
620
  pauseVideo();
621
621
  typeof outViewCallback === 'function' && outViewCallback();
622
622
  }, []);
623
623
 
624
624
  const getVideoWidthAndHeightStyle = () => {
625
625
  const style = {};
626
626
  width && (style['width'] = width);
627
627
  height && (style['height'] = height);
628
628
  return style;
629
629
  };
630
630
 
631
631
  const getMuteBtnBackgroundImageStyle = useCallback(() => {
632
632
  const isMutedPicSrc = muteBtnPicSrcObj?.IS_MUTED;
633
633
  const notMutedPicSrc = muteBtnPicSrcObj?.NOT_MUTED;
634
634
  const finalIsMutedPicSrc =
635
635
  typeof isMutedPicSrc !== 'undefined' && isMutedPicSrc !== ''
636
636
  ? isMutedPicSrc
637
637
  : DEFAULT_MUTE_BTN_PIC.IS_MUTED;
638
638
  const finalNotMutedPicSrc =
639
639
  typeof notMutedPicSrc !== 'undefined' && notMutedPicSrc !== ''
640
640
  ? notMutedPicSrc
641
641
  : DEFAULT_MUTE_BTN_PIC.NOT_MUTED;
642
642
  return {
643
643
  backgroundImage: `url(${videoMutedState ? finalIsMutedPicSrc : finalNotMutedPicSrc})`,
644
644
  };
645
645
  }, [videoMutedState]);
646
646
  return src ? (
647
647
  <InOrOutViewObserver
648
648
  inViewCallback={handleVideoInViewCallback}
649
649
  outViewCallback={handleVideoOutViewCallback}
650
650
  threshold={threshold}
651
651
  >
652
652
  {isH5 ? (
653
653
  <View
654
654
  className={customVideoStyle['d-video-wrap']}
655
655
  style={{ ...style, ...getVideoWidthAndHeightStyle() }}
656
656
  >
657
657
  <video
658
658
  style={{ ...videoStyle }}
659
659
  className={classNames(customVideoStyle['d-video-play'], {
660
660
  'd-video-forbid-fullscreen-button': isSystemVideo,
661
661
  })}
662
662
  id={id}
663
663
  data-jd-video={true}
664
664
  src={src}
665
665
  controls={controls}
666
666
  poster={poster ? addHttps(poster) : ''}
667
667
  ref={ref}
668
668
  loop={loop}
669
669
  autoPlay={autoplay}
670
670
  muted={MUTED}
671
671
  x5-playsinline="true"
672
672
  playsInline
673
673
  webkit-playsinline="true"
674
674
  controlsList={isH5AndJdShopView ? 'nodownload nofullscreen noremoteplayback' : ''}
675
675
  onError={(e) => {
676
676
  const errMsg = formatVedioErrorMsg(e.target?.error);
677
677
  const data = {
678
678
  type: 'video',
679
679
  subType: 'CustomVideo',
680
680
  isSystemVideo,
681
681
  src,
682
682
  autoplay,
683
683
  errMsg,
684
684
  isH5,
685
685
  };
686
686
  console.log('CustomVideo error 1:', data);
687
687
  draBusinessCustomReport(data);
688
688
  }}
689
689
  onPlay={(e) => {
690
690
  lastPlayStatusRef.current = 1;
691
691
  onPlayCallback && onPlayCallback(e);
692
692
  }}
693
693
  onPause={(e) => {
694
694
  if (isInViewStateRef.current) {
695
695
  lastPlayStatusRef.current = 0;
696
696
  }
697
697
  onPauseCallback && onPauseCallback(e);
698
698
  }}
699
699
  />
700
700
  {!controls && showMuteBtn && (
701
701
  <View
702
702
  className={classNames(
703
703
  customVideoStyle['d-video-mute-btn'],
704
704
  customVideoStyle[`d-mute-btn-${muteButtonPostion}`],
705
705
  `${muteBtnClassName}`,
706
706
  )}
707
707
  style={{ ...getMuteBtnBackgroundImageStyle(), ...muteBtnStyle }}
708
708
  onClick={handleMuted}
709
709
  ></View>
710
710
  )}
711
711
  </View>
712
712
  ) : (
713
713
  <Video
714
714
  style={{ ...videoStyle }}
715
715
  ref={ref}
716
716
  className={customVideoStyle['d-video-play']}
717
717
  src={src}
718
718
  id={id}
719
719
  controls={controls}
720
720
  poster={poster ? addHttps(poster) : ''}
721
721
  loop={loop}
722
722
  data-jd-video={true}
723
723
  autoplay={autoplay}
724
724
  muted={MUTED}
725
725
  showMuteBtn={showMuteBtn}
726
726
  showFullscreenBtn={showFullscreenBtn}
727
727
  objectFit={objectFit}
728
728
  onError={(e) => {
729
729
  const errMsg = formatVedioErrorMsg(e.target?.error);
730
730
  const data = {
731
731
  type: 'video',
732
732
  subType: 'CustomVideo',
733
733
  isSystemVideo,
734
734
  src,
735
735
  autoplay,
736
736
  errMsg,
737
737
  isH5,
738
738
  };
739
739
  console.log('CustomVideo error 2:', data);
740
740
  draBusinessCustomReport(data);
741
741
  }}
742
742
  onPlay={(e) => {
743
743
  lastPlayStatusRef.current = 1;
744
744
  onPlayCallback && onPlayCallback(e);
745
745
  }}
746
746
  onPause={(e) => {
747
747
  if (isInViewStateRef.current) {
748
748
  lastPlayStatusRef.current = 0;
749
749
  }
750
750
  onPauseCallback && onPauseCallback(e);
751
751
  }}
752
752
  />
753
753
  )}
754
754
  </InOrOutViewObserver>
755
755
  ) : null;
756
756
  return process.env.BUILD_TYPE !== BUILD_TYPE.DECORATE;
757
757
  isSystemVideo: false,
758
758
  id: '',
759
759
  style: {},
760
760
  videoStyle: {},
761
761
  className: '',
762
762
  src: '',
763
763
  width: '100%',
764
764
  height: '100%',
765
765
  controls: false,
766
766
  poster: '',
767
767
  autoplay: true,
768
768
  mockAutoplay: getDefaultMockAutoplay(),
769
769
  loop: true,
770
770
  showMuteBtn: true,
771
771
  muteButtonPostion: 'topLeft',
772
772
  muteBtnPicSrcObj: DEFAULT_MUTE_BTN_PIC,
773
773
  muteBtnClassName: '',
774
774
  muteBtnStyle: {},
775
775
  showFullscreenBtn: false,
776
776
  objectFit: 'cover',
777
777
  threshold: 0.6,