feat: 添加删除单条历史功能

This commit is contained in:
ZiuChen 2022-09-04 13:28:17 +08:00
parent 4156c915fd
commit fcca51cd07
4 changed files with 47 additions and 25 deletions

View File

@ -106,6 +106,16 @@ class DB {
}) })
this.updateDataBaseLocal() 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 () => { const pbpaste = async () => {
@ -171,12 +181,15 @@ const paste = () => {
else utools.simulateKeyboardTap('v', 'ctrl') 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 focus = () => document.querySelector('.clip-search input')?.focus()
const toTop = () => (document.scrollingElement.scrollTop = 0) const toTop = () => (document.scrollingElement.scrollTop = 0)
const resetNav = () => document.querySelectorAll('.clip-switch-item')[0]?.click() const resetNav = () => document.querySelectorAll('.clip-switch-item')[0]?.click()
const db = new DB(DBPath)
db.init()
watchClipboard(db, (item) => { watchClipboard(db, (item) => {
// 此函数不断执行 // 此函数不断执行
if (!item) return if (!item) return
@ -204,6 +217,7 @@ utools.onPluginEnter(() => {
window.db = db window.db = db
window.copy = copy window.copy = copy
window.paste = paste window.paste = paste
window.remove = remove
window.openFile = utools.shellOpenPath window.openFile = utools.shellOpenPath
window.getIcon = utools.getFileIcon window.getIcon = utools.getFileIcon
window.focus = focus window.focus = focus

View File

@ -75,7 +75,7 @@ const props = defineProps({
required: true required: true
} }
}) })
const emit = defineEmits(['onDataChange']) const emit = defineEmits(['onDataChange', 'onDataRemove'])
const handleItemClick = (ev, item) => { const handleItemClick = (ev, item) => {
const { button } = ev const { button } = ev
if (button === 0) { if (button === 0) {
@ -91,26 +91,20 @@ const handleDataClick = (item) => emit('onDataChange', item)
const activeIndex = ref(0) const activeIndex = ref(0)
const handleMouseOver = (index) => (activeIndex.value = index) const handleMouseOver = (index) => (activeIndex.value = index)
const operation = [ const operation = [
{ { id: 'copy', title: '复制' },
id: 'collect', { id: 'collect', title: '收藏' },
title: '收藏' { id: 'remove', title: '删除' }
},
{
id: 'big-bang',
title: '分词'
},
{
id: 'delete',
title: '删除'
}
] ]
const handleOperateClick = (type) => { const handleOperateClick = ({ id, item }) => {
switch (type) { switch (id) {
case 'copy':
window.copy(item)
break
case 'collect': case 'collect':
break break
case 'big-bang':
break
case 'remove': case 'remove':
window.remove(item)
emit('onDataRemove')
break break
} }
} }

View File

@ -21,7 +21,8 @@ const tabs = ref([
{ name: '📚 全部', type: 'all' }, { name: '📚 全部', type: 'all' },
{ name: '📋 文字', type: 'text' }, { name: '📋 文字', type: 'text' },
{ name: '⛺ 图片', type: 'image' }, { name: '⛺ 图片', type: 'image' },
{ name: '📂 文件', type: 'file' } { name: '📂 文件', type: 'file' },
{ name: '⭐ 收藏', type: 'collect' }
]) ])
const activeTab = ref('all') const activeTab = ref('all')
const emit = defineEmits(['onNavClick']) const emit = defineEmits(['onNavClick'])

View File

@ -13,7 +13,12 @@
</ClipSwitch> </ClipSwitch>
<div class="clip-break"></div> <div class="clip-break"></div>
<div class="clip-empty-status" v-if="showList.length === 0">📪 无记录</div> <div class="clip-empty-status" v-if="showList.length === 0">📪 无记录</div>
<ClipItemList :showList="showList" :fullData="fullData" @onDataChange="toggleFullData"> <ClipItemList
:showList="showList"
:fullData="fullData"
@onDataChange="toggleFullData"
@onDataRemove="handleDataRemove"
>
</ClipItemList> </ClipItemList>
</div> </div>
</template> </template>
@ -67,6 +72,14 @@ const toggleFullData = (item) => {
fullDataShow.value = !fullDataShow.value fullDataShow.value = !fullDataShow.value
} }
const ClipSwitchRef = ref()
const handleDataRemove = () => {
//
list.value = window.db.dataBase.data
updateShowList(ClipSwitchRef.value.activeTab)
}
const restoreDataBase = () => { const restoreDataBase = () => {
// //
const flag = window.confirm('确定要清空剪贴板记录吗?') const flag = window.confirm('确定要清空剪贴板记录吗?')
@ -76,11 +89,11 @@ const restoreDataBase = () => {
} }
} }
const ClipSwitchRef = ref()
onMounted(() => { onMounted(() => {
// Ref // Ref
const activeTab = computed(() => ClipSwitchRef.value.activeTab) const activeTab = computed(() => ClipSwitchRef.value.activeTab)
const toggleNav = ClipSwitchRef.value.toggleNav const toggleNav = ClipSwitchRef.value.toggleNav
const tabs = ClipSwitchRef.value.tabs
// //
list.value = window.db.dataBase.data list.value = window.db.dataBase.data
@ -129,9 +142,9 @@ onMounted(() => {
(ctrlKey && (key === 'F' || key === 'f')) || (ctrlKey && (key === 'L' || key === 'l')) (ctrlKey && (key === 'F' || key === 'f')) || (ctrlKey && (key === 'L' || key === 'l'))
const isExit = key === 'Escape' const isExit = key === 'Escape'
if (isTab) { if (isTab) {
const list = ['all', 'text', 'image', 'file'] const tabTypes = tabs.map((item) => item.type)
const index = list.indexOf(activeTab.value) const index = tabTypes.indexOf(activeTab.value)
const target = index === list.length - 1 ? list[0] : list[index + 1] const target = index === tabTypes.length - 1 ? tabTypes[0] : tabTypes[index + 1]
toggleNav(target) toggleNav(target)
updateShowList(activeTab.value) updateShowList(activeTab.value)
} else if (isSearch) { } else if (isSearch) {