@conecli/cone-render 0.8.20-beta.0 → 0.8.20-beta.2

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 (160) hide show
  1. package/README.md +7 -1
  2. package/dist/api/index.ts +1 -1
  3. package/dist/assets/icon_blue_info.svg +1 -0
  4. package/dist/common/const.ts +1 -1
  5. package/dist/common/environmentType.ts +1 -0
  6. package/dist/common/index.h5.ts +1 -1
  7. package/dist/common/index.jd.ts +1 -1
  8. package/dist/common/index.ts +1 -1
  9. package/dist/common/index.weapp.ts +1 -1
  10. package/dist/common/jdplayerSdk.ts +1 -0
  11. package/dist/common/jssdk.ts +1 -0
  12. package/dist/common/pageType.ts +1 -0
  13. package/dist/common/sgmCustomCode.ts +1 -0
  14. package/dist/common/token/index.h5.ts +1 -1
  15. package/dist/common/token/token.jd.ts +1 -1
  16. package/dist/common/token/token.ts +1 -1
  17. package/dist/common/wxappApi.jd.ts +1 -0
  18. package/dist/common/wxappApi.ts +1 -1
  19. package/dist/components/ErrorBoundary.tsx +1 -1
  20. package/dist/components/base/CommonFloorHead/index.module.scss +126 -111
  21. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  22. package/dist/components/base/CountDown/index.module.scss +49 -44
  23. package/dist/components/base/CountDown/index.tsx +1 -1
  24. package/dist/components/base/CustomScrollView/index.jd.tsx +1 -0
  25. package/dist/components/base/CustomScrollView/index.module.scss +7 -0
  26. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  27. package/dist/components/base/CustomVideo/common.ts +1 -0
  28. package/dist/components/base/CustomVideo/index.tsx +1 -1
  29. package/dist/components/base/Dialog/index.module.scss +16 -0
  30. package/dist/components/base/Dialog/index.tsx +1 -1
  31. package/dist/components/base/Exposure/index.h5.tsx +1 -1
  32. package/dist/components/base/ExposureSmart/const.ts +1 -0
  33. package/dist/components/base/ExposureSmart/index.h5.module.scss +30 -6
  34. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  35. package/dist/components/base/ExposureSmart/index.module.scss +20 -9
  36. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  37. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  38. package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
  39. package/dist/components/base/InViewRender/index.tsx +1 -1
  40. package/dist/components/base/InViewRender/index.weapp.tsx +1 -1
  41. package/dist/components/base/ItemViewExposureSmart/index.module.scss +8 -0
  42. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -0
  43. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  44. package/dist/components/base/LazyLayoutLoad/index.weapp.tsx +1 -1
  45. package/dist/components/base/LazyLoadImage/const.ts +1 -1
  46. package/dist/components/base/LazyLoadImage/index.h5.module.scss +24 -20
  47. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  48. package/dist/components/base/MobileCommonHeader/index.module.scss +17 -0
  49. package/dist/components/base/MobileCommonHeader/index.tsx +1 -0
  50. package/dist/components/base/NetworkDataError/const.ts +1 -1
  51. package/dist/components/base/NetworkDataError/index.module.scss +125 -69
  52. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  53. package/dist/components/base/Price/Base/index.module.scss +12 -0
  54. package/dist/components/base/Price/Base/index.tsx +1 -1
  55. package/dist/components/base/Price/Double/index.module.scss +32 -0
  56. package/dist/components/base/Price/Double/index.tsx +1 -1
  57. package/dist/components/base/Price/index.tsx +1 -1
  58. package/dist/components/base/ShopLeGaoTag/index.h5.module.scss +35 -0
  59. package/dist/components/base/ShopLeGaoTag/index.h5.tsx +1 -0
  60. package/dist/components/base/ShopLeGaoTag/index.module.scss +33 -0
  61. package/dist/components/base/ShopLeGaoTag/index.tsx +1 -0
  62. package/dist/components/base/Skeleton/index.tsx +1 -1
  63. package/dist/components/debug/DebugLayout/index.module.scss +67 -0
  64. package/dist/components/debug/DebugLayout/index.tsx +1 -0
  65. package/dist/components/debug/DebugLayout/utils.ts +1 -0
  66. package/dist/components/decorate/DecorateFloorModule/index.module.scss +32 -2
  67. package/dist/components/decorate/DecorateFloorModule/index.tsx +1 -1
  68. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  69. package/dist/components/decorate/PlaceHolder/index.tsx +1 -1
  70. package/dist/components/floorItem.jd.tsx +1 -1
  71. package/dist/components/floorItem.tsx +1 -1
  72. package/dist/components/floorItem.weapp.tsx +1 -1
  73. package/dist/components/isv/Floor/index.tsx +1 -1
  74. package/dist/components/remoteFloorItem.tsx +1 -0
  75. package/dist/interface/common.ts +1 -1
  76. package/dist/interface/component.ts +1 -1
  77. package/dist/interface/jumpEventReport.ts +1 -1
  78. package/dist/interface/service.ts +1 -1
  79. package/dist/interface/utils.ts +1 -1
  80. package/dist/jumpEventReport/base.ts +1 -1
  81. package/dist/jumpEventReport/const.ts +1 -1
  82. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  83. package/dist/jumpEventReport/index.h5.ts +1 -1
  84. package/dist/jumpEventReport/index.jd.ts +1 -1
  85. package/dist/jumpEventReport/index.ts +1 -1
  86. package/dist/jumpEventReport/index.weapp.ts +1 -1
  87. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  88. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  89. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  90. package/dist/jumpEventReport/web/report.ts +1 -1
  91. package/dist/jumpEventReport/web.base.ts +1 -1
  92. package/dist/jumpEventReport/web.jd.ts +1 -1
  93. package/dist/jumpEventReport/web.jdb.ts +1 -1
  94. package/dist/jumpEventReport/web.jdjch.ts +1 -0
  95. package/dist/jumpEventReport/web.jxwxapp.ts +1 -0
  96. package/dist/jumpEventReport/web.pc.ts +1 -0
  97. package/dist/jumpEventReport/web.tjapp.ts +1 -0
  98. package/dist/jumpEventReport/web.tjm.ts +1 -0
  99. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  100. package/dist/language/en_US.json +231 -0
  101. package/dist/language/zh_CN.json +231 -0
  102. package/dist/language/zh_HK.json +231 -0
  103. package/dist/libs/taroAppReport.js +2 -2
  104. package/dist/modules/ContainerFloorList/index.h5.module.scss +66 -27
  105. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  106. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  107. package/dist/open/api/device.ts +1 -1
  108. package/dist/open/api/environment.ts +1 -1
  109. package/dist/open/api/index.ts +1 -1
  110. package/dist/open/api/jump copy.ts +1 -1
  111. package/dist/open/api/request.ts +1 -1
  112. package/dist/open/api/shopMember.ts +1 -1
  113. package/dist/open/api/track.ts +1 -1
  114. package/dist/open/api/util.ts +1 -1
  115. package/dist/open/components/index.ts +1 -1
  116. package/dist/sass/app.h5.scss +294 -212
  117. package/dist/sass/base.scss +195 -137
  118. package/dist/service/bMallConst.ts +1 -1
  119. package/dist/service/fetchGateway.ts +1 -1
  120. package/dist/service/fetchGateway.weapp.ts +1 -0
  121. package/dist/service/http/colorSign.ts +1 -1
  122. package/dist/service/http/const.ts +1 -1
  123. package/dist/service/http/h5Http.ts +1 -0
  124. package/dist/service/http/index.h5.ts +1 -0
  125. package/dist/service/requestServer.h5.ts +1 -0
  126. package/dist/service/requestServer.ts +1 -1
  127. package/dist/service/requestServer.weapp.ts +1 -0
  128. package/dist/utils/connectNativeJsBridge.ts +1 -1
  129. package/dist/utils/connectNativeJsBridge.weapp.ts +1 -1
  130. package/dist/utils/draExceptionAndProfile.ts +1 -1
  131. package/dist/utils/h5Utils.ts +1 -1
  132. package/dist/utils/index.h5.ts +1 -1
  133. package/dist/utils/index.ts +1 -1
  134. package/dist/utils/index.weapp.ts +1 -1
  135. package/dist/utils/intersectionObserver.ts +1 -1
  136. package/dist/utils/jm-common.js +1 -1
  137. package/dist/utils/jumpExtMapUtil.h5.ts +1 -0
  138. package/dist/utils/jumpExtMapUtil.ts +1 -0
  139. package/dist/utils/sColor.js +1 -0
  140. package/dist/utils/sgmCodeUtils.ts +1 -0
  141. package/dist/utils/taroRenderUtil.ts +1 -0
  142. package/dist/utils/utils.ts +1 -1
  143. package/dist/wxapp/api/helper.js +1 -0
  144. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  145. package/dist/wxapp/common/user_info.js +1 -1
  146. package/dist/wxapp/components/launch-app/index.js +1 -0
  147. package/dist/wxapp/components/launch-app/index.json +5 -0
  148. package/dist/wxapp/components/launch-app/index.wxml +0 -0
  149. package/dist/wxapp/components/launch-app/index.wxss +0 -0
  150. package/dist/wxapp/components/subscribe-guider/helper.js +1 -0
  151. package/dist/wxapp/components/subscribe-guider/index.js +1 -0
  152. package/dist/wxapp/components/subscribe-guider/index.json +5 -0
  153. package/dist/wxapp/components/subscribe-guider/index.wxml +0 -0
  154. package/dist/wxapp/components/subscribe-guider/index.wxss +0 -0
  155. package/package.json +145 -115
  156. package/dist/components/base/Skeleton/old.tsx +0 -1
  157. package/dist/customHooks/useDocumentVisibilitychange.ts +0 -1
  158. package/dist/utils/memberFormatUtils.js +0 -1
  159. /package/dist/service/{bMallConst.wxapp.ts → bMallConst.weapp.ts} +0 -0
  160. /package/dist/service/http/{colorSign.wxapp.ts → colorSign.weapp.ts} +0 -0
@@ -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 Taro from '@tarojs/taro';
317
317
  isH5,
318
318
  addHttps,
319
319
  isH5AndJdShopView,
320
320
  draBusinessCustomReport,
321
321
  isJdAndIosDevice,
322
322
  const {
323
323
  isSystemVideo,
324
324
  floorData,
325
325
  style,
326
326
  videoStyle,
327
327
  src,
328
328
  width,
329
329
  height,
330
330
  controls,
331
331
  id,
332
332
  poster,
333
333
  autoplay: isvAutoplay,
334
334
  loop,
335
335
  showMuteBtn: isvShowMuteBtn,
336
336
  muteButtonPostion,
337
337
  showFullscreenBtn,
338
338
  muteBtnPicSrcObj,
339
339
  muteBtnClassName,
340
340
  muteBtnStyle,
341
341
  objectFit,
342
342
  mockAutoplay,
343
343
  threshold = 0.6,
344
344
  onPlayCallback,
345
345
  onPauseCallback,
346
346
  onVideoApiCall,
347
347
  inViewCallback,
348
348
  outViewCallback,
349
349
  } = props;
350
350
  const { wifiVideoAutoPlay } = global.info.sysInfo;
351
351
  const isFollowAppVideoPlayStatus = global.getDynamicConfig('isFollowAppVideoPlayStatus');
352
352
  let showMuteBtn = isvShowMuteBtn;
353
353
  let autoplay = isvAutoplay;
354
354
  if (isSystemVideo) {
355
355
  showMuteBtn = false;
356
356
  autoplay = wifiVideoAutoPlay;
357
357
  } else {
358
358
  if (isvAutoplay && isFollowAppVideoPlayStatus) {
359
359
  autoplay = wifiVideoAutoPlay;
360
360
  }
361
361
  }
362
362
  console.log(
363
363
  'CustomVideo',
364
364
  'isSystemVideo:',
365
365
  isSystemVideo,
366
366
  'wifiVideoAutoPlay:',
367
367
  wifiVideoAutoPlay,
368
368
  ',isvAutoplay:',
369
369
  isvAutoplay,
370
370
  ',isFollowAppVideoPlayStatus:',
371
371
  isFollowAppVideoPlayStatus,
372
372
  ',autoplay:',
373
373
  autoplay,
374
374
  ',id:',
375
375
  id,
376
376
  );
377
377
  const [videoMutedState, setVideoMutedState] = useState(MUTED);
378
378
  const lastPlayStatusRef = useRef(-1);
379
379
  const manualPauseStateRef = useRef(false);
380
380
  const initPlayStatusRef = useRef(false);
381
381
  const isInViewStateRef = useRef(false);
382
382
  const disposeRef = useRef<Function | null>();
383
383
  const initFloorIndexRef = useRef(-1);
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
  const handleIosFirstScreenVideoPause = useCallback(() => {
409
409
  const floorIndex = initFloorIndexRef.current;
410
410
  if (ref.current && floorIndex >= 0 && floorIndex < 4) {
411
411
  ref.current.setAttribute('data-init-pause', true);
412
412
  if (!ref.current.paused) {
413
413
  ref.current.pause();
414
414
  } else {
415
415
  setTimeout(() => {
416
416
  !ref.current.paused && ref.current.pause();
417
417
  }, 1500);
418
418
  }
419
419
  }
420
420
  }, []);
421
421
 
422
422
  useEffect(() => {
423
423
  isJdAndIosDevice &&
424
424
  autoplay &&
425
425
  mockAutoplay &&
426
426
  Taro.eventCenter.on(TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE_INIT_NOW_TIME, (res) => {
427
427
  console.log('app初始化可见性变化=>', res, '如果是0,表示不可见');
428
428
  res === 0 && handleIosFirstScreenVideoPause();
429
429
  });
430
430
  }, []);
431
431
 
432
432
  useEffect(() => {
433
433
  if (!isH5 || !ref.current) return;
434
434
  if (floorData && floorData.hasOwnProperty('containerIndex')) {
435
435
  initFloorIndexRef.current = floorData.containerIndex;
436
436
  } else {
437
437
  const containerNode = ref.current.closest('[data-container-id]');
438
438
  if (containerNode) {
439
439
  initFloorIndexRef.current = Number(containerNode.getAttribute('data-container-index'));
440
440
  }
441
441
  }
442
442
  if (autoplay && mockAutoplay) {
443
443
 
444
444
  const callInitAutoplay = () => {
445
445
  console.log(`CustomVideo id:${id} 触发初始化autoplay callInitAutoplay`);
446
446
  if (
447
447
  autoplay &&
448
448
  mockAutoplay &&
449
449
  !initPlayStatusRef.current &&
450
450
  isInViewStateRef.current &&
451
451
  ref.current.paused
452
452
  ) {
453
453
  playVideo();
454
454
  }
455
455
  };
456
456
  const onWeixinJSBridgeReady = (e) => {
457
457
  callInitAutoplay();
458
458
  };
459
459
  const onTouchstart = (e) => {
460
460
  callInitAutoplay();
461
461
  };
462
462
  const onScroll = (e) => {
463
463
  callInitAutoplay();
464
464
  };
465
465
  const onPlay = (e) => {
466
466
  if (!initPlayStatusRef.current) {
467
467
  const dispose = disposeRef.current;
468
468
  dispose && dispose();
469
469
  disposeRef.current = null;
470
470
  }
471
471
  initPlayStatusRef.current = true;
472
472
  };
473
473
  document?.addEventListener('WeixinJSBridgeReady', onWeixinJSBridgeReady);
474
474
  document?.addEventListener('touchstart', onTouchstart);
475
475
  document?.addEventListener('scroll', onScroll);
476
476
  ref.current.addEventListener('play', onPlay);
477
477
  const dispose = () => {
478
478
  console.log('调用dispose');
479
479
  document?.removeEventListener('WeixinJSBridgeReady', onWeixinJSBridgeReady);
480
480
  document?.removeEventListener('touchstart', onTouchstart);
481
481
  document?.removeEventListener('scroll', onScroll);
482
482
  ref?.current?.removeEventListener('play', onPlay);
483
483
  };
484
484
  disposeRef.current = dispose;
485
485
  }
486
486
  const handleVideoPlayApiCall = () => {
487
487
  if (!isH5 || !ref.current) return;
488
488
  playVideo();
489
489
  manualPauseStateRef.current = false;
490
490
  };
491
491
  const handleVideoPauseApiCall = () => {
492
492
  if (!isH5 || !ref.current) return;
493
493
  manualPauseStateRef.current = true;
494
494
  pauseVideo();
495
495
  };
496
496
 
497
497
  const handleVideoSeekApiCall = (position: number) => {
498
498
  if (!isH5 || !ref.current) return;
499
499
  if (typeof position === 'undefined' || typeof position !== 'number') return;
500
500
  ref.current.currentTime = position;
501
501
  };
502
502
 
503
503
  if (onVideoApiCall) {
504
504
  onVideoApiCall({
505
505
  play: handleVideoPlayApiCall,
506
506
  pause: handleVideoPauseApiCall,
507
507
  seek: handleVideoSeekApiCall,
508
508
  });
509
509
  }
510
510
  return () => {
511
511
  const dispose = disposeRef.current;
512
512
  dispose && dispose();
513
513
  disposeRef.current = null;
514
514
  };
515
515
  }, []);
516
516
 
517
517
  const handleMuted = useCallback(() => {
518
518
  if (!isH5 || !ref.current) return;
519
519
  const handleMutedState = ref.current.muted;
520
520
  if (handleMutedState === true) {
521
521
  ref.current.muted = false;
522
522
  setVideoMutedState(false);
523
523
  } else {
524
524
  ref.current.muted = true;
525
525
  setVideoMutedState(true);
526
526
  }
527
527
  }, [videoMutedState]);
528
528
 
529
529
  const handleVideoInViewCallback = useCallback(() => {
530
530
  if (!isH5 || !ref.current) return;
531
531
  console.log(
532
532
  `
533
533
  )} CustomVideo handleVideoInViewCallback id:${id} 进入可视区域 lastPlayStatusRef.current:${lastPlayStatusRef.current},paused:${ref.current.paused}`,
534
534
  );
535
535
  isInViewStateRef.current = true;
536
536
  if (
537
537
  autoplay &&
538
538
  ((mockAutoplay && !initPlayStatusRef.current) || lastPlayStatusRef.current === -1) &&
539
539
  ref.current.paused
540
540
  ) {
541
541
  console.log(`CustomVideo id:${id} 首次进入可视区域`);
542
542
  playVideo();
543
543
  } else if (lastPlayStatusRef.current === 1 && ref.current.paused) {
544
544
  console.log(`CustomVideo id:${id} 非首次进入可视区域`);
545
545
  playVideo();
546
546
  }
547
547
  typeof inViewCallback === 'function' && inViewCallback();
548
548
  }, []);
549
549
 
550
550
  const handleVideoOutViewCallback = useCallback(() => {
551
551
  if (!isH5 || !ref.current) return;
552
552
  isInViewStateRef.current = false;
553
553
  console.log(
554
554
  `CustomVideo handleVideoOutViewCallback id:${id} 不在可视区域,视频暂停,lastPlayStatusRef:${lastPlayStatusRef.current}`,
555
555
  );
556
556
  pauseVideo();
557
557
  typeof outViewCallback === 'function' && outViewCallback();
558
558
  }, []);
559
559
 
560
560
  const getVideoWidthAndHeightStyle = () => {
561
561
  const style = {};
562
562
  width && (style['width'] = width);
563
563
  height && (style['height'] = height);
564
564
  return style;
565
565
  };
566
566
 
567
567
  const getMuteBtnBackgroundImageStyle = useCallback(() => {
568
568
  const isMutedPicSrc = muteBtnPicSrcObj?.IS_MUTED;
569
569
  const notMutedPicSrc = muteBtnPicSrcObj?.NOT_MUTED;
570
570
  const finalIsMutedPicSrc =
571
571
  typeof isMutedPicSrc !== 'undefined' && isMutedPicSrc !== ''
572
572
  ? isMutedPicSrc
573
573
  : DEFAULT_MUTE_BTN_PIC.IS_MUTED;
574
574
  const finalNotMutedPicSrc =
575
575
  typeof notMutedPicSrc !== 'undefined' && notMutedPicSrc !== ''
576
576
  ? notMutedPicSrc
577
577
  : DEFAULT_MUTE_BTN_PIC.NOT_MUTED;
578
578
  return {
579
579
  backgroundImage: `url(${videoMutedState ? finalIsMutedPicSrc : finalNotMutedPicSrc})`,
580
580
  };
581
581
  }, [videoMutedState]);
582
582
  return src ? (
583
583
  <InOrOutViewObserver
584
584
  inViewCallback={handleVideoInViewCallback}
585
585
  outViewCallback={handleVideoOutViewCallback}
586
586
  threshold={threshold}
587
587
  >
588
588
  {isH5 ? (
589
589
  <View
590
590
  className={customVideoStyle['d-video-wrap']}
591
591
  style={{ ...style, ...getVideoWidthAndHeightStyle() }}
592
592
  >
593
593
  <video
594
594
  style={{ ...videoStyle }}
595
595
  className={classNames(customVideoStyle['d-video-play'], {
596
596
  'd-video-forbid-fullscreen-button': isSystemVideo,
597
597
  })}
598
598
  id={id}
599
599
  data-jd-video={true}
600
600
  src={src}
601
601
  controls={controls}
602
602
  poster={poster ? addHttps(poster) : ''}
603
603
  ref={ref}
604
604
  loop={loop}
605
605
  autoPlay={autoplay}
606
606
  muted={MUTED}
607
607
  x5-playsinline="true"
608
608
  playsInline
609
609
  webkit-playsinline="true"
610
610
  controlsList={isH5AndJdShopView ? 'nodownload nofullscreen noremoteplayback' : ''}
611
611
  onError={(e) => {
612
612
  const errMsg = formatVedioErrorMsg(e.target?.error);
613
613
  const data = {
614
614
  type: 'video',
615
615
  subType: 'CustomVideo',
616
616
  isSystemVideo,
617
617
  src,
618
618
  autoplay,
619
619
  errMsg,
620
620
  isH5,
621
621
  };
622
622
  console.log('CustomVideo error 1:', data);
623
623
  draBusinessCustomReport(data);
624
624
  }}
625
625
  onPlay={(e) => {
626
626
  lastPlayStatusRef.current = 1;
627
627
  onPlayCallback && onPlayCallback(e);
628
628
  }}
629
629
  onPause={(e) => {
630
630
  if (isInViewStateRef.current) {
631
631
  lastPlayStatusRef.current = 0;
632
632
  }
633
633
  onPauseCallback && onPauseCallback(e);
634
634
  }}
635
635
  />
636
636
  {!controls && showMuteBtn && (
637
637
  <View
638
638
  className={classNames(
639
639
  customVideoStyle['d-video-mute-btn'],
640
640
  customVideoStyle[`d-mute-btn-${muteButtonPostion}`],
641
641
  `${muteBtnClassName}`,
642
642
  )}
643
643
  style={{ ...getMuteBtnBackgroundImageStyle(), ...muteBtnStyle }}
644
644
  onClick={handleMuted}
645
645
  ></View>
646
646
  )}
647
647
  </View>
648
648
  ) : (
649
649
  <Video
650
650
  style={{ ...videoStyle }}
651
651
  ref={ref}
652
652
  className={customVideoStyle['d-video-play']}
653
653
  src={src}
654
654
  id={id}
655
655
  controls={controls}
656
656
  poster={poster ? addHttps(poster) : ''}
657
657
  loop={loop}
658
658
  data-jd-video={true}
659
659
  autoplay={autoplay}
660
660
  muted={MUTED}
661
661
  showMuteBtn={showMuteBtn}
662
662
  showFullscreenBtn={showFullscreenBtn}
663
663
  objectFit={objectFit}
664
664
  onError={(e) => {
665
665
  const errMsg = formatVedioErrorMsg(e.target?.error);
666
666
  const data = {
667
667
  type: 'video',
668
668
  subType: 'CustomVideo',
669
669
  isSystemVideo,
670
670
  src,
671
671
  autoplay,
672
672
  errMsg,
673
673
  isH5,
674
674
  };
675
675
  console.log('CustomVideo error 2:', data);
676
676
  draBusinessCustomReport(data);
677
677
  }}
678
678
  onPlay={(e) => {
679
679
  lastPlayStatusRef.current = 1;
680
680
  onPlayCallback && onPlayCallback(e);
681
681
  }}
682
682
  onPause={(e) => {
683
683
  if (isInViewStateRef.current) {
684
684
  lastPlayStatusRef.current = 0;
685
685
  }
686
686
  onPauseCallback && onPauseCallback(e);
687
687
  }}
688
688
  />
689
689
  )}
690
690
  </InOrOutViewObserver>
691
691
  ) : null;
692
692
  return process.env.BUILD_TYPE !== BUILD_TYPE.DECORATE;
693
693
  isSystemVideo: false,
694
694
  id: '',
695
695
  style: {},
696
696
  videoStyle: {},
697
697
  className: '',
698
698
  src: '',
699
699
  width: '100%',
700
700
  height: '100%',
701
701
  controls: false,
702
702
  poster: '',
703
703
  autoplay: true,
704
704
  mockAutoplay: getDefaultMockAutoplay(),
705
705
  loop: true,
706
706
  showMuteBtn: true,
707
707
  muteButtonPostion: 'topLeft',
708
708
  muteBtnPicSrcObj: DEFAULT_MUTE_BTN_PIC,
709
709
  muteBtnClassName: '',
710
710
  muteBtnStyle: {},
711
711
  showFullscreenBtn: false,
712
712
  objectFit: 'cover',
713
713
  threshold: 0.6,