revert: 恢复支持了插件内置的收藏功能

This commit is contained in:
ZiuChen 2022-09-19 18:34:18 +08:00
parent 1b8e664aac
commit e069f04b5b
5 changed files with 62 additions and 51 deletions

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

@ -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": "💾" }

View File

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

View File

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

View File

@ -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) //