提交 93a4577f 编写于 作者: N ninecents

GenJson GenJava

上级 2732cf89
......@@ -76,7 +76,7 @@
"vue-i18n": "^8.27.0",
"vue-router": "^3.5.3",
"vuedraggable": "^2.24.3",
"x2js": "github:abdolence/x2js",
"x2js": "git+https://hub.fastgit.xyz​​/abdolence/x2js.git",
"xml-formatter": "^2.6.1"
},
"devDependencies": {
......
......@@ -22,6 +22,7 @@ const category = [
{'name': 'generate'},
{'name': 'other'},
{'name': 'yeahmao'},
{'name': 'code_gen'},
]
const tool = [
......@@ -68,6 +69,9 @@ const tool = [
// yeahmao
{'name': 'hexConvert', 'cat': ['yeahmao']},
// code_gen
{'name': 'codeGenJson', 'cat': ['code_gen']},
{'name': 'codeGenJava', 'cat': ['code_gen']},
]
// 工具类功能配置
......
......@@ -40,6 +40,7 @@
"category_generate": "Generate",
"category_other": "Other",
"category_yeahmao": "yeahmao",
"category_code_gen": "code_gen",
// tool
"tool_hash": "Hash",
"tool_encrypt": "Encrypt & Decrypt",
......@@ -75,6 +76,8 @@
"tool_bcrypt": "Bcrypt",
"tool_ipcalc": "Ipcalc",
"tool_hexConvert": "hexConvert",
"tool_codeGenJson": "codeGenJson",
"tool_codeGenJava": "codeGenJava",
// other
"css_main_category_item_style": "padding: 0 10px",
"editor_line_wrapping": "Line Wrapping",
......
......@@ -40,6 +40,7 @@
"category_generate": "生成",
"category_other": "其他",
"category_yeahmao": "夜猫逐梦",
"category_code_gen": "代码生成器",
// 工具
"tool_hash": "哈希(hash)",
"tool_encrypt": "加密/解密",
......@@ -75,6 +76,8 @@
"tool_bcrypt": "Bcrypt",
"tool_ipcalc": "IP网络计算器",
"tool_hexConvert": "字节转换",
"tool_codeGenJson": "代码生成Json",
"tool_codeGenJava": "代码生成Java",
// 其他
"css_main_category_item_style": "padding: 0 20px",
"editor_line_wrapping": "自动换行",
......
......@@ -165,6 +165,14 @@ const routes = [
{
path: '/yeahmao/hexConvert',
component: r => require(['./views/yeahmao/hexConvert.vue'], r)
},
{
path: '/yeahmao/code_gen/codeGenJson',
component: r => require(['./views/yeahmao/code_gen/codeGenJson.vue'], r)
},
{
path: '/yeahmao/code_gen/codeGenJava',
component: r => require(['./views/yeahmao/code_gen/codeGenJava.vue'], r)
}
]
......
......@@ -56,9 +56,12 @@ export default {
},
watch: {
currentTool(name) {
console.log(name)
model.setCurrentTool(name)
if (name == 'hexConvert') {
this.$router.push('/yeahmao/' + name)
} else if (['codeGenJson', 'codeGenJava'].indexOf(name) != -1) {
this.$router.push('/yeahmao/code_gen/' + name)
} else {
this.$router.push('/tool/' + name)
}
......
<template>
<heightResize ignore :append="['.page-option-block']" @resize="resize">
<autoHeightTextarea v-model="current.input" :height="inputHeight" :placeholder="$t('hexString_input')"/>
<option-block class="page-option-block">
<FormItem>
<ButtonGroup>
<Button type="primary" @click="codeGenString()">Convert</Button>
<!-- <Button type="primary" @click="handle('str')">Hex -> String</Button> -->
</ButtonGroup>
</FormItem>
<FormItem>
<Checkbox v-model="current.isUppercase">{{ $t('hexString_uppercase') }}</Checkbox>
</FormItem>
</option-block>
<!-- <span>美化的内容&nbsp;&nbsp;&nbsp;&nbsp;</span><input class="input_width_100" type="text" v-model="current.output_beautiful">
<br>
<span>字符串格式&nbsp;&nbsp;&nbsp;&nbsp;</span><input class="input_width_100" type="text" v-model="current.output_str">
<br>
<span>字节数组格式:</span><input class="input_width_100" type="text" v-model="current.output_bytes"> -->
<autoHeightTextarea :value="current.output" :height="outputHeight" :placeholder="$t('hexString_output')"/>
</heightResize>
</template>
<script>
import heightResize from "../../tool/components/heightResize";
import autoHeightTextarea from "../../tool/components/autoHeightTextarea";
export default {
components: {
heightResize,
autoHeightTextarea
},
created() {
this.$initToolData('input')
},
methods: {
codeGenString() {
console.log('enter...')
var ret = 'StringBuilder sb = new StringBuilder();\n'
if (this.current.input) {
var lst = []
var max_length = 65500;
var count = Math.floor(this.current.input.length / max_length);
let index = 0;
for (; index < count; index++) {
lst.push(
this.current.input.substr(index * max_length, max_length)
)
}
lst.push(
this.current.input.substring(index * max_length, this.current.input.length)
)
for (let index = 0; index < lst.length; index++) {
const element = lst[index];
ret += 'sb.append("' + element + '");\n';
}
ret += '\nString str = sb.toString();'
}
console.log('leave...', ret)
this.current.output = ret
},
resize(height) {
this.inputHeight = Math.min(320, Math.ceil(height / 2))
this.outputHeight = height - this.inputHeight
// this.outputHeight = 180
}
},
data() {
return {
current: {
input: "",
isUppercase: false,
output_beautiful: "", // 一行,全字节内容,美化的内容
output_str: "", // 字符串格式
output_bytes: "", // 字节数组格式
output: "",
operation: ""
},
inputHeight: 100,
outputHeight: 100
}
},
}
</script>
<style scoped>
.input_width_100 {
width: 80%;
margin: 8px 0;
}
</style>
\ No newline at end of file
<template>
<heightResize ignore :append="['.page-option-block']" @resize="resize">
<autoHeightTextarea v-model="current.input" :height="inputHeight" :placeholder="$t('hexString_input')"/>
<option-block class="page-option-block">
<FormItem>
<ButtonGroup>
<Button type="primary" @click="codeGenJson()">Convert</Button>
<!-- <Button type="primary" @click="handle('str')">Hex -> String</Button> -->
</ButtonGroup>
</FormItem>
<FormItem>
<Checkbox v-model="current.isUppercase">{{ $t('hexString_uppercase') }}</Checkbox>
</FormItem>
</option-block>
<!-- <span>美化的内容&nbsp;&nbsp;&nbsp;&nbsp;</span><input class="input_width_100" type="text" v-model="current.output_beautiful">
<br>
<span>字符串格式&nbsp;&nbsp;&nbsp;&nbsp;</span><input class="input_width_100" type="text" v-model="current.output_str">
<br>
<span>字节数组格式:</span><input class="input_width_100" type="text" v-model="current.output_bytes"> -->
<autoHeightTextarea :value="current.output" :height="outputHeight" :placeholder="$t('hexString_output')"/>
</heightResize>
</template>
<script>
import heightResize from "../../tool/components/heightResize";
import autoHeightTextarea from "../../tool/components/autoHeightTextarea";
export default {
components: {
heightResize,
autoHeightTextarea
},
created() {
this.$initToolData('input')
},
methods: {
codeGenJson() {
console.log('enter...')
var objJson = {}
if (this.current.input) {
var lines = this.current.input.split('\n');
lines.forEach(line => {
console.log(line)
var items = line.split(' ')
function del_space(s) {
return (s && s.trim());
}
// 去除空字符串
items = items.filter(del_space)
if (items.length != 2) {
console.log(items)
}
objJson[items[0]] = items[1]
})
}
console.log('leave...', objJson)
this.current.output = JSON.stringify(objJson)
},
resize(height) {
this.inputHeight = Math.min(320, Math.ceil(height / 2))
this.outputHeight = height - this.inputHeight
// this.outputHeight = 180
}
},
data() {
return {
current: {
input: "",
isUppercase: false,
output_beautiful: "", // 一行,全字节内容,美化的内容
output_str: "", // 字符串格式
output_bytes: "", // 字节数组格式
output: "",
operation: ""
},
inputHeight: 100,
outputHeight: 100
}
},
}
</script>
<style scoped>
.input_width_100 {
width: 80%;
margin: 8px 0;
}
</style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册