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

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