2017-12-06 22:26:29 -05:00
|
|
|
<template>
|
|
|
|
<div id="gallery-view">
|
|
|
|
<div class="view-title">
|
2018-07-05 08:21:43 -04:00
|
|
|
相册 - {{ filterList.length }} <i class="el-icon-caret-bottom" @click="toggleHandleBar" :class="{'active': handleBarActive}"></i>
|
2017-12-06 22:26:29 -05:00
|
|
|
</div>
|
2018-07-05 08:21:43 -04:00
|
|
|
<transition name="el-zoom-in-center">
|
|
|
|
<el-row v-show="handleBarActive">
|
|
|
|
<el-col :span="20" :offset="2" :class="{ 'long-list': filterList.length > 4 }">
|
|
|
|
<el-row class="handle-bar" :gutter="16">
|
|
|
|
<el-col :span="6" v-for="item in $picBed" :key="item.type">
|
|
|
|
<div class="pic-bed-item" @click="choosePicBed(item.type)" :class="{active: choosedPicBed.indexOf(item.type) !== -1}">
|
|
|
|
{{ item.name }}
|
|
|
|
</div>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
|
|
|
<el-row class="handle-bar" :gutter="16">
|
|
|
|
<el-col :span="12">
|
2018-07-23 10:24:18 -04:00
|
|
|
<el-input placeholder="搜索" size="mini" v-model="searchText">
|
|
|
|
<i slot="suffix" class="el-input__icon el-icon-close" v-if="searchText" @click="cleanSearch" style="cursor: pointer"></i>
|
|
|
|
</el-input>
|
2018-07-05 08:21:43 -04:00
|
|
|
</el-col>
|
|
|
|
<el-col :span="6">
|
2018-07-23 10:24:18 -04:00
|
|
|
<div class="item-base copy" :class="{ active: isMultiple(choosedList)}" @click="multiCopy">
|
|
|
|
<i class="el-icon-document"></i> 批量复制
|
2018-07-05 08:21:43 -04:00
|
|
|
</div>
|
|
|
|
</el-col>
|
|
|
|
<el-col :span="6">
|
|
|
|
<div class="item-base delete" :class="{ active: isMultiple(choosedList)}" @click="multiDelete">
|
|
|
|
<i class="el-icon-delete"></i> 批量删除
|
|
|
|
</div>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
|
|
|
</transition>
|
|
|
|
<el-row class="gallery-list" :class="{ small: handleBarActive }">
|
2017-12-06 22:26:29 -05:00
|
|
|
<el-col :span="20" :offset="2">
|
|
|
|
<el-row :gutter="16">
|
|
|
|
<gallerys
|
|
|
|
:images="images"
|
|
|
|
:index="idx"
|
|
|
|
@close="handleClose"
|
|
|
|
:options="options"
|
|
|
|
></gallerys>
|
2018-06-19 01:45:07 -04:00
|
|
|
<el-col :span="6" v-for="(item, index) in images" :key="item.id" class="gallery-list__img">
|
2017-12-06 22:26:29 -05:00
|
|
|
<div
|
|
|
|
class="gallery-list__item"
|
2018-06-26 09:11:04 -04:00
|
|
|
v-lazy:background-image="item.imgUrl"
|
2017-12-06 22:26:29 -05:00
|
|
|
@click="zoomImage(index)"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
<div class="gallery-list__tool-panel">
|
2018-04-27 12:16:17 -04:00
|
|
|
<i class="el-icon-document" @click="copy(item.imgUrl)"></i>
|
2018-04-08 11:43:34 -04:00
|
|
|
<i class="el-icon-edit-outline" @click="openDialog(item)"></i>
|
2017-12-06 22:26:29 -05:00
|
|
|
<i class="el-icon-delete" @click="remove(item.id)"></i>
|
2018-07-05 08:21:43 -04:00
|
|
|
<el-checkbox v-model="choosedList[item.id]" class="pull-right" @change=" handleBarActive = true"></el-checkbox>
|
2017-12-06 22:26:29 -05:00
|
|
|
</div>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
2018-04-08 11:43:34 -04:00
|
|
|
<el-dialog
|
|
|
|
:visible.sync="dialogVisible"
|
|
|
|
title="修改图片URL"
|
|
|
|
width="500px"
|
|
|
|
:modal-append-to-body="false"
|
|
|
|
>
|
|
|
|
<el-input v-model="imgInfo.imgUrl"></el-input>
|
|
|
|
<span slot="footer" class="dialog-footer">
|
|
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
|
|
<el-button type="primary" @click="confirmModify">确 定</el-button>
|
|
|
|
</span>
|
|
|
|
</el-dialog>
|
2017-12-06 22:26:29 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import gallerys from 'vue-gallery'
|
|
|
|
import pasteStyle from '../../../main/utils/pasteTemplate'
|
|
|
|
export default {
|
|
|
|
name: 'gallery',
|
|
|
|
components: {
|
|
|
|
gallerys
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
images: [],
|
|
|
|
idx: null,
|
|
|
|
options: {
|
|
|
|
titleProperty: 'fileName',
|
|
|
|
urlProperty: 'imgUrl',
|
|
|
|
closeOnSlideClick: true
|
2018-04-08 11:43:34 -04:00
|
|
|
},
|
|
|
|
dialogVisible: false,
|
|
|
|
imgInfo: {
|
|
|
|
id: null,
|
|
|
|
imgUrl: ''
|
2018-06-19 01:45:07 -04:00
|
|
|
},
|
|
|
|
choosedList: {},
|
2018-06-20 08:45:12 -04:00
|
|
|
choosedPicBed: [],
|
2018-07-05 08:21:43 -04:00
|
|
|
searchText: '',
|
|
|
|
handleBarActive: false
|
2017-12-06 22:26:29 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created () {
|
|
|
|
this.getGallery()
|
2018-08-07 23:21:08 -04:00
|
|
|
this.$electron.ipcRenderer.on('updateGallery', (event) => {
|
|
|
|
this.filterList = this.getGallery()
|
|
|
|
})
|
2017-12-06 22:26:29 -05:00
|
|
|
},
|
2018-06-20 08:45:12 -04:00
|
|
|
computed: {
|
2018-08-07 23:21:08 -04:00
|
|
|
filterList: {
|
|
|
|
get () {
|
|
|
|
return this.getGallery()
|
|
|
|
},
|
|
|
|
set (val) {
|
|
|
|
return this.val
|
|
|
|
}
|
2018-06-20 08:45:12 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getGallery () {
|
|
|
|
if (this.choosedPicBed.length > 0) {
|
2018-06-19 01:45:07 -04:00
|
|
|
let arr = []
|
2018-06-20 08:45:12 -04:00
|
|
|
this.choosedPicBed.forEach(item => {
|
|
|
|
let obj = {
|
|
|
|
type: item
|
|
|
|
}
|
|
|
|
if (this.searchText) {
|
|
|
|
obj.fileName = this.searchText
|
|
|
|
}
|
|
|
|
arr = arr.concat(this.$db.read().get('uploaded').filter(obj => {
|
|
|
|
return obj.fileName.indexOf(this.searchText) !== -1 && obj.type === item
|
|
|
|
}).reverse().value())
|
2018-06-19 01:45:07 -04:00
|
|
|
})
|
|
|
|
this.images = arr
|
|
|
|
} else {
|
2018-06-20 08:45:12 -04:00
|
|
|
if (this.searchText) {
|
|
|
|
let data = this.$db.read().get('uploaded')
|
|
|
|
.filter(item => {
|
|
|
|
return item.fileName.indexOf(this.searchText) !== -1
|
|
|
|
}).reverse().value()
|
|
|
|
this.images = data
|
|
|
|
} else {
|
|
|
|
this.images = this.$db.read().get('uploaded').slice().reverse().value()
|
|
|
|
}
|
2018-06-19 01:45:07 -04:00
|
|
|
}
|
2018-06-20 08:45:12 -04:00
|
|
|
return this.images
|
2017-12-06 22:26:29 -05:00
|
|
|
},
|
|
|
|
zoomImage (index) {
|
|
|
|
this.idx = index
|
|
|
|
},
|
|
|
|
handleClose () {
|
|
|
|
this.idx = null
|
|
|
|
},
|
|
|
|
copy (url) {
|
2018-07-23 10:24:18 -04:00
|
|
|
const style = this.$db.read().get('picBed.pasteStyle').value() || 'markdown'
|
2017-12-06 22:26:29 -05:00
|
|
|
const copyLink = pasteStyle(style, url)
|
|
|
|
const obj = {
|
|
|
|
title: '复制链接成功',
|
|
|
|
body: copyLink,
|
|
|
|
icon: url
|
|
|
|
}
|
|
|
|
const myNotification = new window.Notification(obj.title, obj)
|
|
|
|
this.$electron.clipboard.writeText(copyLink)
|
|
|
|
myNotification.onclick = () => {
|
2018-07-24 11:15:19 -04:00
|
|
|
return true
|
2017-12-06 22:26:29 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
remove (id) {
|
|
|
|
this.$confirm('此操作将把该图片移出相册, 是否继续?', '提示', {
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning'
|
|
|
|
}).then(() => {
|
|
|
|
this.$db.read().get('uploaded').removeById(id).write()
|
|
|
|
const obj = {
|
|
|
|
title: '操作结果',
|
|
|
|
body: '删除成功'
|
|
|
|
}
|
|
|
|
const myNotification = new window.Notification(obj.title, obj)
|
|
|
|
myNotification.onclick = () => {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
this.getGallery()
|
|
|
|
}).catch(() => {
|
|
|
|
return true
|
|
|
|
})
|
2018-04-08 11:43:34 -04:00
|
|
|
},
|
|
|
|
openDialog (item) {
|
|
|
|
this.imgInfo.id = item.id
|
|
|
|
this.imgInfo.imgUrl = item.imgUrl
|
|
|
|
this.dialogVisible = true
|
|
|
|
},
|
|
|
|
confirmModify () {
|
|
|
|
this.$db.read().get('uploaded')
|
|
|
|
.getById(this.imgInfo.id)
|
|
|
|
.assign({imgUrl: this.imgInfo.imgUrl})
|
|
|
|
.write()
|
|
|
|
const obj = {
|
|
|
|
title: '修改图片URL成功',
|
|
|
|
body: this.imgInfo.imgUrl,
|
|
|
|
icon: this.imgInfo.imgUrl
|
|
|
|
}
|
|
|
|
const myNotification = new window.Notification(obj.title, obj)
|
|
|
|
myNotification.onclick = () => {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
this.dialogVisible = false
|
|
|
|
this.getGallery()
|
2018-06-19 01:45:07 -04:00
|
|
|
},
|
|
|
|
choosePicBed (type) {
|
|
|
|
let idx = this.choosedPicBed.indexOf(type)
|
|
|
|
if (idx !== -1) {
|
|
|
|
this.choosedPicBed.splice(idx, 1)
|
|
|
|
} else {
|
|
|
|
this.choosedPicBed.push(type)
|
|
|
|
}
|
2018-06-20 08:45:12 -04:00
|
|
|
},
|
|
|
|
cleanSearch () {
|
|
|
|
this.searchText = ''
|
|
|
|
},
|
|
|
|
isMultiple (obj) {
|
|
|
|
return Object.values(obj).some(item => item)
|
|
|
|
},
|
|
|
|
multiDelete () {
|
|
|
|
if (Object.values(this.choosedList).some(item => item)) {
|
|
|
|
this.$confirm('将删除刚才选中的图片,是否继续?', '提示', {
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning'
|
|
|
|
}).then(() => {
|
|
|
|
Object.keys(this.choosedList).forEach(key => {
|
|
|
|
if (this.choosedList[key]) {
|
|
|
|
this.$db.read().get('uploaded').removeById(key).write()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.choosedList = {}
|
|
|
|
this.getGallery()
|
|
|
|
const obj = {
|
|
|
|
title: '操作结果',
|
|
|
|
body: '删除成功'
|
|
|
|
}
|
|
|
|
const myNotification = new window.Notification(obj.title, obj)
|
|
|
|
myNotification.onclick = () => {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}).catch(() => {
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|
2018-07-05 08:21:43 -04:00
|
|
|
},
|
2018-07-23 10:24:18 -04:00
|
|
|
multiCopy () {
|
2018-07-24 11:15:19 -04:00
|
|
|
if (Object.values(this.choosedList).some(item => item)) {
|
|
|
|
let copyString = ''
|
|
|
|
const style = this.$db.read().get('picBed.pasteStyle').value() || 'markdown'
|
|
|
|
Object.keys(this.choosedList).forEach(key => {
|
|
|
|
if (this.choosedList[key]) {
|
|
|
|
copyString += pasteStyle(style, this.$db.read().get('uploaded').getById(key).value().imgUrl) + '\n'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const obj = {
|
|
|
|
title: '批量复制链接成功',
|
|
|
|
body: copyString
|
|
|
|
}
|
|
|
|
const myNotification = new window.Notification(obj.title, obj)
|
|
|
|
this.$electron.clipboard.writeText(copyString)
|
|
|
|
myNotification.onclick = () => {
|
|
|
|
return true
|
2018-07-23 10:24:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-07-05 08:21:43 -04:00
|
|
|
toggleHandleBar () {
|
|
|
|
this.handleBarActive = !this.handleBarActive
|
2017-12-06 22:26:29 -05:00
|
|
|
}
|
2018-08-07 23:21:08 -04:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
this.$electron.ipcRenderer.removeAllListeners('updateGallery')
|
2017-12-06 22:26:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang='stylus'>
|
|
|
|
.view-title
|
|
|
|
color #eee
|
|
|
|
font-size 20px
|
|
|
|
text-align center
|
2018-04-28 04:22:35 -04:00
|
|
|
margin 10px auto
|
|
|
|
.sub-title
|
|
|
|
font-size 14px
|
2018-07-05 08:21:43 -04:00
|
|
|
.el-icon-caret-bottom
|
|
|
|
cursor: pointer
|
|
|
|
transition all .2s ease-in-out
|
|
|
|
&.active
|
|
|
|
transform: rotate(180deg)
|
2018-06-19 01:45:07 -04:00
|
|
|
.item-base
|
|
|
|
background #2E2E2E
|
|
|
|
text-align center
|
|
|
|
margin-bottom 10px
|
2018-06-20 08:45:12 -04:00
|
|
|
padding 5px 0
|
2018-06-19 01:45:07 -04:00
|
|
|
cursor pointer
|
|
|
|
font-size 13px
|
|
|
|
transition all .2s ease-in-out
|
2018-07-23 10:24:18 -04:00
|
|
|
&.copy
|
|
|
|
cursor not-allowed
|
|
|
|
background #49B1F5
|
|
|
|
&.active
|
|
|
|
cursor pointer
|
|
|
|
background #1B9EF3
|
|
|
|
color #fff
|
2018-06-19 01:45:07 -04:00
|
|
|
&.delete
|
|
|
|
cursor not-allowed
|
2018-06-20 08:45:12 -04:00
|
|
|
background #F47466
|
2018-07-23 10:24:18 -04:00
|
|
|
&.active
|
|
|
|
cursor pointer
|
|
|
|
background #F15140
|
|
|
|
color #fff
|
2018-07-05 08:21:43 -04:00
|
|
|
.long-list
|
|
|
|
width: calc(83.3333333% - 6px)
|
2017-12-06 22:26:29 -05:00
|
|
|
#gallery-view
|
2018-07-05 08:21:43 -04:00
|
|
|
position relative
|
2018-06-19 01:45:07 -04:00
|
|
|
.pull-right
|
|
|
|
float right
|
2017-12-06 22:26:29 -05:00
|
|
|
.gallery-list
|
|
|
|
height 360px
|
|
|
|
box-sizing border-box
|
|
|
|
padding 8px 0
|
|
|
|
overflow-y auto
|
|
|
|
overflow-x hidden
|
2018-07-05 08:21:43 -04:00
|
|
|
position absolute
|
|
|
|
top: 38px
|
|
|
|
transition all .2s ease-in-out .1s
|
2018-07-06 11:54:36 -04:00
|
|
|
width 100%
|
2018-07-05 08:21:43 -04:00
|
|
|
&.small
|
|
|
|
height: 245px
|
|
|
|
top: 152px
|
2018-06-19 01:45:07 -04:00
|
|
|
&__img
|
2017-12-06 22:26:29 -05:00
|
|
|
height 150px
|
|
|
|
position relative
|
|
|
|
margin-bottom 16px
|
|
|
|
&__item
|
|
|
|
width 100%
|
|
|
|
height 120px
|
|
|
|
background-size cover
|
|
|
|
background-position 50% 50%
|
|
|
|
background-repeat no-repeat
|
|
|
|
transition all .2s ease-in-out
|
|
|
|
cursor pointer
|
|
|
|
margin-bottom 8px
|
|
|
|
&-fake
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
left 0
|
|
|
|
opacity 0
|
|
|
|
width 100%
|
|
|
|
z-index -1
|
|
|
|
&:hover
|
|
|
|
background-color #49B1F5
|
|
|
|
transform scale(1.1)
|
|
|
|
&__tool-panel
|
|
|
|
color #ddd
|
|
|
|
i
|
|
|
|
cursor pointer
|
|
|
|
transition all .2s ease-in-out
|
|
|
|
&.el-icon-document
|
|
|
|
&:hover
|
|
|
|
color #49B1F5
|
2018-04-08 11:43:34 -04:00
|
|
|
&.el-icon-edit-outline
|
|
|
|
&:hover
|
|
|
|
color #69C282
|
2017-12-06 22:26:29 -05:00
|
|
|
&.el-icon-delete
|
|
|
|
&:hover
|
|
|
|
color #F15140
|
|
|
|
.blueimp-gallery
|
|
|
|
.title
|
|
|
|
top 30px
|
2018-06-19 01:45:07 -04:00
|
|
|
.handle-bar
|
|
|
|
color #ddd
|
|
|
|
.pic-bed-item
|
|
|
|
@extend .item-base
|
2018-06-20 08:45:12 -04:00
|
|
|
&:hover
|
|
|
|
background #A4D8FA
|
|
|
|
color #fff
|
2018-06-19 01:45:07 -04:00
|
|
|
&.active
|
|
|
|
background #49B1F5
|
|
|
|
color #fff
|
2018-06-20 08:45:12 -04:00
|
|
|
.el-input__inner
|
|
|
|
border-radius 0
|
2017-12-06 22:26:29 -05:00
|
|
|
</style>
|