🔨 Refactor: change vue-js -> vue-ts && add typos

This commit is contained in:
Molunerfinn 2019-12-21 17:28:29 +08:00
parent 29a55ed855
commit b8ec879e23
21 changed files with 333 additions and 300 deletions

View File

@ -252,7 +252,7 @@ const createMiniWidow = () => {
if (miniWindow) {
return false
}
let obj: BrowserWindowOptions = {
let obj: IBrowserWindowOptions = {
height: 64,
width: 64,
show: process.platform === 'linux',
@ -284,7 +284,7 @@ const createMiniWidow = () => {
}
const createSettingWindow = () => {
const options: BrowserWindowOptions = {
const options: IBrowserWindowOptions = {
height: 450,
width: 800,
show: false,
@ -355,7 +355,7 @@ const createMenu = () => {
}
}
const toggleWindow = (bounds: Bounds) => {
const toggleWindow = (bounds: IBounds) => {
if (window!.isVisible()) {
window!.hide()
} else {
@ -363,7 +363,7 @@ const toggleWindow = (bounds: Bounds) => {
}
}
const showWindow = (bounds: Bounds) => {
const showWindow = (bounds: IBounds) => {
window!.setPosition(bounds.x - 98 + 11, bounds.y, false)
window!.webContents.send('updateFiles')
window!.show()
@ -404,7 +404,7 @@ const uploadClipboardFiles = async () => {
}
}
const uploadChoosedFiles = async (webContents: WebContents, files: FileWithPath[]) => {
const uploadChoosedFiles = async (webContents: WebContents, files: IFileWithPath[]) => {
const input = files.map(item => item.path)
const imgs = await new Uploader(input, webContents).upload()
if (imgs !== false) {
@ -458,11 +458,11 @@ ipcMain.on('uploadClipboardFilesFromUploadPage', () => {
uploadClipboardFiles()
})
ipcMain.on('uploadChoosedFiles', async (evt: IpcMainEvent, files: FileWithPath[]) => {
ipcMain.on('uploadChoosedFiles', async (evt: IpcMainEvent, files: IFileWithPath[]) => {
return uploadChoosedFiles(evt.sender, files)
})
ipcMain.on('updateShortKey', (evt: IpcMainEvent, item: ShortKeyConfig, oldKey: string) => {
ipcMain.on('updateShortKey', (evt: IpcMainEvent, item: IShortKeyConfig, oldKey: string) => {
shortKeyUpdater(globalShortcut, item, oldKey)
const notification = new Notification({
title: '操作成功',

View File

@ -1,6 +1,6 @@
import DB from '#/datastore'
// from v2.1.2
const updateShortKeyFromVersion212 = (db: typeof DB, shortKeyConfig: ShortKeyConfigs | OldShortKeyConfigs) => {
const updateShortKeyFromVersion212 = (db: typeof DB, shortKeyConfig: IShortKeyConfigs | IOldShortKeyConfigs) => {
let needUpgrade = false
if (shortKeyConfig.upload) {
needUpgrade = true

View File

@ -12,13 +12,13 @@ const getPicBeds = (app: App) => {
const picBedTypes = picgo.helper.uploader.getIdList()
const picBedFromDB = db.get('picBed.list') || []
const picBeds = picBedTypes.map((item: string) => {
const visible = picBedFromDB.find((i: PicBedType) => i.type === item) // object or undefined
const visible = picBedFromDB.find((i: IPicBedType) => i.type === item) // object or undefined
return {
type: item,
name: picgo.helper.uploader.get(item).name || item,
visible: visible ? visible.visible : true
}
}) as PicBedType[]
}) as IPicBedType[]
picgo.cmd.program.removeAllListeners()
return picBeds
}

View File

@ -24,7 +24,7 @@ const shortKeyHandler = (name: string) => {
/**
*
*/
const shortKeyUpdater = (globalShortcut: GlobalShortcut, item: ShortKeyConfig, oldKey: string) => {
const shortKeyUpdater = (globalShortcut: GlobalShortcut, item: IShortKeyConfig, oldKey: string) => {
// 如果提供了旧key则解绑
if (oldKey) {
globalShortcut.unregister(oldKey)
@ -39,7 +39,7 @@ const shortKeyUpdater = (globalShortcut: GlobalShortcut, item: ShortKeyConfig, o
}
// 初始化阶段的注册
const initShortKeyRegister = (globalShortcut: GlobalShortcut, shortKeys: ShortKeyConfig[]) => {
const initShortKeyRegister = (globalShortcut: GlobalShortcut, shortKeys: IShortKeyConfig[]) => {
let errorList = []
for (let i in shortKeys) {
try {

View File

@ -36,7 +36,7 @@ const renameURL = process.env.NODE_ENV === 'development'
// }
const createRenameWindow = (win: BrowserWindow) => {
let options: BrowserWindowOptions = {
let options: IBrowserWindowOptions = {
height: 175,
width: 300,
show: true,

View File

@ -174,7 +174,7 @@ export default class extends Vue {
shortKey: ShortKeyMap = {
upload: db.get('shortKey.upload')
}
picBed: PicBedType[] = []
picBed: IPicBedType[] = []
// for showInputBox
showInputBoxVisible = false
inputBoxValue = ''
@ -276,7 +276,7 @@ export default class extends Vue {
openMiniWindow () {
ipcRenderer.send('openMiniWindow')
}
getPicBeds (event: IpcRendererEvent, picBeds: PicBedType[]) {
getPicBeds (event: IpcRendererEvent, picBeds: IPicBedType[]) {
this.picBed = picBeds
}
handleInputBoxClose () {

View File

@ -143,7 +143,7 @@ export default class extends Vue {
UBB: 'UBB',
Custom: 'Custom'
}
picBed: PicBedType[] = []
picBed: IPicBedType[] = []
beforeRouteEnter (to: any, from: any, next: any) {
next((vm: any) => {
vm.getGallery()
@ -166,7 +166,7 @@ export default class extends Vue {
set filterList (val) {
this.images = val
}
getPicBeds (event: IpcRendererEvent, picBeds: PicBedType[]) {
getPicBeds (event: IpcRendererEvent, picBeds: IPicBedType[]) {
this.picBed = picBeds
}
getGallery () {

View File

@ -40,7 +40,7 @@ export default class extends Vue {
screenY: number = -1
menu: Electron.Menu | null = null
os = ''
picBed: PicBedType[] = []
picBed: IPicBedType[] = []
created () {
this.os = process.platform
ipcRenderer.on('uploadProgress', (event: IpcRendererEvent, progress: number) => {
@ -90,7 +90,7 @@ export default class extends Vue {
document.getElementById('file-uploader').value = ''
}
ipcSendFiles (files: FileList) {
let sendFiles: FileWithPath[] = []
let sendFiles: IFileWithPath[] = []
Array.from(files).forEach((item, index) => {
let obj = {
name: item.name,

View File

@ -283,7 +283,7 @@ export default class extends Vue {
miniWindowOntop: db.get('settings.miniWindowOntop') || false,
logLevel
}
picBed: PicBedType[] = []
picBed: IPicBedType[] = []
logFileVisible = false
keyBindingVisible = false
customLinkVisible = false
@ -325,7 +325,7 @@ export default class extends Vue {
ipcRenderer.send('getPicBeds')
ipcRenderer.on('getPicBeds', this.getPicBeds)
}
getPicBeds (event: Event, picBeds: PicBedType[]) {
getPicBeds (event: Event, picBeds: IPicBedType[]) {
this.picBed = picBeds
this.form.showPicBedList = this.picBed.map(item => {
if (item.visible) {

View File

@ -102,13 +102,13 @@ import { ipcRenderer } from 'electron'
name: 'shortcut-page'
})
export default class extends Vue {
list: ShortKeyConfig[] = []
list: IShortKeyConfig[] = []
keyBindingVisible = false
shortKeyName = ''
shortKey = ''
currentIndex = 0
created () {
const shortKeyConfig = this.$db.get('settings.shortKey') as ShortKeyConfigs
const shortKeyConfig = this.$db.get('settings.shortKey') as IShortKeyConfigs
this.list = Object.keys(shortKeyConfig).map(item => shortKeyConfig[item])
}
@Watch('keyBindingVisible')
@ -119,7 +119,7 @@ export default class extends Vue {
const [origin] = item.split(':')
return origin
}
toggleEnable (item: ShortKeyConfig) {
toggleEnable (item: IShortKeyConfig) {
const status = !item.enable
item.enable = status
this.$db.set(`settings.shortKey.${item.name}.enable`, status)

View File

@ -72,7 +72,7 @@ export default class extends Vue {
showProgress = false
showError = false
pasteStyle = ''
picBed: PicBedType[] = []
picBed: IPicBedType[] = []
picBedName = ''
menu: Electron.Menu | null= null
mounted () {
@ -122,7 +122,7 @@ export default class extends Vue {
(document.getElementById('file-uploader') as HTMLInputElement).value = ''
}
ipcSendFiles (files: FileList) {
let sendFiles: FileWithPath[] = []
let sendFiles: IFileWithPath[] = []
Array.from(files).forEach((item, index) => {
let obj = {
name: item.name,
@ -149,7 +149,7 @@ export default class extends Vue {
}
})
}
getPicBeds (event: Event, picBeds: PicBedType[]) {
getPicBeds (event: Event, picBeds: IPicBedType[]) {
this.picBed = picBeds
this.getDefaultPicBed()
}

View File

@ -64,47 +64,43 @@
</el-row>
</div>
</template>
<script>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/ConfirmButtonMixin'
export default {
mixins: [mixin],
@Component({
name: 'aliyun',
data () {
return {
form: {
accessKeyId: '',
accessKeySecret: '',
bucket: '',
area: '',
path: '',
customUrl: ''
}
}
},
mixins: [mixin]
})
export default class extends Vue {
form: IAliYunConfig = {
accessKeyId: '',
accessKeySecret: '',
bucket: '',
area: '',
path: '',
customUrl: ''
}
created () {
const config = this.$db.get('picBed.aliyun')
const config = this.$db.get('picBed.aliyun') as IAliYunConfig
if (config) {
for (let i in config) {
this.form[i] = config[i]
}
this.form = Object.assign({}, config)
}
},
methods: {
confirm () {
this.$refs.aliyun.validate((valid) => {
if (valid) {
this.$db.set('picBed.aliyun', this.form).write()
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
} else {
return false
}
confirm () {
// @ts-ignore
this.$refs.aliyun.validate((valid) => {
if (valid) {
this.$db.set('picBed.aliyun', this.form)
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
})
}
} else {
return false
}
})
}
}
</script>

View File

@ -56,46 +56,42 @@
</el-row>
</div>
</template>
<script>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/ConfirmButtonMixin'
export default {
@Component({
name: 'github',
mixins: [mixin],
data () {
return {
form: {
repo: '',
token: '',
path: '',
customUrl: '',
branch: ''
}
}
},
mixins: [mixin]
})
export default class extends Vue {
form: IGitHubConfig = {
repo: '',
token: '',
path: '',
customUrl: '',
branch: ''
}
created () {
const config = this.$db.get('picBed.github')
const config = this.$db.get('picBed.github') as IGitHubConfig
if (config) {
for (let i in config) {
this.form[i] = config[i]
}
this.form = Object.assign({}, config)
}
},
methods: {
confirm () {
this.$refs.github.validate((valid) => {
if (valid) {
this.$db.set('picBed.github', this.form).write()
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
} else {
return false
}
confirm () {
// @ts-ignore
this.$refs.github.validate((valid) => {
if (valid) {
this.$db.set('picBed.github', this.form)
const successNotification = new Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
})
}
} else {
return false
}
})
}
}
</script>

View File

@ -36,43 +36,39 @@
</el-row>
</div>
</template>
<script>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/ConfirmButtonMixin'
export default {
@Component({
name: 'imgur',
mixins: [mixin],
data () {
return {
form: {
clientId: '',
proxy: ''
}
}
},
mixins: [mixin]
})
export default class extends Vue {
form: IImgurConfig = {
clientId: '',
proxy: ''
}
created () {
const config = this.$db.get('picBed.imgur')
const config = this.$db.get('picBed.imgur') as IImgurConfig
if (config) {
for (let i in config) {
this.form[i] = config[i]
}
this.form = Object.assign({}, config)
}
},
methods: {
confirm () {
this.$refs.imgur.validate((valid) => {
if (valid) {
this.$db.set('picBed.imgur', this.form).write()
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
} else {
return false
}
confirm () {
// @ts-ignore
this.$refs.imgur.validate((valid) => {
if (valid) {
this.$db.set('picBed.imgur', this.form)
const successNotification = new Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
})
}
} else {
return false
}
})
}
}
</script>

View File

@ -27,57 +27,61 @@
</el-row>
</div>
</template>
<script>
import ConfigForm from '@/components/ConfigForm'
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import ConfigForm from '@/components/ConfigForm.vue'
import mixin from '@/utils/ConfirmButtonMixin'
export default {
import {
ipcRenderer,
IpcRendererEvent
} from 'electron'
@Component({
name: 'OtherPicBed',
mixins: [mixin],
components: {
ConfigForm
},
data () {
return {
type: '',
config: [],
picBedName: ''
}
},
}
})
export default class extends Vue {
type: string = ''
config: any[] = []
picBedName: string = ''
created () {
this.type = this.$route.params.type
this.$electron.ipcRenderer.send('getPicBedConfig', this.$route.params.type)
this.$electron.ipcRenderer.on('getPicBedConfig', this.getPicBeds)
},
methods: {
async handleConfirm () {
const result = await this.$refs.configForm.validate()
if (result !== false) {
this.$db.set(`picBed.${this.type}`, result)
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
}
},
setDefaultPicBed (type) {
this.$db.set('picBed.current', type)
this.defaultPicBed = type
const successNotification = new window.Notification('设置默认图床', {
ipcRenderer.send('getPicBedConfig', this.$route.params.type)
ipcRenderer.on('getPicBedConfig', this.getPicBeds)
}
async handleConfirm () {
// @ts-ignore
const result = await this.$refs.configForm.validate()
if (result !== false) {
this.$db.set(`picBed.${this.type}`, result)
const successNotification = new Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
},
getPicBeds (event, config, name) {
this.config = config
this.picBedName = name
}
},
}
setDefaultPicBed (type: string) {
this.$db.set('picBed.current', type)
// @ts-ignore mixin
this.defaultPicBed = type
const successNotification = new Notification('设置默认图床', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
}
getPicBeds (event: IpcRendererEvent, config: any[], name: string) {
this.config = config
this.picBedName = name
}
beforeDestroy () {
this.$electron.ipcRenderer.removeListener('getPicBedConfig', this.getPicBeds)
ipcRenderer.removeListener('getPicBedConfig', this.getPicBeds)
}
}
</script>

View File

@ -71,48 +71,44 @@
</el-row>
</div>
</template>
<script>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/ConfirmButtonMixin'
export default {
mixins: [mixin],
@Component({
name: 'qiniu',
data () {
return {
form: {
accessKey: '',
secretKey: '',
bucket: '',
url: '',
area: '',
options: '',
path: ''
}
}
},
mixins: [mixin]
})
export default class extends Vue {
form: IQiniuConfig = {
accessKey: '',
secretKey: '',
bucket: '',
url: '',
area: '',
options: '',
path: ''
}
created () {
const config = this.$db.get('picBed.qiniu')
const config = this.$db.get('picBed.qiniu') as IQiniuConfig
if (config) {
for (let i in config) {
this.form[i] = config[i]
}
this.form = Object.assign({}, config)
}
},
methods: {
confirm () {
this.$refs.qiniu.validate((valid) => {
if (valid) {
this.$db.set('picBed.qiniu', this.form).write()
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
} else {
return false
}
confirm () {
// @ts-ignore
this.$refs.qiniu.validate((valid) => {
if (valid) {
this.$db.set('picBed.qiniu', this.form)
const successNotification = new Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
})
}
} else {
return false
}
})
}
}
</script>

View File

@ -15,24 +15,23 @@
</el-row>
</div>
</template>
<script>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/ConfirmButtonMixin'
export default {
mixins: [mixin],
name: 'upyun',
data () {
return {}
},
methods: {
confirm () {
this.$db.set('picBed.smms', true).write()
this.setDefaultPicBed('smms')
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
@Component({
name: 'smms',
mixins: [mixin]
})
export default class extends Vue {
confirm () {
this.$db.set('picBed.smms', true)
// @ts-ignore mixin
this.setDefaultPicBed('smms')
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
}
}

View File

@ -85,52 +85,49 @@
</el-row>
</div>
</template>
<script>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/ConfirmButtonMixin'
export default {
mixins: [mixin],
import { remote } from 'electron'
@Component({
name: 'tcyun',
data () {
return {
form: {
secretId: '',
secretKey: '',
bucket: '',
appId: '',
area: '',
path: '',
customUrl: '',
version: 'v4'
}
}
},
mixins: [mixin]
})
export default class extends Vue {
form: ITcYunConfig = {
secretId: '',
secretKey: '',
bucket: '',
appId: '',
area: '',
path: '',
customUrl: '',
version: 'v4'
}
created () {
const config = this.$db.get('picBed.tcyun')
const config = this.$db.get('picBed.tcyun') as ITcYunConfig
if (config) {
for (let i in config) {
this.form[i] = config[i]
}
this.form = Object.assign({}, config)
}
},
methods: {
confirm () {
this.$refs.tcyun.validate((valid) => {
if (valid) {
this.$db.set('picBed.tcyun', this.form).write()
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
} else {
return false
}
confirm () {
// @ts-ignore
this.$refs.tcyun.validate((valid) => {
if (valid) {
this.$db.set('picBed.tcyun', this.form)
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
})
},
openWiki () {
this.$electron.remote.shell.openExternal('https://github.com/Molunerfinn/PicGo/wiki/%E8%AF%A6%E7%BB%86%E7%AA%97%E5%8F%A3%E7%9A%84%E4%BD%BF%E7%94%A8#腾讯云cos')
}
} else {
return false
}
})
}
openWiki () {
remote.shell.openExternal('https://github.com/Molunerfinn/PicGo/wiki/%E8%AF%A6%E7%BB%86%E7%AA%97%E5%8F%A3%E7%9A%84%E4%BD%BF%E7%94%A8#腾讯云cos')
}
}
</script>

View File

@ -64,46 +64,42 @@
</el-row>
</div>
</template>
<script>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/ConfirmButtonMixin'
export default {
@Component({
name: 'upyun',
mixins: [mixin],
data () {
return {
form: {
bucket: '',
operator: '',
password: '',
options: '',
path: ''
}
}
},
mixins: [mixin]
})
export default class extends Vue {
form: IUpYunConfig = {
bucket: '',
operator: '',
password: '',
options: '',
path: ''
}
created () {
const config = this.$db.get('picBed.upyun')
const config = this.$db.get('picBed.upyun') as IUpYunConfig
if (config) {
for (let i in config) {
this.form[i] = config[i]
}
this.form = Object.assign({}, config)
}
},
methods: {
confirm () {
this.$refs.tcyun.validate((valid) => {
if (valid) {
this.$db.set('picBed.upyun', this.form).write()
const successNotification = new window.Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
} else {
return false
}
confirm () {
// @ts-ignore
this.$refs.tcyun.validate((valid) => {
if (valid) {
this.$db.set('picBed.upyun', this.form)
const successNotification = new Notification('设置结果', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
})
}
} else {
return false
}
})
}
}
</script>

View File

@ -3,7 +3,7 @@
<el-row :gutter="16">
<el-col :span="16" :offset="4">
<div class="view-title">
微博图床设置
微博图床设置[已停止支持]
</div>
<el-form
ref="weiboForm"

View File

@ -19,30 +19,30 @@ interface ImgInfo {
[propName: string]: any
}
interface PicBedType {
interface IPicBedType {
type: string
name: string
visible: boolean
}
// Config Settings
interface ShortKeyConfig {
interface IShortKeyConfig {
enable: boolean
key: string // 按键
name: string
label: string
}
interface ShortKeyConfigs {
[propName: string]: ShortKeyConfig
interface IShortKeyConfigs {
[propName: string]: IShortKeyConfig
}
interface OldShortKeyConfigs {
interface IOldShortKeyConfigs {
upload: string
}
// Main process
interface BrowserWindowOptions {
interface IBrowserWindowOptions {
height: number,
width: number,
show: boolean,
@ -67,12 +67,12 @@ interface BrowserWindowOptions {
alwaysOnTop?: boolean
}
interface FileWithPath {
interface IFileWithPath {
path: string
name?: string
}
interface Bounds {
interface IBounds {
x: number
y: number
}
@ -140,3 +140,56 @@ interface IShowInputBoxOption {
title: string
placeholder: string
}
// PicBeds
interface IAliYunConfig {
accessKeyId: string
accessKeySecret: string,
bucket: string,
area: string,
path: string,
customUrl: string
}
interface IGitHubConfig {
repo: string,
token: string,
path: string,
customUrl: string,
branch: string
}
interface IImgurConfig {
clientId: string,
proxy: string
}
interface IQiniuConfig {
accessKey: string,
secretKey: string,
bucket: string,
url: string,
area: string,
options: string,
path: string
}
interface ITcYunConfig {
secretId: string,
secretKey: string,
bucket: string,
appId: string,
area: string,
path: string,
customUrl: string,
version: 'v4' | 'v5'
}
interface IUpYunConfig {
bucket: string,
operator: string,
password: string,
options: string,
path: string
}