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()
}
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

View File

@ -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
}
}

View File

@ -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'])

View File

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