@conecli/cone-render 0.10.1-beta.4 → 0.10.1-beta.6

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