diff --git a/README.md b/README.md index 5a437cc3c5a51fcd25f82e7d8405c302426a956d..01becd566f9b23308d76914dd0544dc89850a4b6 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ # 程序开发常用工具 使用过程中的任何问题或者需要新的工具欢迎提交`Issue`,新工具如果可以提供实现代码就完美了O(∩_∩)O -## 安装 +## chrome 安装 - 方法1: 在 [Chrome 网上应用店](https://chrome.google.com/webstore/detail/ipfcebkfhpkjeikaammlkcnalknjahmh)安装 - 方法2: [下载 .crx 安装包](https://github.com/baiy/Ctool/releases/latest)手动安装 [猛戳这里查看手动安装教程](http://www.cnplugins.com/tool/outline-install-crx-file.html) - 方法3: [百度网盘下载](https://pan.baidu.com/s/1mhWbqWC) 安装方法和方法2一致 - > 方法2 / 方法3 不定期维护 仅供网络环境特别恶劣的同学使用 +## 支持 utools + ## 功能列表 |功能|说明|离线使用| |---|---|---| diff --git a/package.json b/package.json index cc84f10dc3b11e804fd26d520e086f7ec9e5407e..b677d45fba293fe0a9d3b7d20afc4a26c4d4ae57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "c-tool", - "version": "1.4.3", + "version": "1.4.4", "private": true, "scripts": { "serve": "vue-cli-service serve --port 8081", diff --git a/public/utools.html b/public/utools.html new file mode 100644 index 0000000000000000000000000000000000000000..02431f4b0a49d3690b8fa1a91aa840b80a683c7b --- /dev/null +++ b/public/utools.html @@ -0,0 +1,33 @@ + + + + + + + Ctool 程序开发常用工具 + + + + + \ No newline at end of file diff --git a/src/adapter/chrome/manifest.json b/src/adapter/chrome/manifest.json index cf7589d2ada4d788d28dbeab436090f74913d53e..5ac9296892a021657943b88c62fa39f2a59a2cac 100644 --- a/src/adapter/chrome/manifest.json +++ b/src/adapter/chrome/manifest.json @@ -12,7 +12,6 @@ "default_title": "常用开发工具", "default_popup": "index.html" }, - "options_page": "setting.html", "icons": { "16": "img/icon128.png", "48": "img/icon128.png", diff --git a/src/adapter/utools/plugin.json b/src/adapter/utools/plugin.json index f90801cce6f39db05414ea47109e2689d5a9e66a..48113c08decf757da7281edb38f1d24e01e48cf1 100644 --- a/src/adapter/utools/plugin.json +++ b/src/adapter/utools/plugin.json @@ -3,14 +3,14 @@ "description": "Ctool 程序开发常用工具", "author": "baiy", "homepage": "https://github.com/baiy/Ctool", - "main": "tool.html", + "main": "utools.html", "version": "##version##", - "logo": "img/icon_utools.png", + "logo": "img/icon128.png", "pluginSetting": { - "single": false + "single": true }, + "features": "##features##", "development": { - "main": "http://localhost:8081/tool.html" - }, - "features": "##features##" + "main": "http://localhost:8081/utools.html" + } } \ No newline at end of file diff --git a/src/config.js b/src/config.js index 6616257d2772cc6c982ff9b18f34e4ef397a7fcc..8971dfd59ac5f4be6c2d372cccf090de88cb5ae2 100644 --- a/src/config.js +++ b/src/config.js @@ -1,134 +1,37 @@ -// 工具缓存数据过期时间(秒) -const TOOL_DATA_EXPIRY = 3600 * 24 -// 徽章过期时间(天) -const BADGE_EXPIRY = 5 -// 分类徽章 -const BADGE_CATEGORY = [] -// 工具徽章 -const BADGE_TOOL = [] -// 默认常用工具 -const DEFAULT_COMMON_TOOL = [ - 'hash', 'encrypt', 'json', 'base64', 'url', 'timestamp', - 'qrCode', 'pinyin', 'ip', 'code', 'unicode', - 'text', 'randomString', 'diffs', -] - const category = [ - {'name': 'common'}, - {'name': 'encryption'}, - {'name': 'conversion'}, - {'name': 'serialize'}, - {'name': 'check'}, - {'name': 'generate'}, - {'name': 'other'}, + {'name': 'common', 'title': '常用工具'}, + {'name': 'encryption', 'title': '加密解密'}, + {'name': 'conversion', 'title': '编码转换'}, + {'name': 'serialize', 'title': '序列化'}, + {'name': 'other', 'title': '其他工具'}, ] const tool = [ - { - 'name': 'hash', - 'cat': ['encryption'] - }, - { - 'name': 'encrypt', - 'cat': ['encryption'] - }, - {'name': 'sign', 'cat': ['encryption','check']}, - {'name': 'base64', 'cat': ['encryption']}, - {'name': 'json', 'cat': ['conversion', 'serialize']}, - {'name': 'url', 'cat': ['conversion']}, - {'name': 'timestamp', 'cat': ['conversion']}, - {'name': 'qrCode', 'cat': ['generate']}, - {'name': 'barcode', 'cat': ['generate']}, - {'name': 'pinyin', 'cat': ['conversion']}, - {'name': 'ip', 'cat': ['other']}, - {'name': 'code', 'cat': ['other']}, - {'name': 'unicode', 'cat': ['conversion']}, - {'name': 'decimalConvert', 'cat': ['conversion']}, - {'name': 'regex', 'cat': ['check']}, - {'name': 'randomString', 'cat': ['generate']}, - {'name': 'serializeConversion', 'cat': ['conversion', 'serialize']}, - {'name': 'diffs', 'cat': ['check']}, - {'name': 'crontab', 'cat': ['check']}, - {'name': 'websocket', 'cat': ['other']}, - {'name': 'unit', 'cat': ['other']}, - {'name': 'time', 'cat': ['other']}, - {'name': 'uuid', 'cat': ['generate']}, - {'name': 'jsonToObject', 'cat': ['conversion', 'serialize']}, - {'name': 'ascii', 'cat': ['conversion']}, - {'name': 'variableConversion', 'cat': ['conversion']}, - {'name': 'jwt', 'cat': ['conversion']}, - {'name': 'hexString', 'cat': ['conversion']}, - {'name': 'text', 'cat': ['other']}, - {'name': 'html', 'cat': ['conversion']}, + {'name': 'hash', 'title': '哈希(hash)', 'cat': ['encryption']}, + {'name': 'encrypt', 'title': '加密/解密', 'cat': ['encryption']}, + {'name': 'base64', 'title': 'BASE64编码', 'cat': ['encryption']}, + {'name': 'json', 'title': 'JSON工具', 'cat': ['conversion', 'serialize']}, + {'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': 'serializeConversion', 'title': '序列化转换', 'cat': ['conversion', 'serialize']}, + {'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': 'uuid', 'title': 'UUID生成', 'cat': ['other']}, + {'name': 'jsonToObject', 'title': 'JSON转实体类', 'cat': ['conversion', 'serialize']}, ] -// 工具类功能配置 -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'], - jwt: ['jwtDecode'], - hexString: ['hex to string', 'string to hex', '十六进制转字符串', '字符串转十六机制'], - text: ['文本处理', '大小写转换', '中英文标点转换', '简繁转换', '字符替换', '字符统计', '行去重', '添加行号', '行排序', '过滤行首尾不可见字符', '过滤空行'], - sign: ['签名', '验签', 'rsa'], - }, - 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, - toolDataExpiry: TOOL_DATA_EXPIRY, - badgeExpiry: BADGE_EXPIRY, - badgeCategory: BADGE_CATEGORY, - badgeTool: BADGE_TOOL, - defaultCommonTool: DEFAULT_COMMON_TOOL -} + tool +} \ No newline at end of file diff --git a/src/helper.js b/src/helper.js index 7be8b500dd8a9371b8e17a709b065fc7df1d4d5a..e7969a18e1df32ef32274e04c06a88ae2d8f9cab 100644 --- a/src/helper.js +++ b/src/helper.js @@ -1,40 +1,58 @@ -import {v4 as uuidV4} from 'uuid'; -import {openUrl as chromiumOpenUrl} from './adapter/chromium/helper'; -import {openUrl as utoolsOpenUrl} from './adapter/utools/helper'; -import {openUrl as firefoxOpenUrl} from './adapter/firefox/helper'; +import {stringify as queryStringify} from "query-string" -export const env = (key) => { +export const env = function (key) { return process['ctool'][key] ? process['ctool'][key] : ""; }; export const isChrome = !!env('isChrome') -export const isEdge = !!env('isEdge') -export const isFirefox = !!env('isFirefox') -export const isChromium = !!env('isChromium') export const isWeb = !!env('isWeb') export const isUtools = !!env('isUtools') -export const uuid = () => { - return uuidV4().toLowerCase(); -} - -export const openUrl = (url) => { - if (isChromium) { - return chromiumOpenUrl(url) +export const trim = function (str, char, type) { + if (char) { + if (type === 'left') { + return str.replace(new RegExp('^\\' + char + '+', 'g'), ''); + } else if (type === 'right') { + return str.replace(new RegExp('\\' + char + '+$', 'g'), ''); + } + return str.replace(new RegExp('^\\' + char + '+|\\' + char + '+$', 'g'), ''); } - if (isUtools) { - return utoolsOpenUrl(url) + return str.replace(/^\s+|\s+$/g, ''); +}; + +export const inArray = function (value, arr) { + return arr.findIndex((v) => { + return value === v + }) !== -1 +}; + +export const openTab = function (url) { + if (isChrome && chrome.tabs) { + return chrome.tabs.create({url: url, selected: true}); } - if (isFirefox) { - return firefoxOpenUrl(url) + if (isUtools && window.utools){ + return window.utools.shellOpenExternal(url) } return window.open(url); }; -export const version = env('version').trim() +export const stat = function (action, data = {}) { + setTimeout(function () { + try { + let img = new Image(1, 1); + img.src = 'https://www.baiy.org/chrome_tool/stat/?' + queryStringify( + Object.assign( + { + v: env('version'), + a: action, + r: Math.random() + }, + data + ) + ); + } catch (e) { + // todo + } + }, 3000) +}; -export const setDisplayMode = (mode) => { - mode = ['light', 'dark', 'auto'].includes(mode) ? mode : 'light' - console.log(`set display mode:${mode}`) - document.getElementsByTagName('html')[0].setAttribute('theme-mode', mode); -} diff --git a/src/setting.js b/src/setting.js deleted file mode 100644 index 19447d49ee02aff8339d7535d410f3d8c41371d7..0000000000000000000000000000000000000000 --- a/src/setting.js +++ /dev/null @@ -1,12 +0,0 @@ -import Vue from 'vue' -import ViewUI from 'view-design'; -import 'view-design/dist/styles/iview.css'; -import App from './setting.vue' - -Vue.config.productionTip = false; - -Vue.use(ViewUI); - -new Vue({ - render: h => h(App) -}).$mount('#app'); diff --git a/src/tool.js b/src/tool.js index 6389deb99b68c16eef1f7edc5f226500ca5ee119..c6d51292a8857f9835cabfe5c707eef07c8957c8 100644 --- a/src/tool.js +++ b/src/tool.js @@ -3,8 +3,10 @@ import ViewUI from 'view-design' import 'view-design/dist/styles/iview.css' import router from './tool.router' import optionBlock from './components/optionBlock' -import { plugin as modelPlugin } from './tool/model' +import model, {plugin as modelPlugin} from './tool/model' import App from './tool.vue' +import {isUtools} from './helper' +import config from "./tool/config"; Vue.config.productionTip = false @@ -13,7 +15,18 @@ Vue.use(modelPlugin) Vue.component('option-block', optionBlock); (function () { - if (document.body.clientWidth > 900) { + if (isUtools) { + let tool = window.utools.db.get("_current_tool_"); + if (tool && tool.data) { + let cat = config.getToolDefaultCategory(tool.data); + if (cat) { + model.setCategoryHistory(cat) + model.setToolHistory(cat, tool.data) + } + } + } + + if (document.body.clientWidth > 900 || isUtools) { console.log('调整窗口大小') const page = document.getElementById('page') page.style.width = 'auto' @@ -21,7 +34,6 @@ Vue.component('option-block', optionBlock); page.style.height = 'auto' } })() - new Vue({ router, render: h => h(App), diff --git a/src/tool.vue b/src/tool.vue index 7bd5d4bdbf5a4acf720c126afb74fdb5a46164f1..979262fda329efe3ddd32e7112e7847a0bc17a23 100644 --- a/src/tool.vue +++ b/src/tool.vue @@ -10,7 +10,7 @@ {{ cat.title }} - + @@ -70,7 +70,7 @@ 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' +import { openTab,isUtools } from './helper' export default { components: { @@ -78,6 +78,7 @@ export default { }, data () { return { + isUtools:isUtools, category: config.category, currentCategory: '', currentTool: '', @@ -145,7 +146,7 @@ export default { this.settingShow = true; break case '_new': - openTab(window.location.href) + openTab(window.location.href) break case '_history': this.history() diff --git a/src/tool/adapter.js b/src/tool/adapter.js index 353a776b623582a047e004ade97d8d62f799ff76..974c538204aca4c2baacc64efffa6024d27cc497 100644 --- a/src/tool/adapter.js +++ b/src/tool/adapter.js @@ -1,205 +1,44 @@ -const path = require('path'); -const _ = require('lodash'); -const fs = require('fs'); -const i18nBuild = require('../i18n/build') +let path = require('path'); // 运行平台适配 let platform = process.env.hasOwnProperty('npm_config_adapter') ? process.env.npm_config_adapter : ""; -platform = ['chrome', 'utools', 'edge', 'firefox', 'web'].includes(platform) ? platform : "web" +platform = ["chrome", 'utools'].includes(platform) ? platform : "web" const IS_CHROME = "chrome" === platform -const IS_EDGE = "edge" === platform -const IS_FIREFOX = "firefox" === platform const IS_UTOOLS = "utools" === platform -const IS_CHROMIUM = ['chrome', 'edge'].includes(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 removeFile = (filePath) => { - fs.existsSync(filePath) && fs.unlinkSync(filePath) -} - -// 删除目录 -const removeDir = function (directoryPath) { - if (fs.existsSync(directoryPath)) { - fs.readdirSync(directoryPath).forEach((file) => { - const curPath = path.join(directoryPath, file); - if (fs.lstatSync(curPath).isDirectory()) { - removeDir(curPath); - } else { - fs.unlinkSync(curPath); - } +const chromeConfigWrite = () => { + let fs = require('fs'); + // 移除环境配置文件 + let manifestPath = path.join(__dirname, '../../public/manifest.json'); + fs.unlink(manifestPath, () => { + }); + if (IS_CHROME) { + fs.readFile(path.join(__dirname, "../adapter/chrome/manifest.json"), 'utf8', function (err, files) { + if (err) return console.log(err); + let result = files.replace(/##version##/g, process.env.npm_package_version); + fs.writeFile(manifestPath, result, 'utf8', function (err) { + if (err) return console.log(err); + }); }); - fs.rmdirSync(directoryPath); - } -}; - -const chromeConfigWrite = { - remove() { - }, - write() { - if (!IS_CHROME) { - return; - } - fs.writeFileSync( - path.join(__dirname, '../../public/manifest.json'), - fs.readFileSync(path.join(__dirname, "../adapter/chrome/manifest.json")).toString().replace(/##version##/g, process.env.npm_package_version) - ); - } -} - -const edgeConfigWrite = { - remove() { - }, - write() { - if (!IS_EDGE) { - return; - } - fs.writeFileSync( - path.join(__dirname, '../../public/manifest.json'), - fs.readFileSync(path.join(__dirname, "../adapter/edge/manifest.json")).toString().replace(/##version##/g, process.env.npm_package_version) - ); - } -} - -const chromiumConfigWrite = { - remove() { - removeFile(path.join(__dirname, '../../public/manifest.json')); - removeFile(path.join(__dirname, '../../public/background.js')); - // 移除语言包目录 - removeDir(path.join(__dirname, '../../public/_locales/')) - }, - write() { - if (!IS_CHROMIUM) { - return; - } - fs.copyFileSync( - path.join(__dirname, "../adapter/chromium/background.js"), - path.join(__dirname, '../../public/background.js') - ); - // 生成语言包 - const locales = i18nBuild.getLocales().detail - const localeDir = path.join(__dirname, '../../public/_locales/') - fs.mkdirSync(localeDir); - Object.keys(locales).forEach((_locale) => { - fs.mkdirSync(path.join(localeDir, _locale)); - let messages = {} - Object.keys(locales[_locale]).forEach((key) => { - let message = { - message: locales[_locale][key]['message'].replace(new RegExp("{.+?}", 'g'), (item) => { - return `$${item.replace("{", "").replace("}", "").toUpperCase()}$`; - }) - } - if ("placeholders" in locales[_locale][key]) { - message.placeholders = {} - let index = 1; - locales[_locale][key]['placeholders'].forEach((placeholder) => { - message.placeholders[placeholder] = {content: "$" + (index++)} - }) - } - messages[key] = message - }) - fs.writeFileSync(path.join(localeDir, `${_locale}/messages.json`), JSON.stringify(messages, null, 4)); - }) - } -} - -const firefoxConfigWrite = { - remove() { - removeFile(path.join(__dirname, '../../public/manifest.json')); - removeFile(path.join(__dirname, '../../public/background.js')); - }, - write() { - if (!IS_FIREFOX) { - return; - } - fs.copyFileSync( - path.join(__dirname, "../adapter/firefox/background.js"), - path.join(__dirname, '../../public/background.js') - ); - fs.writeFileSync( - path.join(__dirname, '../../public/manifest.json'), - fs.readFileSync(path.join(__dirname, "../adapter/firefox/manifest.json")).toString().replace(/##version##/g, process.env.npm_package_version) - ); } } +const utoolsConfigWrite = () => { + let fs = require('fs'); + // 移除环境配置文件 + let fileArr = ['plugin.json', 'README.md'] + fileArr.forEach((file) => { + let filePath = path.join(__dirname, '../../public/' + file); + fs.unlink(filePath, () => { + }); + }) -const utoolsConfigWrite = { - remove() { - removeFile(path.join(__dirname, '../../public/plugin.json')); - }, - write() { - if (!IS_UTOOLS) { - return; - } + 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 toolTitle = i18nBuild.translate(`main_tool_${tool.name}`) - let toolFeatures = featureConfig.hasOwnProperty(tool.name) ? featureConfig[tool.name] : [] - if (!utoolsToolFeature.hasOwnProperty(code)) { - utoolsToolFeature[code] = { - "code": code, - "explain": toolTitle, - "cmds": [] - } - if (toolFeatures.length > 0) { - for (let toolFeature of toolFeatures) { - let toolFeatureCode = code + '-' + toolFeature['name'] - utoolsToolFeature[toolFeatureCode] = { - "code": toolFeatureCode, - "explain": toolTitle + ' - ' + toolFeature['title'], - "cmds": [] - } - } - } - } - - // 关键字 - let keyword = utoolsConfig['keyword'].hasOwnProperty(tool.name) ? utoolsConfig['keyword'][tool.name] : [] - utoolsToolFeature[code].cmds.push( - ...Array.from(new Set([tool.name, toolTitle, "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'] = toolTitle - utoolsToolFeature[code].cmds.push(cmd) - continue; - } - let toolFeatureCode = code + '-' + cmd.feature - if (utoolsToolFeature.hasOwnProperty(toolFeatureCode)) { - cmd['label'] = toolTitle + ' - ' + getToolFeatureTitle(cmd.feature, toolFeatures) - delete cmd.feature - utoolsToolFeature[toolFeatureCode].cmds.push(cmd) - } - } - } let features = [ { @@ -207,13 +46,24 @@ const utoolsConfigWrite = { "explain": "程序开发常用工具", "cmds": ['ctool', '程序开发常用工具'] }, - ...Object.values(utoolsToolFeature) - ]; - + ...toolConfig.tool.map((item) => { + return { + "code": "ctool-" + item.name, + "explain": item.title, + "cmds": [item.name, item.title, "ctool-" + item.name] + } + }) + ] let result = files .replace(/##version##/g, process.env.npm_package_version) .replace(/"##features##"/g, JSON.stringify(features)); - fs.writeFileSync(pluginPath, result); + fs.writeFile(pluginPath, result, 'utf8', function (err) { + if (err) return console.log(err); + }); + }); + let readmePath = path.join(__dirname, '../../public/README.md'); + fs.copyFile(path.join(__dirname, "../../README.md"), readmePath, function (err) { + if (err) return console.log(err); }); } } @@ -221,25 +71,10 @@ const utoolsConfigWrite = { module.exports = { platform: platform, isChrome: IS_CHROME, - isChromium: IS_CHROMIUM, - isFirefox: IS_FIREFOX, - isEdge: IS_EDGE, isWeb: IS_WEB, isUtools: IS_UTOOLS, initialize: function () { - // 移除配置文件 - chromiumConfigWrite.remove(); - chromeConfigWrite.remove(); - edgeConfigWrite.remove(); - firefoxConfigWrite.remove(); - utoolsConfigWrite.remove(); - // 添加配置文件 - chromiumConfigWrite.write(); - chromeConfigWrite.write(); - edgeConfigWrite.write(); - firefoxConfigWrite.write(); - utoolsConfigWrite.write(); - // 生成运行时语言包 - i18nBuild.generate() + chromeConfigWrite(); + utoolsConfigWrite(); } -} +} \ No newline at end of file diff --git a/src/tool/config.js b/src/tool/config.js index 574421f5d5742145109e335d879e7e0857ba4de5..58a70b65427f65dc7b39eb16da0f2fc0fe9e581c 100644 --- a/src/tool/config.js +++ b/src/tool/config.js @@ -6,9 +6,9 @@ export const TOOL_DATA_EXPIRY = 3600 * 24 // 徽章过期时间(天) export const BADGE_EXPIRY = 10 // 分类徽章 -export const BADGE_CATEGORY = ['serialize','other'] +export const BADGE_CATEGORY = [] // 工具徽章 -export const BADGE_TOOL = ['uuid','serializeConversion'] +export const BADGE_TOOL = [] // 默认常用工具 export const DEFAULT_COMMON_TOOL = [ 'hash', 'encrypt', 'json', 'base64', 'url', 'timestamp', @@ -16,37 +16,11 @@ export const DEFAULT_COMMON_TOOL = [ 'decimalConvert', 'randomString', 'diffs', ] -const category = [ - {'name': 'common', 'title': '常用工具'}, - {'name': 'encryption', 'title': '加密解密'}, - {'name': 'conversion', 'title': '编码转换'}, - {'name': 'serialize', 'title': '序列化'}, - {'name': 'other', 'title': '其他工具'}, -] +const toolConfig = require('../config') -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', 'serialize']}, - {'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': 'serializeConversion', 'title': '序列化转换', 'cat': ['conversion', 'serialize']}, - {'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': 'uuid', 'title': 'UUID生成', 'cat': ['other']}, -] +const category = toolConfig.category + +const tool = toolConfig.tool // 徽章是否显示 const badgeIsShow = function () { @@ -72,6 +46,15 @@ const getToolTitle = function (name) { return '' } +const getToolDefaultCategory = function (name) { + for (let i = 0; i < tool.length; i++) { + if (tool[i].name === name) { + return tool[i].cat[0] + } + } + return '' +} + const getSetting = function (name, defaultValue = null) { let setting = cache.getNoVersion('setting', {}) return !setting.hasOwnProperty(name) ? defaultValue : setting[name] @@ -99,6 +82,7 @@ export default { return inArray(cat, t.cat) }) }, + getToolDefaultCategory, badgeToolIsShow(tool) { return badgeIsShow() && inArray(tool, BADGE_TOOL) }, diff --git a/src/views/setting/block.vue b/src/views/setting/block.vue index a0d84f5712a2eb627edc41aab2baead5bbe371d3..a7f0463d580e656d47249003932347704e3d1faa 100644 --- a/src/views/setting/block.vue +++ b/src/views/setting/block.vue @@ -1,29 +1,40 @@