Merge pull request '写入剪贴板实现方式更改为document.execCommand' (#28) from feat-20240118 into main
Reviewed-on: https://git.wishpal.cn/wishpal_ironfan/tiefen_space_web/pulls/28
This commit is contained in:
commit
de5756fd65
|
@ -12,6 +12,7 @@ import verification from "@/public/icon/verification.png";
|
||||||
import icon_border from "@/public/images/icon_border.png";
|
import icon_border from "@/public/images/icon_border.png";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { setCookie } from "cookies-next";
|
import { setCookie } from "cookies-next";
|
||||||
|
import copy from "@/utils/copy";
|
||||||
|
|
||||||
export default function StreamerDetail({ params }) {
|
export default function StreamerDetail({ params }) {
|
||||||
//页面数据
|
//页面数据
|
||||||
|
@ -53,15 +54,11 @@ export default function StreamerDetail({ params }) {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
//将主播链接复制到剪贴板,并存cookie
|
//将主播链接复制到剪贴板,并存cookie
|
||||||
const copyAndSetCookieInviter = async () => {
|
const copyAndSetCookieInviter = () => {
|
||||||
try {
|
setCookie("inviter", data?.user_id);
|
||||||
setCookie("inviter", data?.user_id);
|
copy(
|
||||||
await navigator.clipboard.writeText(
|
`【${data?.name}】『ID:${data?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${data?.user_id}`
|
||||||
`【${data?.name}】『ID:${data?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${data?.user_id}`
|
);
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("复制到剪贴板时出现错误:", error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -15,6 +15,7 @@ import baseRequest from "@/utils/baseRequest";
|
||||||
import { generateSignature } from "@/utils/crypto";
|
import { generateSignature } from "@/utils/crypto";
|
||||||
import { Toast } from "antd-mobile";
|
import { Toast } from "antd-mobile";
|
||||||
import icon_border from "@/public/images/icon_border.png";
|
import icon_border from "@/public/images/icon_border.png";
|
||||||
|
import copy from "@/utils/copy";
|
||||||
|
|
||||||
export default function Download({ params }) {
|
export default function Download({ params }) {
|
||||||
const [deviceType, setDeviceType] = useState("");
|
const [deviceType, setDeviceType] = useState("");
|
||||||
|
@ -31,14 +32,10 @@ export default function Download({ params }) {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
//点下载在剪贴板写入主播邀请信息
|
//点下载在剪贴板写入主播邀请信息
|
||||||
const copyInviter = async () => {
|
const copyInviter = () => {
|
||||||
try {
|
copy(
|
||||||
await navigator.clipboard.writeText(
|
`【${data?.name}】『ID:${data?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${data?.user_id}`
|
||||||
`复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${params.user_id}`
|
);
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("复制到剪贴板时出现错误:", error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//页面数据
|
//页面数据
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { checkAuth } from "@/utils/auth";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import baseRequest from "@/utils/baseRequest";
|
import baseRequest from "@/utils/baseRequest";
|
||||||
import { generateSignature } from "@/utils/crypto";
|
import { generateSignature } from "@/utils/crypto";
|
||||||
|
import copy from "@/utils/copy";
|
||||||
|
|
||||||
export default function Purchased() {
|
export default function Purchased() {
|
||||||
//如果没登录直接跳转下载页
|
//如果没登录直接跳转下载页
|
||||||
|
@ -159,7 +160,7 @@ export default function Purchased() {
|
||||||
|
|
||||||
const GetWechatModal = () => {
|
const GetWechatModal = () => {
|
||||||
const handleCopy = () => {
|
const handleCopy = () => {
|
||||||
navigator.clipboard.writeText(currentWechat);
|
copy(currentWechat);
|
||||||
Toast.show({
|
Toast.show({
|
||||||
content: "复制成功",
|
content: "复制成功",
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { generateSignature } from "@/utils/crypto";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import verification from "@/public/icon/verification.png";
|
import verification from "@/public/icon/verification.png";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import copy from "@/utils/copy";
|
||||||
|
|
||||||
export default function Weibo({ params }) {
|
export default function Weibo({ params }) {
|
||||||
//页面数据
|
//页面数据
|
||||||
|
@ -49,27 +50,10 @@ export default function Weibo({ params }) {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
//将主播链接复制到剪贴板
|
//将主播链接复制到剪贴板
|
||||||
const copyInviter = async () => {
|
const copyInviter = () => {
|
||||||
let input = document.createElement("input");
|
copy(
|
||||||
input.style.position = "fixed";
|
`【${data?.name}】『ID:${data?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/${data?.user_id}`
|
||||||
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("当前浏览器不支持复制功能,请检查更新或更换其他浏览器操作");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
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