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

ascii编码转换 #41

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