Browse Source

代码生成器支持直接使用字典

修复查询涉及sql关键字时sql语句报错问题
main
QM303176530 4 years ago
parent
commit
8560f2f03a
  1. 9
      web/src/components/mixins/infoList.js
  2. 349
      web/src/view/systemTools/autoCode/component/fieldDialog.vue
  3. 7
      web/src/view/systemTools/autoCode/index.vue

9
web/src/components/mixins/infoList.js

@ -1,3 +1,4 @@
import { getDict } from "@/utils/dictionary";
export default {
data() {
return {
@ -9,6 +10,14 @@ export default {
}
},
methods: {
filterDict(value,type){
const rowLabel = this[type+"Options"]&&this[type+"Options"].filter(item=>item.value == value)
return rowLabel&&rowLabel[0]&&rowLabel[0].label
},
async getDict(type){
const dicts = await getDict(type)
this[type+"Options"] = dicts
},
handleSizeChange(val) {
this.pageSize = val
this.getTableData()

349
web/src/view/systemTools/autoCode/component/fieldDialog.vue

@ -1,160 +1,209 @@
<template>
<div>
<span style="color:red">搜索时如果条件为LIKE只支持字符串</span>
<el-form :model="dialogMiddle" ref="fieldDialogFrom" label-width="120px" label-position="left" :rules="rules">
<el-form-item label="Field名称" prop="fieldName">
<el-col :span="6">
<el-input v-model="dialogMiddle.fieldName" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="Field中文名" prop="fieldDesc">
<el-col :span="6">
<el-input v-model="dialogMiddle.fieldDesc" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="FieldJSON" prop="fieldJson">
<el-col :span="6">
<el-input v-model="dialogMiddle.fieldJson" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="数据库字段名" prop="columnName">
<el-col :span="6">
<el-input v-model="dialogMiddle.columnName" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="数据库字段描述" prop="comment">
<el-col :span="6">
<el-input v-model="dialogMiddle.comment" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="Field数据类型" prop="fieldType">
<el-col :span="8">
<el-select v-model="dialogMiddle.fieldType" placeholder="请选择field数据类型" @change="getDbfdOptions" clearable >
<el-option
v-for="item in typeOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-col>
</el-form-item>
<div>
<span style="color:red">搜索时如果条件为LIKE只支持字符串</span>
<el-form
:model="dialogMiddle"
ref="fieldDialogFrom"
label-width="120px"
label-position="left"
:rules="rules"
>
<el-form-item label="Field名称" prop="fieldName">
<el-col :span="6">
<el-input v-model="dialogMiddle.fieldName" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="Field中文名" prop="fieldDesc">
<el-col :span="6">
<el-input v-model="dialogMiddle.fieldDesc" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="FieldJSON" prop="fieldJson">
<el-col :span="6">
<el-input v-model="dialogMiddle.fieldJson" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="数据库字段名" prop="columnName">
<el-col :span="6">
<el-input v-model="dialogMiddle.columnName" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="数据库字段描述" prop="comment">
<el-col :span="6">
<el-input v-model="dialogMiddle.comment" autocomplete="off"></el-input>
</el-col>
</el-form-item>
<el-form-item label="Field数据类型" prop="fieldType">
<el-col :span="8">
<el-select
v-model="dialogMiddle.fieldType"
placeholder="请选择field数据类型"
@change="getDbfdOptions"
clearable
>
<el-option
v-for="item in typeOptions"
:key="item.value"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
</el-col>
</el-form-item>
<el-form-item label="数据库字段类型" prop="dataType">
<el-col :span="8">
<el-select :disabled="!dialogMiddle.fieldType" v-model="dialogMiddle.dataType" placeholder="请选择数据库字段类型" clearable >
<el-option
v-for="item in dbfdOptions"
:key="item.label"
:label="item.label"
:value="item.label">
</el-option>
</el-select>
</el-col>
</el-form-item>
<el-form-item label="数据库字段长度" prop="dataTypeLong">
<el-col :span="6">
<el-input :disabled="!dialogMiddle.dataType" v-model="dialogMiddle.dataTypeLong"></el-input>
</el-col>
</el-form-item>
<el-form-item label="Field查询条件" prop="fieldSearchType">
<el-col :span="8">
<el-select v-model="dialogMiddle.fieldSearchType" placeholder="请选择Field查询条件" clearable >
<el-option
v-for="item in typeSearchOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-col>
</el-form-item>
</el-form>
</div>
<el-form-item label="数据库字段类型" prop="dataType">
<el-col :span="8">
<el-select
:disabled="!dialogMiddle.fieldType"
v-model="dialogMiddle.dataType"
placeholder="请选择数据库字段类型"
clearable
>
<el-option
v-for="item in dbfdOptions"
:key="item.label"
:label="item.label"
:value="item.label"
></el-option>
</el-select>
</el-col>
</el-form-item>
<el-form-item label="数据库字段长度" prop="dataTypeLong">
<el-col :span="6">
<el-input :disabled="!dialogMiddle.dataType" v-model="dialogMiddle.dataTypeLong"></el-input>
</el-col>
</el-form-item>
<el-form-item label="Field查询条件" prop="fieldSearchType">
<el-col :span="8">
<el-select v-model="dialogMiddle.fieldSearchType" placeholder="请选择Field查询条件" clearable>
<el-option
v-for="item in typeSearchOptions"
:key="item.value"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
</el-col>
</el-form-item>
<el-form-item label="关联字典" prop="dictType">
<el-col :span="8">
<el-select :disabled="dialogMiddle.fieldType!='int'" v-model="dialogMiddle.dictType" placeholder="请选择字典" clearable>
<el-option
v-for="item in dictOptions"
:key="item.type"
:label="`${item.type}(${item.name})`"
:value="item.type"
></el-option>
</el-select>
</el-col>
</el-form-item>
</el-form>
</div>
</template>
<script>
import {getDict} from '@/utils/dictionary'
import { getDict } from "@/utils/dictionary";
import { getSysDictionaryList } from "@/api/sysDictionary";
export default {
name:"FieldDialog",
props:{
dialogMiddle:{
type:Object,
default:function(){
return {}
}
}
},
data(){
return{
dbfdOptions:[],
visible:false,
typeSearchOptions:[
{
label:"=",
value:"="
},
{
label:"<>",
value:"<>"
},
{
label:">",
value:">"
},
{
label:"<",
value:"<"
},
{
label:"LIKE",
value:"LIKE"
},
],
typeOptions:[
{
label:"字符串",
value:"string"
},
{
label:"整型",
value:"int"
},
{
label:"布尔值",
value:"bool"
},
{
label:"浮点型",
value:"float64"
},
{
label:"时间",
value:"time.Time"
},
],
rules:{
fieldName:[ { required: true, message: '请输入field英文名', trigger: 'blur' }],
fieldDesc:[ { required: true, message: '请输入field中文名', trigger: 'blur' }],
fieldJson:[ { required: true, message: '请输入field格式化json', trigger: 'blur' }],
columnName:[{ required: true, message: '请输入数据库字段', trigger: 'blur' }],
fieldType:[ { required: true, message: '请选择field数据类型', trigger: 'blur' }]
}
name: "FieldDialog",
props: {
dialogMiddle: {
type: Object,
default: function() {
return {};
}
}
},
data() {
return {
dbfdOptions: [],
visible: false,
dictOptions: [],
typeSearchOptions: [
{
label: "=",
value: "="
},
{
label: "<>",
value: "<>"
},
{
label: ">",
value: ">"
},
{
label: "<",
value: "<"
},
{
label: "LIKE",
value: "LIKE"
}
},
methods: {
async getDbfdOptions(){
if(this.dialogMiddle.fieldType){
const res = await getDict(this.dialogMiddle.fieldType)
this.dbfdOptions = res
}
],
typeOptions: [
{
label: "字符串",
value: "string"
},
{
label: "整型",
value: "int"
},
{
label: "布尔值",
value: "bool"
},
{
label: "浮点型",
value: "float64"
},
{
label: "时间",
value: "time.Time"
}
},
created() {
this.getDbfdOptions()
},
}
],
rules: {
fieldName: [
{ required: true, message: "请输入field英文名", trigger: "blur" }
],
fieldDesc: [
{ required: true, message: "请输入field中文名", trigger: "blur" }
],
fieldJson: [
{ required: true, message: "请输入field格式化json", trigger: "blur" }
],
columnName: [
{ required: true, message: "请输入数据库字段", trigger: "blur" }
],
fieldType: [
{ required: true, message: "请选择field数据类型", trigger: "blur" }
]
}
};
},
methods: {
async getDbfdOptions() {
this.dialogMiddle.dataType = ""
this.dialogMiddle.dataTypeLong = ""
this.dialogMiddle.fieldSearchType = ""
this.dialogMiddle.dictType = ""
if (this.dialogMiddle.fieldType) {
const res = await getDict(this.dialogMiddle.fieldType);
this.dbfdOptions = res;
}
}
},
async created() {
this.getDbfdOptions();
const dictRes = await getSysDictionaryList({
page: 1,
pageSize: 999999
});
this.dictOptions = dictRes.data.list
}
};
</script>
<style lang="scss">
</style>

7
web/src/view/systemTools/autoCode/index.vue

@ -79,6 +79,7 @@
<el-table-column prop="columnName" label="数据库字段" width="130"></el-table-column>
<el-table-column prop="comment" label="数据库字段描述" width="130"></el-table-column>
<el-table-column prop="fieldSearchType" label="搜索条件" width="130"></el-table-column>
<el-table-column prop="dictType" label="字典" width="130"></el-table-column>
<el-table-column label="操作" width="300">
<template slot-scope="scope">
<el-button
@ -135,7 +136,8 @@ const fieldTemplate = {
columnName: "",
dataTypeLong: "",
comment: "",
fieldSearchType: ""
fieldSearchType: "",
dictType:""
};
import FieldDialog from "@/view/systemTools/autoCode/component/fieldDialog.vue";
@ -332,7 +334,8 @@ export default {
dataTypeLong: item.dataTypeLong,
columnName: item.columeName,
comment: item.columeComment,
fieldSearchType: ""
fieldSearchType: "",
dictType:""
});
}
});

Loading…
Cancel
Save