|
|
@@ -1,5 +1,11 @@
|
|
|
/* eslint-disable jsx-a11y/iframe-has-title */
|
|
|
-import React, { useCallback, useMemo, useRef, useState } from "react";
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
import { Goods } from "@/types";
|
|
|
import { baseURL } from "@/utils/http";
|
|
|
@@ -16,6 +22,9 @@ import {
|
|
|
import ImageLazy from "@/components/ImageLazy";
|
|
|
import { ImageViewer } from "antd-mobile";
|
|
|
|
|
|
+import musicImg from "@/assets/img/icon-music.png";
|
|
|
+import musicImgX from "@/assets/img/icon-musicX.png";
|
|
|
+
|
|
|
type Props = {
|
|
|
info: Goods;
|
|
|
colseFu: () => void;
|
|
|
@@ -80,7 +89,7 @@ function GoodsInfoM({ info, colseFu, type }: Props) {
|
|
|
|
|
|
// 整理右边的信息
|
|
|
const filterArr = useMemo(() => {
|
|
|
- return ["id", "type1", "type2", "name", "showType", "showNum"];
|
|
|
+ return ["id", "type1", "type2", "name", "showType", "showNum", "isAudio"];
|
|
|
}, []);
|
|
|
|
|
|
const rightTxtInfo = useMemo(() => {
|
|
|
@@ -94,6 +103,25 @@ function GoodsInfoM({ info, colseFu, type }: Props) {
|
|
|
return arr;
|
|
|
}, [filterArr, info]);
|
|
|
|
|
|
+ // 音频的播放和暂停
|
|
|
+ const [audioSta, setAudioSta] = useState(false);
|
|
|
+ const audioRef = useRef<HTMLAudioElement>(null);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ const dom = audioRef.current;
|
|
|
+ if (dom) {
|
|
|
+ if (audioSta) {
|
|
|
+ dom.play();
|
|
|
+ dom.onended = () => {
|
|
|
+ // 音频播放结束
|
|
|
+ setAudioSta(false);
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ dom.pause();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, [audioSta]);
|
|
|
+
|
|
|
return (
|
|
|
<div
|
|
|
className={styles.GoodsInfoM}
|
|
|
@@ -104,7 +132,22 @@ function GoodsInfoM({ info, colseFu, type }: Props) {
|
|
|
<div className="GoodsInfoMmian mySorrl">
|
|
|
{/* 返回 */}
|
|
|
<img onClick={colseFu} className="A3IBack" src={backImg} alt="" />
|
|
|
-
|
|
|
+ {/* 新增加的音频 */}
|
|
|
+ {info.isAudio ? (
|
|
|
+ <>
|
|
|
+ <audio
|
|
|
+ ref={audioRef}
|
|
|
+ src={`${baseURL}/audio/${info.isAudio}`}
|
|
|
+ ></audio>
|
|
|
+ <div
|
|
|
+ className="A3audio"
|
|
|
+ title={audioSta ? "关闭音频" : "打开音频"}
|
|
|
+ onClick={() => setAudioSta(!audioSta)}
|
|
|
+ >
|
|
|
+ <img src={audioSta ? musicImg : musicImgX} alt="" />
|
|
|
+ </div>
|
|
|
+ </>
|
|
|
+ ) : null}
|
|
|
{/* 标题 */}
|
|
|
<div className="A3IRtit">
|
|
|
<img src={name1Img} alt="" />
|