2018-09-17 04:52:01 -04:00
|
|
|
<template>
|
|
|
|
<div id="plugin-view">
|
|
|
|
<div class="view-title">
|
|
|
|
插件设置
|
|
|
|
</div>
|
|
|
|
<el-row class="handle-bar">
|
|
|
|
<el-input
|
|
|
|
v-model="searchText"
|
|
|
|
placeholder="搜索npm上的PicGo插件"
|
|
|
|
size="small"
|
|
|
|
></el-input>
|
|
|
|
</el-row>
|
2018-09-18 06:48:55 -04:00
|
|
|
<el-row :gutter="10" class="plugin-list">
|
|
|
|
<el-col :span="12" v-for="(item, index) in pluginList" :key="item.name">
|
2018-09-17 04:52:01 -04:00
|
|
|
<div class="plugin-item">
|
2018-09-18 06:48:55 -04:00
|
|
|
<img class="plugin-item__logo" :src="'file://' + item.logo">
|
2018-09-17 04:52:01 -04:00
|
|
|
<div class="plugin-item__content">
|
|
|
|
<div class="plugin-item__name">
|
2018-09-18 06:48:55 -04:00
|
|
|
{{ item.name }}
|
2018-09-17 04:52:01 -04:00
|
|
|
</div>
|
|
|
|
<div class="plugin-item__desc">
|
2018-09-18 06:48:55 -04:00
|
|
|
{{ item.description }}
|
2018-09-17 04:52:01 -04:00
|
|
|
</div>
|
|
|
|
<div class="plugin-item__info-bar">
|
|
|
|
<span class="plugin-item__author">
|
2018-09-18 06:48:55 -04:00
|
|
|
{{ item.author }}
|
2018-09-17 04:52:01 -04:00
|
|
|
</span>
|
2018-09-18 06:48:55 -04:00
|
|
|
<span class="plugin-item__config" >
|
2018-09-20 02:49:20 -04:00
|
|
|
<!-- <span class="reload-button" v-if="item.reload" @click="reloadApp">
|
2018-09-18 06:48:55 -04:00
|
|
|
重启
|
2018-09-20 02:49:20 -04:00
|
|
|
</span> -->
|
2018-09-18 06:48:55 -04:00
|
|
|
<i
|
|
|
|
class="el-icon-setting"
|
|
|
|
@click="buildContextMenu(item)"
|
|
|
|
></i>
|
2018-09-17 04:52:01 -04:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
2018-09-19 05:27:09 -04:00
|
|
|
<el-dialog
|
|
|
|
:visible.sync="dialogVisible"
|
|
|
|
:modal-append-to-body="false"
|
|
|
|
:title="`配置${configName}`"
|
|
|
|
width="70%"
|
|
|
|
>
|
|
|
|
<config-form
|
|
|
|
:config="config"
|
|
|
|
:type="currentType"
|
|
|
|
:name="configName"
|
|
|
|
ref="configForm"
|
|
|
|
>
|
|
|
|
</config-form>
|
|
|
|
<span slot="footer">
|
|
|
|
<el-button @click="dialogVisible = false" round>取消</el-button>
|
|
|
|
<el-button type="primary" @click="handleConfirmConfig" round>确定</el-button>
|
|
|
|
</span>
|
|
|
|
</el-dialog>
|
2018-09-17 04:52:01 -04:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2018-09-19 05:27:09 -04:00
|
|
|
import ConfigForm from '../ConfigForm'
|
2018-09-17 04:52:01 -04:00
|
|
|
export default {
|
|
|
|
name: 'plugin',
|
2018-09-19 05:27:09 -04:00
|
|
|
components: {
|
|
|
|
ConfigForm
|
|
|
|
},
|
2018-09-17 04:52:01 -04:00
|
|
|
data () {
|
|
|
|
return {
|
2018-09-18 06:48:55 -04:00
|
|
|
searchText: '',
|
|
|
|
pluginList: [],
|
2018-09-19 05:27:09 -04:00
|
|
|
menu: null,
|
|
|
|
config: [],
|
|
|
|
currentType: '',
|
|
|
|
configName: '',
|
|
|
|
dialogVisible: false
|
2018-09-18 06:48:55 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created () {
|
|
|
|
this.$electron.ipcRenderer.on('pluginList', (evt, list) => {
|
|
|
|
this.pluginList = list.map(item => {
|
2018-09-20 02:49:20 -04:00
|
|
|
// item.reload = false
|
2018-09-18 06:48:55 -04:00
|
|
|
return item
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.getPluginList()
|
|
|
|
document.addEventListener('keydown', (e) => {
|
|
|
|
if (e.which === 123) {
|
|
|
|
this.$electron.remote.getCurrentWindow().toggleDevTools()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
buildContextMenu (plugin) {
|
|
|
|
const _this = this
|
|
|
|
let menu = [{
|
|
|
|
label: '启用插件',
|
|
|
|
enabled: !plugin.enabled,
|
|
|
|
click () {
|
2018-09-19 05:27:09 -04:00
|
|
|
_this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, true).write()
|
2018-09-18 06:48:55 -04:00
|
|
|
plugin.enabled = true
|
2018-09-20 02:49:20 -04:00
|
|
|
// plugin.reload = true
|
2018-09-18 06:48:55 -04:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
label: '禁用插件',
|
|
|
|
enabled: plugin.enabled,
|
|
|
|
click () {
|
2018-09-19 05:27:09 -04:00
|
|
|
_this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, false).write()
|
2018-09-18 06:48:55 -04:00
|
|
|
plugin.enabled = false
|
2018-09-20 02:49:20 -04:00
|
|
|
// plugin.reload = true
|
2018-09-18 06:48:55 -04:00
|
|
|
}
|
|
|
|
}]
|
2018-09-19 05:27:09 -04:00
|
|
|
for (let i in plugin.config) {
|
|
|
|
if (plugin.config[i].config.length > 0) {
|
|
|
|
const obj = {
|
|
|
|
label: `配置${i} - ${plugin.config[i].name}`,
|
|
|
|
click () {
|
2018-09-20 02:49:20 -04:00
|
|
|
_this.currentType = i
|
2018-09-19 05:27:09 -04:00
|
|
|
_this.configName = plugin.config[i].name
|
|
|
|
_this.dialogVisible = true
|
|
|
|
_this.config = plugin.config[i].config
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu.push(obj)
|
|
|
|
}
|
|
|
|
}
|
2018-09-18 06:48:55 -04:00
|
|
|
this.menu = this.$electron.remote.Menu.buildFromTemplate(menu)
|
|
|
|
this.menu.popup(this.$electron.remote.getCurrentWindow())
|
|
|
|
},
|
|
|
|
getPluginList () {
|
|
|
|
this.$electron.ipcRenderer.send('getPluginList')
|
|
|
|
},
|
|
|
|
reloadApp () {
|
|
|
|
this.$electron.remote.app.relaunch()
|
|
|
|
this.$electron.remote.app.exit(0)
|
2018-09-19 05:27:09 -04:00
|
|
|
},
|
2018-09-20 02:49:20 -04:00
|
|
|
async handleConfirmConfig () {
|
|
|
|
const result = await this.$refs.configForm.validate()
|
|
|
|
if (result !== false) {
|
|
|
|
switch (this.currentType) {
|
|
|
|
case 'plugin':
|
|
|
|
this.$db.read().set(`picgo-plugin-${this.configName}`, result).write()
|
|
|
|
break
|
|
|
|
case 'uploader':
|
|
|
|
this.$db.read().set(`picBed.${this.configName}`, result).write()
|
|
|
|
break
|
|
|
|
case 'transformer':
|
|
|
|
this.$db.read().set(`transformer.${this.configName}`, result).write()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
const successNotification = new window.Notification('设置结果', {
|
|
|
|
body: '设置成功'
|
|
|
|
})
|
|
|
|
successNotification.onclick = () => {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
this.dialogVisible = false
|
|
|
|
this.getPluginList()
|
|
|
|
}
|
2018-09-17 04:52:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang='stylus'>
|
|
|
|
.view-title
|
|
|
|
color #eee
|
|
|
|
font-size 20px
|
|
|
|
text-align center
|
|
|
|
margin 10px auto
|
|
|
|
#plugin-view
|
|
|
|
padding 0 20px 0
|
|
|
|
.handle-bar
|
|
|
|
margin-bottom 20px
|
|
|
|
.el-input__inner
|
|
|
|
border-radius 0
|
|
|
|
.plugin-item
|
|
|
|
box-sizing border-box
|
|
|
|
height 80px
|
|
|
|
background #444
|
|
|
|
padding 8px
|
|
|
|
user-select text
|
|
|
|
transition all .2s ease-in-out
|
|
|
|
cursor pointer
|
2018-09-18 06:48:55 -04:00
|
|
|
margin-bottom 10px
|
2018-09-17 04:52:01 -04:00
|
|
|
&:hover
|
|
|
|
background #333
|
|
|
|
&__logo
|
|
|
|
width 64px
|
|
|
|
height 64px
|
|
|
|
float left
|
|
|
|
&__content
|
|
|
|
float left
|
2018-09-18 06:48:55 -04:00
|
|
|
width calc(100% - 72px)
|
2018-09-17 04:52:01 -04:00
|
|
|
height 64px
|
|
|
|
color #aaa
|
|
|
|
margin-left 8px
|
|
|
|
display flex
|
|
|
|
flex-direction column
|
|
|
|
justify-content space-between
|
|
|
|
&__name
|
|
|
|
font-size 16px
|
|
|
|
height 22px
|
|
|
|
line-height 22px
|
2018-09-19 05:27:09 -04:00
|
|
|
// font-weight 600
|
|
|
|
font-weight 600
|
2018-09-17 04:52:01 -04:00
|
|
|
&__desc
|
|
|
|
font-size 14px
|
|
|
|
height 21px
|
|
|
|
line-height 21px
|
|
|
|
overflow hidden
|
|
|
|
text-overflow ellipsis
|
|
|
|
white-space nowrap
|
|
|
|
&__info-bar
|
|
|
|
font-size 14px
|
|
|
|
height 21px
|
|
|
|
line-height 28px
|
2018-09-18 06:48:55 -04:00
|
|
|
position relative
|
2018-09-17 04:52:01 -04:00
|
|
|
&__author
|
|
|
|
overflow hidden
|
|
|
|
text-overflow ellipsis
|
|
|
|
white-space nowrap
|
|
|
|
&__config
|
|
|
|
float right
|
|
|
|
font-size 16px
|
2018-09-18 06:48:55 -04:00
|
|
|
.reload-button
|
|
|
|
font-size 12px
|
|
|
|
color #ddd
|
|
|
|
background #222
|
|
|
|
padding 1px 8px
|
|
|
|
height 18px
|
|
|
|
line-height 18px
|
|
|
|
text-align center
|
|
|
|
position absolute
|
|
|
|
top 4px
|
|
|
|
right 20px
|
2018-09-17 04:52:01 -04:00
|
|
|
</style>
|