2017-11-27 19:21:12 -05:00
|
|
|
|
<template>
|
|
|
|
|
<div id="upload-view">
|
2017-11-28 10:56:15 -05:00
|
|
|
|
<el-row :gutter="16">
|
2018-03-09 01:35:41 -05:00
|
|
|
|
<el-col :span="20" :offset="2">
|
2017-11-28 10:56:15 -05:00
|
|
|
|
<div class="view-title">
|
2019-02-26 22:11:48 -05:00
|
|
|
|
图片上传 - {{ picBedName }} <i class="el-icon-caret-bottom" @click="handleChangePicBed"></i>
|
2017-11-28 10:56:15 -05:00
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
id="upload-area"
|
2018-12-10 04:13:48 -05:00
|
|
|
|
:class="{ 'is-dragover': dragover }"
|
|
|
|
|
@drop.prevent="onDrop"
|
|
|
|
|
@dragover.prevent="dragover = true"
|
|
|
|
|
@dragleave.prevent="dragover = false"
|
2017-11-28 10:56:15 -05:00
|
|
|
|
>
|
|
|
|
|
<div id="upload-dragger" @click="openUplodWindow">
|
|
|
|
|
<i class="el-icon-upload"></i>
|
|
|
|
|
<div class="upload-dragger__text">
|
|
|
|
|
将文件拖到此处,或 <span>点击上传</span>
|
|
|
|
|
</div>
|
|
|
|
|
<input type="file" id="file-uploader" @change="onChange" multiple>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-12-19 06:17:21 -05:00
|
|
|
|
<el-progress
|
|
|
|
|
:percentage="progress"
|
|
|
|
|
:show-text="false"
|
2017-11-28 10:56:15 -05:00
|
|
|
|
class="upload-progress"
|
|
|
|
|
:class="{ 'show': showProgress }"
|
2019-12-19 06:17:21 -05:00
|
|
|
|
:status="showError ? 'exception' : undefined"
|
2017-11-28 10:56:15 -05:00
|
|
|
|
></el-progress>
|
|
|
|
|
<div class="paste-style">
|
2018-01-30 02:35:05 -05:00
|
|
|
|
<div class="el-col-16">
|
|
|
|
|
<div class="paste-style__text">
|
|
|
|
|
链接格式
|
|
|
|
|
</div>
|
|
|
|
|
<el-radio-group v-model="pasteStyle" size="mini"
|
|
|
|
|
@change="handlePasteStyleChange"
|
|
|
|
|
>
|
|
|
|
|
<el-radio-button label="markdown">
|
|
|
|
|
Markdown
|
|
|
|
|
</el-radio-button>
|
|
|
|
|
<el-radio-button label="HTML"></el-radio-button>
|
|
|
|
|
<el-radio-button label="URL"></el-radio-button>
|
|
|
|
|
<el-radio-button label="UBB"></el-radio-button>
|
2018-03-09 01:35:41 -05:00
|
|
|
|
<el-radio-button label="Custom" title="自定义"></el-radio-button>
|
2018-01-30 02:35:05 -05:00
|
|
|
|
</el-radio-group>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="el-col-8">
|
|
|
|
|
<div class="paste-style__text">
|
|
|
|
|
快捷上传
|
|
|
|
|
</div>
|
2020-02-21 09:25:48 -05:00
|
|
|
|
<el-button type="primary" round size="mini" @click="uploadClipboardFiles" class="quick-upload">剪贴板</el-button>
|
|
|
|
|
<el-button type="primary" round size="mini" @click="uploadURLFiles" class="quick-upload">URL</el-button>
|
2017-11-28 10:56:15 -05:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
2017-11-27 19:21:12 -05:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2019-12-19 06:17:21 -05:00
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { Component, Vue, Watch } from 'vue-property-decorator'
|
|
|
|
|
import {
|
|
|
|
|
ipcRenderer,
|
|
|
|
|
IpcRendererEvent,
|
|
|
|
|
remote
|
|
|
|
|
} from 'electron'
|
2020-02-21 09:25:48 -05:00
|
|
|
|
import {
|
|
|
|
|
SHOW_INPUT_BOX,
|
|
|
|
|
SHOW_INPUT_BOX_RESPONSE
|
|
|
|
|
} from '~/universal/events/constants'
|
2019-12-19 06:17:21 -05:00
|
|
|
|
const { Menu } = remote
|
|
|
|
|
@Component({
|
|
|
|
|
name: 'upload'
|
|
|
|
|
})
|
|
|
|
|
export default class extends Vue {
|
|
|
|
|
dragover = false
|
|
|
|
|
progress = 0
|
|
|
|
|
showProgress = false
|
|
|
|
|
showError = false
|
|
|
|
|
pasteStyle = ''
|
2019-12-21 04:28:29 -05:00
|
|
|
|
picBed: IPicBedType[] = []
|
2019-12-19 06:17:21 -05:00
|
|
|
|
picBedName = ''
|
|
|
|
|
menu: Electron.Menu | null= null
|
2017-11-28 10:56:15 -05:00
|
|
|
|
mounted () {
|
2019-12-19 06:17:21 -05:00
|
|
|
|
ipcRenderer.on('uploadProgress', (event: IpcRendererEvent, progress: number) => {
|
2017-11-28 10:56:15 -05:00
|
|
|
|
if (progress !== -1) {
|
|
|
|
|
this.showProgress = true
|
|
|
|
|
this.progress = progress
|
|
|
|
|
} else {
|
|
|
|
|
this.progress = 100
|
|
|
|
|
this.showError = true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.getPasteStyle()
|
2018-04-06 10:18:57 -04:00
|
|
|
|
this.getDefaultPicBed()
|
2019-12-19 06:17:21 -05:00
|
|
|
|
ipcRenderer.on('syncPicBed', () => {
|
2018-07-10 10:37:29 -04:00
|
|
|
|
this.getDefaultPicBed()
|
|
|
|
|
})
|
2019-12-19 06:17:21 -05:00
|
|
|
|
ipcRenderer.send('getPicBeds')
|
|
|
|
|
ipcRenderer.on('getPicBeds', this.getPicBeds)
|
2020-02-21 09:25:48 -05:00
|
|
|
|
this.$bus.$on(SHOW_INPUT_BOX_RESPONSE, this.handleInputBoxValue)
|
2019-12-19 06:17:21 -05:00
|
|
|
|
}
|
|
|
|
|
@Watch('progress')
|
|
|
|
|
onProgressChange (val: number) {
|
|
|
|
|
if (val === 100) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.showProgress = false
|
|
|
|
|
this.showError = false
|
|
|
|
|
}, 1000)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.progress = 0
|
|
|
|
|
}, 1200)
|
2017-11-28 10:56:15 -05:00
|
|
|
|
}
|
2019-12-19 06:17:21 -05:00
|
|
|
|
}
|
2017-11-28 10:56:15 -05:00
|
|
|
|
beforeDestroy () {
|
2019-12-19 06:17:21 -05:00
|
|
|
|
ipcRenderer.removeAllListeners('uploadProgress')
|
|
|
|
|
ipcRenderer.removeAllListeners('syncPicBed')
|
|
|
|
|
ipcRenderer.removeListener('getPicBeds', this.getPicBeds)
|
|
|
|
|
}
|
|
|
|
|
onDrop (e: DragEvent) {
|
|
|
|
|
this.dragover = false
|
|
|
|
|
this.ipcSendFiles(e.dataTransfer!.files)
|
|
|
|
|
}
|
|
|
|
|
openUplodWindow () {
|
|
|
|
|
document.getElementById('file-uploader')!.click()
|
|
|
|
|
}
|
|
|
|
|
onChange (e: any) {
|
|
|
|
|
this.ipcSendFiles(e.target.files);
|
|
|
|
|
(document.getElementById('file-uploader') as HTMLInputElement).value = ''
|
|
|
|
|
}
|
|
|
|
|
ipcSendFiles (files: FileList) {
|
2019-12-21 04:28:29 -05:00
|
|
|
|
let sendFiles: IFileWithPath[] = []
|
2019-12-19 06:17:21 -05:00
|
|
|
|
Array.from(files).forEach((item, index) => {
|
|
|
|
|
let obj = {
|
|
|
|
|
name: item.name,
|
|
|
|
|
path: item.path
|
|
|
|
|
}
|
|
|
|
|
sendFiles.push(obj)
|
|
|
|
|
})
|
|
|
|
|
ipcRenderer.send('uploadChoosedFiles', sendFiles)
|
|
|
|
|
}
|
|
|
|
|
getPasteStyle () {
|
|
|
|
|
this.pasteStyle = this.$db.get('settings.pasteStyle') || 'markdown'
|
|
|
|
|
}
|
|
|
|
|
handlePasteStyleChange (val: string) {
|
|
|
|
|
this.$db.set('settings.pasteStyle', val)
|
|
|
|
|
}
|
|
|
|
|
uploadClipboardFiles () {
|
|
|
|
|
ipcRenderer.send('uploadClipboardFilesFromUploadPage')
|
|
|
|
|
}
|
2020-02-21 09:25:48 -05:00
|
|
|
|
uploadURLFiles () {
|
|
|
|
|
this.$bus.$emit(SHOW_INPUT_BOX, {
|
|
|
|
|
title: '请输入URL',
|
|
|
|
|
placeholder: 'http://或者https://开头'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
handleInputBoxValue (val: string) {
|
|
|
|
|
if (val === '') return false
|
2020-02-23 02:20:07 -05:00
|
|
|
|
if (val.startsWith('http://') || val.startsWith('https://')) {
|
|
|
|
|
ipcRenderer.send('uploadChoosedFiles', [{
|
2020-02-21 09:25:48 -05:00
|
|
|
|
path: val
|
2020-02-23 02:20:07 -05:00
|
|
|
|
}])
|
2020-02-21 09:25:48 -05:00
|
|
|
|
} else {
|
|
|
|
|
this.$message.error('请输入合法的URL')
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-19 06:17:21 -05:00
|
|
|
|
getDefaultPicBed () {
|
|
|
|
|
const current: string = this.$db.get('picBed.current')
|
|
|
|
|
this.picBed.forEach(item => {
|
|
|
|
|
if (item.type === current) {
|
|
|
|
|
this.picBedName = item.name
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2019-12-21 04:28:29 -05:00
|
|
|
|
getPicBeds (event: Event, picBeds: IPicBedType[]) {
|
2019-12-19 06:17:21 -05:00
|
|
|
|
this.picBed = picBeds
|
|
|
|
|
this.getDefaultPicBed()
|
|
|
|
|
}
|
|
|
|
|
handleChangePicBed () {
|
|
|
|
|
this.buildMenu()
|
|
|
|
|
// this.menu.popup(remote.getCurrentWindow())
|
|
|
|
|
this.menu!.popup()
|
|
|
|
|
}
|
|
|
|
|
buildMenu () {
|
|
|
|
|
const _this = this
|
2019-12-28 03:23:16 -05:00
|
|
|
|
const submenu = this.picBed.filter(item => item.visible).map(item => {
|
2019-12-19 06:17:21 -05:00
|
|
|
|
return {
|
|
|
|
|
label: item.name,
|
|
|
|
|
type: 'radio',
|
|
|
|
|
checked: this.$db.get('picBed.current') === item.type,
|
|
|
|
|
click () {
|
2019-12-26 07:15:41 -05:00
|
|
|
|
_this.letPicGoSaveData({
|
|
|
|
|
'picBed.current': item.type
|
|
|
|
|
})
|
2019-12-19 06:17:21 -05:00
|
|
|
|
ipcRenderer.send('syncPicBed')
|
2019-02-26 22:11:48 -05:00
|
|
|
|
}
|
2019-12-19 06:17:21 -05:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
this.menu = Menu.buildFromTemplate(submenu)
|
2017-11-27 19:21:12 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<style lang='stylus'>
|
2017-11-28 10:56:15 -05:00
|
|
|
|
.view-title
|
|
|
|
|
color #eee
|
|
|
|
|
font-size 20px
|
|
|
|
|
text-align center
|
2018-12-19 03:46:07 -05:00
|
|
|
|
margin 10px auto
|
2017-11-28 10:56:15 -05:00
|
|
|
|
#upload-view
|
2018-12-27 22:10:28 -05:00
|
|
|
|
.view-title
|
|
|
|
|
margin 20px auto
|
2017-11-28 10:56:15 -05:00
|
|
|
|
#upload-area
|
|
|
|
|
height 220px
|
|
|
|
|
border 2px dashed #dddddd
|
|
|
|
|
border-radius 8px
|
|
|
|
|
text-align center
|
2018-03-09 01:35:41 -05:00
|
|
|
|
width 450px
|
2018-05-02 02:24:59 -04:00
|
|
|
|
margin 0 auto
|
2017-11-28 10:56:15 -05:00
|
|
|
|
color #dddddd
|
|
|
|
|
cursor pointer
|
|
|
|
|
transition all .2s ease-in-out
|
|
|
|
|
#upload-dragger
|
|
|
|
|
height 100%
|
|
|
|
|
&.is-dragover,
|
|
|
|
|
&:hover
|
|
|
|
|
border 2px dashed #A4D8FA
|
|
|
|
|
background-color rgba(164, 216, 250, 0.3)
|
|
|
|
|
color #fff
|
|
|
|
|
i
|
|
|
|
|
font-size 66px
|
|
|
|
|
margin 50px 0 16px
|
|
|
|
|
line-height 66px
|
|
|
|
|
span
|
|
|
|
|
color #409EFF
|
|
|
|
|
#file-uploader
|
|
|
|
|
display none
|
|
|
|
|
.upload-progress
|
|
|
|
|
opacity 0
|
|
|
|
|
transition all .2s ease-in-out
|
2018-03-09 10:24:48 -05:00
|
|
|
|
width 450px
|
2018-05-08 02:04:43 -04:00
|
|
|
|
margin 20px auto 0
|
2017-11-28 10:56:15 -05:00
|
|
|
|
&.show
|
|
|
|
|
opacity 1
|
|
|
|
|
.el-progress-bar__inner
|
|
|
|
|
transition all .2s ease-in-out
|
|
|
|
|
.paste-style
|
|
|
|
|
text-align center
|
|
|
|
|
margin-top 16px
|
|
|
|
|
&__text
|
|
|
|
|
font-size 12px
|
|
|
|
|
color #eeeeee
|
|
|
|
|
margin-bottom 4px
|
|
|
|
|
.el-radio-button:first-child
|
|
|
|
|
.el-radio-button__inner
|
|
|
|
|
border-left none
|
2017-11-29 03:23:05 -05:00
|
|
|
|
.el-radio-button:first-child
|
|
|
|
|
.el-radio-button__inner
|
|
|
|
|
border-left none
|
|
|
|
|
border-radius 14px 0 0 14px
|
|
|
|
|
.el-radio-button:last-child
|
|
|
|
|
.el-radio-button__inner
|
|
|
|
|
border-left none
|
|
|
|
|
border-radius 0 14px 14px 0
|
2020-02-21 09:25:48 -05:00
|
|
|
|
.quick-upload
|
|
|
|
|
width 46%
|
2019-12-19 06:17:21 -05:00
|
|
|
|
.el-icon-caret-bottom
|
|
|
|
|
cursor pointer
|
|
|
|
|
</style>
|