@conecli/cone-render 0.10.1-shop-beta.22 → 0.10.1-shop-beta.24

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