mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
🐛 Fix: url uploader bug
This commit is contained in:
parent
a28c67848d
commit
96544f5475
@ -42,7 +42,7 @@
|
|||||||
"keycode": "^2.2.0",
|
"keycode": "^2.2.0",
|
||||||
"lodash-id": "^0.14.0",
|
"lodash-id": "^0.14.0",
|
||||||
"lowdb": "^1.0.0",
|
"lowdb": "^1.0.0",
|
||||||
"picgo": "^1.4.5",
|
"picgo": "^1.4.6",
|
||||||
"vue": "^2.6.10",
|
"vue": "^2.6.10",
|
||||||
"vue-gallery": "^2.0.1",
|
"vue-gallery": "^2.0.1",
|
||||||
"vue-lazyload": "^1.2.6",
|
"vue-lazyload": "^1.2.6",
|
||||||
|
@ -39,15 +39,15 @@ export default class extends Vue {
|
|||||||
this.initInputBoxValue(options)
|
this.initInputBoxValue(options)
|
||||||
}
|
}
|
||||||
initInputBoxValue (options: IShowInputBoxOption) {
|
initInputBoxValue (options: IShowInputBoxOption) {
|
||||||
this.inputBoxValue = ''
|
this.inputBoxValue = options.value || ''
|
||||||
this.inputBoxOptions.title = options.title || ''
|
this.inputBoxOptions.title = options.title || ''
|
||||||
this.inputBoxOptions.placeholder = options.placeholder || ''
|
this.inputBoxOptions.placeholder = options.placeholder || ''
|
||||||
this.showInputBoxVisible = true
|
this.showInputBoxVisible = true
|
||||||
}
|
}
|
||||||
handleInputBoxClose () {
|
handleInputBoxClose () {
|
||||||
// TODO: RPCServer
|
// TODO: RPCServer
|
||||||
ipcRenderer.send(SHOW_INPUT_BOX, this.inputBoxValue)
|
ipcRenderer.send(SHOW_INPUT_BOX, '')
|
||||||
this.$bus.$emit(SHOW_INPUT_BOX_RESPONSE, this.inputBoxValue)
|
this.$bus.$emit(SHOW_INPUT_BOX_RESPONSE, '')
|
||||||
}
|
}
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
ipcRenderer.removeListener(SHOW_INPUT_BOX, this.ipcEventHandler)
|
ipcRenderer.removeListener(SHOW_INPUT_BOX, this.ipcEventHandler)
|
||||||
|
@ -48,8 +48,8 @@
|
|||||||
<div class="paste-style__text">
|
<div class="paste-style__text">
|
||||||
快捷上传
|
快捷上传
|
||||||
</div>
|
</div>
|
||||||
<el-button type="primary" round size="mini" @click="uploadClipboardFiles" class="quick-upload">剪贴板</el-button>
|
<el-button type="primary" round size="mini" @click="uploadClipboardFiles" class="quick-upload" style="width: 50%">剪贴板图片</el-button>
|
||||||
<el-button type="primary" round size="mini" @click="uploadURLFiles" class="quick-upload">URL</el-button>
|
<el-button type="primary" round size="mini" @click="uploadURLFiles" class="quick-upload" style="width: 46%; margin-left: 6px">URL</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -67,6 +67,9 @@ import {
|
|||||||
SHOW_INPUT_BOX,
|
SHOW_INPUT_BOX,
|
||||||
SHOW_INPUT_BOX_RESPONSE
|
SHOW_INPUT_BOX_RESPONSE
|
||||||
} from '~/universal/events/constants'
|
} from '~/universal/events/constants'
|
||||||
|
import {
|
||||||
|
isUrl
|
||||||
|
} from '~/universal/utils/common'
|
||||||
const { Menu } = remote
|
const { Menu } = remote
|
||||||
@Component({
|
@Component({
|
||||||
name: 'upload'
|
name: 'upload'
|
||||||
@ -118,7 +121,34 @@ export default class extends Vue {
|
|||||||
}
|
}
|
||||||
onDrop (e: DragEvent) {
|
onDrop (e: DragEvent) {
|
||||||
this.dragover = false
|
this.dragover = false
|
||||||
this.ipcSendFiles(e.dataTransfer!.files)
|
const items = e.dataTransfer!.items
|
||||||
|
if (items.length === 2 && items[0].type === 'text/uri-list') {
|
||||||
|
this.handleURLDrag(items, e.dataTransfer!)
|
||||||
|
} else if (items[0].type === 'text/plain') {
|
||||||
|
const str = e.dataTransfer!.getData(items[0].type)
|
||||||
|
if (isUrl(str)) {
|
||||||
|
ipcRenderer.send('uploadChoosedFiles', [{ path: str }])
|
||||||
|
} else {
|
||||||
|
this.$message.error('请拖入合法的图片文件或者图片URL地址')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.ipcSendFiles(e.dataTransfer!.files)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
ipcRenderer.send('uploadChoosedFiles', [
|
||||||
|
{
|
||||||
|
path: urlMatch[1]
|
||||||
|
}
|
||||||
|
])
|
||||||
|
} else {
|
||||||
|
this.$message.error('请拖入合法的图片文件或者图片URL地址')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
openUplodWindow () {
|
openUplodWindow () {
|
||||||
document.getElementById('file-uploader')!.click()
|
document.getElementById('file-uploader')!.click()
|
||||||
@ -147,15 +177,17 @@ export default class extends Vue {
|
|||||||
uploadClipboardFiles () {
|
uploadClipboardFiles () {
|
||||||
ipcRenderer.send('uploadClipboardFilesFromUploadPage')
|
ipcRenderer.send('uploadClipboardFilesFromUploadPage')
|
||||||
}
|
}
|
||||||
uploadURLFiles () {
|
async uploadURLFiles () {
|
||||||
|
const str = await navigator.clipboard.readText()
|
||||||
this.$bus.$emit(SHOW_INPUT_BOX, {
|
this.$bus.$emit(SHOW_INPUT_BOX, {
|
||||||
|
value: isUrl(str) ? str : '',
|
||||||
title: '请输入URL',
|
title: '请输入URL',
|
||||||
placeholder: 'http://或者https://开头'
|
placeholder: 'http://或者https://开头'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
handleInputBoxValue (val: string) {
|
handleInputBoxValue (val: string) {
|
||||||
if (val === '') return false
|
if (val === '') return false
|
||||||
if (val.startsWith('http://') || val.startsWith('https://')) {
|
if (isUrl(val)) {
|
||||||
ipcRenderer.send('uploadChoosedFiles', [{
|
ipcRenderer.send('uploadChoosedFiles', [{
|
||||||
path: val
|
path: val
|
||||||
}])
|
}])
|
||||||
@ -261,8 +293,6 @@ export default class extends Vue {
|
|||||||
.el-radio-button__inner
|
.el-radio-button__inner
|
||||||
border-left none
|
border-left none
|
||||||
border-radius 0 14px 14px 0
|
border-radius 0 14px 14px 0
|
||||||
.quick-upload
|
|
||||||
width 46%
|
|
||||||
.el-icon-caret-bottom
|
.el-icon-caret-bottom
|
||||||
cursor pointer
|
cursor pointer
|
||||||
</style>
|
</style>
|
||||||
|
1
src/universal/types/types.d.ts
vendored
1
src/universal/types/types.d.ts
vendored
@ -179,6 +179,7 @@ interface IGuiApi {
|
|||||||
showMessageBox: (options?: IShowMessageBoxOption) => Promise<IShowMessageBoxResult>
|
showMessageBox: (options?: IShowMessageBoxOption) => Promise<IShowMessageBoxResult>
|
||||||
}
|
}
|
||||||
interface IShowInputBoxOption {
|
interface IShowInputBoxOption {
|
||||||
|
value?: string
|
||||||
title: string
|
title: string
|
||||||
placeholder: string
|
placeholder: string
|
||||||
}
|
}
|
||||||
|
1
src/universal/utils/common.ts
Normal file
1
src/universal/utils/common.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const isUrl = (url: string): boolean => (url.startsWith('http://') || url.startsWith('https://'))
|
@ -8292,10 +8292,10 @@ performance-now@^2.1.0:
|
|||||||
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
|
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
|
||||||
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
|
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
|
||||||
|
|
||||||
picgo@^1.4.5:
|
picgo@^1.4.6:
|
||||||
version "1.4.5"
|
version "1.4.6"
|
||||||
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.4.5.tgz#3579aea9017a68c4b1e80e7af9060eb70ab98a9a"
|
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.4.6.tgz#aa90439a253c5a07068b136a0d1426f63236735b"
|
||||||
integrity sha512-uef5tkOsswj6XJX2kYlUkuIPhaUS4PNSCMZ3IYgSCZvvxC4e1o8Qro4PIYlMAIEDPqP30OrKNab/wmaJxizv+g==
|
integrity sha512-VNh5el0hkh0OrxqTPGkRAUtGmncr7cdKrjdvp6yf2Iwx+O+uJ4IHgKMmzAj+siJGTBENL0eWoujmzX07zAt30g==
|
||||||
dependencies:
|
dependencies:
|
||||||
chalk "^2.4.1"
|
chalk "^2.4.1"
|
||||||
commander "^2.17.0"
|
commander "^2.17.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user