提交 dfccb6e4 编写于 作者: B baiy 提交者: ninecents

unicode 工具优化 #57

上级 ed7d4ed2
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
使用过程中的任何问题或者需要新的工具欢迎提交`Issue`,新工具如果可以提供实现代码就完美了O(∩_∩)O 使用过程中的任何问题或者需要新的工具欢迎提交`Issue`,新工具如果可以提供实现代码就完美了O(∩_∩)O
## 先睹为快
![](https://cdn.jsdelivr.net/gh/baiy/Ctool@master/images/v2_1.png)
## chrome 安装 ## chrome 安装
- 方法1: 在 [Chrome 应用商店](https://chrome.google.com/webstore/detail/ipfcebkfhpkjeikaammlkcnalknjahmh) 安装 - 方法1: 在 [Chrome 应用商店](https://chrome.google.com/webstore/detail/ipfcebkfhpkjeikaammlkcnalknjahmh) 安装
...@@ -45,9 +49,9 @@ npm run build -adapter=[chrome|edge|utools|web] ...@@ -45,9 +49,9 @@ npm run build -adapter=[chrome|edge|utools|web]
|时间戳|双向转换|√| |时间戳|双向转换|√|
|二维码|`生成`,`解析`|√| |二维码|`生成`,`解析`|√|
|汉字转拼音|`声调`,`首字母`,`分隔符`|√| |汉字转拼音|`声调`,`首字母`,`分隔符`|√|
|IP地址查询|`运营商`,`城市`|`×`| |IP地址查询|`运营商`,`城市`|×|
|代码格式化|`js`, `html`, `css`, `xml`, `sql`, `压缩`|√| |代码格式化|`js`, `html`, `css`, `xml`, `sql`, `压缩`|√|
|Unicode|双向转换|√| |Unicode|`双向转换`,`emoji`,`html 实体`,`css 实体`|√|
|进制转换|2-64进制互转|√| |进制转换|2-64进制互转|√|
|正则表达式|字符匹配|√| |正则表达式|字符匹配|√|
|随机字符生成器|`批量`,`特殊字符`|√| |随机字符生成器|`批量`,`特殊字符`|√|
...@@ -70,7 +74,6 @@ npm run build -adapter=[chrome|edge|utools|web] ...@@ -70,7 +74,6 @@ npm run build -adapter=[chrome|edge|utools|web]
项目诞生离不开这些优秀的开源程序 项目诞生离不开这些优秀的开源程序
- [ajax-request](https://www.npmjs.com/package/ajax-request)
- [code-formatter](https://www.npmjs.com/package/code-formatter) - [code-formatter](https://www.npmjs.com/package/code-formatter)
- [crypto-js](https://www.npmjs.com/package/crypto-js) - [crypto-js](https://www.npmjs.com/package/crypto-js)
- [ipinyinjs](https://www.npmjs.com/package/ipinyinjs) - [ipinyinjs](https://www.npmjs.com/package/ipinyinjs)
...@@ -102,9 +105,6 @@ npm run build -adapter=[chrome|edge|utools|web] ...@@ -102,9 +105,6 @@ npm run build -adapter=[chrome|edge|utools|web]
- [camelcaseplugin](https://github.com/netnexus/camelcaseplugin) - [camelcaseplugin](https://github.com/netnexus/camelcaseplugin)
- [jwt-decode](https://www.npmjs.com/package/jwt-decode) - [jwt-decode](https://www.npmjs.com/package/jwt-decode)
- [jian_fan](https://www.npmjs.com/package/jian_fan) - [jian_fan](https://www.npmjs.com/package/jian_fan)
- [axios](https://www.npmjs.com/package/axios)
> 当然项目中还使用很多不知道姓名的大神的代码, 在这里就不一一感谢 > 当然项目中还使用很多不知道姓名的大神的代码, 在这里就不一一感谢
\ No newline at end of file
## 先睹为快
![](https://cdn.jsdelivr.net/gh/baiy/Ctool@master/images/v2_1.png)
{ {
"name": "c-tool", "name": "c-tool",
"version": "1.6.5", "version": "1.6.8",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
...@@ -1846,15 +1846,6 @@ ...@@ -1846,15 +1846,6 @@
"integrity": "sha512-aT6camzM4xEA54YVJYSqxz1kv4IHnQZRtThJJHhUMRExaU5spC7jX5ugSwTaTgJliIgs4VhZOk7htClvQ/LmRA==", "integrity": "sha512-aT6camzM4xEA54YVJYSqxz1kv4IHnQZRtThJJHhUMRExaU5spC7jX5ugSwTaTgJliIgs4VhZOk7htClvQ/LmRA==",
"dev": true "dev": true
}, },
"ajax-request": {
"version": "1.2.3",
"resolved": "https://registry.npm.taobao.org/ajax-request/download/ajax-request-1.2.3.tgz",
"integrity": "sha1-mfy+wdbSeS+F+pSVNTMr0U9fN5A=",
"requires": {
"file-system": "^2.1.1",
"utils-extend": "^1.0.7"
}
},
"ajv": { "ajv": {
"version": "6.12.6", "version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
...@@ -2144,6 +2135,14 @@ ...@@ -2144,6 +2135,14 @@
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==",
"dev": true "dev": true
}, },
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"babel-code-frame": { "babel-code-frame": {
"version": "6.26.0", "version": "6.26.0",
"resolved": "https://registry.npm.taobao.org/babel-code-frame/download/babel-code-frame-6.26.0.tgz", "resolved": "https://registry.npm.taobao.org/babel-code-frame/download/babel-code-frame-6.26.0.tgz",
...@@ -5222,23 +5221,6 @@ ...@@ -5222,23 +5221,6 @@
} }
} }
}, },
"file-match": {
"version": "1.0.2",
"resolved": "https://registry.npm.taobao.org/file-match/download/file-match-1.0.2.tgz",
"integrity": "sha1-ycrSZdLIrfOoFHWw30dYWQafrvc=",
"requires": {
"utils-extend": "^1.0.6"
}
},
"file-system": {
"version": "2.2.2",
"resolved": "https://registry.npm.taobao.org/file-system/download/file-system-2.2.2.tgz",
"integrity": "sha1-fWWDPjojR9zZVqgTxncVPtPt2Yc=",
"requires": {
"file-match": "^1.0.1",
"utils-extend": "^1.0.4"
}
},
"file-uri-to-path": { "file-uri-to-path": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
...@@ -5406,8 +5388,7 @@ ...@@ -5406,8 +5388,7 @@
"follow-redirects": { "follow-redirects": {
"version": "1.13.3", "version": "1.13.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==", "integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA=="
"dev": true
}, },
"for-in": { "for-in": {
"version": "1.0.2", "version": "1.0.2",
...@@ -11833,11 +11814,6 @@ ...@@ -11833,11 +11814,6 @@
"integrity": "sha1-ihagXURWV6Oupe7MWxKk+lN5dyw=", "integrity": "sha1-ihagXURWV6Oupe7MWxKk+lN5dyw=",
"dev": true "dev": true
}, },
"utils-extend": {
"version": "1.0.8",
"resolved": "https://registry.npm.taobao.org/utils-extend/download/utils-extend-1.0.8.tgz",
"integrity": "sha1-zP17ZFQPjpDuIe7Fd2nQZRyril8="
},
"utils-merge": { "utils-merge": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "http://registry.npm.taobao.org/utils-merge/download/utils-merge-1.0.1.tgz", "resolved": "http://registry.npm.taobao.org/utils-merge/download/utils-merge-1.0.1.tgz",
......
{ {
"name": "c-tool", "name": "c-tool",
"version": "1.6.7", "version": "1.6.8",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve --port 8081", "serve": "vue-cli-service serve --port 8081",
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
"ajax-request": "^1.2.3", "axios": "^0.21.1",
"babel-runtime": "^6.26.0", "babel-runtime": "^6.26.0",
"code-formatter": "0.0.1", "code-formatter": "0.0.1",
"cron-parser": "^2.16.3", "cron-parser": "^2.16.3",
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</style> </style>
</head> </head>
<body> <body>
<div id="page" style="width: 800px;height: 550px;margin: 0 auto;"> <div id="page" style="width: 800px;height: 580px;margin: 0 auto;">
<div style="text-align: center;padding-top: 200px;font-size: 16px;color: #666">加载中...</div> <div style="text-align: center;padding-top: 200px;font-size: 16px;color: #666">加载中...</div>
</div> </div>
<script src=/index.js></script> <script src=/index.js></script>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Ctool 程序开发常用工具</title> <title>Ctool 程序开发常用工具</title>
</head> </head>
<body> <body style="padding-bottom: 30px">
<div id="page" style="width: 800px;height: 550px;margin: 0 auto;padding: 0 10px;overflow-y:auto;"> <div id="page" style="width: 800px;height: 550px;margin: 0 auto;padding: 0 10px;overflow-y:auto;">
<div id="app"></div> <div id="app"></div>
</div> </div>
......
export const openUrl = (url) => { export const openUrl = (url) => {
// return chrome.tabs.create(); // return chrome.tabs.create();
// return chrome.windows.create(); // return chrome.windows.create();
if (url.indexOf('chrome://') === 0) {
return chrome.tabs.create({url: url});
}
return window.open(url); return window.open(url);
} }
\ No newline at end of file
export const getMessage = (messageName, values = {}, placeholders = [], options = {}) => {
let substitutions = []
placeholders.forEach((key) => {
substitutions.push((key in values) ? values[key] : "")
})
return chrome.i18n.getMessage(messageName, substitutions, options);
}
...@@ -6,10 +6,10 @@ const panel = { ...@@ -6,10 +6,10 @@ const panel = {
chrome.windows.create({ chrome.windows.create({
url: chrome.runtime.getURL("tool.html"), url: chrome.runtime.getURL("tool.html"),
type: "popup", type: "popup",
width: 850, width: 810,
left: 200, left: 200,
top: 200, top: 200,
height: 580, height: 610,
}, (w) => { }, (w) => {
cache.set(this.cacheName, w.id) cache.set(this.cacheName, w.id)
}) })
......
...@@ -29,7 +29,7 @@ export default { ...@@ -29,7 +29,7 @@ export default {
.ctool-bottom { .ctool-bottom {
width: 100%; width: 100%;
position: fixed; position: fixed;
z-index: 999; z-index: 9999;
bottom: 0; bottom: 0;
left: 0; left: 0;
height: 30px; height: 30px;
......
...@@ -55,7 +55,7 @@ const handleNoticeItems = ({code, data, info}) => { ...@@ -55,7 +55,7 @@ const handleNoticeItems = ({code, data, info}) => {
} }
const logError = (e) => { const logError = (e) => {
console.log(e) // console.log(e)
} }
export default { export default {
......
import {stringify as queryStringify} from "query-string" import {v4 as uuidV4} from 'uuid';
import {openUrl as chromiumOpenUrl} from './adapter/chromium/helper';
import {openUrl as utoolsOpenUrl} from './adapter/utools/helper';
export const env = function (key) { export const env = (key) => {
return process['ctool'][key] ? process['ctool'][key] : ""; return process['ctool'][key] ? process['ctool'][key] : "";
}; };
...@@ -10,52 +12,16 @@ export const isChromium = !!env('isChromium') ...@@ -10,52 +12,16 @@ export const isChromium = !!env('isChromium')
export const isWeb = !!env('isWeb') export const isWeb = !!env('isWeb')
export const isUtools = !!env('isUtools') export const isUtools = !!env('isUtools')
export const trim = function (str, char, type) { export const uuid = () => {
if (char) { return uuidV4().toLowerCase();
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'), '');
}
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) { export const openUrl = (url) => {
if (isChromium && chrome.tabs) { if (isChromium) {
return chrome.tabs.create({url: url, selected: true}); return chromiumOpenUrl(url)
} }
if (isUtools && window.utools) { if (isUtools) {
return window.utools.shellOpenExternal(url) return utoolsOpenUrl(url)
} }
return window.open(url); return window.open(url);
}; };
\ No newline at end of file
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,
p: env('platform'),
r: Math.random()
},
data
)
);
} catch (e) {
// todo
}
}, 3000)
};
...@@ -13,7 +13,7 @@ import {isUtools} from './helper' ...@@ -13,7 +13,7 @@ import {isUtools} from './helper'
const page = document.getElementById('page') const page = document.getElementById('page')
page.style.width = 'auto' page.style.width = 'auto'
page.style.height = 'auto' page.style.height = 'auto'
page.style.minHeight = '500px' page.style.minHeight = '550px'
} }
})() })()
......
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
import { stat } from './helper' import {env} from './helper'
import {stringify as queryStringify} from "query-string";
import user from "./tool/user";
Vue.use(Router) Vue.use(Router)
export const stat = (action, data = {}) => {
setTimeout(() => {
try {
let img = new Image(1, 1);
img.src = 'https://www.baiy.org/chrome_tool/stat/?' + queryStringify({
v: env('version'),
a: action,
u: user.uid(),
p: env('platform'),
r: Math.random(),
...data
});
} catch (e) {
// todo
}
}, 3000)
};
// 路由配置 // 路由配置
const routes = [ const routes = [
{ {
...@@ -116,12 +136,12 @@ const routes = [ ...@@ -116,12 +136,12 @@ const routes = [
} }
] ]
const router = new Router({ routes }) const router = new Router({routes})
stat('index') stat('index')
router.afterEach(to => { router.afterEach(to => {
stat('tool', { tool: to.path }) stat('tool', {tool: to.path})
}) })
export default router export default router
\ No newline at end of file
...@@ -61,79 +61,82 @@ ...@@ -61,79 +61,82 @@
<Drawer title="设置" v-model="settingShow" :width="400"> <Drawer title="设置" v-model="settingShow" :width="400">
<setting-block v-if="settingShow"></setting-block> <setting-block v-if="settingShow"></setting-block>
</Drawer> </Drawer>
<bottom-block/>
</div> </div>
</template> </template>
<script> <script>
import config from './tool/config' import config from './tool/config'
import instance from './tool/instance'
import BottomBlock from './bottom'
import settingBlock from "./views/setting/block" import settingBlock from "./views/setting/block"
import model from './tool/model' import model from './tool/model'
import historyFactory from './tool/history' import historyFactory, {setLoadHistoryIndex} from './tool/history'
import {setLoadHistoryIndex} from './tool/history' import {isUtools, openUrl} from './helper'
import { openTab,isUtools } from './helper'
export default { export default {
components: { components: {
"setting-block": settingBlock "setting-block": settingBlock,
"bottom-block": BottomBlock
}, },
data () { data() {
return { return {
isRouterAlive:true, isRouterAlive: true,
isUtools:isUtools, isUtools: isUtools,
category: config.category, category: config.category,
currentCategory: '', currentCategory: '',
currentTool: '', currentTool: '',
historyData: [], historyData: [],
settingShow:false, settingShow: false,
historyShow: false, historyShow: false,
historyColumns: [ historyColumns: [
{ {
title: '操作时间', title: '操作时间',
key: 'time', key: 'time',
width:180 width: 180
}, },
{ {
title: '数据', title: '数据',
slot: '_value', slot: '_value',
ellipsis:true, ellipsis: true,
}, },
{ {
title: '操作', title: '操作',
slot: '_op', slot: '_op',
width:150 width: 150
} }
], ],
} }
}, },
computed: { computed: {
tools () { tools() {
return config.getToolByCategory(this.currentCategory) return config.getToolByCategory(this.currentCategory)
}, },
historyLength(){ historyLength() {
return historyFactory(this.currentTool).length() return historyFactory(this.currentTool).length()
}, },
historyTableHeight() { historyTableHeight() {
// 设置表格高度 // 设置表格高度
return window.innerHeight - 140 return window.innerHeight - 140
}, },
currentToolTitle(){ currentToolTitle() {
return config.getToolTitle(this.currentTool) return config.getToolTitle(this.currentTool)
} }
}, },
watch: { watch: {
currentTool (name) { currentTool(name) {
model.setCurrentTool(name) model.setCurrentTool(name)
this.$router.push('/tool/' + name) this.$router.push('/tool/' + name)
}, },
}, },
created () { created() {
if (this.isUtools){ if (this.isUtools) {
window.utools.onPluginEnter(({code,payload,type}) => { window.utools.onPluginEnter(({code, payload, type}) => {
let tool = ""; let tool = "";
let feature = ""; let feature = "";
if (code.indexOf('ctool-') !== -1) { if (code.indexOf('ctool-') !== -1) {
tool = code.replace(/ctool-/g, "") tool = code.replace(/ctool-/g, "")
if (tool.indexOf('-') !== -1){ if (tool.indexOf('-') !== -1) {
let temp = tool.split('-'); let temp = tool.split('-');
tool = temp[0] tool = temp[0]
feature = temp[1] feature = temp[1]
...@@ -141,11 +144,11 @@ export default { ...@@ -141,11 +144,11 @@ export default {
} }
// 写入正则匹配数据到固定数据数据 // 写入正则匹配数据到固定数据数据
if (type === "regex" && payload){ if (type === "regex" && payload) {
model.setFixeInputData(payload) model.setFixeInputData(payload)
} }
if(feature){ if (feature) {
// 设置工具内功能 // 设置工具内功能
model.setToolCurrentFeature(feature) model.setToolCurrentFeature(feature)
} }
...@@ -169,25 +172,27 @@ export default { ...@@ -169,25 +172,27 @@ export default {
top: 150, top: 150,
}) })
}, },
mounted () {}, mounted() {
instance.set(this)
},
methods: { methods: {
reload () { reload() {
this.isRouterAlive = false this.isRouterAlive = false
this.$nextTick(() => (this.isRouterAlive = true)) this.$nextTick(() => (this.isRouterAlive = true))
}, },
categorySelect (name) { categorySelect(name) {
switch (name) { switch (name) {
case '_feedback': case '_feedback':
openTab('https://github.com/baiy/Ctool/issues') openUrl('https://github.com/baiy/Ctool/issues')
break break
case '_about': case '_about':
openTab('https://github.com/baiy/Ctool') openUrl('https://github.com/baiy/Ctool')
break break
case '_setting': case '_setting':
this.settingShow = true; this.settingShow = true;
break break
case '_new': case '_new':
openTab(window.location.href) openUrl(window.location.href)
break break
case '_history': case '_history':
this.history() this.history()
...@@ -199,7 +204,7 @@ export default { ...@@ -199,7 +204,7 @@ export default {
break break
} }
}, },
history () { history() {
let history = historyFactory(this.currentTool) let history = historyFactory(this.currentTool)
if (history.length() < 1) { if (history.length() < 1) {
return this.$Message.error('暂无历史记录') return this.$Message.error('暂无历史记录')
...@@ -207,53 +212,53 @@ export default { ...@@ -207,53 +212,53 @@ export default {
this.historyData = history.all() this.historyData = history.all()
this.historyShow = true this.historyShow = true
}, },
historyValue (value) { historyValue(value) {
return JSON.stringify(value) return JSON.stringify(value)
}, },
historyView(index){ historyView(index) {
this.$Modal.info({ this.$Modal.info({
render: (h) => { render: (h) => {
return h('Input', { return h('Input', {
props: { props: {
type:"textarea", type: "textarea",
rows:10, rows: 10,
value: JSON.stringify(historyFactory(this.currentTool).get(index), null, "\t"), value: JSON.stringify(historyFactory(this.currentTool).get(index), null, "\t"),
} }
}) })
}, },
width:700, width: 700,
okText:"关闭" okText: "关闭"
}) })
}, },
historyClear(){ historyClear() {
historyFactory(this.currentTool).clear() historyFactory(this.currentTool).clear()
this.historyShow = false; this.historyShow = false;
}, },
historyLoad(index){ historyLoad(index) {
setLoadHistoryIndex(index) setLoadHistoryIndex(index)
this.historyShow = false; this.historyShow = false;
this.$router.push({ this.$router.push({
path:this.$router.currentRoute.fullPath, path: this.$router.currentRoute.fullPath,
query:{ query: {
t:Date.now(), t: Date.now(),
}, },
}); });
}, },
toolSelect (name) { toolSelect(name) {
model.setToolHistory(this.currentCategory, name) model.setToolHistory(this.currentCategory, name)
this.currentTool = name this.currentTool = name
}, },
badgeToolIsShow (tool) { badgeToolIsShow(tool) {
return config.badgeToolIsShow(tool) return config.badgeToolIsShow(tool)
}, },
badgeCategoryIsShow (cat) { badgeCategoryIsShow(cat) {
return config.badgeCategoryIsShow(cat) return config.badgeCategoryIsShow(cat)
}, },
}, },
} }
</script> </script>
<style scoped> <style scoped>
.drawer-footer{ .drawer-footer {
width: 100%; width: 100%;
position: absolute; position: absolute;
bottom: 0; bottom: 0;
......
import {env, inArray} from '../helper' import {env} from '../helper'
import cache from './cache' import cache from './cache'
const toolConfig = require('../config') const toolConfig = require('../config')
...@@ -84,16 +84,16 @@ export default { ...@@ -84,16 +84,16 @@ export default {
getToolByCategory(cat) { getToolByCategory(cat) {
return tool.filter((t) => { return tool.filter((t) => {
if (cat === 'common') { if (cat === 'common') {
return inArray(t.name, getUserCommon()) return getUserCommon().includes(t.name)
} }
return inArray(cat, t.cat) return t.cat.includes(cat);
}) })
}, },
getToolDefaultCategory, getToolDefaultCategory,
badgeToolIsShow(tool) { badgeToolIsShow(tool) {
return badgeIsShow() && inArray(tool, BADGE_TOOL) return badgeIsShow() && BADGE_TOOL.includes(tool)
}, },
badgeCategoryIsShow(cat) { badgeCategoryIsShow(cat) {
return badgeIsShow() && inArray(cat, BADGE_CATEGORY) return badgeIsShow() && BADGE_CATEGORY.includes(cat)
}, },
} }
\ No newline at end of file
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</template> </template>
<script> <script>
import {isChromium, isUtools, openTab} from '../../helper' import {isChromium, isUtools, openUrl} from '../../helper'
import setting from '../../tool/setting' import setting from '../../tool/setting'
import settingBlock from './setting' import settingBlock from './setting'
...@@ -56,7 +56,7 @@ export default { ...@@ -56,7 +56,7 @@ export default {
open(name) { open(name) {
switch (name) { switch (name) {
case 'shortcuts': case 'shortcuts':
openTab('chrome://extensions/shortcuts') openUrl('chrome://extensions/shortcuts')
break break
case 'setting': case 'setting':
this.settingShow = true this.settingShow = true
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
</div> </div>
</template> </template>
<script> <script>
import request from "ajax-request" import axios from "axios"
import { codemirror } from 'vue-codemirror' import { codemirror } from 'vue-codemirror'
import 'codemirror/lib/codemirror.css' import 'codemirror/lib/codemirror.css'
import 'codemirror/mode/javascript/javascript.js' import 'codemirror/mode/javascript/javascript.js'
...@@ -48,13 +48,17 @@ ...@@ -48,13 +48,17 @@
methods: { methods: {
handle() { handle() {
if (this.current.input) { if (this.current.input) {
request({ axios({
url:"https://ifconfig.co/json", url: 'https://ifconfig.co/json',
data:this.current.input !== "localhost" ? {ip:this.current.input} : null, responseType: 'json',
},(err, res, result)=>{ params: this.current.input !== "localhost" ? {ip:this.current.input} : {}
if (err) return this.$Message.error("ip地址信息查询错误:"+err); }).then((response)=>{
this.current.output = JSON.stringify(JSON.parse(result),null, 4); console.log(response)
this.$saveToolData(this.current); // if (err) return this.$Message.error("ip地址信息查询错误:"+err);
// this.current.output = JSON.stringify(JSON.parse(result),null, 4);
// this.$saveToolData(this.current);
}).catch((error)=>{
console.log(error)
}); });
} }
}, },
......
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
this.current = Object.assign(this.current, this.$getToolData('content')) this.current = Object.assign(this.current, this.$getToolData('content'))
}, },
mounted(){ mounted(){
this.codemirror.setSize(null, window.innerHeight - 200) setTimeout(()=>{
this.codemirror.setSize(null, window.innerHeight - 220)
},100)
}, },
computed: { computed: {
codemirror() { codemirror() {
......
...@@ -16,12 +16,12 @@ export default { ...@@ -16,12 +16,12 @@ export default {
html_entity_16, html_entity_16,
css_entitie css_entitie
}, },
decode(str, type = unicode_point_default) { decode(str, type) {
const errorListener = (item, callback) => { const errorListener = (item, callback) => {
try { try {
return callback && callback() return callback && callback()
} catch (e) { } catch (e) {
throw new Error(`${item} decode error:${e.message}`) throw new Error(`${item} 解码异常:${e.message}`)
} }
} }
...@@ -55,7 +55,7 @@ export default { ...@@ -55,7 +55,7 @@ export default {
return errorListener(item, () => String.fromCodePoint(parseInt(`0x${item.replace("\\", "").toLowerCase()}`))) return errorListener(item, () => String.fromCodePoint(parseInt(`0x${item.replace("\\", "").toLowerCase()}`)))
}); });
} }
throw new Error("decode type error") throw new Error("解码类型异常")
}, },
encode(string, type = unicode_point_default, ignore_ascii = false) { encode(string, type = unicode_point_default, ignore_ascii = false) {
let code = [] let code = []
...@@ -97,7 +97,7 @@ export default { ...@@ -97,7 +97,7 @@ export default {
code.push(`\\${hexRepairStr}`); code.push(`\\${hexRepairStr}`);
break; break;
default: default:
throw new Error("encode type error") throw new Error("编码类型异常")
} }
} }
return code.join(""); return code.join("");
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
<script> <script>
import generator from 'qrcode' import generator from 'qrcode'
import qrcodeParser from 'qrcode-parser' import qrcodeParser from 'qrcode-parser'
import { trim } from '../../helper'
import model from '../../tool/model' import model from '../../tool/model'
export default { export default {
...@@ -102,7 +101,7 @@ ...@@ -102,7 +101,7 @@
return false return false
}, },
substr (str) { substr (str) {
str = trim(str.replace(/[\r\n]/g, '')) str = str.replace(/[\r\n]/g, '').trim()
const strLength = 100 const strLength = 100
return str.length > strLength ? str.substr(0, strLength) + '...' : str return str.length > strLength ? str.substr(0, strLength) + '...' : str
}, },
......
<template> <template>
<heightResize class="tool-timestamp-page"> <div>
<div class="tool-timestamp-block"> <Input v-model="current.input" :rows="7" type="textarea" placeholder="内容(标准时间(YYYY-MM-DD HH:mm:ss[.SSS])/时间戳(秒/毫秒))"></Input>
<option-block> <option-block>
<input-block bottom="8px" right="8px"> <FormItem>
<Input size="large" v-model="current.input"> <Button type="primary" @click="handle()">转换</Button>
<span slot="prepend">{{ $t('timestamp_input') }}</span> <Dropdown style="margin-left: 10px" @on-click="currentTime">
</Input> <Button type="primary">
<template slot="extra"> 当前时间
<Dropdown @on-click="currentTime" transfer>
<Button size="small" type="primary">
{{ $t('timestamp_get') }}
<Icon type="ios-arrow-down"></Icon> <Icon type="ios-arrow-down"></Icon>
</Button> </Button>
<DropdownMenu slot="list"> <DropdownMenu slot="list">
<DropdownItem name="normalSecond">{{ $t('timestamp_normal_second') }}</DropdownItem> <DropdownItem name="normalSecond">标准时间(秒)</DropdownItem>
<DropdownItem name="normalMillisecond">{{ <DropdownItem name="normalMillisecond">标准时间(毫秒)</DropdownItem>
$t('timestamp_normal_millisecond') <DropdownItem name="unixSecond">UNIX时间戳(秒)</DropdownItem>
}} <DropdownItem name="unixMillisecond">UNIX时间戳(毫秒)</DropdownItem>
</DropdownItem>
<DropdownItem name="unixSecond">{{ $t('timestamp_unix_second') }}</DropdownItem>
<DropdownItem name="unixMillisecond">{{
$t('timestamp_unix_millisecond')
}}
</DropdownItem>
</DropdownMenu> </DropdownMenu>
</Dropdown> </Dropdown>
</template> </FormItem>
</input-block>
</option-block> </option-block>
<option-block> <Input v-model="current.output" :rows="7" type="textarea" placeholder="结果"></Input>
<input-block bottom="8px" right="8px">
<Input size="large" :value="output">
<span slot="prepend">{{ $t('timestamp_output') }}</span>
</Input>
<template slot="extra">
<Button size="small" type="primary" @click="()=>copy(output)">{{
$t('timestamp_copy')
}}
</Button>
</template>
</input-block>
</option-block>
<Table :columns="exampleColumns" stripe border size="small" :data="example">
<template slot-scope="{ row }" slot="_value">
<Button size="small" type="text" @click="()=>copy(row.value)">{{ row.value }}</Button>
</template>
</Table>
</div> </div>
</heightResize>
</template> </template>
<script> <script>
import moment from 'moment' import moment from 'moment'
import heightResize from "./components/heightResize";
let inputType = { let inputType = {
'normalSecond': 1, 'normalSecond': 1,
'normalMillisecond': 2, 'normalMillisecond': 2,
'unixSecond': 3, 'unixSecond': 3,
'unixMillisecond': 4, 'unixMillisecond': 4,
'error': 0, 'error': 0,
} }
export default { export default {
components: { created () {
heightResize this.current = Object.assign(this.current, this.$getToolData('input'))
},
created() {
this.$initToolData('input', (data) => {
return (
(new RegExp(/^\d+-\d+-\d+ \d+:\d+:\d+$/)).test(data)
|| (new RegExp(/^\d+-\d+-\d+ \d+:\d+:\d+\.\d+$/)).test(data)
|| (new RegExp(/^\d{10}$/)).test(data)
|| (new RegExp(/^\d{13}$/)).test(data)
)
})
},
mounted() {
this.timer = setInterval(() => {
this.timestamp = moment().format('x')
}, 100);
}, },
beforeDestroy() { methods: {
clearInterval(this.timer); handle () {
},
computed: {
example() {
let time = moment(parseInt(this.timestamp))
return [
{format: this.$t('timestamp_normal_second'), value: time.format('YYYY-MM-DD HH:mm:ss')},
{format: this.$t('timestamp_unix_second'), value: time.format('X')},
{format: this.$t('timestamp_normal_millisecond'), value: time.format('YYYY-MM-DD HH:mm:ss.SSS')},
{format: this.$t('timestamp_unix_millisecond'), value: time.format('x')},
]
},
output() {
let result = "";
if (!this.current.input) {
return result;
}
try {
let type = function (input) { let type = function (input) {
if ((new RegExp(/^\d+-\d+-\d+ \d+:\d+:\d+$/)).test(input)) { if ((new RegExp(/^\d+-\d+-\d+ \d+:\d+:\d+$/)).test(input)) {
return inputType.normalSecond return inputType.normalSecond
...@@ -115,78 +54,48 @@ export default { ...@@ -115,78 +54,48 @@ export default {
return inputType.error return inputType.error
}(this.current.input.trim()) }(this.current.input.trim())
if (type === inputType.error) { if (type === inputType.error) {
throw new Error(this.$t('timestamp_error_format').toString()) return this.$Message.error('输入时间格式错误')
} }
switch (type) { switch (type) {
case inputType.normalSecond: case inputType.normalSecond:
result = moment(this.current.input).format('X') this.current.output = moment(this.current.input).format('X')
break break
case inputType.normalMillisecond: case inputType.normalMillisecond:
result = moment(this.current.input).format('x') this.current.output = moment(this.current.input).format('x')
break break
case inputType.unixSecond: case inputType.unixSecond:
result = moment(parseInt(this.current.input) * 1000).format('YYYY-MM-DD HH:mm:ss') this.current.output = moment(parseInt(this.current.input)*1000).format('YYYY-MM-DD HH:mm:ss')
break break
case inputType.unixMillisecond: case inputType.unixMillisecond:
result = moment(parseInt(this.current.input)).format('YYYY-MM-DD HH:mm:ss.SSS') this.current.output = moment(parseInt(this.current.input)).format('YYYY-MM-DD HH:mm:ss.SSS')
break break
} }
this.$clipboardCopy(this.current.output)
this.$saveToolData(this.current) this.$saveToolData(this.current)
} catch (e) {
result = this.$t('timestamp_error', [e.message])
}
return result;
}
},
methods: {
copy(data) {
if (data) {
this.$clipboardCopy(data, true)
}
}, },
currentTime(type) { currentTime (type) {
if (type === "normalSecond") { if(type === "normalSecond"){
this.current.input = moment().format('YYYY-MM-DD HH:mm:ss') this.current.input = moment().format('YYYY-MM-DD HH:mm:ss')
} else if (type === "normalMillisecond") { }
else if(type === "normalMillisecond"){
this.current.input = moment().format('YYYY-MM-DD HH:mm:ss.SSS') this.current.input = moment().format('YYYY-MM-DD HH:mm:ss.SSS')
} else if (type === "unixSecond") { }
else if(type === "unixSecond"){
this.current.input = moment().format('X') this.current.input = moment().format('X')
} else { }
else{
this.current.input = moment().format('x') this.current.input = moment().format('x')
} }
this.handle();
}, },
}, },
data() { data () {
return { return {
current: { current: {
input: moment().format('YYYY-MM-DD HH:mm:ss') input: '',
}, output: '',
timer: null,
timestamp: 0,
exampleColumns: [
{
title: this.$t('timestamp_format'),
key: 'format',
width: 200
}, },
{
title: this.$t('timestamp_value'),
slot: '_value',
}
]
} }
}, },
} }
</script> </script>
\ No newline at end of file
<style>
.tool-timestamp-page {
display: flex;
display: -webkit-flex;
align-items: center;
justify-content: center;
}
.tool-timestamp-block {
width: 600px;
}
</style>
<template> <template>
<heightResize :append="['.page-option-block']" ignore @resize="resize"> <div>
<autoHeightTextarea :height="inputHeight" v-model="current.input" :placeholder="$t('unicode_input')" /> <Input v-model="current.input" :rows="7" type="textarea" placeholder="内容"></Input>
<option-block class="page-option-block"> <option-block>
<FormItem> <FormItem>
<ButtonGroup> <ButtonGroup>
<Button type="primary" @click="handle('encode')">{{ $t('unicode_encode') }}</Button> <Button type="primary" @click="handle('encode')">字符转Unicode(编码)</Button>
<Button type="primary" @click="handle('decode')">{{ $t('unicode_decode') }}</Button> <Button type="primary" @click="handle('decode')">Unicode转字符(解码)</Button>
</ButtonGroup> </ButtonGroup>
</FormItem> </FormItem>
<FormItem> <FormItem>
<Select v-model="current.type" style="width:250px"> <Select v-model="current.type" style="width:250px">
<Option value="unicode_point_default">{{ $t('unicode_mode_default') }} \u[0-9a-f]{4}</Option> <Option value="unicode_point_default">Unicode 默认模式 \u[0-9a-f]{4}</Option>
<Option value="unicode_point_wide">{{ $t('unicode_mode_wide') }} \u[0-9a-f]{4,6}</Option> <Option value="unicode_point_wide">Unicode 宽字符模式 \u[0-9a-f]{4,6}</Option>
<Option value="unicode_point_wide_brace">{{ $t('unicode_mode_wide_bracket') }} \u{[0-9a-f]{4,6}}</Option> <Option value="unicode_point_wide_brace">Unicode 宽字符模式(带大括号) \u{[0-9a-f]{4,6}}</Option>
<Option value="unicode_number">{{ $t('unicode_mode_number') }} U+[0-9A-F]{4,6}</Option> <Option value="unicode_number">Unicode 编码模式 U+[0-9A-F]{4,6}</Option>
<Option value="html_entity_10">{{ $t('unicode_mode_html_10') }} &amp;#[0-9]+;</Option> <Option value="html_entity_10">html 实体(10进制) &amp;#[0-9]+;</Option>
<Option value="html_entity_16">{{ $t('unicode_mode_html_16') }} &amp;#x[0-9a-f]{1,6};</Option> <Option value="html_entity_16">html 实体(16进制) &amp;#x[0-9a-f]{1,6};</Option>
<Option value="css_entitie">{{ $t('unicode_mode_css_16') }} \[0-9a-f]{4,6}</Option> <Option value="css_entitie">css 实体(16进制) \[0-9a-f]{4,6}</Option>
</Select> </Select>
</FormItem> </FormItem>
<FormItem v-if="!disable_ignore_ascii_select.includes(current.type)"> <FormItem v-if="!disable_ignore_ascii_select.includes(current.type)">
<Checkbox v-model="current.ignore_ascii">{{ $t('unicode_ignore_ascii') }}</Checkbox> <Checkbox v-model="current.ignore_ascii">禁止 ASCII 字符编码</Checkbox>
</FormItem> </FormItem>
</option-block> </option-block>
<autoHeightTextarea :height="outputHeight" :value="current.output" :placeholder="$t('unicode_output')" /> <Input v-model="current.output" :rows="7" type="textarea" placeholder="结果"></Input>
</heightResize> </div>
</template> </template>
<script> <script>
import Unicode from "./library/unicode" import Unicode from "./library/unicode"
import heightResize from "./components/heightResize";
import autoHeightTextarea from "./components/autoHeightTextarea";
export default { export default {
components:{
heightResize,
autoHeightTextarea
},
created() { created() {
this.$initToolData('input') this.current = Object.assign(this.current, this.$getToolData("input"))
}, },
methods: { methods: {
handle(operation) { handle(operation) {
...@@ -52,16 +47,12 @@ export default { ...@@ -52,16 +47,12 @@ export default {
this.current.output = Unicode.decode(this.current.input, this.current.type); this.current.output = Unicode.decode(this.current.input, this.current.type);
} }
} catch (e) { } catch (e) {
return this.$Message.error(this.$t('unicode_error',[e.message]).toString()) return this.$Message.error(e.message)
} }
this.current.operation = operation; this.current.operation = operation;
this.$clipboardCopy(this.current.output); this.$clipboardCopy(this.current.output);
this.$saveToolData(this.current); this.$saveToolData(this.current);
} }
},
resize(height){
this.inputHeight = Math.ceil(height/2);
this.outputHeight = height - this.inputHeight;
} }
}, },
data() { data() {
...@@ -73,8 +64,6 @@ export default { ...@@ -73,8 +64,6 @@ export default {
type: "unicode_point_default", type: "unicode_point_default",
ignore_ascii: true, ignore_ascii: true,
}, },
inputHeight:100,
outputHeight:100,
disable_ignore_ascii_select: ['unicode_point_wide', 'unicode_number', 'css_entitie'] disable_ignore_ascii_select: ['unicode_point_wide', 'unicode_number', 'css_entitie']
} }
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册