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

界面优化

上级 c0a5daf8
<template>
<Row :gutter="10">
<Col span="10">
<Card :padding="0">
<p slot="title">JSON内容</p>
<codemirror ref="json" v-model="current.json" :options="options('Json')"></codemirror>
</Card>
<option-block>
<FormItem>
<Input v-model="current.package">
<div slot="prepend">namespace/package</div>
</Input>
</FormItem>
</option-block>
<option-block>
<FormItem>
<Input v-model="current.class">
<div slot="prepend">class/struct</div>
</Input>
</FormItem>
</option-block>
</Col>
<Col span="14">
<Card :padding="0">
<p slot="title">转换结果</p>
<template slot="extra">
<Button style="margin-right: 5px" size="small" v-for="(item,key) in type" :key="key" type="primary"
@click="handle(item)">{{ item }} 实体
</Button>
</template>
<codemirror ref="output" v-model="current.output"
:options="options(this.current.type)"></codemirror>
</Card>
</Col>
</Row>
</template>
<script>
import json2Go from './library/json2Go'
import json2CSharp from './library/json2CSharp'
import json2Java from './library/json2Java'
import {codemirror} from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
import 'codemirror/mode/javascript/javascript.js'
import 'codemirror/mode/go/go.js'
import 'codemirror/mode/clike/clike.js'
import 'codemirror/addon/fold/foldcode.js'
import 'codemirror/addon/fold/foldgutter.js'
import 'codemirror/addon/fold/brace-fold.js'
import 'codemirror/addon/fold/comment-fold.js'
import 'codemirror/addon/fold/foldgutter.css'
export default {
components: {
codemirror,
},
created() {
this.current = Object.assign(this.current, this.$getToolData())
},
mounted() {
this.$refs.json.codemirror.setSize(null, window.innerHeight - 330)
this.$refs.output.codemirror.setSize(null, window.innerHeight - 230)
},
methods: {
handle(type) {
try {
require('jsonlint').parse(this.current.json)
if (!this.type.includes(type)) {
throw new Error("转换类型错误")
}
this.current.type = type;
switch (type) {
case "Go":
this.current.output = json2Go(this.current.json, this.current.class, this.current.package).go
break;
case "Java":
this.current.output = json2Java(JSON.parse(this.current.json), this.current.class, this.current.package)
break;
case "C#":
this.current.output = json2CSharp.convert(JSON.parse(this.current.json), this.current.class, this.current.package)
break;
}
} catch (error) {
this.$Notice.error({
title: '错误提示',
desc: error.message,
})
return
}
this.$saveToolData(this.current)
},
options(mode) {
return {
mode: this.codemirrorMode[mode],
lineWrapping: false,
foldGutter: true,
indentUnit: 4,
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
}
}
},
data() {
return {
current: {
json: "",
type: "Java",
package: "pag",
class: "RootName",
output: "",
},
type: ["Java", "C#", "Go"],
codemirrorMode: {
"Json": "application/json",
"Java": "text/x-java",
"C#": "text/x-csharp",
"Go": "text/x-go"
},
}
},
}
</script>
\ No newline at end of file
<template>
<div>
<option-block>
<FormItem>
<FormItem style="width: 140px">
<Input v-model="current.amount">
<div slot="prepend" style="width: 70px">生成数量</div>
<div slot="prepend">生成数量</div>
</Input>
</FormItem>
<FormItem>
<FormItem style="width: 140px">
<Input v-model="current.delimiter">
<div slot="prepend" style="width: 70px">分隔符</div>
<div slot="prepend">分隔符</div>
</Input>
</FormItem>
<FormItem>
......@@ -27,11 +27,11 @@
<Button type="primary" @click="handle()">生成</Button>
</FormItem>
</option-block>
<Input v-model="current.output" :rows="12" type="textarea" placeholder="结果"></Input>
<Input v-model="current.output" :rows="14" type="textarea" placeholder="结果"></Input>
</div>
</template>
<script>
import {v4 as uuidV4,parse as uuidParse} from 'uuid';
import {parse as uuidParse, v4 as uuidV4} from 'uuid';
export default {
created() {
......@@ -48,8 +48,8 @@ export default {
},
generate() {
let uuid = uuidV4()
if(this.current.uint8Array){
return "["+uuidParse(uuid).toString()+"]"
if (this.current.uint8Array) {
return "[" + uuidParse(uuid).toString() + "]"
}
if (this.current.filterLine) {
uuid = uuid.replace(/-/g, "")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册