feat: update

This commit is contained in:
ZiuChen 2022-08-14 18:16:13 +08:00
parent c2ce1cdeec
commit d405590d01
3 changed files with 38 additions and 15 deletions

View File

@ -56,7 +56,6 @@ class DB {
} }
updateDataBaseLocal(dataBase) { updateDataBaseLocal(dataBase) {
// 更新文件数据 // 更新文件数据
console.log('updateDataBaseLocal')
fs.writeFileSync(this.path, JSON.stringify(dataBase || this.dataBase), (err) => { fs.writeFileSync(this.path, JSON.stringify(dataBase || this.dataBase), (err) => {
if (err) { if (err) {
utools.showNotification('写入剪切板出错' + err) utools.showNotification('写入剪切板出错' + err)
@ -86,7 +85,6 @@ class DB {
} }
updateItemViaId(id) { updateItemViaId(id) {
for (const item of this.dataBase.data) { for (const item of this.dataBase.data) {
console.log(item.id, id)
if (item.id === id) { if (item.id === id) {
item.updateTime = new Date().getTime() item.updateTime = new Date().getTime()
this.sortDataBaseViaTime() this.sortDataBaseViaTime()

View File

@ -2,8 +2,6 @@
<div class="clip-file-list"> <div class="clip-file-list">
<div class="clip-file" v-for="file of data.slice(0, 8)" @click.stop="openFile(file.path)"> <div class="clip-file" v-for="file of data.slice(0, 8)" @click.stop="openFile(file.path)">
<img class="clip-file-icon" :src="getIcon(file.path)" alt="icon" /> <img class="clip-file-icon" :src="getIcon(file.path)" alt="icon" />
<!-- <span class="clip-file-icon" v-if="file.isFile">📄</span>
<span class="clip-folder-icon" v-else>📁</span> -->
{{ file.name }} {{ file.name }}
</div> </div>
</div> </div>
@ -30,6 +28,12 @@ export default {
</script> </script>
<style scoped> <style scoped>
.clip-file {
display: flex;
justify-content: flex-start;
align-items: center;
cursor: pointer;
}
.clip-file:hover { .clip-file:hover {
font-weight: 600; font-weight: 600;
} }

View File

@ -6,7 +6,7 @@
<div v-if="fullData.type === 'text'"> <div v-if="fullData.type === 'text'">
<div v-text="fullData.data"></div> <div v-text="fullData.data"></div>
</div> </div>
<div v-if="fullData.type === 'file'"> <div v-else>
<file-list :data="fullData.data"></file-list> <file-list :data="fullData.data"></file-list>
</div> </div>
</div> </div>
@ -76,7 +76,7 @@ export default {
offset: 0, offset: 0,
showList: [], showList: [],
list: [], list: [],
fullData: { type: '', data: '' }, fullData: { type: 'text', data: '' },
fullDataShow: false, fullDataShow: false,
tabs: [ tabs: [
{ {
@ -105,12 +105,24 @@ export default {
// //
this.toggleNav(this.activeTab) this.toggleNav(this.activeTab)
//
let prev = {}
setInterval(() => {
const now = window.db.dataBase.data[0]
if (prev?.id === now?.id) {
} else {
//
this.list = window.db.dataBase.data
this.toggleNav(this.activeTab)
prev = now
}
}, 500)
// //
document.addEventListener('scroll', (e) => { const callBack = (e) => {
console.log('scroll')
const { scrollTop, clientHeight, scrollHeight } = e.target.scrollingElement const { scrollTop, clientHeight, scrollHeight } = e.target.scrollingElement
if (scrollTop + clientHeight + 25 >= scrollHeight) { if (scrollTop + clientHeight + 10 >= scrollHeight) {
console.log('bottom')
this.offset += this.GAP + 1 this.offset += this.GAP + 1
let addition = [] let addition = []
if (this.activeTab !== 'all') { if (this.activeTab !== 'all') {
@ -123,11 +135,16 @@ export default {
this.showList.push(...addition) this.showList.push(...addition)
} }
} }
}) }
document.addEventListener('scroll', callBack)
}, },
methods: { methods: {
toggleNav(type) { toggleNav(type) {
//
this.activeTab = type this.activeTab = type
this.updateShowList()
},
updateShowList(type = this.activeTab) {
if (type === 'all') { if (type === 'all') {
this.showList = this.list.slice(0, this.GAP) this.showList = this.list.slice(0, this.GAP)
} else { } else {
@ -159,20 +176,24 @@ export default {
// only text || file // only text || file
const { type, data } = item const { type, data } = item
if (type === 'text') { if (type === 'text') {
this.fullData.type === 'text' this.fullData.type = 'text'
this.fullData.data = data this.fullData.data = data
} else if (type === 'file') { } else if (type === 'file') {
this.fullData.type === 'file' this.fullData.type = 'file'
this.fullData.data = JSON.parse(data) this.fullData.data = JSON.parse(data)
} }
this.fullDataShow = !this.fullDataShow this.fullDataShow = !this.fullDataShow
}, },
executeCopy(item) { executeCopy(item) {
window.copy(item) window.copy(item)
}, },
restoreDataBase() { restoreDataBase() {
console.log('restore clicked') const flag = window.confirm('确定要清空剪贴板记录吗?')
// window.db.emptyDataBase() if (flag) {
window.db.emptyDataBase()
this.updateShowList()
}
} }
} }
} }