zy-react-library 1.0.130 → 1.0.131
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.
- package/components/Map/MapSelector.js +3 -0
- package/components/Map/index.js +8 -5
- package/components/Video/AliPlayer.d.ts +42 -0
- package/components/Video/AliPlayer.js +159 -0
- package/components/Video/index.d.ts +20 -0
- package/components/Video/index.js +89 -0
- package/package.json +1 -1
- package/utils/index.d.ts +10 -0
- package/utils/index.js +29 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Button, Col, Form, Input, Modal, Row, Select, Spin } from "antd";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { dynamicLoadJs } from "../../utils";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* 定位组件弹窗
|
|
@@ -33,6 +34,8 @@ const MapSelector = (props) => {
|
|
|
33
34
|
|
|
34
35
|
// 初始化地图
|
|
35
36
|
const initMap = async () => {
|
|
37
|
+
await dynamicLoadJs("https://api.map.baidu.com/api?v=1.0&type=webgl&ak=OElqFYoKiAH8KFtph8ftLKF5NlNrbCUr");
|
|
38
|
+
|
|
36
39
|
if (!window.BMapGL) {
|
|
37
40
|
console.error("BMapGL is not loaded");
|
|
38
41
|
return;
|
package/components/Map/index.js
CHANGED
|
@@ -45,11 +45,14 @@ const Map = (props) => {
|
|
|
45
45
|
<Form.Item name={latitudeProps} noStyle rules={[{ required, message: "请选择纬度" }]}>
|
|
46
46
|
<Input disabled />
|
|
47
47
|
</Form.Item>
|
|
48
|
-
<Button
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
<Button
|
|
49
|
+
type="primary"
|
|
50
|
+
onClick={() => {
|
|
51
|
+
setMapVisible(true);
|
|
52
|
+
setCurrentLongitude(form.getFieldValue(longitudeProps));
|
|
53
|
+
setCurrentLatitude(form.getFieldValue(latitudeProps));
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
53
56
|
地图定位
|
|
54
57
|
</Button>
|
|
55
58
|
</div>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ForwardRefExoticComponent, RefAttributes } from "react";
|
|
2
|
+
|
|
3
|
+
export interface AliPlayerProps {
|
|
4
|
+
/** 播放地址 */
|
|
5
|
+
source?: string | string[];
|
|
6
|
+
/** 阿里的 vid */
|
|
7
|
+
vid?: string;
|
|
8
|
+
/** 阿里的 playAuth */
|
|
9
|
+
playAuth?: string;
|
|
10
|
+
/** 封面地址 */
|
|
11
|
+
cover?: string;
|
|
12
|
+
/** 播放器宽度,默认 100% */
|
|
13
|
+
width?: string;
|
|
14
|
+
/** 播放器高度,默认 600px */
|
|
15
|
+
height?: string;
|
|
16
|
+
/** 是否自动播放 */
|
|
17
|
+
autoplay?: boolean;
|
|
18
|
+
/** 是否显示进度条 */
|
|
19
|
+
showProgress?: boolean;
|
|
20
|
+
/** 是否直播模式 */
|
|
21
|
+
isLive?: boolean;
|
|
22
|
+
/** 播放开始时间 */
|
|
23
|
+
playTime?: number;
|
|
24
|
+
/** 播放结束事件 */
|
|
25
|
+
onEnded?: () => void;
|
|
26
|
+
/** 播放进度更新事件 */
|
|
27
|
+
onTimeupdate?: (currentTime: number) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface AliPlayerRef {
|
|
31
|
+
play: () => void;
|
|
32
|
+
pause: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 视频播放组件
|
|
37
|
+
*/
|
|
38
|
+
declare const AliPlayer: ForwardRefExoticComponent<
|
|
39
|
+
AliPlayerProps & RefAttributes<AliPlayerRef>
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
export default AliPlayer;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { useDocumentVisibility } from "ahooks";
|
|
2
|
+
import { uniqueId } from "lodash-es";
|
|
3
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
4
|
+
import { dynamicLoadCss, dynamicLoadJs } from "../../utils";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 视频播放组件
|
|
8
|
+
*/
|
|
9
|
+
const AliPlayer = forwardRef(({
|
|
10
|
+
source = "",
|
|
11
|
+
vid = "",
|
|
12
|
+
playAuth = "",
|
|
13
|
+
cover = "",
|
|
14
|
+
width = "100%",
|
|
15
|
+
height = "600px",
|
|
16
|
+
autoplay = true,
|
|
17
|
+
showProgress = true,
|
|
18
|
+
isLive = false,
|
|
19
|
+
playTime = 0,
|
|
20
|
+
onEnded,
|
|
21
|
+
onTimeupdate,
|
|
22
|
+
}, ref) => {
|
|
23
|
+
const playerRef = useRef(null);
|
|
24
|
+
const containerRef = useRef(null);
|
|
25
|
+
const visibility = useDocumentVisibility();
|
|
26
|
+
const className = useRef(uniqueId("_")).current;
|
|
27
|
+
|
|
28
|
+
useImperativeHandle(ref, () => ({
|
|
29
|
+
play: () => {
|
|
30
|
+
playerRef.current && playerRef.current.play();
|
|
31
|
+
},
|
|
32
|
+
pause: () => {
|
|
33
|
+
playerRef.current && playerRef.current.pause();
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const onDisposeAliPlayer = () => {
|
|
38
|
+
if (!playerRef.current)
|
|
39
|
+
return;
|
|
40
|
+
playerRef.current.dispose();
|
|
41
|
+
playerRef.current = null;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const onCreateAliPlayer = async () => {
|
|
45
|
+
if (!containerRef.current)
|
|
46
|
+
return;
|
|
47
|
+
await dynamicLoadJs("https://g.alicdn.com/apsara-media-box/imp-web-player/2.16.3/aliplayer-min.js");
|
|
48
|
+
await dynamicLoadCss("https://g.alicdn.com/apsara-media-box/imp-web-player/2.16.3/skins/default/aliplayer-min.css");
|
|
49
|
+
onDisposeAliPlayer();
|
|
50
|
+
|
|
51
|
+
const skinLayout = [
|
|
52
|
+
{ name: "bigPlayButton", align: "blabs", x: 30, y: 80 },
|
|
53
|
+
{ name: "H5Loading", align: "cc" },
|
|
54
|
+
{ name: "errorDisplay", align: "tlabs", x: 0, y: 0 },
|
|
55
|
+
{ name: "infoDisplay" },
|
|
56
|
+
{ name: "tooltip", align: "blabs", x: 0, y: 56 },
|
|
57
|
+
{ name: "thumbnail" },
|
|
58
|
+
{
|
|
59
|
+
name: "controlBar",
|
|
60
|
+
align: "blabs",
|
|
61
|
+
x: 0,
|
|
62
|
+
y: 0,
|
|
63
|
+
children: [
|
|
64
|
+
{ name: "playButton", align: "tl", x: 15, y: 12 },
|
|
65
|
+
{ name: "timeDisplay", align: "tl", x: 10, y: 7 },
|
|
66
|
+
{ name: "fullScreenButton", align: "tr", x: 10, y: 12 },
|
|
67
|
+
{ name: "setting", align: "tr", x: 15, y: 12 },
|
|
68
|
+
{ name: "volume", align: "tr", x: 5, y: 10 },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
if (showProgress) {
|
|
74
|
+
skinLayout[skinLayout.length - 1].children.unshift({
|
|
75
|
+
name: "progress",
|
|
76
|
+
align: "blabs",
|
|
77
|
+
x: 0,
|
|
78
|
+
y: 44,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (typeof window.Aliplayer !== "undefined") {
|
|
83
|
+
playerRef.current = new window.Aliplayer(
|
|
84
|
+
{
|
|
85
|
+
id: className,
|
|
86
|
+
...(source
|
|
87
|
+
? { source }
|
|
88
|
+
: {
|
|
89
|
+
vid,
|
|
90
|
+
playauth: playAuth,
|
|
91
|
+
qualitySort: "asc",
|
|
92
|
+
format: "m3u8",
|
|
93
|
+
encryptType: 1,
|
|
94
|
+
mediaType: "video",
|
|
95
|
+
isLive: true,
|
|
96
|
+
rePlay: false,
|
|
97
|
+
playsinline: true,
|
|
98
|
+
controlBarVisibility: "hover",
|
|
99
|
+
}),
|
|
100
|
+
cover,
|
|
101
|
+
width,
|
|
102
|
+
height,
|
|
103
|
+
autoplay,
|
|
104
|
+
isLive,
|
|
105
|
+
useH5Prism: true,
|
|
106
|
+
skinLayout,
|
|
107
|
+
},
|
|
108
|
+
(player) => {
|
|
109
|
+
if (autoplay) {
|
|
110
|
+
player.play();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
player.on("ended", () => {
|
|
114
|
+
onEnded && onEnded();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
player.on("timeupdate", () => {
|
|
118
|
+
onTimeupdate && onTimeupdate(player.getCurrentTime());
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (playTime > 0) {
|
|
122
|
+
player.seek(playTime);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (source || (vid && playAuth)) {
|
|
131
|
+
onCreateAliPlayer();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return () => {
|
|
135
|
+
onDisposeAliPlayer();
|
|
136
|
+
};
|
|
137
|
+
}, [source, vid, playAuth]);
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (visibility === "hidden") {
|
|
141
|
+
playerRef.current && playerRef.current.pause();
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
playerRef.current && playerRef.current.play();
|
|
145
|
+
}
|
|
146
|
+
}, [visibility]);
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<div
|
|
150
|
+
ref={containerRef}
|
|
151
|
+
id={className}
|
|
152
|
+
style={{ width, height }}
|
|
153
|
+
/>
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
AliPlayer.displayName = "AliPlayer";
|
|
158
|
+
|
|
159
|
+
export default AliPlayer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ForwardRefExoticComponent, RefAttributes } from "react";
|
|
2
|
+
import type { AliPlayerProps, AliPlayerRef } from "./AliPlayer";
|
|
3
|
+
|
|
4
|
+
export interface VideoProps extends Omit<AliPlayerProps, "onEnded" | "onTimeupdate"> {
|
|
5
|
+
/** 是否显示弹窗 */
|
|
6
|
+
visible?: boolean;
|
|
7
|
+
/** 是否内联模式 */
|
|
8
|
+
inline?: boolean;
|
|
9
|
+
/** 弹窗关闭事件 */
|
|
10
|
+
onCancel?: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 视频播放组件
|
|
15
|
+
*/
|
|
16
|
+
declare const Video: ForwardRefExoticComponent<
|
|
17
|
+
VideoProps & RefAttributes<AliPlayerRef>
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export default Video;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Modal } from "antd";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { getFileUrl } from "../../utils";
|
|
4
|
+
import AliPlayer from "./AliPlayer";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 视频播放组件
|
|
8
|
+
*/
|
|
9
|
+
const Video = ({
|
|
10
|
+
source = "",
|
|
11
|
+
vid = "",
|
|
12
|
+
playAuth = "",
|
|
13
|
+
cover = "",
|
|
14
|
+
autoplay = true,
|
|
15
|
+
showProgress = true,
|
|
16
|
+
playTime = 0,
|
|
17
|
+
inline = false,
|
|
18
|
+
isLive = false,
|
|
19
|
+
width = "100%",
|
|
20
|
+
height = "600px",
|
|
21
|
+
title = "视频",
|
|
22
|
+
visible: externalVisible = false,
|
|
23
|
+
onCancel,
|
|
24
|
+
...restProps
|
|
25
|
+
}) => {
|
|
26
|
+
const [internalVisible, setInternalVisible] = useState(false);
|
|
27
|
+
const playerRef = useRef(null);
|
|
28
|
+
|
|
29
|
+
const visible = onCancel ? externalVisible : internalVisible;
|
|
30
|
+
const setVisible = onCancel || setInternalVisible;
|
|
31
|
+
|
|
32
|
+
const getSource = () => {
|
|
33
|
+
if (!source)
|
|
34
|
+
return;
|
|
35
|
+
if (source.includes("http") || source.includes("https"))
|
|
36
|
+
return source;
|
|
37
|
+
else return getFileUrl() + source;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!inline) {
|
|
42
|
+
if (visible) {
|
|
43
|
+
playerRef.current && playerRef.current.play();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
playerRef.current && playerRef.current.pause();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, [visible, inline]);
|
|
50
|
+
|
|
51
|
+
const playerElement = (
|
|
52
|
+
<AliPlayer
|
|
53
|
+
ref={playerRef}
|
|
54
|
+
source={getSource()}
|
|
55
|
+
vid={vid}
|
|
56
|
+
playAuth={playAuth}
|
|
57
|
+
cover={cover}
|
|
58
|
+
autoplay={autoplay}
|
|
59
|
+
showProgress={showProgress}
|
|
60
|
+
playTime={playTime}
|
|
61
|
+
isLive={isLive}
|
|
62
|
+
width={width}
|
|
63
|
+
height={height}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
if (!inline) {
|
|
68
|
+
return (
|
|
69
|
+
<Modal
|
|
70
|
+
open={visible}
|
|
71
|
+
title={title}
|
|
72
|
+
footer={[
|
|
73
|
+
<button key="cancel" onClick={() => setVisible(false)}>
|
|
74
|
+
取消
|
|
75
|
+
</button>,
|
|
76
|
+
]}
|
|
77
|
+
maskClosable={false}
|
|
78
|
+
onCancel={() => setVisible(false)}
|
|
79
|
+
{...restProps}
|
|
80
|
+
>
|
|
81
|
+
{playerElement}
|
|
82
|
+
</Modal>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return playerElement;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default Video;
|
package/package.json
CHANGED
package/utils/index.d.ts
CHANGED
|
@@ -332,3 +332,13 @@ export function processTreeDataForOnlyLastLevel(
|
|
|
332
332
|
export function validatorEndTime(timeStart: string): {
|
|
333
333
|
validator: (_: any, value: any) => Promise<void | string>;
|
|
334
334
|
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* 动态加载js资源
|
|
338
|
+
*/
|
|
339
|
+
export function dynamicLoadJs(url: string): Promise<void>;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* 动态加载css资源
|
|
343
|
+
*/
|
|
344
|
+
export function dynamicLoadCss(url: string): Promise<void>;
|
package/utils/index.js
CHANGED
|
@@ -523,6 +523,35 @@ export const validatorEndTime = (timeStart) => {
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
+
/**
|
|
527
|
+
* 动态加载js资源
|
|
528
|
+
*/
|
|
529
|
+
export function dynamicLoadJs(url) {
|
|
530
|
+
return new Promise((resolve, reject) => {
|
|
531
|
+
const script = document.createElement("script");
|
|
532
|
+
script.type = "text/javascript";
|
|
533
|
+
script.src = url;
|
|
534
|
+
script.onload = resolve;
|
|
535
|
+
script.onerror = reject;
|
|
536
|
+
document.body.appendChild(script);
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* 动态加载css资源
|
|
542
|
+
*/
|
|
543
|
+
export function dynamicLoadCss(url) {
|
|
544
|
+
return new Promise((resolve, reject) => {
|
|
545
|
+
const link = document.createElement("link");
|
|
546
|
+
link.rel = "stylesheet";
|
|
547
|
+
link.type = "text/css";
|
|
548
|
+
link.href = url;
|
|
549
|
+
link.onload = resolve;
|
|
550
|
+
link.onerror = reject;
|
|
551
|
+
document.head.appendChild(link);
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
|
|
526
555
|
/**
|
|
527
556
|
* 获取文件url
|
|
528
557
|
*/
|