From 813cc96ce07aa1455068e45f105a6f80b2ff5465 Mon Sep 17 00:00:00 2001 From: ZiuChen <457353192@qq.com> Date: Sun, 18 Sep 2022 13:04:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8C=B9=E9=85=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8=E6=AD=A3=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/setting.json | 14 ++++++++++++++ src/hooks/useClipOperate.js | 30 ++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/data/setting.json b/src/data/setting.json index 52d1a7e..f7abdd1 100644 --- a/src/data/setting.json +++ b/src/data/setting.json @@ -17,6 +17,20 @@ "icon": "🔍", "match": ["text"], "command": "redirect:百度一下" + }, + { + "id": "custom.1663468466", + "title": "上传到图床", + "icon": "🚀", + "match": ["image", { "type": "file", "regex": "/.*(jpg|png|jpeg|gif)$/i" }], + "command": "redirect:上传到图床" + }, + { + "id": "custom.1663476961", + "title": "翻译", + "icon": "🌎", + "match": ["text"], + "command": "redirect:翻译" } ] } diff --git a/src/hooks/useClipOperate.js b/src/hooks/useClipOperate.js index a216f98..0b73050 100644 --- a/src/hooks/useClipOperate.js +++ b/src/hooks/useClipOperate.js @@ -32,7 +32,7 @@ export default function useClipOperate({ emit }) { } else if (id === 'save-file') { utools.redirect('收集文件', { type: typeMap[item.type], - data: item.data + data: item.type === 'file' ? JSON.parse(item.data).map((f) => f.path) : item.data }) } else if (id === 'remove') { window.remove(item) @@ -42,13 +42,12 @@ export default function useClipOperate({ emit }) { if (a[0] === 'redirect') { utools.redirect(a[1], { type: typeMap[item.type], - data: item.data + data: item.type === 'file' ? JSON.parse(item.data).map((f) => f.path) : item.data }) } } emit('onOperateExecute') }, - filterOperate: (operation, item, isFullData) => { const { id } = operation if (!isFullData) { @@ -69,14 +68,33 @@ export default function useClipOperate({ emit }) { } else if (id === 'word-break') { return item.type === 'text' && item.data.length <= 500 && item.data.length >= 2 } else if (id === 'save-file') { - return item.type === 'file' + return true } else if (id === 'remove') { return true } else if (id.indexOf('custom') !== -1) { // 如果匹配到了自定义的操作 则展示 for (const m of operation.match) { - if (item.type === m) { - return true + if (typeof m === 'string') { + if (item.type === m) { + return true + } + } else if (typeof m === 'object') { + // 根据正则匹配内容 + const r = new RegExp(m.regex) + if (item.type === 'file') { + const fl = JSON.parse(item.data) + for (const f of fl) { + console.log(f.name, r.test(f.name)) + // TODO: fix: 图片文件不能正确匹配 + if (r.test(f.name)) { + return true + } + } + } else { + if (r.test(item.data)) { + return true + } + } } } return false