课程详情课件下载

This commit is contained in:
unknown 2023-07-30 15:43:47 +08:00
parent 22533dc828
commit b9901b12cb
2 changed files with 19 additions and 8 deletions

View File

@ -4,7 +4,7 @@ import styles from "./index.module.scss";
import { useNavigate, useLocation, useParams } from "react-router-dom";
import backIcon from "../../assets/images/commen/icon-back-n.png";
import { course as vod } from "../../api/index";
import { isEmptyObject } from "../../utils/index";
import { isEmptyObject, isWechat } from "../../utils/index";
import { Empty } from "../../components";
import { HourCompenent } from "./compenents/hour";
@ -117,13 +117,19 @@ const CoursePage = () => {
const downLoadFile = (cid: number, id: number) => {
vod.downloadAttachment(cid, id).then((res: any) => {
var input = document.createElement("input");
input.value = res.data.download_url;
document.body.appendChild(input);
input.select();
document.execCommand("Copy");
document.body.removeChild(input);
Toast.show("下载链接已复制,请在浏览器中粘贴下载");
if (isWechat()) {
const input = document.createElement("input");
document.body.appendChild(input);
input.setAttribute("value", res.data.download_url);
input.select();
if (document.execCommand("copy")) {
document.execCommand("copy");
Toast.show("下载链接已复制,请在浏览器中粘贴下载");
}
document.body.removeChild(input);
} else {
window.open(res.data.download_url);
}
});
};

View File

@ -80,3 +80,8 @@ export function isMobile() {
export function isEmptyObject(obj: Object) {
return Object.keys(obj).length === 0;
}
export function isWechat() {
let ua = window.navigator.userAgent.toLowerCase();
return /micromessenger/.test(ua);
}