mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
🚧 WIP: add support for URL uploading
This commit is contained in:
parent
024d9cf41e
commit
23ba2338c6
@ -3,8 +3,8 @@
|
|||||||
"version": "2.2.2",
|
"version": "2.2.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"dev": "vue-cli-service electron:serve",
|
||||||
"build": "vue-cli-service build",
|
"build": "vue-cli-service electron:build",
|
||||||
"lint": "vue-cli-service lint",
|
"lint": "vue-cli-service lint",
|
||||||
"electron:build": "vue-cli-service electron:build",
|
"electron:build": "vue-cli-service electron:build",
|
||||||
"electron:serve": "vue-cli-service electron:serve",
|
"electron:serve": "vue-cli-service electron:serve",
|
||||||
|
@ -8,6 +8,7 @@ import 'element-ui/lib/theme-chalk/index.css'
|
|||||||
import VueLazyLoad from 'vue-lazyload'
|
import VueLazyLoad from 'vue-lazyload'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import mainMixin from './renderer/utils/mainMixin'
|
import mainMixin from './renderer/utils/mainMixin'
|
||||||
|
import bus from '@/utils/bus'
|
||||||
|
|
||||||
webFrame.setVisualZoomLevelLimits(1, 1)
|
webFrame.setVisualZoomLevelLimits(1, 1)
|
||||||
webFrame.setLayoutZoomLevelLimits(0, 0)
|
webFrame.setLayoutZoomLevelLimits(0, 0)
|
||||||
@ -25,6 +26,7 @@ Vue.prototype.$builtInPicBed = [
|
|||||||
]
|
]
|
||||||
Vue.prototype.$db = db
|
Vue.prototype.$db = db
|
||||||
Vue.prototype.$http = axios
|
Vue.prototype.$http = axios
|
||||||
|
Vue.prototype.$bus = bus
|
||||||
|
|
||||||
Vue.use(ElementUI)
|
Vue.use(ElementUI)
|
||||||
Vue.use(VueLazyLoad)
|
Vue.use(VueLazyLoad)
|
||||||
|
@ -12,6 +12,9 @@ import {
|
|||||||
getWindowId,
|
getWindowId,
|
||||||
getSettingWindowId
|
getSettingWindowId
|
||||||
} from '~/main/apis/bus'
|
} from '~/main/apis/bus'
|
||||||
|
import {
|
||||||
|
SHOW_INPUT_BOX
|
||||||
|
} from '~/universal/events/constants'
|
||||||
|
|
||||||
class GuiApi implements IGuiApi {
|
class GuiApi implements IGuiApi {
|
||||||
private windowId: number = -1
|
private windowId: number = -1
|
||||||
@ -40,9 +43,9 @@ class GuiApi implements IGuiApi {
|
|||||||
}) {
|
}) {
|
||||||
await this.showSettingWindow()
|
await this.showSettingWindow()
|
||||||
this.getWebcontentsByWindowId(this.settingWindowId)
|
this.getWebcontentsByWindowId(this.settingWindowId)
|
||||||
.send('showInputBox', options)
|
.send(SHOW_INPUT_BOX, options)
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
ipcMain.once('showInputBox', (event: Event, value: string) => {
|
ipcMain.once(SHOW_INPUT_BOX, (event: Event, value: string) => {
|
||||||
resolve(value)
|
resolve(value)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
59
src/renderer/components/InputBoxDialog.vue
Normal file
59
src/renderer/components/InputBoxDialog.vue
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
:title="inputBoxOptions.title || '输入框'"
|
||||||
|
:visible.sync="showInputBoxVisible"
|
||||||
|
:modal-append-to-body="false"
|
||||||
|
@close="handleInputBoxClose"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
v-model="inputBoxValue"
|
||||||
|
:placeholder="inputBoxOptions.placeholder"></el-input>
|
||||||
|
<span slot="footer">
|
||||||
|
<el-button @click="showInputBoxVisible = false" round>取消</el-button>
|
||||||
|
<el-button type="primary" @click="showInputBoxVisible = false" round>确定</el-button>
|
||||||
|
</span>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
<script lang="ts">
|
||||||
|
import { Component, Vue } from 'vue-property-decorator'
|
||||||
|
import { remote, ipcRenderer, IpcRendererEvent } from 'electron'
|
||||||
|
import {
|
||||||
|
SHOW_INPUT_BOX,
|
||||||
|
SHOW_INPUT_BOX_RESPONSE
|
||||||
|
} from '~/universal/events/constants'
|
||||||
|
@Component({
|
||||||
|
name: 'input-box-dialog'
|
||||||
|
})
|
||||||
|
export default class extends Vue {
|
||||||
|
inputBoxValue = ''
|
||||||
|
showInputBoxVisible = false
|
||||||
|
inputBoxOptions = {
|
||||||
|
title: '',
|
||||||
|
placeholder: ''
|
||||||
|
}
|
||||||
|
created () {
|
||||||
|
ipcRenderer.on(SHOW_INPUT_BOX, this.ipcEventHandler)
|
||||||
|
this.$bus.$on(SHOW_INPUT_BOX, this.initInputBoxValue)
|
||||||
|
}
|
||||||
|
ipcEventHandler (evt: IpcRendererEvent, options: IShowInputBoxOption) {
|
||||||
|
this.initInputBoxValue(options)
|
||||||
|
}
|
||||||
|
initInputBoxValue (options: IShowInputBoxOption) {
|
||||||
|
this.inputBoxValue = ''
|
||||||
|
this.inputBoxOptions.title = options.title || ''
|
||||||
|
this.inputBoxOptions.placeholder = options.placeholder || ''
|
||||||
|
this.showInputBoxVisible = true
|
||||||
|
}
|
||||||
|
handleInputBoxClose () {
|
||||||
|
// TODO: RPCServer
|
||||||
|
ipcRenderer.send(SHOW_INPUT_BOX, this.inputBoxValue)
|
||||||
|
this.$bus.$emit(SHOW_INPUT_BOX_RESPONSE, this.inputBoxValue)
|
||||||
|
}
|
||||||
|
beforeDestroy () {
|
||||||
|
ipcRenderer.removeListener(SHOW_INPUT_BOX, this.ipcEventHandler)
|
||||||
|
this.$bus.$off(SHOW_INPUT_BOX)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang='stylus'>
|
||||||
|
</style>
|
@ -120,20 +120,7 @@
|
|||||||
<el-button type="primary" @click="confirmCustomLink">确定</el-button>
|
<el-button type="primary" @click="confirmCustomLink">确定</el-button>
|
||||||
</span>
|
</span>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
<el-dialog
|
<input-box-dialog />
|
||||||
:title="inputBoxOptions.title || '输入框'"
|
|
||||||
:visible.sync="showInputBoxVisible"
|
|
||||||
:modal-append-to-body="false"
|
|
||||||
@close="handleInputBoxClose"
|
|
||||||
>
|
|
||||||
<el-input
|
|
||||||
v-model="inputBoxValue"
|
|
||||||
:placeholder="inputBoxOptions.placeholder"></el-input>
|
|
||||||
<span slot="footer">
|
|
||||||
<el-button @click="showInputBoxVisible = false" round>取消</el-button>
|
|
||||||
<el-button type="primary" @click="showInputBoxVisible = false" round>确定</el-button>
|
|
||||||
</span>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@ -143,6 +130,7 @@ import keyDetect from '@/utils/key-binding'
|
|||||||
import { remote, ipcRenderer, IpcRendererEvent } from 'electron'
|
import { remote, ipcRenderer, IpcRendererEvent } from 'electron'
|
||||||
import db from '#/datastore'
|
import db from '#/datastore'
|
||||||
import mixin from '@/utils/mixin'
|
import mixin from '@/utils/mixin'
|
||||||
|
import InputBoxDialog from '@/components/InputBoxDialog.vue'
|
||||||
const { Menu, dialog, BrowserWindow } = remote
|
const { Menu, dialog, BrowserWindow } = remote
|
||||||
const customLinkRule = (rule: string, value: string, callback: (arg0?: Error) => void) => {
|
const customLinkRule = (rule: string, value: string, callback: (arg0?: Error) => void) => {
|
||||||
if (!/\$url/.test(value)) {
|
if (!/\$url/.test(value)) {
|
||||||
@ -153,7 +141,10 @@ const customLinkRule = (rule: string, value: string, callback: (arg0?: Error) =>
|
|||||||
}
|
}
|
||||||
@Component({
|
@Component({
|
||||||
name: 'setting-page',
|
name: 'setting-page',
|
||||||
mixins: [mixin]
|
mixins: [mixin],
|
||||||
|
components: {
|
||||||
|
InputBoxDialog
|
||||||
|
}
|
||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
version = process.env.NODE_ENV === 'production' ? pkg.version : 'Dev'
|
version = process.env.NODE_ENV === 'production' ? pkg.version : 'Dev'
|
||||||
@ -175,24 +166,11 @@ export default class extends Vue {
|
|||||||
upload: db.get('shortKey.upload')
|
upload: db.get('shortKey.upload')
|
||||||
}
|
}
|
||||||
picBed: IPicBedType[] = []
|
picBed: IPicBedType[] = []
|
||||||
// for showInputBox
|
|
||||||
showInputBoxVisible = false
|
|
||||||
inputBoxValue = ''
|
|
||||||
inputBoxOptions = {
|
|
||||||
title: '',
|
|
||||||
placeholder: ''
|
|
||||||
}
|
|
||||||
created () {
|
created () {
|
||||||
this.os = process.platform
|
this.os = process.platform
|
||||||
this.buildMenu()
|
this.buildMenu()
|
||||||
ipcRenderer.send('getPicBeds')
|
ipcRenderer.send('getPicBeds')
|
||||||
ipcRenderer.on('getPicBeds', this.getPicBeds)
|
ipcRenderer.on('getPicBeds', this.getPicBeds)
|
||||||
ipcRenderer.on('showInputBox', (evt: IpcRendererEvent, options: IShowInputBoxOption) => {
|
|
||||||
this.inputBoxValue = ''
|
|
||||||
this.inputBoxOptions.title = options.title || ''
|
|
||||||
this.inputBoxOptions.placeholder = options.placeholder || ''
|
|
||||||
this.showInputBoxVisible = true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
handleSelect (index: string) {
|
handleSelect (index: string) {
|
||||||
const type = index.match(/picbeds-/)
|
const type = index.match(/picbeds-/)
|
||||||
@ -279,9 +257,6 @@ export default class extends Vue {
|
|||||||
getPicBeds (event: IpcRendererEvent, picBeds: IPicBedType[]) {
|
getPicBeds (event: IpcRendererEvent, picBeds: IPicBedType[]) {
|
||||||
this.picBed = picBeds
|
this.picBed = picBeds
|
||||||
}
|
}
|
||||||
handleInputBoxClose () {
|
|
||||||
ipcRenderer.send('showInputBox', this.inputBoxValue)
|
|
||||||
}
|
|
||||||
beforeRouteEnter (to: any, from: any, next: any) {
|
beforeRouteEnter (to: any, from: any, next: any) {
|
||||||
next((vm: this) => {
|
next((vm: this) => {
|
||||||
vm.defaultActive = to.name
|
vm.defaultActive = to.name
|
||||||
@ -289,7 +264,6 @@ export default class extends Vue {
|
|||||||
}
|
}
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
ipcRenderer.removeListener('getPicBeds', this.getPicBeds)
|
ipcRenderer.removeListener('getPicBeds', this.getPicBeds)
|
||||||
ipcRenderer.removeAllListeners('showInputBox')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -48,7 +48,8 @@
|
|||||||
<div class="paste-style__text">
|
<div class="paste-style__text">
|
||||||
快捷上传
|
快捷上传
|
||||||
</div>
|
</div>
|
||||||
<el-button type="primary" round size="mini" @click="uploadClipboardFiles" class="paste-upload">剪贴板图片上传</el-button>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -62,6 +63,10 @@ import {
|
|||||||
IpcRendererEvent,
|
IpcRendererEvent,
|
||||||
remote
|
remote
|
||||||
} from 'electron'
|
} from 'electron'
|
||||||
|
import {
|
||||||
|
SHOW_INPUT_BOX,
|
||||||
|
SHOW_INPUT_BOX_RESPONSE
|
||||||
|
} from '~/universal/events/constants'
|
||||||
const { Menu } = remote
|
const { Menu } = remote
|
||||||
@Component({
|
@Component({
|
||||||
name: 'upload'
|
name: 'upload'
|
||||||
@ -92,6 +97,7 @@ export default class extends Vue {
|
|||||||
})
|
})
|
||||||
ipcRenderer.send('getPicBeds')
|
ipcRenderer.send('getPicBeds')
|
||||||
ipcRenderer.on('getPicBeds', this.getPicBeds)
|
ipcRenderer.on('getPicBeds', this.getPicBeds)
|
||||||
|
this.$bus.$on(SHOW_INPUT_BOX_RESPONSE, this.handleInputBoxValue)
|
||||||
}
|
}
|
||||||
@Watch('progress')
|
@Watch('progress')
|
||||||
onProgressChange (val: number) {
|
onProgressChange (val: number) {
|
||||||
@ -141,6 +147,22 @@ export default class extends Vue {
|
|||||||
uploadClipboardFiles () {
|
uploadClipboardFiles () {
|
||||||
ipcRenderer.send('uploadClipboardFilesFromUploadPage')
|
ipcRenderer.send('uploadClipboardFilesFromUploadPage')
|
||||||
}
|
}
|
||||||
|
uploadURLFiles () {
|
||||||
|
this.$bus.$emit(SHOW_INPUT_BOX, {
|
||||||
|
title: '请输入URL',
|
||||||
|
placeholder: 'http://或者https://开头'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
handleInputBoxValue (val: string) {
|
||||||
|
if (val === '') return false
|
||||||
|
if (val.includes('http://') || val.includes('https://')) {
|
||||||
|
ipcRenderer.send('uploadChoosedFiles', {
|
||||||
|
path: val
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.$message.error('请输入合法的URL')
|
||||||
|
}
|
||||||
|
}
|
||||||
getDefaultPicBed () {
|
getDefaultPicBed () {
|
||||||
const current: string = this.$db.get('picBed.current')
|
const current: string = this.$db.get('picBed.current')
|
||||||
this.picBed.forEach(item => {
|
this.picBed.forEach(item => {
|
||||||
@ -239,8 +261,8 @@ 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
|
||||||
.paste-upload
|
.quick-upload
|
||||||
width 100%
|
width 46%
|
||||||
.el-icon-caret-bottom
|
.el-icon-caret-bottom
|
||||||
cursor pointer
|
cursor pointer
|
||||||
</style>
|
</style>
|
||||||
|
2
src/renderer/utils/bus.ts
Normal file
2
src/renderer/utils/bus.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
export default new Vue()
|
@ -0,0 +1,2 @@
|
|||||||
|
export const SHOW_INPUT_BOX = 'SHOW_INPUT_BOX'
|
||||||
|
export const SHOW_INPUT_BOX_RESPONSE = 'SHOW_INPUT_BOX_RESPONSE'
|
1
src/universal/types/extra-vue.d.ts
vendored
1
src/universal/types/extra-vue.d.ts
vendored
@ -8,6 +8,7 @@ declare module 'vue/types/vue' {
|
|||||||
$db: typeof db
|
$db: typeof db
|
||||||
$http: typeof axios
|
$http: typeof axios
|
||||||
$builtInPicBed: string[]
|
$builtInPicBed: string[]
|
||||||
|
$bus: Vue
|
||||||
letPicGoSaveData(data: IObj): void
|
letPicGoSaveData(data: IObj): void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user