PicList/src/renderer/components/TrayPage.vue

158 lines
4.5 KiB
Vue
Raw Normal View History

2017-11-27 19:21:12 -05:00
<template>
<div id="tray-page">
2017-11-28 10:56:15 -05:00
<!-- <div class="header-arrow"></div> -->
2017-11-27 19:21:12 -05:00
<div class="content">
<div class="wait-upload-img" v-if="clipboardFiles.length > 0">
<div class="list-title">等待上传</div>
<div v-for="(item, index) in clipboardFiles" :key="index" class="img-list" :style="{height: calcHeight(item.width, item.height) + 'px'}">
<div class="upload-img__container" @click="uploadClipboardFiles">
<img :src="item.imgUrl" class="upload-img">
</div>
</div>
</div>
<div class="uploaded-img">
<div class="list-title">已上传</div>
<div v-for="(item, index) in files" :key="index" class="img-list" :style="{height: calcHeight(item.width, item.height) + 'px'}">
<div class="upload-img__container" @click="copyTheLink(item)">
<img :src="item.imgUrl" class="upload-img">
</div>
</div>
</div>
</div>
</div>
</template>
<script>
2017-11-29 03:23:05 -05:00
import pasteTemplate from '../../main/utils/pasteTemplate'
2017-11-27 19:21:12 -05:00
export default {
name: 'tray-page',
data () {
return {
files: [],
notification: {
title: '复制链接成功',
body: '',
icon: ''
},
clipboardFiles: []
}
},
computed: {
reverseList () {
return this.files.slice().reverse()
}
},
mounted () {
this.disableDragFile()
this.getData()
this.$electron.ipcRenderer.on('dragFiles', (event, files) => {
2017-11-29 10:13:35 -05:00
files.forEach(item => {
this.$db.read().get('uploaded').insert(item).write()
})
this.files = this.$db.read().get('uploaded').slice().reverse().slice(0, 5).value()
2017-11-27 19:21:12 -05:00
})
this.$electron.ipcRenderer.on('clipboardFiles', (event, files) => {
this.clipboardFiles = files
})
2017-11-29 03:23:05 -05:00
this.$electron.ipcRenderer.on('uploadFiles', (event, files) => {
2017-11-29 10:13:35 -05:00
files.forEach(item => {
this.$db.read().get('uploaded').insert(item).write()
})
this.files = this.$db.read().get('uploaded').slice().reverse().slice(0, 5).value()
2017-11-27 19:21:12 -05:00
})
2017-12-07 01:33:14 -05:00
this.$electron.ipcRenderer.on('updateFiles', (event) => {
this.getData()
})
2017-11-27 19:21:12 -05:00
},
2017-11-28 10:56:15 -05:00
beforeDestroy () {
this.$electron.ipcRenderer.removeAllListeners('dragFiles')
this.$electron.ipcRenderer.removeAllListeners('clipboardFiles')
this.$electron.ipcRenderer.removeAllListeners('uploadClipboardFiles')
2017-12-07 01:33:14 -05:00
this.$electron.ipcRenderer.removeAllListeners('updateFiles')
2017-11-28 10:56:15 -05:00
},
2017-11-27 19:21:12 -05:00
methods: {
getData () {
2017-11-29 10:13:35 -05:00
this.files = this.$db.read().get('uploaded').slice().reverse().slice(0, 5).value()
2017-11-27 19:21:12 -05:00
},
copyTheLink (item) {
this.notification.body = item.imgUrl
this.notification.icon = item.imgUrl
const myNotification = new window.Notification(this.notification.title, this.notification)
2017-11-29 03:23:05 -05:00
const pasteStyle = this.$db.read().get('picBed.pasteStyle').value()
this.$electron.clipboard.writeText(pasteTemplate(pasteStyle, item.imgUrl))
2017-11-27 19:21:12 -05:00
myNotification.onclick = () => {
2017-11-29 03:23:05 -05:00
return true
2017-11-27 19:21:12 -05:00
}
},
calcHeight (width, height) {
return height * 160 / width
},
disableDragFile () {
window.addEventListener('dragover', (e) => {
e = e || event
e.preventDefault()
}, false)
window.addEventListener('drop', (e) => {
e = e || event
e.preventDefault()
}, false)
},
uploadClipboardFiles () {
this.$electron.ipcRenderer.send('uploadClipboardFiles', this.clipboardFiles[0])
}
}
}
</script>
<style lang="stylus">
#tray-page
.list-title
text-align center
color #858585
font-size 12px
padding 6px 0
position relative
&:before
content ''
position absolute
height 1px
width calc(100% - 36px)
bottom 0
left 18px
background #858585
.header-arrow
position absolute
top 12px
left 50%
margin-left -10px
width: 0;
height: 0;
border-left: 10px solid transparent
border-right: 10px solid transparent
border-bottom: 10px solid rgba(255,255,255, 1)
.content
position absolute
top 0px
width 100%
.img-list
padding 16px 8px
display flex
justify-content space-between
align-items center
height 45px
cursor pointer
transition all .2s ease-in-out
&:hover
background #49B1F5
.upload-img__index
color #fff
.upload-img
height 100%
width 100%
margin 0 auto
&__container
width 100%
padding 8px 10px
height 100%
</style>