提交 04502c8c 编写于 作者: B baiy 提交者: ninecents

界面优化

上级 7113e019
<template> <template>
<Row :gutter="10"> <Row :gutter="10">
<Col span="10"> <Col span="10">
<div class="page-option-block"> <Card :padding="0">
<option-block style="padding: 0 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"> <Input v-model="current.package">
<div slot="prepend">namespace/package</div> <div slot="prepend">namespace/package</div>
</Input> </Input>
</option-block> </FormItem>
<option-block> </option-block>
<option-block>
<FormItem>
<Input v-model="current.class"> <Input v-model="current.class">
<div slot="prepend">class/struct</div> <div slot="prepend">class/struct</div>
</Input> </Input>
</option-block> </FormItem>
</div> </option-block>
<input-block top="10px" right="10px" :text="$t('jsonToObject_format')"
@on-default-right-bottom-click="format">
<heightResize :append="['.page-option-block']">
<code-editor v-model="current.input" :placeholder="$t('jsonToObject_input')" language="json"/>
</heightResize>
</input-block>
</Col> </Col>
<Col span="14"> <Col span="14">
<input-block top="10px" right="10px"> <Card :padding="0">
<heightResize> <p slot="title">转换结果</p>
<code-editor :placeholder="$t('jsonToObject_output')" :value="output"
:language="languages[current.type]"/>
</heightResize>
<template slot="extra"> <template slot="extra">
<RadioGroup v-model="current.type" type="button" button-style="solid"> <Button style="margin-right: 5px" size="small" v-for="(item,key) in type" :key="key" type="primary"
<Radio :label="type" v-for="(type) in types" :key="type"> @click="handle(item)">{{ item }} 实体
<span>{{ type }}</span> </Button>
</Radio>
</RadioGroup>
</template> </template>
</input-block> <codemirror ref="output" v-model="current.output"
:options="options(this.current.type)"></codemirror>
</Card>
</Col> </Col>
</Row> </Row>
</template> </template>
<script> <script>
import codeEditor from "./components/codeEditor";
import json2Go from './library/json2Go' import json2Go from './library/json2Go'
import jsonFormatter from './library/formatter/json'
import json2CSharp from './library/json2CSharp' import json2CSharp from './library/json2CSharp'
import json2Java from './library/json2Java' import json2Java from './library/json2Java'
import json2Dart from './library/json2Dart' import {codemirror} from 'vue-codemirror'
import heightResize from "./components/heightResize"; 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 { export default {
components: { components: {
codeEditor, codemirror,
heightResize
}, },
created() { created() {
this.$initToolData('input', (input) => { this.current = Object.assign(this.current, this.$getToolData())
try {
require('jsonlint').parse(input)
} catch (e) {
return false
}
return true
})
}, },
computed: { mounted() {
output() { this.$refs.json.codemirror.setSize(null, window.innerHeight - 330)
if (!this.current.input.trim()) { this.$refs.output.codemirror.setSize(null, window.innerHeight - 230)
return ""; },
} methods: {
handle(type) {
try { try {
let result = ""; require('jsonlint').parse(this.current.json)
require('jsonlint').parse(this.current.input) if (!this.type.includes(type)) {
switch (this.current.type) { throw new Error("转换类型错误")
}
this.current.type = type;
switch (type) {
case "Go": case "Go":
result = json2Go(this.current.input, this.current.class, this.current.package).go this.current.output = json2Go(this.current.json, this.current.class, this.current.package).go
break break;
case "Java": case "Java":
result = json2Java(JSON.parse(this.current.input), this.current.class, this.current.package) this.current.output = json2Java(JSON.parse(this.current.json), this.current.class, this.current.package)
break break;
case "Dart":
result = json2Dart(JSON.parse(this.current.input), this.current.class)
break
case "C#": case "C#":
result = json2CSharp.convert(JSON.parse(this.current.input), this.current.class, this.current.package) this.current.output = json2CSharp.convert(JSON.parse(this.current.json), this.current.class, this.current.package)
break
default: break;
throw new Error(this.$t('jsonToObject_type_error').toString())
} }
this.$saveToolData(this.current)
return result;
} catch (error) { } catch (error) {
return this.$t('jsonToObject_error', [error.message]).toString() this.$Notice.error({
title: '错误提示',
desc: error.message,
})
return
} }
this.$saveToolData(this.current)
}, },
types() { options(mode) {
return Object.keys(this.languages) return {
} mode: this.codemirrorMode[mode],
}, lineWrapping: false,
methods: { foldGutter: true,
format() { indentUnit: 4,
if (this.current.input.trim()) { gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
this.current.input = jsonFormatter.beautify(this.current.input)
} }
} }
}, },
data() { data() {
return { return {
current: { current: {
input: "", json: "",
type: "Java", type: "Java",
package: "pag", package: "pag",
class: "RootName", class: "RootName",
output: "",
}, },
languages: { type: ["Java", "C#", "Go"],
"Java": "java", codemirrorMode: {
"Dart": "dart", "Json": "application/json",
"C#": "csharp", "Java": "text/x-java",
"Go": "go" "C#": "text/x-csharp",
"Go": "text/x-go"
}, },
} }
}, },
} }
</script> </script>
\ No newline at end of file
<template> <template>
<div> <div>
<option-block> <option-block>
<FormItem> <FormItem style="width: 140px">
<Input v-model="current.amount"> <Input v-model="current.amount">
<div slot="prepend" style="width: 70px">生成数量</div> <div slot="prepend">生成数量</div>
</Input> </Input>
</FormItem> </FormItem>
<FormItem> <FormItem style="width: 140px">
<Input v-model="current.delimiter"> <Input v-model="current.delimiter">
<div slot="prepend" style="width: 70px">分隔符</div> <div slot="prepend">分隔符</div>
</Input> </Input>
</FormItem> </FormItem>
<FormItem> <FormItem>
...@@ -27,11 +27,11 @@ ...@@ -27,11 +27,11 @@
<Button type="primary" @click="handle()">生成</Button> <Button type="primary" @click="handle()">生成</Button>
</FormItem> </FormItem>
</option-block> </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> </div>
</template> </template>
<script> <script>
import {v4 as uuidV4,parse as uuidParse} from 'uuid'; import {parse as uuidParse, v4 as uuidV4} from 'uuid';
export default { export default {
created() { created() {
...@@ -48,8 +48,8 @@ export default { ...@@ -48,8 +48,8 @@ export default {
}, },
generate() { generate() {
let uuid = uuidV4() let uuid = uuidV4()
if(this.current.uint8Array){ if (this.current.uint8Array) {
return "["+uuidParse(uuid).toString()+"]" return "[" + uuidParse(uuid).toString() + "]"
} }
if (this.current.filterLine) { if (this.current.filterLine) {
uuid = uuid.replace(/-/g, "") uuid = uuid.replace(/-/g, "")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册