Browse Source

fix

main
LonglyCode 4 years ago
parent
commit
93b21c2e84
  1. 160
      package-lock.json
  2. 78
      src/components/HelloWorld.vue

160
package-lock.json

@ -2058,6 +2058,44 @@
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==",
"dev": true "dev": true
}, },
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmmirror.com/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"fs-extra": { "fs-extra": {
"version": "7.0.1", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz",
@ -2069,6 +2107,13 @@
"universalify": "^0.1.0" "universalify": "^0.1.0"
} }
}, },
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"jsonfile": { "jsonfile": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
@ -2078,6 +2123,18 @@
"graceful-fs": "^4.1.6" "graceful-fs": "^4.1.6"
} }
}, },
"loader-utils": {
"version": "2.0.2",
"resolved": "https://registry.npmmirror.com/loader-utils/-/loader-utils-2.0.2.tgz",
"integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"ssri": { "ssri": {
"version": "8.0.1", "version": "8.0.1",
"resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz", "resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz",
@ -2086,6 +2143,28 @@
"requires": { "requires": {
"minipass": "^3.1.1" "minipass": "^3.1.1"
} }
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
},
"vue-loader-v16": {
"version": "npm:vue-loader@16.8.3",
"resolved": "https://registry.npmmirror.com/vue-loader/-/vue-loader-16.8.3.tgz",
"integrity": "sha512-7vKN45IxsKxe5GcVCbc2qFU5aWzyiLrYJyUuMz4BQLKctCj/fmCa0w6fGiiQ2cLFetNcek1ppGJQDCup0c1hpA==",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
}
} }
} }
}, },
@ -11748,87 +11827,6 @@
} }
} }
}, },
"vue-loader-v16": {
"version": "npm:vue-loader@16.8.3",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.8.3.tgz",
"integrity": "sha512-7vKN45IxsKxe5GcVCbc2qFU5aWzyiLrYJyUuMz4BQLKctCj/fmCa0w6fGiiQ2cLFetNcek1ppGJQDCup0c1hpA==",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"loader-utils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz",
"integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"vue-style-loader": { "vue-style-loader": {
"version": "4.1.3", "version": "4.1.3",
"resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.3.tgz", "resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.3.tgz",

78
src/components/HelloWorld.vue

@ -22,7 +22,7 @@
</s-json-schema-editor> </s-json-schema-editor>
</el-col> </el-col>
</el-row> </el-row>
<el-button type="primary" @click="renderer()">生成代码</el-button>
<el-button type="primary" @click="genCode()">生成代码</el-button>
<div style="margin: 20px 0"></div> <div style="margin: 20px 0"></div>
<el-row> <el-row>
<vue-json-editor <vue-json-editor
@ -40,18 +40,33 @@
<el-dialog <el-dialog
title="生成代码" title="生成代码"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
:before-close="handleClose()"
width="80%" width="80%"
> >
<el-button type="primary" @click="selectText()">复制当前页</el-button>
<el-tabs v-model="activeName">
<!-- <el-button type="primary" @click="selectText()">复制当前页</el-button> -->
<el-tabs v-model="activeName" :key="renderKey">
<el-tab-pane <el-tab-pane
v-for="(item, key) in output" v-for="(item, key) in output"
:key="key" :key="key"
:label="key" :label="key"
:name="key" :name="key"
> >
<div :id="key" class="tab-info" style="height:50vh;background: #fff;padding: 0 20px;overflow-y: scroll;" />
<el-input
:key="renderKey"
type="textarea"
v-model="codeOutput"
:autosize="{ minRows: 2, maxRows: 10 }"
placeholder="请输入内容"
></el-input>
<!-- <div
:id="key"
class="tab-info"
style="
height: 50vh;
background: #fff;
padding: 0 20px;
overflow-y: scroll;
"
/> -->
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</el-dialog> </el-dialog>
@ -61,8 +76,8 @@
<script> <script>
import vueJsonEditor from "vue-json-editor"; import vueJsonEditor from "vue-json-editor";
import { Parser } from "sql-ddl-to-json-schema"; import { Parser } from "sql-ddl-to-json-schema";
import { marked } from "marked";
import hljs from "highlight.js";
// import { marked } from "marked";
// import hljs from "highlight.js";
// import "highlight.js/styles/atelier-plateau-light.css"; // import "highlight.js/styles/atelier-plateau-light.css";
function toCamelCase(str) { function toCamelCase(str) {
@ -99,6 +114,7 @@ export default {
data() { data() {
return { return {
schemaKey: "19878878", schemaKey: "19878878",
renderKey: 1,
activeName: "", activeName: "",
dialogVisible: false, dialogVisible: false,
schema: { schema: {
@ -119,37 +135,17 @@ export default {
}; };
}, },
created() {}, created() {},
computed: {
codeOutput() {
return this.output[this.activeName];
},
},
mounted() { mounted() {
this.sqlchange(this.sqlinput); this.sqlchange(this.sqlinput);
this.schemaKey = Date.now(); this.schemaKey = Date.now();
}, },
methods: { methods: {
handleClose() {
console.log("close");
},
renderer() {
this.dialogVisible = true;
marked.setOptions({
renderer: new marked.Renderer(),
highlight: function (code) {
return hljs.highlightAuto(code).value;
},
pedantic: false,
gfm: true,
tables: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false,
});
for (const key in this.output) {
if (this.activeName === "") {
this.activeName = key;
}
document.getElementById(key).innerHTML = marked(this.output[key]);
}
},
selectText() { selectText() {
const element = document.getElementById(this.activeName); const element = document.getElementById(this.activeName);
if (document.body.createTextRange) { if (document.body.createTextRange) {
@ -178,6 +174,15 @@ export default {
this.schemaKey = Date.now(); this.schemaKey = Date.now();
this.schema = Object.assign({}, value); this.schema = Object.assign({}, value);
}, },
genCode() {
let v = this.schema;
this.output["model"] = this.handleModelOutput(v);
this.output["service"] = this.handleServiceOutput(v);
this.output["api"] = this.handleApiOutput(v);
this.renderKey++;
this.activeName = "";
this.dialogVisible = true;
},
sqlchange(v) { sqlchange(v) {
// 1. sql json schema // 1. sql json schema
const parser = new Parser("mysql"); const parser = new Parser("mysql");
@ -194,11 +199,12 @@ export default {
console.log("json渲染错误了value:", value); console.log("json渲染错误了value:", value);
}, },
onSchemaChange(v) { onSchemaChange(v) {
this.jsonformat = v;
this.schema = JSON.stringify(v, null, 2); this.schema = JSON.stringify(v, null, 2);
this.output["model"] = this.handleModelOutput(v); this.output["model"] = this.handleModelOutput(v);
this.output["service"] = this.handleServiceOutput(v); this.output["service"] = this.handleServiceOutput(v);
this.output["api"] = this.handleApiOutput(v); this.output["api"] = this.handleApiOutput(v);
// this.renderer();
console.log("output", this.output);
this.schemaKey = Date.now(); this.schemaKey = Date.now();
}, },
handleApiOutput(v) { handleApiOutput(v) {
@ -564,10 +570,11 @@ export default {
`; `;
var enumcenter = ``; var enumcenter = ``;
var enumend = `)`; var enumend = `)`;
//
enumdesc.split("\n").forEach(function (value, index) { enumdesc.split("\n").forEach(function (value, index) {
const v = enumlist[index]; const v = enumlist[index];
var s = ` var s = `
${tableKey}${value} ${skey} = ${v} \n
${tableKey}${value} ${tableKey} = ${v} \n
`; `;
var f = ` var f = `
func (g ${tableKey}) ${value}() bool { func (g ${tableKey}) ${value}() bool {
@ -577,7 +584,6 @@ export default {
return obj.Updates(ctx, &${tableName}{${skey}: ${tableKey}${value}}, obj.Q().${primary}(id)) return obj.Updates(ctx, &${tableName}{${skey}: ${tableKey}${value}}, obj.Q().${primary}(id))
} \n } \n
`; `;
console.log(value);
enumcenter += s; enumcenter += s;
enumUpdate += f; enumUpdate += f;
}); });

Loading…
Cancel
Save