|
|
@@ -2,11 +2,11 @@
|
|
|
import Image from '@/components/Image';
|
|
|
import { useTranslations } from 'next-intl';
|
|
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
-import { fetchUrl } from '@/config';
|
|
|
import { fetchFileInfo, fetchFilePreview } from './actions';
|
|
|
import dynamic from 'next/dynamic';
|
|
|
import crypt from "@/lib/crypt"
|
|
|
-
|
|
|
+import { getHosts } from "@/envHosts";
|
|
|
+import {fetchUrl} from "@/config"
|
|
|
const PdfPreview = dynamic(() => import('@/components/PdfPreview'), {
|
|
|
ssr: false, // 禁用 SSR
|
|
|
});
|
|
|
@@ -38,6 +38,8 @@ type NewsItem = {
|
|
|
};
|
|
|
export function VideoPlayer({ locale }: Props) {
|
|
|
const t = useTranslations('CardGuide');
|
|
|
+ // const { Host00, Host05 } = getHosts()
|
|
|
+ const Host00 = fetchUrl
|
|
|
const [fileData, setFileData] = useState<NewsItem>({
|
|
|
id: 0,
|
|
|
title: '',
|
|
|
@@ -61,20 +63,32 @@ export function VideoPlayer({ locale }: Props) {
|
|
|
}
|
|
|
// 确保有默认值
|
|
|
const steps = Array.isArray(fileInfo.setpList) && fileInfo.setpList.length
|
|
|
- ? fileInfo.setpList.map((s: any, i) => ({
|
|
|
- step: s.step || i + 1,
|
|
|
- type: s.type || '2',
|
|
|
- d: s.d || '',
|
|
|
- img: s.img || ''
|
|
|
- })).sort((a, b) => a.step - b.step)
|
|
|
+ ? fileInfo.setpList
|
|
|
+ .map((s: any, i) => {
|
|
|
+ const step = s.step || i + 1;
|
|
|
+ const type = s.type || '2';
|
|
|
+ const d = s.d || '';
|
|
|
+ let img = s.img || '';
|
|
|
+ if (type === '1' && img) {
|
|
|
+ img = img.startsWith('http') ? img : Host00 + img;
|
|
|
+ }
|
|
|
+ return { step, type, d, img };
|
|
|
+ })
|
|
|
+ .sort((a, b) => a.step - b.step)
|
|
|
: [{ step: 1, type: '2', d: '', img: '' }];
|
|
|
|
|
|
const videos = Array.isArray(fileInfo.videoList) && fileInfo.videoList.length
|
|
|
- ? fileInfo.videoList.map((v: any) => ({
|
|
|
- type: v.type || '2',
|
|
|
- fileUrl: v.fileUrl || '',
|
|
|
- d: v.d || ''
|
|
|
- }))
|
|
|
+ ? fileInfo.videoList.map((v: any) => {
|
|
|
+ const type = v.type || '2';
|
|
|
+ let fileUrl = v.fileUrl || '';
|
|
|
+ const d = v.d || '';
|
|
|
+ if (type === '1' && fileUrl) {
|
|
|
+ if (!fileUrl.startsWith('http')) {
|
|
|
+ fileUrl = Host00 + fileUrl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return { type, fileUrl, d };
|
|
|
+ })
|
|
|
: [{ type: '2', fileUrl: '', d: '' }];
|
|
|
setStepList(steps);
|
|
|
setVideoList(videos);
|
|
|
@@ -91,7 +105,7 @@ export function VideoPlayer({ locale }: Props) {
|
|
|
}, [getData]);
|
|
|
|
|
|
const handleDownload = async () => {
|
|
|
- const url = fetchUrl + fileData.pdfPath;
|
|
|
+ const url = Host00 + fileData.pdfPath;
|
|
|
const res = await fetch(url);
|
|
|
const blob = await res.blob();
|
|
|
const a = document.createElement("a");
|
|
|
@@ -146,23 +160,16 @@ export function VideoPlayer({ locale }: Props) {
|
|
|
<h6 className="text-white">{step.d}</h6>
|
|
|
</div>
|
|
|
);
|
|
|
-
|
|
|
- // 在手机上:文案在上,图片在下
|
|
|
- // 在桌面:保持原有左右交替布局
|
|
|
const mobileText = Text;
|
|
|
const mobileImg = Img;
|
|
|
-
|
|
|
const left = isEven ? Img : Text;
|
|
|
const right = isEven ? Text : Img;
|
|
|
-
|
|
|
return (
|
|
|
<React.Fragment key={step.step || index}>
|
|
|
- {/* 手机布局:文案在上,图片在下 */}
|
|
|
<div className="d-block d-lg-none w-100">
|
|
|
<div className="col-12 mb-4">{mobileText}</div>
|
|
|
<div className="col-12">{mobileImg}</div>
|
|
|
</div>
|
|
|
- {/* 桌面布局:左右交替 */}
|
|
|
<div className="d-none d-lg-block col-lg-6 1">{left}</div>
|
|
|
<div className="d-none d-lg-block col-lg-6 1">{right}</div>
|
|
|
</React.Fragment>
|
|
|
@@ -305,7 +312,7 @@ export function VideoPlayer({ locale }: Props) {
|
|
|
</div>
|
|
|
|
|
|
<PdfPreview
|
|
|
- url={fetchUrl + fileData.pdfPath}
|
|
|
+ url={Host00 + fileData.pdfPath}
|
|
|
password={fileData.pdfPassword}
|
|
|
isOpen={show}
|
|
|
onClose={() => setShow(false)}
|