From e069f04b5b48383ccd10f36a3221803eabf887f5 Mon Sep 17 00:00:00 2001 From: ZiuChen <457353192@qq.com> Date: Mon, 19 Sep 2022 18:34:18 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E6=81=A2=E5=A4=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BA=86=E6=8F=92=E4=BB=B6=E5=86=85=E7=BD=AE=E7=9A=84`?= =?UTF-8?q?=E6=94=B6=E8=97=8F`=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cpns/ClipSwitch.vue | 3 +- src/data/operation.json | 1 + src/global/initPlugin.js | 12 +++-- src/hooks/useClipOperate.js | 93 +++++++++++++++++++------------------ src/views/Main.vue | 4 +- 5 files changed, 62 insertions(+), 51 deletions(-) diff --git a/src/cpns/ClipSwitch.vue b/src/cpns/ClipSwitch.vue index 1962b39..3c7bdab 100644 --- a/src/cpns/ClipSwitch.vue +++ b/src/cpns/ClipSwitch.vue @@ -21,7 +21,8 @@ const tabs = ref([ { name: '📚 全部', type: 'all' }, { name: '📋 文字', type: 'text' }, { name: '⛺ 图片', type: 'image' }, - { name: '📂 文件', type: 'file' } + { name: '📂 文件', type: 'file' }, + { name: '⭐ 收藏', type: 'collect' } ]) const activeTab = ref('all') const emit = defineEmits(['onNavClick']) diff --git a/src/data/operation.json b/src/data/operation.json index 52e6e6e..703a2c8 100644 --- a/src/data/operation.json +++ b/src/data/operation.json @@ -3,6 +3,7 @@ { "id": "view", "title": "查看全部", "icon": "💬" }, { "id": "open-folder", "title": "打开文件夹", "icon": "📁" }, { "id": "collect", "title": "收藏", "icon": "⭐" }, + { "id": "un-collect", "title": "移出收藏", "icon": "📤" }, { "id": "remove", "title": "删除", "icon": "❌" }, { "id": "word-break", "title": "分词", "icon": "💣" }, { "id": "save-file", "title": "保存", "icon": "💾" } diff --git a/src/global/initPlugin.js b/src/global/initPlugin.js index 8d37c59..e3cfee2 100644 --- a/src/global/initPlugin.js +++ b/src/global/initPlugin.js @@ -25,7 +25,9 @@ export default function initPlugin() { // 将超过14天的数据删除 排除掉收藏 const now = new Date().getTime() const deleteTime = now - setting.database.maxage * 24 * 60 * 60 * 1000 // unicode - this.dataBase.data = this.dataBase.data?.filter((item) => item.updateTime > deleteTime) + this.dataBase.data = this.dataBase.data?.filter( + (item) => item.updateTime > deleteTime || item.collect + ) this.updateDataBaseLocal() } catch (err) { utools.showNotification('读取剪切板出错: ' + err) @@ -59,10 +61,14 @@ export default function initPlugin() { this.updateDataBase() const exceedCount = this.dataBase.data.length - setting.database.maxsize if (exceedCount > 0) { - // 达到条数限制 删除超出部分 + // 达到条数限制 在收藏条数限制内遍历非收藏历史并删除 + // 所有被移除的 item都存入tempList + const tmpList = [] for (let i = 0; i < exceedCount; i++) { - this.dataBase.data.pop() + const item = this.dataBase.data.pop() + tmpList.push(item) } + tmpList.forEach((item) => !item.collect || this.dataBase.data.push(item)) // 收藏内容 重新入栈 } this.updateDataBaseLocal() } diff --git a/src/hooks/useClipOperate.js b/src/hooks/useClipOperate.js index d761e76..85b0a88 100644 --- a/src/hooks/useClipOperate.js +++ b/src/hooks/useClipOperate.js @@ -23,10 +23,11 @@ export default function useClipOperate({ emit }) { const fl = JSON.parse(data) utools.shellShowItemInFolder(fl[0].path) // 取第一个文件的路径打开 } else if (id === 'collect') { - utools.redirect('添加到「备忘快贴」', { - type: typeMap[item.type], - data: item.data - }) + item.collect = true + window.db.updateDataBaseLocal() + } else if (id === 'un-collect') { + item.collect = undefined + window.db.updateDataBaseLocal() } else if (id === 'word-break') { utools.redirect('超级分词', item.data) } else if (id === 'save-file') { @@ -51,51 +52,51 @@ export default function useClipOperate({ emit }) { filterOperate: (operation, item, isFullData) => { const { id } = operation if (!isFullData) { - // 在非预览页 只展示配置在shown中的功能按钮 大小为 4 - for (const sid of setting.operation.shown) { - if (id === sid) return true - } - return false - } else { - if (id === 'copy') { - return true - } else if (id === 'view') { - return !isFullData - } else if (id === 'open-folder') { - return item.type === 'file' - } else if (id === 'collect') { - return item.type !== 'file' - } else if (id === 'word-break') { - return item.type === 'text' && item.data.length <= 500 && item.data.length >= 2 - } else if (id === 'save-file') { - return true - } else if (id === 'remove') { - return true - } else if (id.indexOf('custom') !== -1) { - // 如果匹配到了自定义的操作 则展示 - for (const m of operation.match) { - 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) { - if (r.test(f.name)) { - return true - } - } - } else { - return r.test(item.data) - } - } - } + // 在非预览页 只展示setting.operation.shown中的功能按钮 + if (!setting.operation.shown.includes(id)) { return false } } + if (id === 'copy') { + return true + } else if (id === 'view') { + return !isFullData + } else if (id === 'open-folder') { + return item.type === 'file' + } else if (id === 'collect') { + return item.type !== 'file' && !item.collect + } else if (id === 'un-collect') { + return item.type !== 'file' && item.collect + } else if (id === 'word-break') { + return item.type === 'text' && item.data.length <= 500 && item.data.length >= 2 + } else if (id === 'save-file') { + return true + } else if (id === 'remove') { + return true + } else if (id.indexOf('custom') !== -1) { + // 如果匹配到了自定义的操作 则展示 + for (const m of operation.match) { + 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) { + if (r.test(f.name)) { + return true + } + } + } else { + return r.test(item.data) + } + } + } + return false + } } } } diff --git a/src/views/Main.vue b/src/views/Main.vue index 4ffed48..251b750 100644 --- a/src/views/Main.vue +++ b/src/views/Main.vue @@ -156,7 +156,9 @@ const textFilterCallBack = (item) => { const updateShowList = (type) => { // 更新显示列表 showList.value = list.value - .filter((item) => (type === 'all' ? item : item.type === type)) // 是 all则返回所有 否则按照 type返回 + .filter((item) => + type === 'collect' ? item.collect === true : type === 'all' ? item : item.type === type + ) // 是 collect则返回所有收藏 否则按照 type返回 .filter((item) => (filterText.value ? item.type !== 'image' : item)) // 有过滤词 排除掉图片 DataURL .filter((item) => textFilterCallBack(item)) .slice(0, GAP) // 重新切分懒加载列表