PicList/src/renderer/components/SettingPage.vue

345 lines
8.9 KiB
Vue
Raw Normal View History

2017-11-27 19:21:12 -05:00
<template>
<div id="setting-page">
<div class="fake-title-bar">
PicGo - {{ version }}
2018-01-10 03:51:09 -05:00
<div class="handle-bar" v-if="os === 'win32'">
<i class="el-icon-minus" @click="minimizeWindow"></i>
<i class="el-icon-close" @click="closeWindow"></i>
</div>
2017-11-27 19:21:12 -05:00
</div>
2018-01-10 03:51:09 -05:00
<el-row style="padding-top: 22px;" class="main-content">
2018-04-13 23:02:02 -04:00
<el-col :span="5" class="side-bar-menu">
2017-11-27 19:21:12 -05:00
<el-menu
class="picgo-sidebar"
:default-active="defaultActive"
@select="handleSelect"
2018-04-27 12:16:17 -04:00
:unique-opened="true"
2017-11-27 19:21:12 -05:00
>
<el-menu-item index="upload">
<i class="el-icon-upload"></i>
<span slot="title">上传区</span>
</el-menu-item>
2017-12-06 22:26:29 -05:00
<el-menu-item index="gallery">
<i class="el-icon-picture"></i>
<span slot="title">相册</span>
</el-menu-item>
2018-04-13 23:02:02 -04:00
<el-submenu
index="sub-menu"
>
<template slot="title">
<i class="el-icon-menu"></i>
<span>图床设置</span>
</template>
<template
2018-04-27 12:16:17 -04:00
v-for="item in picBed"
>
<el-menu-item
v-if="item.visible"
:index="item.type"
:key="item.type"
>
2018-06-04 09:30:36 -04:00
<!-- <i :class="`el-icon-ui-${item.type}`"></i> -->
<span slot="title">{{ item.name }}</span>
</el-menu-item>
</template>
2018-04-13 23:02:02 -04:00
</el-submenu>
2018-04-27 12:16:17 -04:00
<el-menu-item index="setting">
<i class="el-icon-setting"></i>
<span slot="title">PicGo设置</span>
</el-menu-item>
2017-11-27 19:21:12 -05:00
</el-menu>
2018-04-28 04:22:35 -04:00
<i class="el-icon-info setting-window" @click="openDialog"></i>
2017-11-27 19:21:12 -05:00
</el-col>
2017-12-06 22:26:29 -05:00
<el-col :span="19" :offset="5">
2017-11-27 19:21:12 -05:00
<router-view></router-view>
</el-col>
</el-row>
<el-dialog
title="赞助PicGo"
:visible.sync="visible"
width="70%"
top="10vh"
>
PicGo是免费开源的软件如果你喜欢它对你有帮助不妨请我喝杯咖啡
<el-row class="support">
<el-col :span="12">
<img src="https://user-images.githubusercontent.com/12621342/34188165-e7cdf372-e56f-11e7-8732-1338c88b9bb7.jpg" alt="支付宝">
<div class="support-title">支付宝</div>
</el-col>
<el-col :span="12">
<img src="https://user-images.githubusercontent.com/12621342/34188201-212cda84-e570-11e7-9b7a-abb298699d85.jpg" alt="支付宝">
<div class="support-title">微信</div>
</el-col>
</el-row>
</el-dialog>
2018-01-30 02:20:19 -05:00
<el-dialog
title="修改快捷键"
:visible.sync="keyBindingVisible"
>
<el-form
label-width="80px"
>
<el-form-item
label="快捷上传"
>
<el-input
class="align-center"
@keydown.native.prevent="keyDetect('upload', $event)"
v-model="shortKey.upload"
:autofocus="true"
></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<el-button @click="cancelKeyBinding">取消</el-button>
<el-button type="primary" @click="confirmKeyBinding">确定</el-button>
</span>
</el-dialog>
<el-dialog
title="自定义链接格式"
:visible.sync="customLinkVisible"
>
<el-form
label-position="top"
2018-03-09 03:18:17 -05:00
:model="customLink"
ref="customLink"
:rules="rules"
>
<el-form-item
label="用占位符$url来表示url的位置"
2018-03-09 03:18:17 -05:00
prop="value"
>
<el-input
class="align-center"
2018-03-09 03:18:17 -05:00
v-model="customLink.value"
:autofocus="true"
></el-input>
</el-form-item>
</el-form>
<div>
[]($url)
</div>
<span slot="footer">
<el-button @click="cancelCustomLink">取消</el-button>
<el-button type="primary" @click="confirmCustomLink">确定</el-button>
</span>
</el-dialog>
2017-11-27 19:21:12 -05:00
</div>
</template>
<script>
import pkg from '../../../package.json'
2018-01-30 02:20:19 -05:00
import keyDetect from 'utils/key-binding'
import { remote } from 'electron'
2018-01-30 02:20:19 -05:00
import db from '../../datastore'
2018-01-10 03:51:09 -05:00
const { Menu, dialog, BrowserWindow } = remote
2017-11-27 19:21:12 -05:00
export default {
name: 'setting-page',
data () {
2018-03-09 03:18:17 -05:00
const customLinkRule = (rule, value, callback) => {
if (!/\$url/.test(value)) {
return callback(new Error('必须含有$url'))
} else {
return callback()
}
}
2017-11-27 19:21:12 -05:00
return {
version: process.env.NODE_ENV === 'production' ? pkg.version : 'Dev',
defaultActive: 'upload',
menu: null,
2018-01-10 03:51:09 -05:00
visible: false,
2018-01-30 02:20:19 -05:00
keyBindingVisible: false,
customLinkVisible: false,
2018-03-09 03:18:17 -05:00
customLink: {
value: db.read().get('customLink').value() || '$url'
},
rules: {
value: [
{ validator: customLinkRule, trigger: 'blur' }
]
},
2018-01-30 02:20:19 -05:00
os: '',
shortKey: {
upload: db.read().get('shortKey.upload').value()
2018-04-27 12:16:17 -04:00
},
2018-04-28 04:22:35 -04:00
picBed: this.$picBed
2017-11-27 19:21:12 -05:00
}
},
created () {
2018-01-10 04:12:24 -05:00
this.os = process.platform
this.buildMenu()
},
2017-11-27 19:21:12 -05:00
methods: {
handleSelect (index) {
this.$router.push({
name: index
})
},
2018-01-10 03:51:09 -05:00
minimizeWindow () {
const window = BrowserWindow.getFocusedWindow()
window.minimize()
},
closeWindow () {
const window = BrowserWindow.getFocusedWindow()
window.close()
},
buildMenu () {
const _this = this
const template = [
{
label: '关于',
click () {
dialog.showMessageBox({
title: 'PicGo',
message: 'PicGo',
detail: `Version: ${pkg.version}\nAuthor: Molunerfinn\nGithub: https://github.com/Molunerfinn/PicGo`
})
}
},
{
label: '赞助PicGo',
click () {
_this.visible = true
}
}
]
this.menu = Menu.buildFromTemplate(template)
},
openDialog () {
this.menu.popup(remote.getCurrentWindow)
2018-01-30 02:20:19 -05:00
},
keyDetect (type, event) {
this.shortKey[type] = keyDetect(event).join('+')
},
cancelKeyBinding () {
this.keyBindingVisible = false
this.shortKey = db.read().get('shortKey').value()
},
confirmKeyBinding () {
const oldKey = db.read().get('shortKey').value()
db.read().set('shortKey', this.shortKey).write()
this.keyBindingVisible = false
this.$electron.ipcRenderer.send('updateShortKey', oldKey)
},
cancelCustomLink () {
this.customLinkVisible = false
2018-03-09 03:18:17 -05:00
this.customLink.value = db.read().get('customLink').value() || '$url'
},
confirmCustomLink () {
2018-03-09 03:18:17 -05:00
this.$refs.customLink.validate((valid) => {
if (valid) {
db.read().set('customLink', this.customLink.value).write()
this.customLinkVisible = false
this.$electron.ipcRenderer.send('updateCustomLink')
} else {
return false
}
})
2017-11-27 19:21:12 -05:00
}
},
beforeRouteEnter: (to, from, next) => {
next(vm => {
vm.defaultActive = to.name
})
}
}
</script>
<style lang='stylus'>
#setting-page
.fake-title-bar
-webkit-app-region drag
height h = 22px
width 100%
text-align center
color #eee
font-size 12px
line-height h
2017-12-06 22:26:29 -05:00
position fixed
2018-01-10 03:51:09 -05:00
z-index 100
.handle-bar
position absolute
top 2px
right 4px
width 40px
z-index 10000
-webkit-app-region no-drag
i
cursor pointer
font-size 16px
.el-icon-minus
&:hover
color #409EFF
.el-icon-close
&:hover
color #F15140
2018-04-13 23:02:02 -04:00
.side-bar-menu
2017-12-06 22:26:29 -05:00
position fixed
2018-04-13 23:02:02 -04:00
height calc(100vh - 22px)
overflow-x hidden
overflow-y auto
width 170px
2018-04-28 04:22:35 -04:00
.el-icon-info.setting-window
2018-04-13 23:02:02 -04:00
position fixed
bottom 4px
left 4px
cursor pointer
color #878d99
transition .2s all ease-in-out
&:hover
color #409EFF
2018-04-13 23:02:02 -04:00
.el-menu
border-right none
background transparent
width 170px
2017-11-27 19:21:12 -05:00
&-item
color #eee
position relative
&:focus,
&:hover
color #fff
background transparent
&.is-active
color active-color = #409EFF
&:before
content ''
position absolute
width 3px
height 20px
right 0
top 18px
background active-color
2018-04-13 23:02:02 -04:00
.el-submenu__title
span
color #eee
&:hover
background transparent
span
color #fff
.el-submenu
.el-menu-item
min-width 166px
&.is-active
&:before
top 16px
2018-01-10 03:51:09 -05:00
.main-content
padding-top 22px
position relative
z-index 10
.el-dialog__body
padding 20px
.support
text-align center
&-title
text-align center
color #878d99
2018-01-30 02:20:19 -05:00
.align-center
input
text-align center
2018-06-12 01:36:44 -04:00
*::-webkit-scrollbar
width 8px
height 8px
*::-webkit-scrollbar-thumb
border-radius 4px
background #6f6f6f
*::-webkit-scrollbar-track
background-color transparent
2017-11-27 19:21:12 -05:00
</style>