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">
|
2023-01-06 04:21:27 -05:00
|
|
|
<el-col
|
|
|
|
:span="20"
|
|
|
|
:offset="2"
|
|
|
|
>
|
2017-11-28 10:56:15 -05:00
|
|
|
<div class="view-title">
|
2023-01-06 04:21:27 -05:00
|
|
|
{{ $T('PICTURE_UPLOAD') }} - {{ picBedName }}
|
|
|
|
<el-icon
|
|
|
|
style="cursor: pointer; margin-left: 4px;"
|
|
|
|
@click="handleChangePicBed"
|
|
|
|
>
|
|
|
|
<CaretBottom />
|
|
|
|
</el-icon>
|
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
|
|
|
>
|
2023-01-06 04:21:27 -05:00
|
|
|
<div
|
|
|
|
id="upload-dragger"
|
|
|
|
@click="openUplodWindow"
|
|
|
|
>
|
|
|
|
<el-icon>
|
|
|
|
<UploadFilled />
|
|
|
|
</el-icon>
|
2017-11-28 10:56:15 -05:00
|
|
|
<div class="upload-dragger__text">
|
2022-01-19 10:21:17 -05:00
|
|
|
{{ $T('DRAG_FILE_TO_HERE') }} <span>{{ $T('CLICK_TO_UPLOAD') }}</span>
|
2017-11-28 10:56:15 -05:00
|
|
|
</div>
|
2023-01-06 04:21:27 -05:00
|
|
|
<input
|
|
|
|
id="file-uploader"
|
|
|
|
type="file"
|
|
|
|
multiple
|
|
|
|
@change="onChange"
|
|
|
|
>
|
2017-11-28 10:56:15 -05:00
|
|
|
</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"
|
2023-01-06 04:21:27 -05:00
|
|
|
/>
|
2017-11-28 10:56:15 -05:00
|
|
|
<div class="paste-style">
|
2018-01-30 02:35:05 -05:00
|
|
|
<div class="el-col-16">
|
|
|
|
<div class="paste-style__text">
|
2022-01-19 10:21:17 -05:00
|
|
|
{{ $T('LINK_FORMAT') }}
|
2018-01-30 02:35:05 -05:00
|
|
|
</div>
|
2023-01-06 04:21:27 -05:00
|
|
|
<el-radio-group
|
|
|
|
v-model="pasteStyle"
|
|
|
|
size="small"
|
2018-01-30 02:35:05 -05:00
|
|
|
@change="handlePasteStyleChange"
|
|
|
|
>
|
|
|
|
<el-radio-button label="markdown">
|
|
|
|
Markdown
|
|
|
|
</el-radio-button>
|
2023-01-06 04:21:27 -05:00
|
|
|
<el-radio-button label="HTML" />
|
|
|
|
<el-radio-button label="URL" />
|
|
|
|
<el-radio-button label="UBB" />
|
|
|
|
<el-radio-button
|
|
|
|
label="Custom"
|
|
|
|
:title="$T('CUSTOM')"
|
|
|
|
/>
|
2018-01-30 02:35:05 -05:00
|
|
|
</el-radio-group>
|
|
|
|
</div>
|
|
|
|
<div class="el-col-8">
|
|
|
|
<div class="paste-style__text">
|
2022-01-19 10:21:17 -05:00
|
|
|
{{ $T('QUICK_UPLOAD') }}
|
2018-01-30 02:35:05 -05:00
|
|
|
</div>
|
2023-01-06 04:21:27 -05:00
|
|
|
<el-button
|
|
|
|
type="primary"
|
|
|
|
round
|
|
|
|
size="small"
|
|
|
|
class="quick-upload"
|
|
|
|
style="width: 50%"
|
|
|
|
@click="uploadClipboardFiles"
|
|
|
|
>
|
|
|
|
{{ $T('CLIPBOARD_PICTURE') }}
|
|
|
|
</el-button>
|
|
|
|
<el-button
|
|
|
|
type="primary"
|
|
|
|
round
|
|
|
|
size="small"
|
|
|
|
class="quick-upload"
|
|
|
|
style="width: 46%; margin-left: 6px"
|
|
|
|
@click="uploadURLFiles"
|
|
|
|
>
|
|
|
|
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>
|
2023-01-06 04:21:27 -05:00
|
|
|
<script lang="ts" setup>
|
|
|
|
// import { Component, Vue, Watch } from 'vue-property-decorator'
|
|
|
|
import { UploadFilled, CaretBottom } from '@element-plus/icons-vue'
|
2019-12-19 06:17:21 -05:00
|
|
|
import {
|
|
|
|
ipcRenderer,
|
2022-01-04 10:40:28 -05:00
|
|
|
IpcRendererEvent
|
2019-12-19 06:17:21 -05:00
|
|
|
} from 'electron'
|
2023-01-06 04:21:27 -05:00
|
|
|
import { ref, onBeforeMount, onBeforeUnmount, watch } from 'vue'
|
|
|
|
import { T as $T } from '@/i18n'
|
|
|
|
import $bus from '@/utils/bus'
|
2020-02-21 09:25:48 -05:00
|
|
|
import {
|
|
|
|
SHOW_INPUT_BOX,
|
2022-01-04 10:40:28 -05:00
|
|
|
SHOW_INPUT_BOX_RESPONSE,
|
2022-08-20 22:54:30 -04:00
|
|
|
SHOW_UPLOAD_PAGE_MENU,
|
|
|
|
GET_PICBEDS
|
2020-02-21 09:25:48 -05:00
|
|
|
} from '~/universal/events/constants'
|
2020-02-23 04:48:12 -05:00
|
|
|
import {
|
|
|
|
isUrl
|
|
|
|
} from '~/universal/utils/common'
|
2023-01-06 04:21:27 -05:00
|
|
|
import { ElMessage as $message } from 'element-plus'
|
|
|
|
import { getConfig, saveConfig, sendToMain } from '@/utils/dataSender'
|
|
|
|
const dragover = ref(false)
|
|
|
|
const progress = ref(0)
|
|
|
|
const showProgress = ref(false)
|
|
|
|
const showError = ref(false)
|
|
|
|
const pasteStyle = ref('')
|
|
|
|
const picBed = ref<IPicBedType[]>([])
|
|
|
|
const picBedName = ref('')
|
|
|
|
onBeforeMount(() => {
|
|
|
|
ipcRenderer.on('uploadProgress', (event: IpcRendererEvent, _progress: number) => {
|
|
|
|
if (_progress !== -1) {
|
|
|
|
showProgress.value = true
|
|
|
|
progress.value = _progress
|
|
|
|
} else {
|
|
|
|
progress.value = 100
|
|
|
|
showError.value = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
getPasteStyle()
|
|
|
|
getDefaultPicBed()
|
|
|
|
ipcRenderer.on('syncPicBed', () => {
|
|
|
|
getDefaultPicBed()
|
|
|
|
})
|
|
|
|
sendToMain(GET_PICBEDS)
|
|
|
|
ipcRenderer.on(GET_PICBEDS, getPicBeds)
|
|
|
|
$bus.on(SHOW_INPUT_BOX_RESPONSE, handleInputBoxValue)
|
2019-12-19 06:17:21 -05:00
|
|
|
})
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
watch(progress, onProgressChange)
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function onProgressChange (val: number) {
|
|
|
|
if (val === 100) {
|
|
|
|
setTimeout(() => {
|
|
|
|
showProgress.value = false
|
|
|
|
showError.value = false
|
|
|
|
}, 1000)
|
|
|
|
setTimeout(() => {
|
|
|
|
progress.value = 0
|
|
|
|
}, 1200)
|
2019-12-19 06:17:21 -05:00
|
|
|
}
|
2023-01-06 04:21:27 -05:00
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
onBeforeUnmount(() => {
|
|
|
|
$bus.off(SHOW_INPUT_BOX_RESPONSE)
|
|
|
|
ipcRenderer.removeAllListeners('uploadProgress')
|
|
|
|
ipcRenderer.removeAllListeners('syncPicBed')
|
|
|
|
ipcRenderer.removeListener(GET_PICBEDS, getPicBeds)
|
|
|
|
})
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function onDrop (e: DragEvent) {
|
|
|
|
dragover.value = false
|
|
|
|
const items = e.dataTransfer!.items
|
|
|
|
if (items.length === 2 && items[0].type === 'text/uri-list') {
|
|
|
|
handleURLDrag(items, e.dataTransfer!)
|
|
|
|
} else if (items[0].type === 'text/plain') {
|
|
|
|
const str = e.dataTransfer!.getData(items[0].type)
|
|
|
|
if (isUrl(str)) {
|
|
|
|
sendToMain('uploadChoosedFiles', [{ path: str }])
|
2020-02-23 04:48:12 -05:00
|
|
|
} else {
|
2023-01-06 04:21:27 -05:00
|
|
|
$message.error($T('TIPS_DRAG_VALID_PICTURE_OR_URL'))
|
2020-02-23 04:48:12 -05:00
|
|
|
}
|
2023-01-06 04:21:27 -05:00
|
|
|
} else {
|
|
|
|
ipcSendFiles(e.dataTransfer!.files)
|
2019-12-19 06:17:21 -05:00
|
|
|
}
|
2023-01-06 04:21:27 -05:00
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function handleURLDrag (items: DataTransferItemList, dataTransfer: DataTransfer) {
|
|
|
|
// text/html
|
|
|
|
// Use this data to get a more precise URL
|
|
|
|
const urlString = dataTransfer.getData(items[1].type)
|
|
|
|
const urlMatch = urlString.match(/<img.*src="(.*?)"/)
|
|
|
|
if (urlMatch) {
|
|
|
|
sendToMain('uploadChoosedFiles', [
|
|
|
|
{
|
|
|
|
path: urlMatch[1]
|
|
|
|
}
|
|
|
|
])
|
|
|
|
} else {
|
|
|
|
$message.error($T('TIPS_DRAG_VALID_PICTURE_OR_URL'))
|
2019-12-19 06:17:21 -05:00
|
|
|
}
|
2023-01-06 04:21:27 -05:00
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function openUplodWindow () {
|
|
|
|
document.getElementById('file-uploader')!.click()
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function onChange (e: any) {
|
|
|
|
ipcSendFiles(e.target.files);
|
|
|
|
(document.getElementById('file-uploader') as HTMLInputElement).value = ''
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function ipcSendFiles (files: FileList) {
|
|
|
|
const sendFiles: IFileWithPath[] = []
|
|
|
|
Array.from(files).forEach((item) => {
|
|
|
|
const obj = {
|
|
|
|
name: item.name,
|
|
|
|
path: item.path
|
|
|
|
}
|
|
|
|
sendFiles.push(obj)
|
|
|
|
})
|
|
|
|
sendToMain('uploadChoosedFiles', sendFiles)
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
async function getPasteStyle () {
|
|
|
|
pasteStyle.value = await getConfig('settings.pasteStyle') || 'markdown'
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function handlePasteStyleChange (val: string | number | boolean) {
|
|
|
|
saveConfig({
|
|
|
|
'settings.pasteStyle': val
|
|
|
|
})
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function uploadClipboardFiles () {
|
|
|
|
sendToMain('uploadClipboardFilesFromUploadPage')
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
async function uploadURLFiles () {
|
|
|
|
const str = await navigator.clipboard.readText()
|
|
|
|
$bus.emit(SHOW_INPUT_BOX, {
|
|
|
|
value: isUrl(str) ? str : '',
|
|
|
|
title: $T('TIPS_INPUT_URL'),
|
|
|
|
placeholder: $T('TIPS_HTTP_PREFIX')
|
|
|
|
})
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function handleInputBoxValue (val: string) {
|
|
|
|
if (val === '') return
|
|
|
|
if (isUrl(val)) {
|
|
|
|
sendToMain('uploadChoosedFiles', [{
|
|
|
|
path: val
|
|
|
|
}])
|
|
|
|
} else {
|
|
|
|
$message.error($T('TIPS_INPUT_VALID_URL'))
|
2019-12-19 06:17:21 -05:00
|
|
|
}
|
2023-01-06 04:21:27 -05:00
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
async function getDefaultPicBed () {
|
|
|
|
const currentPicBed = await getConfig<string>('picBed.current')
|
|
|
|
picBed.value.forEach(item => {
|
|
|
|
if (item.type === currentPicBed) {
|
|
|
|
picBedName.value = item.name
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2023-01-06 04:21:27 -05:00
|
|
|
function getPicBeds (event: Event, picBeds: IPicBedType[]) {
|
|
|
|
picBed.value = picBeds
|
|
|
|
getDefaultPicBed()
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleChangePicBed () {
|
|
|
|
sendToMain(SHOW_UPLOAD_PAGE_MENU)
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
|
|
export default {
|
|
|
|
name: 'UploadPage'
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang='stylus'>
|
2017-11-28 10:56:15 -05:00
|
|
|
.view-title
|
2023-01-06 04:21:27 -05:00
|
|
|
display flex
|
2017-11-28 10:56:15 -05:00
|
|
|
color #eee
|
|
|
|
font-size 20px
|
|
|
|
text-align center
|
2018-12-19 03:46:07 -05:00
|
|
|
margin 10px auto
|
2023-01-06 04:21:27 -05:00
|
|
|
align-items center
|
|
|
|
justify-content center
|
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
|
2023-01-06 04:21:27 -05:00
|
|
|
display flex
|
|
|
|
align-items flex-end
|
2017-11-28 10:56:15 -05:00
|
|
|
&__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
|
2019-12-19 06:17:21 -05:00
|
|
|
.el-icon-caret-bottom
|
|
|
|
cursor pointer
|
|
|
|
</style>
|