Skip to content

Commit

Permalink
添加剪贴板配置项 #33
Browse files Browse the repository at this point in the history
添加快捷键配置快速入口 #32
  • Loading branch information
baiy committed Dec 21, 2020
1 parent f09c3f2 commit 31aec93
Show file tree
Hide file tree
Showing 6 changed files with 22,002 additions and 8,046 deletions.
29,891 changes: 21,872 additions & 8,019 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions src/tool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,31 @@
<Button type="primary" @click="historyClear">清空历史记录</Button>
</div>
</Drawer>
<Drawer title="设置" v-model="settingShow" :width="300">
<setting-block v-if="settingShow"></setting-block>
</Drawer>
</div>
</template>

<script>
import config from './tool/config'
import settingBlock from "./views/setting/block"
import model from './tool/model'
import historyFactory from './tool/history'
import {setLoadHistoryIndex} from './tool/history'
import { openTab } from './helper'
export default {
components: {
"setting-block": settingBlock
},
data () {
return {
category: config.category,
currentCategory: '',
currentTool: '',
historyData: [],
settingShow:false,
historyShow: false,
historyColumns: [
{
Expand Down Expand Up @@ -134,7 +142,7 @@ export default {
openTab('https://github.com/baiy/Ctool')
break
case '_setting':
openTab('/setting.html')
this.settingShow = true;
break
case '_new':
openTab(window.location.href)
Expand All @@ -161,7 +169,19 @@ export default {
return JSON.stringify(value)
},
historyView(index){
console.log(historyFactory(this.currentTool).get(index))
this.$Modal.info({
render: (h) => {
return h('Input', {
props: {
type:"textarea",
rows:"10",
value: JSON.stringify(historyFactory(this.currentTool).get(index), null, "\t"),
}
})
},
width:700,
okText:"关闭"
})
},
historyClear(){
historyFactory(this.currentTool).clear()
Expand Down
55 changes: 34 additions & 21 deletions src/tool/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ const category = [
]

const tool = [
{ 'name': 'hash', 'title': '哈希(hash)', cat: ['encryption'] },
{ 'name': 'encrypt', 'title': '加密/解密', cat: ['encryption'] },
{ 'name': 'base64', 'title': 'BASE64编码', cat: ['encryption'] },
{ 'name': 'json', 'title': 'JSON工具', cat: ['conversion', 'json'] },
{ 'name': 'url', 'title': 'URL编码', cat: ['conversion'] },
{ 'name': 'timestamp', 'title': '时间戳', cat: ['conversion'] },
{ 'name': 'qrCode', 'title': '二维码', cat: ['other'] },
{ 'name': 'pinyin', 'title': '汉字转拼音', cat: ['conversion'] },
{ 'name': 'ip', 'title': 'IP地址查询', cat: ['other'] },
{ 'name': 'code', 'title': '代码格式化', cat: ['other'] },
{ 'name': 'unicode', 'title': 'Unicode', cat: ['conversion'] },
{ 'name': 'decimalConvert', 'title': '进制转换', cat: ['conversion'] },
{ 'name': 'regex', 'title': '正则表达式', cat: ['other'] },
{ 'name': 'randomString', 'title': '随机字符生成', cat: ['other'] },
{ 'name': 'hash', 'title': '哈希(hash)', 'cat': ['encryption'] },
{ 'name': 'encrypt', 'title': '加密/解密', 'cat': ['encryption'] },
{ 'name': 'base64', 'title': 'BASE64编码', 'cat': ['encryption'] },
{ 'name': 'json', 'title': 'JSON工具', 'cat': ['conversion', 'json'] },
{ 'name': 'url', 'title': 'URL编码', 'cat': ['conversion'] },
{ 'name': 'timestamp', 'title': '时间戳', 'cat': ['conversion'] },
{ 'name': 'qrCode', 'title': '二维码', 'cat': ['other'] },
{ 'name': 'pinyin', 'title': '汉字转拼音', 'cat': ['conversion'] },
{ 'name': 'ip', 'title': 'IP地址查询', 'cat': ['other'] },
{ 'name': 'code', 'title': '代码格式化', 'cat': ['other'] },
{ 'name': 'unicode', 'title': 'Unicode', 'cat': ['conversion'] },
{ 'name': 'decimalConvert', 'title': '进制转换', 'cat': ['conversion'] },
{ 'name': 'regex', 'title': '正则表达式', 'cat': ['other'] },
{ 'name': 'randomString', 'title': '随机字符生成', 'cat': ['other'] },
{
'name': 'phpArraySerialize',
'title': 'PHP数组/序列化',
cat: ['conversion', 'json'],
'cat': ['conversion', 'json'],
},
{ 'name': 'diffs', 'title': '文本差异化对比', cat: ['other'] },
{ 'name': 'crontab', 'title': 'crontab校验', cat: ['other'] },
{ 'name': 'websocket', 'title': 'websocket调试', cat: ['other'] },
{ 'name': 'unit', 'title': '单位换算', cat: ['other'] },
{ 'name': 'time', 'title': '时间计算器', cat: ['other'] },
{ 'name': 'diffs', 'title': '文本差异化对比', 'cat': ['other'] },
{ 'name': 'crontab', 'title': 'crontab校验', 'cat': ['other'] },
{ 'name': 'websocket', 'title': 'websocket调试', 'cat': ['other'] },
{ 'name': 'unit', 'title': '单位换算', 'cat': ['other'] },
{ 'name': 'time', 'title': '时间计算器', 'cat': ['other'] },
]

// 徽章是否显示
Expand All @@ -72,11 +72,24 @@ const getToolTitle = function (name) {
return tool[i].title
}
}
return ""
return ''
}

const getSetting = function (name, defaultValue = null) {
let setting = cache.getNoVersion('setting', {})
return !setting.hasOwnProperty(name) ? defaultValue : setting[name]
}

const saveSetting = function (name, value) {
let setting = cache.getNoVersion('setting', {})
setting[name] = value
cache.setNoVersion('setting',setting);
}

export default {
tool,
saveSetting,
getSetting,
category,
setUserCommon,
getToolTitle,
Expand Down
11 changes: 7 additions & 4 deletions src/tool/model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import config from './config'
import setting from './setting'
import cache from './cache'
import history from './history.js'

Expand Down Expand Up @@ -44,17 +45,19 @@ export const plugin = {
install: function (Vue) {
Vue.prototype.$getToolData = function (clipboardField = '') {
let data = history(model.getCurrentTool()).current()
let paste = clipboardPaste()
if (clipboardField && !data[clipboardField] && paste) {
data[clipboardField] = paste
if (setting.autoReadCopy()){
let paste = clipboardPaste()
if (clipboardField && !data[clipboardField] && paste) {
data[clipboardField] = paste
}
}
return data
}
Vue.prototype.$saveToolData = function (data) {
return history(model.getCurrentTool()).push(data)
}
Vue.prototype.$clipboardCopy = function (data) {
if (!data) return
if (!setting.autoSaveCopy() || !data) return
document.querySelector(
'#clipboard').innerHTML = '<textarea id="clipboard-text"></textarea>'
document.querySelector('#clipboard-text').value = data
Expand Down
16 changes: 16 additions & 0 deletions src/tool/setting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import config from './config'

export default {
autoSaveCopy (value = null) {
if (value === null) {
return config.getSetting('auto_save_copy', true)
}
return config.saveSetting('auto_save_copy', value)
},
autoReadCopy (value = null) {
if (value === null) {
return config.getSetting('auto_read_copy', true)
}
return config.saveSetting('auto_read_copy', value)
},
}
51 changes: 51 additions & 0 deletions src/views/setting/block.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<div>
<CellGroup @on-click="open">
<Cell title="常用工具设置" name="setting"/>
<Cell title="快捷键设置" name="shortcuts"/>
</CellGroup>
<CellGroup>
<Cell title="自动复制结果到剪贴板">
<i-switch v-model="auto_save_copy" slot="extra"/>
</Cell>
<Cell title="自动读取剪贴板内容">
<i-switch v-model="auto_read_copy" slot="extra"/>
</Cell>
</CellGroup>
</div>
</template>

<script>
import { openTab } from '../../helper'
import setting from '../../tool/setting'
export default {
data () {
return {
auto_save_copy: true,
auto_read_copy: true,
}
},
created () {
this.auto_save_copy = setting.autoSaveCopy()
this.auto_read_copy = setting.autoReadCopy()
},
beforeDestroy () {
setting.autoSaveCopy(this.auto_save_copy)
setting.autoReadCopy(this.auto_read_copy)
},
methods: {
open (name) {
console.log(name)
switch (name) {
case 'shortcuts':
openTab('chrome://extensions/shortcuts')
break
case 'setting':
openTab('/setting.html')
break
}
},
},
}
</script>

0 comments on commit 31aec93

Please sign in to comment.