写入剪贴板实现方式更改为document.execCommand
This commit is contained in:
parent
3333823400
commit
f7d6d7767a
|
@ -12,6 +12,7 @@ import verification from "@/public/icon/verification.png";
|
|||
import icon_border from "@/public/images/icon_border.png";
|
||||
import Link from "next/link";
|
||||
import { setCookie } from "cookies-next";
|
||||
import copy from "@/utils/copy";
|
||||
|
||||
export default function StreamerDetail({ params }) {
|
||||
//页面数据
|
||||
|
@ -53,15 +54,11 @@ export default function StreamerDetail({ params }) {
|
|||
}, []);
|
||||
|
||||
//将主播链接复制到剪贴板,并存cookie
|
||||
const copyAndSetCookieInviter = async () => {
|
||||
try {
|
||||
setCookie("inviter", data?.user_id);
|
||||
await navigator.clipboard.writeText(
|
||||
`【${data?.name}】『ID:${data?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${data?.user_id}`
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("复制到剪贴板时出现错误:", error);
|
||||
}
|
||||
const copyAndSetCookieInviter = () => {
|
||||
setCookie("inviter", data?.user_id);
|
||||
copy(
|
||||
`【${data?.name}】『ID:${data?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${data?.user_id}`
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -15,6 +15,7 @@ import baseRequest from "@/utils/baseRequest";
|
|||
import { generateSignature } from "@/utils/crypto";
|
||||
import { Toast } from "antd-mobile";
|
||||
import icon_border from "@/public/images/icon_border.png";
|
||||
import copy from "@/utils/copy";
|
||||
|
||||
export default function Download({ params }) {
|
||||
const [deviceType, setDeviceType] = useState("");
|
||||
|
@ -31,14 +32,10 @@ export default function Download({ params }) {
|
|||
}, []);
|
||||
|
||||
//点下载在剪贴板写入主播邀请信息
|
||||
const copyInviter = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(
|
||||
`复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${params.user_id}`
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("复制到剪贴板时出现错误:", error);
|
||||
}
|
||||
const copyInviter = () => {
|
||||
copy(
|
||||
`【${data?.name}】『ID:${data?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${data?.user_id}`
|
||||
);
|
||||
};
|
||||
|
||||
//页面数据
|
||||
|
|
|
@ -6,6 +6,7 @@ import { checkAuth } from "@/utils/auth";
|
|||
import { useRouter } from "next/navigation";
|
||||
import baseRequest from "@/utils/baseRequest";
|
||||
import { generateSignature } from "@/utils/crypto";
|
||||
import copy from "@/utils/copy";
|
||||
|
||||
export default function Purchased() {
|
||||
//如果没登录直接跳转下载页
|
||||
|
@ -159,7 +160,7 @@ export default function Purchased() {
|
|||
|
||||
const GetWechatModal = () => {
|
||||
const handleCopy = () => {
|
||||
navigator.clipboard.writeText(currentWechat);
|
||||
copy(currentWechat);
|
||||
Toast.show({
|
||||
content: "复制成功",
|
||||
});
|
||||
|
|
|
@ -8,6 +8,7 @@ import { generateSignature } from "@/utils/crypto";
|
|||
import Image from "next/image";
|
||||
import verification from "@/public/icon/verification.png";
|
||||
import Link from "next/link";
|
||||
import copy from "@/utils/copy";
|
||||
|
||||
export default function Weibo({ params }) {
|
||||
//页面数据
|
||||
|
@ -49,27 +50,10 @@ export default function Weibo({ params }) {
|
|||
}, []);
|
||||
|
||||
//将主播链接复制到剪贴板
|
||||
const copyInviter = async () => {
|
||||
let input = document.createElement("input");
|
||||
input.style.position = "fixed";
|
||||
input.style.top = "-10000px";
|
||||
input.style.zIndex = "-999";
|
||||
document.body.appendChild(input);
|
||||
input.value = `【${data?.name}】『ID:${data?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${data?.user_id}`;
|
||||
input.focus();
|
||||
input.select();
|
||||
try {
|
||||
let result = document.execCommand("copy");
|
||||
document.body.removeChild(input);
|
||||
if (!result || result === "unsuccessful") {
|
||||
console.log("复制失败");
|
||||
} else {
|
||||
console.log("复制成功");
|
||||
}
|
||||
} catch (e) {
|
||||
document.body.removeChild(input);
|
||||
console.log("当前浏览器不支持复制功能,请检查更新或更换其他浏览器操作");
|
||||
}
|
||||
const copyInviter = () => {
|
||||
copy(
|
||||
`【${data?.name}】『ID:${data?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${data?.user_id}`
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
export default function copy(text = "") {
|
||||
let input = document.createElement("input");
|
||||
input.style.position = "fixed";
|
||||
input.style.top = "-10000px";
|
||||
input.style.zIndex = "-999";
|
||||
document.body.appendChild(input);
|
||||
input.value = text;
|
||||
input.focus();
|
||||
input.select();
|
||||
try {
|
||||
let result = document.execCommand("copy");
|
||||
document.body.removeChild(input);
|
||||
if (!result || result === "unsuccessful") {
|
||||
console.log("复制失败");
|
||||
} else {
|
||||
console.log("复制成功");
|
||||
}
|
||||
} catch (e) {
|
||||
document.body.removeChild(input);
|
||||
console.log("当前浏览器不支持复制功能,请检查更新或更换其他浏览器操作");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue