提交 7468a820 编写于 作者: B baiy 提交者: ninecents

ascii编码转换 #41

上级 12d4a524
......@@ -39,6 +39,7 @@ const tool = [
{'name': 'time', 'title': '时间计算器', 'cat': ['other']},
{'name': 'uuid', 'title': 'UUID生成', 'cat': ['other']},
{'name': 'jsonToObject', 'title': 'JSON转实体类', 'cat': ['conversion', 'serialize']},
{'name': 'ascii', 'title': 'ascii转换', 'cat': ['conversion']},
]
module.exports = {
......
......@@ -89,6 +89,14 @@ const routes = [
{
path: '/tool/uuid',
component: r => require(['./views/tool/uuid.vue'], r)
},
{
path: '/tool/jsonToObject',
component: r => require(['./views/tool/jsonToObject.vue'], r)
},
{
path: '/tool/ascii',
component: r => require(['./views/tool/ascii.vue'], r)
}
]
......
<template>
<div>
<Tabs v-model="operation">
<TabPane :label="$t('ascii_convent')" name="convent">
<TabPane label="转换" name="convent">
<option-block>
<Input v-model="current.data.dec" :placeholder="$t('ascii_input_prompt')">
<div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_10') }}</strong></div>
<Input v-model="current.data.dec" placeholder="多个字符用空格分隔">
<div slot="prepend" style="width: 100px"><strong>十进制</strong></div>
</Input>
</option-block>
<option-block>
<Input v-model="current.data.hex" :placeholder="$t('ascii_input_prompt')">
<div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_16') }}</strong></div>
<Input v-model="current.data.hex" placeholder="多个字符用空格分隔">
<div slot="prepend" style="width: 100px"><strong>十六进制</strong></div>
</Input>
</option-block>
<option-block>
<Input v-model="current.data.oct" :placeholder="$t('ascii_input_prompt')">
<div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_8') }}</strong></div>
<Input v-model="current.data.oct" placeholder="多个字符用空格分隔">
<div slot="prepend" style="width: 100px"><strong>八进制</strong></div>
</Input>
</option-block>
<option-block>
<Input v-model="current.data.bin" :placeholder="$t('ascii_input_prompt')">
<div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_2') }}</strong></div>
<Input v-model="current.data.bin" placeholder="多个字符用空格分隔">
<div slot="prepend" style="width: 100px"><strong>二进制</strong></div>
</Input>
</option-block>
<option-block>
<Input v-model="current.data.str">
<div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_string') }}</strong></div>
<div slot="prepend" style="width: 100px"><strong>字符串</strong></div>
</Input>
</option-block>
<option-block :style="{textAlign:'center'}">
<FormItem>
<ButtonGroup>
<Button type="primary" @click="handle()" style="margin-right: 5px">{{ $t('ascii_convent') }}</Button>
<Button type="primary" @click="clear()">{{ $t('ascii_clear') }}</Button>
<Button type="primary" @click="handle()" style="margin-right: 5px">转换</Button>
<Button type="primary" @click="clear()">清空</Button>
</ButtonGroup>
</FormItem>
</option-block>
</TabPane>
<TabPane :label="$t('ascii_code_table')" name="reader">
<TabPane label="编码表" name="reader">
<Table :columns="referenceColumns" :data="reference">
</Table>
</TabPane>
......@@ -59,7 +59,7 @@ export default {
oct:ob.oct(),
bin:ob.bin(),
str:ob.str(),
show:isShow ? this.$t('ascii_yes'): this.$t('ascii_no'),
show:isShow ? "" : "",
explain:isShow ? ob.str() : ascii.ascii_hidden[ascii.ascii_map[index]]
})
}
......@@ -67,7 +67,7 @@ export default {
},
},
created() {
this.$initToolData()
this.current = Object.assign(this.current, this.$getToolData())
},
methods: {
handle() {
......@@ -82,12 +82,10 @@ export default {
}
}
if (!s){
throw new Error(this.$t('ascii_input_null_prompt').toString())
throw "请输入对应的待转换编码"
}
} catch (err) {
return this.$Message.error(
this.$t('ascii_convent_error',[err.message]).toString()
);
return this.$Message.error("转换异常:" + err);
}
for (const type of this.types) {
this.current.data[type] = ascii.convent(s,currentType,type)
......@@ -115,40 +113,40 @@ export default {
operation: "convent",
referenceColumns: [
{
title: this.$t('ascii_input_10'),
title: '十进制',
key: 'dec',
width:100
},
{
title: this.$t('ascii_input_16'),
title: '十六进制',
key: 'hex',
width:100
},
{
title: this.$t('ascii_input_8'),
title: '八进制',
key: 'oct',
width:100
},
{
title: this.$t('ascii_input_2'),
title: '二进制',
key: 'bin',
},
{
title: this.$t('ascii_input_string'),
title: '字符',
key: 'str',
width:100
},
{
title: this.$t('ascii_is_show'),
title: '是否可见',
key: 'show',
width:100
},
{
title: this.$t('ascii_description'),
title: '字符说明',
key: 'explain',
}
],
}
}
}
</script>
</script>
\ No newline at end of file
// ASCII MAP
import Radix from "./radix.js";
import Radix from "radix.js";
const ASCII_MAP = ['NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'TAB', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI',
'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', 'FS', 'GS', 'RS', 'US',
......@@ -10,39 +10,39 @@ const ASCII_MAP = ['NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'DEL']
// ASCII 不可显示字符
const ASCII_HIDDEN = {
'NUL': __('ascii_code_nul'),
'SOH': __('ascii_code_soh'),
'STX': __('ascii_code_stx'),
'ETX': __('ascii_code_etx'),
'EOT': __('ascii_code_eot'),
'ENQ': __('ascii_code_enq'),
'ACK': __('ascii_code_ack'),
'BEL': __('ascii_code_bel'),
'BS': __('ascii_code_bs'),
'TAB': __('ascii_code_tab'),
'LF': __('ascii_code_lf'),
'VT': __('ascii_code_vt'),
'FF': __('ascii_code_ff'),
'CR': __('ascii_code_cr'),
'SO': __('ascii_code_so'),
'SI': __('ascii_code_si'),
'DLE': __('ascii_code_dle'),
'DC1': __('ascii_code_dc1'),
'DC2': __('ascii_code_dc2'),
'DC3': __('ascii_code_dc3'),
'DC4': __('ascii_code_dc4'),
'NAK': __('ascii_code_nak'),
'SYN': __('ascii_code_syn'),
'ETB': __('ascii_code_etb'),
'CAN': __('ascii_code_can'),
'EM': __('ascii_code_em'),
'SUB': __('ascii_code_sub'),
'ESC': __('ascii_code_esc'),
'FS': __('ascii_code_fs'),
'GS': __('ascii_code_gs'),
'RS': __('ascii_code_rs'),
'US': __('ascii_code_us'),
'DEL': __('ascii_code_del'),
'NUL': "空字符(Null)",
'SOH': "标题开始",
'STX': "本文开始",
'ETX': "本文结束",
'EOT': "传输结束",
'ENQ': "请求",
'ACK': "确认回应",
'BEL': "响铃",
'BS': "退格",
'TAB': "水平定位符号",
'LF': "换行键",
'VT': "垂直定位符号",
'FF': "换页键",
'CR': "归位键",
'SO': "取消变换(Shift out)",
'SI': "启用变换(Shift in)",
'DLE': "跳出数据通讯",
'DC1': "设备控制一(XON 启用软件速度控制)",
'DC2': "设备控制二",
'DC3': "设备控制三(XOFF 停用软件速度控制)",
'DC4': "设备控制四",
'NAK': "确认失败回应",
'SYN': "同步用暂停",
'ETB': "区块传输结束",
'CAN': "取消",
'EM': "连接介质中断",
'SUB': "替换",
'ESC': "跳出",
'FS': "文件分割符",
'GS': "组群分隔符",
'RS': "记录分隔符",
'US': "单元分隔符",
'DEL': "删除",
}
const radix = new Radix();
......@@ -50,7 +50,7 @@ class Ascii {
constructor(c, type = "str") {
let dec = -1;
c = c + "";
if (type !== "str") {
if (type !== "str"){
c = c.toLowerCase();
}
switch (type) {
......@@ -95,7 +95,7 @@ class Ascii {
}
str() {
return ASCII_MAP[this.decData] === " " ? __('ascii_code_space') : ASCII_MAP[this.decData]
return ASCII_MAP[this.decData]
}
}
......@@ -117,4 +117,4 @@ export default {
Ascii,
ascii_map: ASCII_MAP,
ascii_hidden: ASCII_HIDDEN,
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册