提交 3c5f9115 编写于 作者: B baiy 提交者: ninecents

添加剪贴板配置项 #33

添加快捷键配置快速入口 #32
上级 40ffde1f
此差异已折叠。
......@@ -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: [
{
......@@ -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)
......@@ -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()
......
......@@ -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'] },
]
// 徽章是否显示
......@@ -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,
......
import config from './config'
import setting from './setting'
import cache from './cache'
import history from './history.js'
......@@ -44,9 +45,11 @@ 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
}
......@@ -54,7 +57,7 @@ export const plugin = {
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
......
import config from './config'
export default {
/**
* @param value
* @return {boolean}
*/
autoSaveCopy(value = null) {
autoSaveCopy (value = null) {
if (value === null) {
return config.getSetting('auto_save_copy', true)
}
return config.saveSetting('auto_save_copy', value)
},
/**
* @param value
* @return {boolean}
*/
autoReadCopy(value = null) {
autoReadCopy (value = null) {
if (value === null) {
return config.getSetting('auto_read_copy', true)
}
return config.saveSetting('auto_read_copy', value)
},
/**
* @param value
* @return {boolean}
*/
autoReadCopyFilter(value = null) {
if (value === null) {
return config.getSetting('auto_read_copy_filter', false)
}
return config.saveSetting('auto_read_copy_filter', value)
},
/**
* @param value
* @return {boolean}
*/
displayMode(value = null) {
if (value === null) {
return config.getSetting('display_mode', 'light')
}
return config.saveSetting('display_mode', value)
},
/**
* @param value
* @return {boolean}
*/
locale(value = null) {
if (value === null) {
return config.getSetting('locale', '_default')
}
return config.saveSetting('locale', value)
},
}
}
\ No newline at end of file
<template>
<div>
<div>
<CellGroup @on-click="open">
<Cell :title="$t('main_common_tool')" name="setting"/>
<Cell v-if="is_chromium || is_firefox" :title="$t('main_keyboard_setting')" name="shortcuts"/>
<Cell :title="$t('main_display_mode')">
<Select v-model="display_mode" slot="extra" transfer>
<Option v-for="item in display_mode_list" :value="item" :key="item">{{ $t('main_display_mode_'+item)}}</Option>
</Select>
</Cell>
<Cell :title="$t('main_setting_language')">
<Select v-model="locale" slot="extra" transfer>
<Option v-for="item in locales" :value="item.code" :key="item.code">{{ item.name }}</Option>
</Select>
</Cell>
</CellGroup>
<CellGroup>
<Cell :title="$t('main_copy_results_to_clipboard')">
<i-switch v-model="auto_save_copy" slot="extra"/>
</Cell>
<Cell :title="$t('main_read_content_from_clipboard')">
<i-switch v-model="auto_read_copy" slot="extra"/>
</Cell>
<Cell :title="$t('main_read_clipboard_content_trim')">
<i-switch v-model="auto_read_copy_filter" slot="extra"/>
</Cell>
</CellGroup>
</div>
<Drawer :title="$t('main_ui_setting')" placement="left" v-model="settingShow" :width="90">
<setting-block v-if="settingShow"></setting-block>
</Drawer>
<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 {isChromium, isFirefox, isUtools, openUrl, setDisplayMode} from '../../helper'
import {LOCALE_LISTS, setCurrentLocale} from '../../i18n'
import { openTab } from '../../helper'
import setting from '../../tool/setting'
import settingBlock from './setting'
export default {
components: {
"setting-block": settingBlock
},
data() {
data () {
return {
settingShow: false,
auto_save_copy: true,
auto_read_copy: true,
display_mode: "light",
auto_read_copy_filter: false,
is_chromium: isChromium,
is_utools: isUtools,
is_firefox: isFirefox,
display_mode_list: ["light","dark","auto"],
locales: LOCALE_LISTS,
locale: "",
}
},
watch: {
display_mode(value) {
setDisplayMode(value)
},
locale(value) {
setCurrentLocale(value)
}
},
created() {
created () {
this.auto_save_copy = setting.autoSaveCopy()
this.auto_read_copy = setting.autoReadCopy()
this.auto_read_copy_filter = setting.autoReadCopyFilter()
this.display_mode = setting.displayMode()
this.locale = setting.locale()
},
beforeDestroy() {
beforeDestroy () {
setting.autoSaveCopy(this.auto_save_copy)
setting.autoReadCopy(this.auto_read_copy)
setting.autoReadCopyFilter(this.auto_read_copy_filter)
setting.displayMode(this.display_mode)
setting.locale(this.locale)
},
methods: {
open(name) {
open (name) {
console.log(name)
switch (name) {
case 'shortcuts':
if (this.is_firefox) {
return this.$Notice.success({
title: this.$t('main_keyboard_firefox_1'),
render: h => {
return h('span', [
this.$t('main_keyboard_firefox_2'),
h('a', {
attrs: {
href: 'https://jingyan.baidu.com/article/3ea51489f1d0a713e61bbaff.html',
target: '_blank'
}
}, this.$t('main_keyboard_firefox_3')),
])
}
});
}
openUrl('chrome://extensions/shortcuts')
openTab('chrome://extensions/shortcuts')
break
case 'setting':
this.settingShow = true
openTab('/setting.html')
break
}
}
},
},
}
</script>
</script>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册