Files
tonePage/apps/frontend/app/console/(with-menu)/web/blog/components/utils.ts

32 lines
933 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { BlogPermission } from "@/lib/types/Blog.Permission.enum";
import { toast } from "sonner";
export function copyShareURL(data: {
slug: string;
password: string;
permissions: BlogPermission[];
}) {
const slug = data.slug.trim();
const password = data.password.trim();
const permissions = data.permissions;
if (slug.length === 0) {
return toast.warning('请先填写Slug')
}
let url = `${window.location.origin}/blog/${slug}`;
if (permissions.includes(BlogPermission.ByPassword)) {
if (password.length === 0) {
return toast.warning('开启了密码保护但无法获取有效的密码无法生成有效URL')
} else {
url += `?p=${password}`;
}
}
navigator.clipboard.writeText(url).then(() => {
toast.success('复制成功');
}, () => {
toast.error('复制失败,请手动复制');
});
};