提交 0beb21ee 编写于 作者: B baiy 提交者: ninecents

支持 utools 输入框直接输入数据带入界面中 #42

上级 1738d996
demo.jpg

169.0 KB

此差异已折叠。
{
"name": "c-tool",
"version": "1.5.6",
"version": "1.6.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --port 8081",
......@@ -23,6 +23,7 @@
"js-yaml": "^3.14.1",
"json-to-properties": "^1.1.3",
"jsonlint": "^1.6.3",
"lodash": "^4.17.21",
"lscache": "^1.3.0",
"moment": "^2.29.1",
"php-array-reader": "^1.2.0",
......
......@@ -41,15 +41,64 @@ const tool = [
{'name': 'variableConversion', 'title': '变量名转换', 'cat': ['conversion']},
]
// 工具类功能配置
const feature = {
qrCode: [
{name: "generate", title: '生成'},
{name: "reader", title: '解析'}
]
}
const utools = {
keyword: {
hash: ['md5', 'sha1', 'sha256', 'sha512', 'sm3'],
encrypt: ['AES', 'DES', 'RC4', 'Rabbit', 'TripleDes', 'sm2']
},
cmds: {
timestamp: [
{
"type": "regex",
// "label": "", //程序自动根据tool title填充
"match": "/(^\\d{10}(?:\\d{3})?$)|(^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?$)/i",
"minLength": 10,
"maxLength": 25
}
],
qrCode: [
{
"type": "regex",
"match": "/[a-zA-z]+://[^\\s]*/i",
"minLength": 8,
"feature":'generate' // 适配工具内功能
},
{
"type": "regex",
"match": "/[a-zA-z]+://[^\\s]*/i",
"minLength": 8,
"feature":'reader' // 适配工具内功能
}
],
ip: [
{
"type": "regex",
"match": "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/i",
"minLength": 7,
"maxLength": 15
}
],
unicode: [
{
"type": "regex",
"match": "/\\\\u[0-9a-f]{4}/i",
"minLength": 6
}
]
}
}
module.exports = {
category,
tool,
feature,
utools
}
\ No newline at end of file
......@@ -42,7 +42,7 @@
</Radio>
</RadioGroup>
<div>
<router-view :key="$route.path + $route.query.t"/>
<router-view v-if="isRouterAlive" :key="$route.path + $route.query.t"/>
</div>
<Drawer :title="currentToolTitle+' - 历史记录'" v-model="historyShow" :width="100">
<Table ref="historyTable" border :columns="historyColumns" :data="historyData" :height="historyTableHeight">
......@@ -78,6 +78,7 @@ export default {
},
data () {
return {
isRouterAlive:true,
isUtools:isUtools,
category: config.category,
currentCategory: '',
......@@ -127,11 +128,28 @@ export default {
},
created () {
if (this.isUtools){
window.utools.onPluginEnter(({code}) => {
window.utools.onPluginEnter(({code,payload,type}) => {
let tool = "";
let feature = "";
if (code.indexOf('ctool-') !== -1) {
tool = code.replace(/ctool-/g, "")
if (tool.indexOf('-') !== -1){
let temp = tool.split('-');
tool = temp[0]
feature = temp[1]
}
}
// 写入正则匹配数据到固定数据数据
if (type === "regex" && payload){
model.setFixeInputData(payload)
}
if(feature){
// 设置工具内功能
model.setToolCurrentFeature(feature)
}
if (tool && this.currentTool !== tool) {
let cat = config.getToolDefaultCategory(tool);
if (cat) {
......@@ -141,6 +159,7 @@ export default {
this.currentTool = tool;
}
}
this.reload()
})
}
......@@ -152,6 +171,10 @@ export default {
},
mounted () {},
methods: {
reload () {
this.isRouterAlive = false
this.$nextTick(() => (this.isRouterAlive = true))
},
categorySelect (name) {
switch (name) {
case '_feedback':
......
let path = require('path');
const path = require('path');
const _ = require('lodash');
// 运行平台适配
let platform = process.env.hasOwnProperty('npm_config_adapter') ? process.env.npm_config_adapter : "";
platform = ["chrome", 'utools'].includes(platform) ? platform : "web"
......@@ -7,6 +8,20 @@ const IS_CHROME = "chrome" === platform
const IS_UTOOLS = "utools" === platform
const IS_WEB = "web" === platform
const toolConfig = require('../config')
const tools = toolConfig.tool
const utoolsConfig = toolConfig.utools
const featureConfig = toolConfig.feature
const getToolFeatureTitle = (name, features = []) => {
for (let i = 0; i < features.length; i++) {
if (features[i]['name'] === name) {
return features[i].title
}
}
return name
}
const chromeConfigWrite = () => {
let fs = require('fs');
// 移除环境配置文件
......@@ -33,12 +48,61 @@ const utoolsConfigWrite = () => {
fs.unlink(filePath, () => {
});
})
if (IS_UTOOLS) {
const toolConfig = require('../config')
let pluginPath = path.join(__dirname, '../../public/plugin.json');
fs.readFile(path.join(__dirname, "../adapter/utools/plugin.json"), 'utf8', function (err, files) {
if (err) return console.log(err);
let utoolsToolFeature = {};
for (let tool of tools) {
// 初始化数据
let code = "ctool-" + tool.name;
let toolFeatures = featureConfig.hasOwnProperty(tool.name) ? featureConfig[tool.name] : []
if (!utoolsToolFeature.hasOwnProperty(code)) {
utoolsToolFeature[code] = {
"code": code,
"explain": tool.title,
"cmds": []
}
if (toolFeatures.length > 0) {
for (let toolFeature of toolFeatures) {
let toolFeatureCode = code + '-' + toolFeature['name']
utoolsToolFeature[toolFeatureCode] = {
"code": toolFeatureCode,
"explain": tool.title + ' - ' + toolFeature['title'],
"cmds": []
}
}
}
}
// 关键字
let keyword = utoolsConfig['keyword'].hasOwnProperty(tool.name) ? utoolsConfig['keyword'][tool.name] : []
utoolsToolFeature[code].cmds.push(
...Array.from(new Set([tool.name, tool.title, "ctool-" + tool.name, ...keyword]))
)
// cmds手动配置
let cmds = utoolsConfig['cmds'].hasOwnProperty(tool.name) ? utoolsConfig['cmds'][tool.name] : []
if (!cmds.length) {
continue;
}
for (let _cmd of cmds) {
let cmd = _.cloneDeep(_cmd);
if (!cmd.hasOwnProperty('feature')) {
cmd['label'] = tool.title
utoolsToolFeature[code].cmds.push(cmd)
continue;
}
let toolFeatureCode = code + '-' + cmd.feature
if (utoolsToolFeature.hasOwnProperty(toolFeatureCode)) {
cmd['label'] = tool.title + ' - ' + getToolFeatureTitle(cmd.feature, toolFeatures)
delete cmd.feature
utoolsToolFeature[toolFeatureCode].cmds.push(cmd)
}
}
}
let features = [
{
......@@ -46,15 +110,9 @@ const utoolsConfigWrite = () => {
"explain": "程序开发常用工具",
"cmds": ['ctool', '程序开发常用工具']
},
...toolConfig.tool.map((item) => {
let keyword = toolConfig['keyword'].hasOwnProperty(item.name) ? toolConfig['keyword'][item.name] : [];
return {
"code": "ctool-" + item.name,
"explain": item.title,
"cmds": Array.from(new Set([item.name, item.title, "ctool-" + item.name, ...keyword]))
}
})
]
...Object.values(utoolsToolFeature)
];
let result = files
.replace(/##version##/g, process.env.npm_package_version)
.replace(/"##features##"/g, JSON.stringify(features));
......
......@@ -3,30 +3,43 @@ import setting from './setting'
import cache from './cache'
import history from './history.js'
let fixeInputData;
let toolCurrentFeature = "";
const model = {
getCategoryHistory () {
getCategoryHistory() {
return cache.get('page_category_history', 'common')
},
setCategoryHistory (cat) {
setCategoryHistory(cat) {
return cache.set('page_category_history', cat)
},
getToolHistory (cat) {
getToolHistory(cat) {
let all = cache.get('category_tool_history', {})
if (all[cat]) {
return all[cat]
}
return config.getToolByCategory(cat)[0]['name']
},
setToolHistory (cat, name) {
setToolHistory(cat, name) {
let all = cache.get('category_tool_history', {})
all[cat] = name
return cache.set('category_tool_history', all)
},
getCurrentTool () {
getCurrentTool() {
return cache.get('current_tool', '')
},
setCurrentTool (name) {
setCurrentTool(name) {
return cache.set('current_tool', name)
},
setFixeInputData: (value) => {
fixeInputData = value;
},
setToolCurrentFeature: (value) => {
toolCurrentFeature = value;
},
getToolCurrentFeature: (def = "") => {
let temp = toolCurrentFeature
toolCurrentFeature = "";
return temp ? temp : def
}
}
......@@ -45,10 +58,15 @@ export const plugin = {
install: function (Vue) {
Vue.prototype.$getToolData = function (clipboardField = '') {
let data = history(model.getCurrentTool()).current()
if (setting.autoReadCopy()){
let paste = clipboardPaste()
if (clipboardField && !data[clipboardField] && paste) {
data[clipboardField] = paste
if (clipboardField) {
if (fixeInputData) { // 使用固定输入数据
data[clipboardField] = fixeInputData
fixeInputData = ""
} else if (setting.autoReadCopy()) {
let paste = clipboardPaste()
if (!data[clipboardField] && paste) {
data[clipboardField] = paste
}
}
}
return data
......
......@@ -42,6 +42,7 @@
import generator from 'qrcode'
import qrcodeParser from 'qrcode-parser'
import { trim } from '../../helper'
import model from '../../tool/model'
export default {
computed: {
......@@ -53,7 +54,18 @@
},
},
created () {
this.current = Object.assign(this.current, this.$getToolData())
let feature = model.getToolCurrentFeature('generate')
if(feature === 'generate'){
this.current = Object.assign(this.current, this.$getToolData('generateInput'))
this.current.operation = feature;
}
else if(feature === 'reader'){
this.current = Object.assign(this.current, this.$getToolData('readerInput'))
this.current.operation = feature;
}
else{
this.current = Object.assign(this.current, this.$getToolData())
}
},
methods: {
generate () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册