index.tsx
3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React, {useEffect, useState} from 'react'
import './style.less'
import NavBar from '@/components/nav-bar'
import VideoPlay from '@/components/video-play'
import PdfPreview from '@/components/pdf-preview'
import {useSearchParams} from "react-router-dom";
import {getCarouselSettings} from "@/api/apiConfig";
import _ from 'lodash';
import { useNavigate } from 'react-router-dom';
const ProductionDetail: React.FC = () => {
let navigate = useNavigate();
const [title, setTitle] = useState<string>('');
const [filePathItem, setFilePathItem] = useState();
// 自动预览 定时器
const [preViewTimer, setPreViewTimer] = useState<any>(null);
// // 因是hook,必须写在组件的顶部执行,useSearchParams() 返回的是数组
const [params] = useSearchParams();
// // 通过 get 方法获取目标参数
const name = params.get("name") || "";
const sxPreViewList = localStorage.getItem('sxPreViewListStorage') ? JSON.parse(localStorage.getItem('sxPreViewListStorage')) : [];
useEffect(() => {
if (sxPreViewList?.length) {
const _isLoop = sxPreViewList?.length > 1;
const loopPreView = (index: number, interval: number) => {
setFilePathItem(sxPreViewList?.[index]);
clearInterval(preViewTimer);
// 3秒调一次
let _preViewTimer = setInterval(() => {
index = index + 1;
if (index > sxPreViewList?.length - 1) {
index = 0;
}
setFilePathItem(sxPreViewList?.[index]);
}, interval * 1000);
setPreViewTimer(_preViewTimer);
}
if (_isLoop) {
getCarouselSettings().then((res: any) => {
const interval = res?.carousel?.interval || 10;
loopPreView(0, interval);
}).catch(() => {
loopPreView(0, 10)
})
} else {
setFilePathItem(sxPreViewList?.[0]);
}
}
}, [JSON.stringify(sxPreViewList)])
useEffect(() => {
if (name) {
setTitle(name)
}
}, [name])
useEffect(() => {
return () => {
clearInterval(preViewTimer);
};
}, [])
useEffect(() => {
console.log('filePathItem', filePathItem)
if (!_.isEmpty(filePathItem)) {
setTitle(filePathItem?.name)
}
}, [filePathItem])
return (
<div className={'sxjx-content-main sxjx-layout-main-unfoot'}>
<div className={'production-detail'}>
<NavBar showBack={true} title={title} customBack={{onClick: () => {
const _url = localStorage.getItem('sxListPath');
navigate(_url, { replace: true });
}}}
/>
{
filePathItem?.type === 'mp4' ? <div className={'production-detail-video-box'}>
<VideoPlay
key={filePathItem?.url}
url={filePathItem?.url || ''}
className={'production-detail-video'}
/>
</div> : filePathItem?.type === 'pdf' ? <PdfPreview url={filePathItem?.url}/> : ''
}
</div>
</div>
)
}
export default ProductionDetail;