🚧 WIP: gallery db in progress

This commit is contained in:
PiEgg
2021-07-25 23:25:36 +08:00
parent 12cecc27e7
commit 76964ff1a5
48 changed files with 529 additions and 468 deletions
+41 -32
View File
@@ -111,7 +111,9 @@
// @ts-ignore
import gallerys from 'vue-gallery'
import pasteStyle from '#/utils/pasteTemplate'
import { IPasteStyle } from '#/types/enum'
import { Component, Vue, Watch } from 'vue-property-decorator'
import { IResult } from '@picgo/store/dist/types'
import {
ipcRenderer,
clipboard,
@@ -194,6 +196,7 @@ export default class extends Vue {
getPicBeds (event: IpcRendererEvent, picBeds: IPicBedType[]) {
this.picBed = picBeds
}
// FIXME: gallery db && async computed - -||.....
getGallery () {
if (this.choosedPicBed.length > 0) {
let arr: ImgInfo[] = []
@@ -204,7 +207,6 @@ export default class extends Vue {
if (this.searchText) {
obj.fileName = this.searchText
}
// @ts-ignore
arr = arr.concat(this.$db.read().get('uploaded').filter(obj => {
return obj.fileName.indexOf(this.searchText) !== -1 && obj.type === item
}).reverse().value())
@@ -212,6 +214,7 @@ export default class extends Vue {
this.images = arr
} else {
if (this.searchText) {
// FIXME: gallery db
let data = this.$db.read().get('uploaded')
// @ts-ignore
.filter(item => {
@@ -219,7 +222,7 @@ export default class extends Vue {
}).reverse().value()
this.images = data
} else {
// @ts-ignore
// FIXME: gallery db
this.images = this.$db.read().get('uploaded').slice().reverse().value()
}
}
@@ -267,8 +270,8 @@ export default class extends Vue {
this.idx = null
this.changeZIndexForGallery(false)
}
copy (item: ImgInfo) {
const style = this.$db.get('settings.pasteStyle') || 'markdown'
async copy (item: ImgInfo) {
const style = await this.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
const copyLink = pasteStyle(style, item)
const obj = {
title: '复制链接成功',
@@ -286,9 +289,9 @@ export default class extends Vue {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const file = this.$db.getById('uploaded', id)
this.$db.removeById('uploaded', id)
}).then(async () => {
const file = await this.$$db.getById(id)
await this.$$db.removeById(id)
ipcRenderer.send('removeFiles', [file])
const obj = {
title: '操作结果',
@@ -309,12 +312,10 @@ export default class extends Vue {
this.imgInfo.imgUrl = item.imgUrl as string
this.dialogVisible = true
}
confirmModify () {
this.$db.read().get('uploaded')
// @ts-ignore
.getById(this.imgInfo.id)
.assign({ imgUrl: this.imgInfo.imgUrl })
.write()
async confirmModify () {
await this.$$db.updateById(this.imgInfo.id, {
imgUrl: this.imgInfo.imgUrl
})
const obj = {
title: '修改图片URL成功',
body: this.imgInfo.imgUrl,
@@ -355,15 +356,19 @@ export default class extends Vue {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let files: ImgInfo[] = []
Object.keys(this.choosedList).forEach(key => {
}).then(async () => {
let files: IResult<ImgInfo>[] = []
const imageIDList = Object.keys(this.choosedList)
for (let i = 0; i < imageIDList.length; i++) {
const key = imageIDList[i]
if (this.choosedList[key]) {
const file = this.$db.getById('uploaded', key)
files.push(file)
this.$db.removeById('uploaded', key)
const file = await this.$$db.getById<ImgInfo>(key)
if (file) {
files.push(file)
await this.$$db.removeById(key)
}
}
})
}
this.clearChoosedList()
this.choosedList = {} // 只有删除才能将这个置空
this.getGallery()
@@ -381,18 +386,22 @@ export default class extends Vue {
})
}
}
multiCopy () {
async multiCopy () {
if (Object.values(this.choosedList).some(item => item)) {
const copyString: string[] = []
const style = this.$db.get('settings.pasteStyle') || 'markdown'
const style = await this.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
Object.keys(this.choosedList).forEach(key => {
const imageIDList = Object.keys(this.choosedList)
for (let i = 0; i < imageIDList.length; i++) {
const key = imageIDList[i]
if (this.choosedList[key]) {
const item = this.$db.getById('uploaded', key)
copyString.push(pasteStyle(style, item))
this.choosedList[key] = false
const item = await this.$$db.getById<ImgInfo>(key)
if (item) {
copyString.push(pasteStyle(style, item))
this.choosedList[key] = false
}
}
})
}
const obj = {
title: '批量复制链接成功',
body: copyString.join('\n')
@@ -407,11 +416,11 @@ export default class extends Vue {
toggleHandleBar () {
this.handleBarActive = !this.handleBarActive
}
getPasteStyle () {
this.pasteStyle = this.$db.get('settings.pasteStyle') || 'markdown'
}
handlePasteStyleChange (val: string) {
this.$db.set('settings.pasteStyle', val)
// getPasteStyle () {
// this.pasteStyle = this.$db.get('settings.pasteStyle') || 'markdown'
// }
async handlePasteStyleChange (val: string) {
this.saveConfig('settings.pasteStyle', val)
this.pasteStyle = val
}
beforeDestroy () {
+4 -3
View File
@@ -136,15 +136,16 @@ export default class extends Vue {
openContextMenu () {
this.menu!.popup()
}
buildMenu () {
async buildMenu () {
const _this = this
const current = await this.getConfig('picBed.current')
const submenu = this.picBed.filter(item => item.visible).map(item => {
return {
label: item.name,
type: 'radio',
checked: this.$db.get('picBed.current') === item.type,
checked: current === item.type,
click () {
_this.letPicGoSaveData({
_this.saveConfig({
'picBed.current': item.type,
'picBed.uploader': item.type
})
+80 -45
View File
@@ -339,12 +339,13 @@
import keyDetect from '@/utils/key-binding'
import pkg from 'root/package.json'
import path from 'path'
import { IConfig } from 'picgo/dist/src/types/index'
import {
ipcRenderer,
remote
} from 'electron'
import { Component, Vue } from 'vue-property-decorator'
import db from '#/datastore'
// import db from '#/datastore'
const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest'
const releaseUrlBackup = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo@latest/package.json'
const downloadUrl = 'https://github.com/Molunerfinn/PicGo/releases/latest'
@@ -355,30 +356,22 @@ const customLinkRule = (rule: string, value: string, callback: (arg0?: Error) =>
return callback()
}
}
let logLevel = db.get('settings.logLevel')
if (!Array.isArray(logLevel)) {
if (logLevel && logLevel.length > 0) {
logLevel = [logLevel]
} else {
logLevel = ['all']
}
}
@Component({
name: 'picgo-setting'
})
export default class extends Vue {
form: ISettingForm = {
updateHelper: db.get('settings.showUpdateTip'),
updateHelper: false,
showPicBedList: [],
autoStart: db.get('settings.autoStart') || false,
rename: db.get('settings.rename') || false,
autoRename: db.get('settings.autoRename') || false,
uploadNotification: db.get('settings.uploadNotification') || false,
miniWindowOntop: db.get('settings.miniWindowOntop') || false,
logLevel,
autoCopyUrl: db.get('settings.autoCopy') === undefined ? true : db.get('settings.autoCopy'),
checkBetaUpdate: db.get('settings.checkBetaUpdate') === undefined ? true : db.get('settings.checkBetaUpdate')
autoStart: false,
rename: false,
autoRename: false,
uploadNotification: false,
miniWindowOntop: false,
logLevel: ['all'],
autoCopyUrl: true,
checkBetaUpdate: true
}
picBed: IPicBedType[] = []
logFileVisible = false
@@ -388,14 +381,14 @@ export default class extends Vue {
serverVisible = false
proxyVisible = false
customLink = {
value: db.get('settings.customLink') || '$url'
value: '$url'
}
shortKey: IShortKeyMap = {
upload: db.get('settings.shortKey.upload')
upload: ''
}
proxy = db.get('picBed.proxy') || ''
npmRegistry = db.get('settings.registry') || ''
npmProxy = db.get('settings.proxy') || ''
proxy = ''
npmRegistry = ''
npmProxy = ''
rules = {
value: [
{ validator: customLinkRule, trigger: 'blur' }
@@ -409,7 +402,7 @@ export default class extends Vue {
warn: '提醒-Warn',
none: '不记录日志-None'
}
server = db.get('settings.server') || {
server = {
port: 36677,
host: '127.0.0.1',
enable: true
@@ -430,6 +423,45 @@ export default class extends Vue {
ipcRenderer.send('getPicBeds')
ipcRenderer.on('getPicBeds', this.getPicBeds)
}
async initData () {
const config = (await this.getConfig<IConfig>())!
if (config !== undefined) {
const settings = config.settings || {}
const picBed = config.picBed
this.form.updateHelper = settings.showUpdateTip || false
this.form.autoStart = settings.autoStart || false
this.form.rename = settings.rename || false
this.form.autoRename = settings.autoRename || false
this.form.uploadNotification = settings.uploadNotification || false
this.form.miniWindowOntop = settings.miniWindowOntop || false
this.form.logLevel = this.initLogLevel(settings.logLevel || [])
this.form.autoCopyUrl = settings.autoCopy === undefined ? true : settings.autoCopy
this.form.checkBetaUpdate = settings.checkBetaUpdate === undefined ? true : settings.checkBetaUpdate
this.customLink.value = settings.customLink || '$url'
this.shortKey.upload = settings.shortKey.upload
this.proxy = picBed.proxy || ''
this.npmRegistry = settings.registry || ''
this.npmProxy = settings.proxy || ''
this.server = settings.server || {
port: 36677,
host: '127.0.0.1',
enable: true
}
}
}
initLogLevel (logLevel: string | string[]) {
if (!Array.isArray(logLevel)) {
if (logLevel && logLevel.length > 0) {
logLevel = [logLevel]
} else {
logLevel = ['all']
}
}
return logLevel
}
getPicBeds (event: Event, picBeds: IPicBedType[]) {
this.picBed = picBeds
this.form.showPicBedList = this.picBed.map(item => {
@@ -450,15 +482,15 @@ export default class extends Vue {
keyDetect (type: string, event: KeyboardEvent) {
this.shortKey[type] = keyDetect(event).join('+')
}
cancelCustomLink () {
async cancelCustomLink () {
this.customLinkVisible = false
this.customLink.value = db.get('settings.customLink') || '$url'
this.customLink.value = await this.getConfig<string>('settings.customLink') || '$url'
}
confirmCustomLink () {
// @ts-ignore
this.$refs.customLink.validate((valid: boolean) => {
if (valid) {
db.set('settings.customLink', this.customLink.value)
this.saveConfig('settings.customLink', this.customLink.value)
this.customLinkVisible = false
ipcRenderer.send('updateCustomLink')
} else {
@@ -466,13 +498,13 @@ export default class extends Vue {
}
})
}
cancelProxy () {
async cancelProxy () {
this.proxyVisible = false
this.proxy = db.get('picBed.proxy') || undefined
this.proxy = await this.getConfig<string>('picBed.proxy') || ''
}
confirmProxy () {
this.proxyVisible = false
this.letPicGoSaveData({
this.saveConfig({
'picBed.proxy': this.proxy,
'settings.proxy': this.npmProxy,
'settings.registry': this.npmRegistry
@@ -485,10 +517,10 @@ export default class extends Vue {
}
}
updateHelperChange (val: boolean) {
db.set('settings.showUpdateTip', val)
this.saveConfig('settings.showUpdateTip', val)
}
checkBetaUpdateChange (val: boolean) {
db.set('settings.checkBetaUpdate', val)
this.saveConfig('settings.checkBetaUpdate', val)
}
handleShowPicBedListChange (val: string[]) {
const list = this.picBed.map(item => {
@@ -499,22 +531,22 @@ export default class extends Vue {
}
return item
})
this.letPicGoSaveData({
this.saveConfig({
'picBed.list': list
})
ipcRenderer.send('getPicBeds')
}
handleAutoStartChange (val: boolean) {
db.set('settings.autoStart', val)
this.saveConfig('settings.autoStart', val)
ipcRenderer.send('autoStart', val)
}
handleRename (val: boolean) {
this.letPicGoSaveData({
this.saveConfig({
'settings.rename': val
})
}
handleAutoRename (val: boolean) {
this.letPicGoSaveData({
this.saveConfig({
'settings.autoRename': val
})
}
@@ -556,14 +588,16 @@ export default class extends Vue {
this.checkUpdateVisible = false
}
handleUploadNotification (val: boolean) {
db.set('settings.uploadNotification', val)
this.saveConfig({
'settings.uploadNotification': val
})
}
handleMiniWindowOntop (val: boolean) {
db.set('settings.miniWindowOntop', val)
this.saveConfig('settings.miniWindowOntop', val)
this.$message.info('需要重启生效')
}
handleAutoCopyUrl (val: boolean) {
db.set('settings.autoCopy', val)
this.saveConfig('settings.autoCopy', val)
const successNotification = new Notification('设置自动复制链接', {
body: '设置成功'
})
@@ -575,7 +609,7 @@ export default class extends Vue {
if (this.form.logLevel.length === 0) {
return this.$message.error('请选择日志记录等级')
}
this.letPicGoSaveData({
this.saveConfig({
'settings.logLevel': this.form.logLevel
})
const successNotification = new Notification('设置日志', {
@@ -586,9 +620,9 @@ export default class extends Vue {
}
this.logFileVisible = false
}
cancelLogLevelSetting () {
async cancelLogLevelSetting () {
this.logFileVisible = false
let logLevel = db.get('settings.logLevel')
let logLevel = await this.getConfig<string | string[]>('settings.logLevel')
if (!Array.isArray(logLevel)) {
if (logLevel && logLevel.length > 0) {
logLevel = [logLevel]
@@ -599,8 +633,9 @@ export default class extends Vue {
this.form.logLevel = logLevel
}
confirmServerSetting () {
// @ts-ignore
this.server.port = parseInt(this.server.port, 10)
this.letPicGoSaveData({
this.saveConfig({
'settings.server': this.server
})
const successNotification = new Notification('设置PicGo-Server', {
@@ -612,9 +647,9 @@ export default class extends Vue {
this.serverVisible = false
ipcRenderer.send('updateServer')
}
cancelServerSetting () {
async cancelServerSetting () {
this.serverVisible = false
this.server = db.get('settings.server') || {
this.server = await this.getConfig('settings.server') || {
port: 36677,
host: '127.0.0.1',
enable: true
+23 -21
View File
@@ -164,7 +164,7 @@ export default class extends Vue {
document.querySelector('.main-content.el-row').style.zIndex = 10
}
}
created () {
async created () {
this.os = process.platform
ipcRenderer.on('hideLoading', () => {
this.loading = false
@@ -216,15 +216,15 @@ export default class extends Vue {
})
this.getPluginList()
this.getSearchResult = debounce(this.getSearchResult, 50)
this.needReload = this.$db.get('needReload')
this.needReload = await this.getConfig<boolean>('needReload') || false
}
buildContextMenu (plugin: IPicGoPlugin) {
async buildContextMenu (plugin: IPicGoPlugin) {
const _this = this
let menu = [{
label: '启用插件',
enabled: !plugin.enabled,
click () {
_this.letPicGoSaveData({
_this.saveConfig({
[`picgoPlugins.${plugin.fullName}`]: true
})
plugin.enabled = true
@@ -235,7 +235,7 @@ export default class extends Vue {
label: '禁用插件',
enabled: plugin.enabled,
click () {
_this.letPicGoSaveData({
_this.saveConfig({
[`picgoPlugins.${plugin.fullName}`]: false
})
plugin.enabled = false
@@ -276,7 +276,7 @@ export default class extends Vue {
// handle transformer
if (plugin.config.transformer.name) {
let currentTransformer = this.$db.get('picBed.transformer') || 'path'
let currentTransformer = await this.getConfig<string>('picBed.transformer') || 'path'
let pluginTransformer = plugin.config.transformer.name
const obj = {
label: `${currentTransformer === pluginTransformer ? '禁用' : '启用'}transformer - ${plugin.config.transformer.name}`,
@@ -351,8 +351,10 @@ export default class extends Vue {
remote.app.relaunch()
remote.app.exit(0)
}
handleReload () {
this.$db.set('needReload', true)
async handleReload () {
this.saveConfig({
needReload: true
})
this.needReload = true
const successNotification = new Notification('更新成功', {
body: '请点击此通知重启应用以生效'
@@ -364,14 +366,14 @@ export default class extends Vue {
cleanSearch () {
this.searchText = ''
}
toggleTransformer (transformer: string) {
let currentTransformer = this.$db.get('picBed.transformer') || 'path'
async toggleTransformer (transformer: string) {
let currentTransformer = await this.getConfig<string>('picBed.transformer') || 'path'
if (currentTransformer === transformer) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.transformer': 'path'
})
} else {
this.letPicGoSaveData({
this.saveConfig({
'picBed.transformer': transformer
})
}
@@ -382,17 +384,17 @@ export default class extends Vue {
if (result !== false) {
switch (this.currentType) {
case 'plugin':
this.letPicGoSaveData({
this.saveConfig({
[`${this.configName}`]: result
})
break
case 'uploader':
this.letPicGoSaveData({
this.saveConfig({
[`picBed.${this.configName}`]: result
})
break
case 'transformer':
this.letPicGoSaveData({
this.saveConfig({
[`transformer.${this.configName}`]: result
})
break
@@ -448,20 +450,20 @@ export default class extends Vue {
}
}
// restore Uploader & Transformer
handleRestoreState (item: string, name: string) {
async handleRestoreState (item: string, name: string) {
if (item === 'uploader') {
const current = this.$db.get('picBed.current')
const current = await this.getConfig('picBed.current')
if (current === name) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.current': 'smms',
'picBed.uploader': 'smms'
})
}
}
if (item === 'transformer') {
const current = this.$db.get('picBed.transformer')
const current = await this.getConfig('picBed.transformer')
if (current === name) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.transformer': 'path'
})
}
@@ -475,7 +477,7 @@ export default class extends Vue {
goAwesomeList () {
remote.shell.openExternal('https://github.com/PicGo/Awesome-PicGo')
}
letPicGoSaveData (data: IObj) {
saveConfig (data: IObj) {
ipcRenderer.send('picgoSaveData', data)
}
handleImportLocalPlugin () {
+8 -11
View File
@@ -109,8 +109,8 @@ export default class extends Vue {
command = ''
shortKey = ''
currentIndex = 0
created () {
const shortKeyConfig = this.$db.get('settings.shortKey') as IShortKeyConfigs
async created () {
const shortKeyConfig = (await this.getConfig<IShortKeyConfigs>('settings.shortKey'))!
this.list = Object.keys(shortKeyConfig).map(item => {
return {
...shortKeyConfig[item],
@@ -132,26 +132,23 @@ export default class extends Vue {
toggleEnable (item: IShortKeyConfig) {
const status = !item.enable
item.enable = status
// this.$db.set(`settings.shortKey.${item.name}.enable`, status)
ipcRenderer.send('bindOrUnbindShortKey', item, item.from)
}
keyDetect (event: KeyboardEvent) {
this.shortKey = keyDetect(event).join('+')
}
openKeyBindingDialog (config: IShortKeyConfig, index: number) {
async openKeyBindingDialog (config: IShortKeyConfig, index: number) {
this.command = `${config.from}:${config.name}`
this.shortKey = this.$db.get(`settings.shortKey.${this.command}.key`)
this.shortKey = await this.getConfig(`settings.shortKey.${this.command}.key`) || ''
this.currentIndex = index
this.keyBindingVisible = true
}
cancelKeyBinding () {
async cancelKeyBinding () {
this.keyBindingVisible = false
this.shortKey = this.$db.get(`settings.shortKey.${this.command}.key`)
this.shortKey = await this.getConfig<string>(`settings.shortKey.${this.command}.key`) || ''
}
confirmKeyBinding () {
const oldKey = this.$db.get(`settings.shortKey.${this.command}.key`)
// this.$db.set(`settings.shortKey.${this.command}.key`, this.shortKey)
// const newKey = this.$db.get(`settings.shortKey.${this.command}`)
async confirmKeyBinding () {
const oldKey = await this.getConfig<string>(`settings.shortKey.${this.command}.key`)
const config = Object.assign({}, this.list[this.currentIndex])
config.key = this.shortKey
ipcRenderer.send('updateShortKey', config, oldKey, config.from)
+16 -15
View File
@@ -30,12 +30,15 @@ import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/mixin'
import pasteTemplate from '#/utils/pasteTemplate'
import { ipcRenderer, clipboard } from 'electron'
import { IPasteStyle } from '#/types/enum'
import { IResult } from '@picgo/store/dist/types'
@Component({
name: 'tray-page',
mixins: [mixin]
})
export default class extends Vue {
files = []
files: IResult<ImgInfo>[] = []
notification = {
title: '复制链接成功',
body: '',
@@ -46,15 +49,14 @@ export default class extends Vue {
get reverseList () {
return this.files.slice().reverse()
}
getData () {
// @ts-ignore
this.files = this.$db.read().get('uploaded').slice().reverse().slice(0, 5).value()
async getData () {
this.files = (await this.$$db.get<ImgInfo>()).slice().reverse().slice(0, 5)
}
copyTheLink (item: ImgInfo) {
async copyTheLink (item: ImgInfo) {
this.notification.body = item.imgUrl!
this.notification.icon = item.imgUrl!
const myNotification = new Notification(this.notification.title, this.notification)
const pasteStyle = this.$db.get('settings.pasteStyle') || 'markdown'
const pasteStyle = await this.getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
clipboard.writeText(pasteTemplate(pasteStyle, item))
myNotification.onclick = () => {
return true
@@ -83,19 +85,18 @@ export default class extends Vue {
mounted () {
this.disableDragFile()
this.getData()
ipcRenderer.on('dragFiles', (event: Event, files: string[]) => {
files.forEach(item => {
this.$db.insert('uploaded', item)
})
// @ts-ignore
this.files = this.$db.read().get('uploaded').slice().reverse().slice(0, 5).value()
ipcRenderer.on('dragFiles', async (event: Event, files: string[]) => {
for (let i = 0; i < files.length; i++) {
const item = files[i]
await this.$$db.insert(item)
}
this.files = (await this.$$db.get<ImgInfo>()).slice().reverse().slice(0, 5)
})
ipcRenderer.on('clipboardFiles', (event: Event, files: ImgInfo[]) => {
this.clipboardFiles = files
})
ipcRenderer.on('uploadFiles', (event: Event) => {
// @ts-ignore
this.files = this.$db.read().get('uploaded').slice().reverse().slice(0, 5).value()
ipcRenderer.on('uploadFiles', async (event: Event) => {
this.files = (await this.$$db.get()).slice().reverse().slice(0, 5)
console.log(this.files)
this.uploadFlag = false
})
+14 -11
View File
@@ -169,11 +169,13 @@ export default class extends Vue {
})
ipcRenderer.send('uploadChoosedFiles', sendFiles)
}
getPasteStyle () {
this.pasteStyle = this.$db.get('settings.pasteStyle') || 'markdown'
async getPasteStyle () {
this.pasteStyle = await this.getConfig('settings.pasteStyle') || 'markdown'
}
handlePasteStyleChange (val: string) {
this.$db.set('settings.pasteStyle', val)
this.saveConfig({
'settings.pasteStyle': val
})
}
uploadClipboardFiles () {
ipcRenderer.send('uploadClipboardFilesFromUploadPage')
@@ -196,10 +198,10 @@ export default class extends Vue {
this.$message.error('请输入合法的URL')
}
}
getDefaultPicBed () {
const current: string = this.$db.get('picBed.current')
async getDefaultPicBed () {
const currentPicBed = await this.getConfig<string>('picBed.current')
this.picBed.forEach(item => {
if (item.type === current) {
if (item.type === currentPicBed) {
this.picBedName = item.name
}
})
@@ -208,20 +210,21 @@ export default class extends Vue {
this.picBed = picBeds
this.getDefaultPicBed()
}
handleChangePicBed () {
this.buildMenu()
async handleChangePicBed () {
await this.buildMenu()
// this.menu.popup(remote.getCurrentWindow())
this.menu!.popup()
}
buildMenu () {
async buildMenu () {
const _this = this
const currentPicBed = await this.getConfig<string>('picBed.current')
const submenu = this.picBed.filter(item => item.visible).map(item => {
return {
label: item.name,
type: 'radio',
checked: this.$db.get('picBed.current') === item.type,
checked: currentPicBed === item.type,
click () {
_this.letPicGoSaveData({
_this.saveConfig({
'picBed.current': item.type,
'picBed.uploader': item.type
})
+3 -3
View File
@@ -86,8 +86,8 @@ export default class extends Vue {
customUrl: '',
options: ''
}
created () {
const config = this.$db.get('picBed.aliyun') as IAliYunConfig
async created () {
const config = await this.getConfig<IAliYunConfig>('picBed.aliyun')
if (config) {
this.form = Object.assign({}, config)
}
@@ -96,7 +96,7 @@ export default class extends Vue {
// @ts-ignore
this.$refs.aliyun.validate((valid) => {
if (valid) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.aliyun': this.form
})
const successNotification = new window.Notification('设置结果', {
+3 -3
View File
@@ -71,8 +71,8 @@ export default class extends Vue {
customUrl: '',
branch: ''
}
created () {
const config = this.$db.get('picBed.github') as IGitHubConfig
async created () {
const config = await this.getConfig<IGitHubConfig>('picBed.github')
if (config) {
this.form = Object.assign({}, config)
}
@@ -81,7 +81,7 @@ export default class extends Vue {
// @ts-ignore
this.$refs.github.validate((valid) => {
if (valid) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.github': this.form
})
const successNotification = new Notification('设置结果', {
+3 -3
View File
@@ -48,8 +48,8 @@ export default class extends Vue {
clientId: '',
proxy: ''
}
created () {
const config = this.$db.get('picBed.imgur') as IImgurConfig
async created () {
const config = await this.getConfig<IImgurConfig>('picBed.imgur')
if (config) {
this.form = Object.assign({}, config)
}
@@ -58,7 +58,7 @@ export default class extends Vue {
// @ts-ignore
this.$refs.imgur.validate((valid) => {
if (valid) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.imgur': this.form
})
const successNotification = new Notification('设置结果', {
+2 -2
View File
@@ -56,7 +56,7 @@ export default class extends Vue {
// @ts-ignore
const result = await this.$refs.configForm.validate()
if (result !== false) {
this.letPicGoSaveData({
this.saveConfig({
[`picBed.${this.type}`]: result
})
const successNotification = new Notification('设置结果', {
@@ -68,7 +68,7 @@ export default class extends Vue {
}
}
setDefaultPicBed (type: string) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.current': type,
'picBed.uploader': type
})
+4 -4
View File
@@ -17,7 +17,7 @@
:rules="{
required: true, message: 'AccessKey不能为空', trigger: 'blur'
}">
<el-input v-model="form.accessKey" placeholder="AccessKey" @keyup.native.enter="confirm('weiboForm')"></el-input>
<el-input v-model="form.accessKey" placeholder="AccessKey" @keyup.native.enter="confirm"></el-input>
</el-form-item>
<el-form-item
label="设定SecretKey"
@@ -88,8 +88,8 @@ export default class extends Vue {
options: '',
path: ''
}
created () {
const config = this.$db.get('picBed.qiniu') as IQiniuConfig
async created () {
const config = await this.getConfig<IQiniuConfig>('picBed.qiniu')
if (config) {
this.form = Object.assign({}, config)
}
@@ -98,7 +98,7 @@ export default class extends Vue {
// @ts-ignore
this.$refs.qiniu.validate((valid) => {
if (valid) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.qiniu': this.form
})
const successNotification = new Notification('设置结果', {
+4 -4
View File
@@ -41,17 +41,17 @@ export default class extends Vue {
form: ISMMSConfig = {
token: ''
}
created () {
const config = this.$db.get('picBed.smms.token') as (string | boolean)
async created () {
const config = await this.getConfig<string | boolean>('picBed.smms.token')
if (typeof config !== 'boolean') {
this.form.token = config
this.form.token = config || ''
}
}
confirm () {
// @ts-ignore
this.$refs.smms.validate((valid) => {
if (valid) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.smms': this.form
})
const successNotification = new window.Notification('设置结果', {
+4 -4
View File
@@ -30,7 +30,7 @@
:rules="{
required: true, message: 'SecretId不能为空', trigger: 'blur'
}">
<el-input v-model="form.secretId" placeholder="SecretId" @keyup.native.enter="confirm('weiboForm')"></el-input>
<el-input v-model="form.secretId" placeholder="SecretId" @keyup.native.enter="confirm"></el-input>
</el-form-item>
<el-form-item
label="设定SecretKey"
@@ -104,8 +104,8 @@ export default class extends Vue {
customUrl: '',
version: 'v4'
}
created () {
const config = this.$db.get('picBed.tcyun') as ITcYunConfig
async created () {
const config = await this.getConfig<ITcYunConfig>('picBed.tcyun')
if (config) {
this.form = Object.assign({}, config)
}
@@ -114,7 +114,7 @@ export default class extends Vue {
// @ts-ignore
this.$refs.tcyun.validate((valid) => {
if (valid) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.tcyun': this.form
})
const successNotification = new window.Notification('设置结果', {
+3 -3
View File
@@ -79,8 +79,8 @@ export default class extends Vue {
options: '',
path: ''
}
created () {
const config = this.$db.get('picBed.upyun') as IUpYunConfig
async created () {
const config = await this.getConfig<IUpYunConfig>('picBed.upyun')
if (config) {
this.form = Object.assign({}, config)
}
@@ -89,7 +89,7 @@ export default class extends Vue {
// @ts-ignore
this.$refs.tcyun.validate((valid) => {
if (valid) {
this.letPicGoSaveData({
this.saveConfig({
'picBed.upyun': this.form
})
const successNotification = new Notification('设置结果', {
-153
View File
@@ -1,153 +0,0 @@
<template>
<div id="weibo-view">
<el-row :gutter="16">
<el-col :span="16" :offset="4">
<div class="view-title">
微博图床设置[已停止支持]
</div>
<el-form
ref="weiboForm"
label-position="right"
label-width="120px"
size="small"
:model="form">
<el-form-item
label="设定用户名"
prop="username"
:rules="{
required: !chooseCookie, message: '用户名不能为空', trigger: 'blur'
}">
<el-input v-model="form.username" placeholder="用户名" @keyup.native.enter="confirm('weiboForm')" :disabled="chooseCookie"></el-input>
</el-form-item>
<el-form-item
label="设定密码"
prop="password"
:rules="{required: !chooseCookie,messsage: '密码不能为空',trigger: 'blur'}">
<el-input v-model="form.password" type="password" @keyup.native.enter="confirm('weiboForm')" placeholder="密码" :disabled="chooseCookie"></el-input>
</el-form-item>
<el-form-item
label="使用Cookie上传"
>
<el-switch
v-model="chooseCookie"
active-text="cookie模式"
@change="handleSwitchChange"
></el-switch>
<i class="el-icon-question" @click="openWiki"></i>
</el-form-item>
<el-form-item
label="设定Cookie"
prop="cookie"
:rules="{
required: chooseCookie, message: '密码不能为空', trigger: 'blur'
}">
<el-input v-model="form.cookie" @keyup.native.enter="confirm('weiboForm')" placeholder="Cookie" :disabled="!chooseCookie"></el-input>
</el-form-item>
<el-form-item label="* 图片质量">
<el-radio-group v-model="quality">
<el-radio label="thumbnail">缩略图</el-radio>
<el-radio label="mw690">中等尺寸</el-radio>
<el-radio label="large">原图</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item>
<el-button-group>
<el-button type="primary" @click="confirm('weiboForm')" round>确定</el-button>
<el-button type="success" @click="setDefaultPicBed('weibo')" round :disabled="defaultPicBed === 'weibo'">设为默认图床</el-button>
</el-button-group>
</el-form-item>
</el-form>
</el-col>
</el-row>
</div>
</template>
<script>
import mixin from '@/utils/ConfirmButtonMixin'
export default {
name: 'weibo',
mixins: [mixin],
data () {
return {
form: {
username: '',
password: '',
cookie: ''
},
chooseCookie: false,
quality: 'large'
}
},
created () {
const config = this.$db.get('picBed.weibo')
if (config) {
this.form.username = config.username
this.form.password = config.password
this.quality = config.quality || 'large'
this.form.cookie = config.cookie
this.chooseCookie = config.chooseCookie
}
},
methods: {
confirm (formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.letPicGoSaveData({
'picBed.weibo': {
username: this.form.username,
password: this.form.password,
quality: this.quality,
cookie: this.form.cookie,
chooseCookie: this.chooseCookie
}
})
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
} else {
return false
}
})
},
handleSwitchChange () {
this.$refs['weiboForm'].resetFields()
},
openWiki () {
this.$electron.remote.shell.openExternal('https://picgo.github.io/PicGo-Doc/zh/guide/config.html#微博图床')
}
}
}
</script>
<style lang='stylus'>
.el-message
left 60%
#weibo-view
.el-form
label
line-height 22px
padding-bottom 0
color #eee
.el-button-group
width 100%
.el-button
width 50%
.el-input__inner
border-radius 19px
.el-radio-group
margin-left 25px
.el-switch__label
color #eee
&.is-active
color #409EFF
.el-icon-question
font-size 20px
float right
margin-top 9px
color #eee
cursor pointer
transition .2s color ease-in-out
&:hover
color #409EFF
</style>