From 3290dece37a3f331d44ac7ec62e9bfd416c6ab59 Mon Sep 17 00:00:00 2001 From: mereith Date: Mon, 26 Jun 2023 19:21:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=AC=E5=9C=B0=E5=9B=BE=E5=BA=8A?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=92=8C=E6=8F=92=E5=85=A5markdown=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E6=94=B9=E4=B8=BA=E7=9B=B8=E5=AF=B9url=20#303?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/admin/src/components/Editor/imgUpload.tsx | 2 +- packages/admin/src/pages/Static/img/index.tsx | 10 +++++++++- packages/admin/src/pages/Static/img/tools.tsx | 12 ++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/admin/src/components/Editor/imgUpload.tsx b/packages/admin/src/components/Editor/imgUpload.tsx index 589c414fb..807554927 100644 --- a/packages/admin/src/components/Editor/imgUpload.tsx +++ b/packages/admin/src/components/Editor/imgUpload.tsx @@ -17,7 +17,7 @@ export const uploadImg = async (file: File) => { }); const data = await res.json(); if (data && data.statusCode == 200) { - const url = getImgLink(data.data.src); + const url = getImgLink(data.data.src, false); copyImgLink(data.data.src, true, '上传成功! '); return url; } else { diff --git a/packages/admin/src/pages/Static/img/index.tsx b/packages/admin/src/pages/Static/img/index.tsx index 9ea582f13..2f007b5ec 100644 --- a/packages/admin/src/pages/Static/img/index.tsx +++ b/packages/admin/src/pages/Static/img/index.tsx @@ -92,7 +92,10 @@ const ImgPage = () => { copyImgLink(clickItem.realPath); break; case 'copyMarkdown': - copyImgLink(clickItem.realPath, true); + copyImgLink(clickItem.realPath, true, undefined, false); + break; + case 'copyMarkdownAbsolutely': + copyImgLink(clickItem.realPath, true, undefined, true); break; case 'delete': Modal.confirm({ @@ -216,6 +219,7 @@ const ImgPage = () => { data.src, true, data.isNew ? '剪切板图片上传成功! ' : '剪切板图片已存在! ', + false ); fetchData(); @@ -232,6 +236,7 @@ const ImgPage = () => { info?.response?.data?.src, true, info?.response?.data?.isNew ? `${info.name} 上传成功! ` : `${info.name} 已存在! `, + false ); fetchData(); @@ -250,6 +255,9 @@ const ImgPage = () => { 复制 Markdown 链接 + + 复制完整 Markdown 链接 + 下载 diff --git a/packages/admin/src/pages/Static/img/tools.tsx b/packages/admin/src/pages/Static/img/tools.tsx index e96772a93..7b6320408 100644 --- a/packages/admin/src/pages/Static/img/tools.tsx +++ b/packages/admin/src/pages/Static/img/tools.tsx @@ -1,17 +1,21 @@ import { writeClipBoardText } from '@/services/van-blog/clipboard'; import { message } from 'antd'; import { StaticItem } from '../type'; -export const getImgLink = (realPath) => { - let url = `${window.location.protocol}//${window.location.host}${realPath}`; +export const getImgLink = (realPath, autoCompleteHost = true) => { + let url = realPath; if (realPath.includes('http://') || realPath.includes('https://')) { url = realPath; + } else { + if (autoCompleteHost) { + url = `${window.location.protocol}//${window.location.host}${realPath}`; + } } url = url.replace(/\)/g, '%29'); url = url.replace(/\(/g, '%28'); return url; }; -export const copyImgLink = (realPath, isMarkdown = false, info = undefined) => { - let url = getImgLink(realPath); +export const copyImgLink = (realPath, isMarkdown = false, info = undefined, autoCompleteHost= true) => { + let url = getImgLink(realPath, autoCompleteHost); if (isMarkdown) { url = `![](${url})`; }