diff --git a/public/preload.js b/public/preload.js index 0bd7a67..11b1f11 100644 --- a/public/preload.js +++ b/public/preload.js @@ -106,6 +106,16 @@ class DB { }) this.updateDataBaseLocal() } + removeItemViaId(id) { + for (const item of this.dataBase.data) { + if (item.id === id) { + this.dataBase.data.splice(this.dataBase.data.indexOf(item), 1) + this.updateDataBaseLocal() + return true + } + } + return false + } } const pbpaste = async () => { @@ -171,12 +181,15 @@ const paste = () => { else utools.simulateKeyboardTap('v', 'ctrl') } +const db = new DB(DBPath) +db.init() + +const remove = (item) => db.removeItemViaId(item.id) + const focus = () => document.querySelector('.clip-search input')?.focus() const toTop = () => (document.scrollingElement.scrollTop = 0) const resetNav = () => document.querySelectorAll('.clip-switch-item')[0]?.click() -const db = new DB(DBPath) -db.init() watchClipboard(db, (item) => { // 此函数不断执行 if (!item) return @@ -204,6 +217,7 @@ utools.onPluginEnter(() => { window.db = db window.copy = copy window.paste = paste +window.remove = remove window.openFile = utools.shellOpenPath window.getIcon = utools.getFileIcon window.focus = focus diff --git a/src/cpns/ClipItemList.vue b/src/cpns/ClipItemList.vue index 1078997..3cc6e80 100644 --- a/src/cpns/ClipItemList.vue +++ b/src/cpns/ClipItemList.vue @@ -75,7 +75,7 @@ const props = defineProps({ required: true } }) -const emit = defineEmits(['onDataChange']) +const emit = defineEmits(['onDataChange', 'onDataRemove']) const handleItemClick = (ev, item) => { const { button } = ev if (button === 0) { @@ -91,26 +91,20 @@ const handleDataClick = (item) => emit('onDataChange', item) const activeIndex = ref(0) const handleMouseOver = (index) => (activeIndex.value = index) const operation = [ - { - id: 'collect', - title: '收藏' - }, - { - id: 'big-bang', - title: '分词' - }, - { - id: 'delete', - title: '删除' - } + { id: 'copy', title: '复制' }, + { id: 'collect', title: '收藏' }, + { id: 'remove', title: '删除' } ] -const handleOperateClick = (type) => { - switch (type) { +const handleOperateClick = ({ id, item }) => { + switch (id) { + case 'copy': + window.copy(item) + break case 'collect': break - case 'big-bang': - break case 'remove': + window.remove(item) + emit('onDataRemove') break } } 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/views/Main.vue b/src/views/Main.vue index c487d26..9576336 100644 --- a/src/views/Main.vue +++ b/src/views/Main.vue @@ -13,7 +13,12 @@