Skip to content

Commit 7c5939d

Browse files
author
piexlmax
committed
自动化代码取消数据库类型定义 对会产生报错的地方做了统一处理
1 parent 54a375e commit 7c5939d

File tree

5 files changed

+18
-44
lines changed

5 files changed

+18
-44
lines changed

server/model/system/sys_auto_code.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type Field struct {
2121
FieldDesc string `json:"fieldDesc"` // 中文名
2222
FieldType string `json:"fieldType"` // Field数据类型
2323
FieldJson string `json:"fieldJson"` // FieldJson
24-
DataType string `json:"dataType"` // 数据库字段类型
2524
DataTypeLong string `json:"dataTypeLong"` // 数据库字段长度
2625
Comment string `json:"comment"` // 数据库字段描述
2726
ColumnName string `json:"columnName"` // 数据库字段

server/resource/template/server/model.go.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
type {{.StructName}} struct {
1111
global.GVA_MODEL {{- range .Fields}}
1212
{{- if ne .FieldType "string" }}
13-
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- end }}"`
13+
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}"`
1414
{{- else }}
15-
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if eq .FieldType "string" -}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}};{{- if ne .FieldType "string" -}}{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}{{- end -}}"`
15+
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}"`
1616
{{- end }} {{- end }}
1717
}
1818

web/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"screenfull": "^5.0.2",
2525
"script-ext-html-webpack-plugin": "^2.1.4",
2626
"spark-md5": "^3.0.1",
27-
"vue": "^3.2.0",
27+
"vue": "^3.2.25",
2828
"vue-particle-line": "^0.1.4",
2929
"vue-router": "^4.0.0-0",
3030
"vuex": "^4.0.0-0",
@@ -47,8 +47,8 @@
4747
"eslint-plugin-vue": "^7.0.0",
4848
"sass": "^1.26.5",
4949
"sass-loader": "^8.0.2",
50-
"vite": "2.5.3",
50+
"vite": "2.5.10",
5151
"vite-plugin-banner": "^0.1.3",
5252
"vite-plugin-importer": "^0.2.5"
5353
}
54-
}
54+
}

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,8 @@
4040
/>
4141
</el-select>
4242
</el-form-item>
43-
44-
<el-form-item label="数据库字段类型" prop="dataType">
45-
<el-select
46-
v-model="middleDate.dataType"
47-
style="width:100%"
48-
:disabled="!middleDate.fieldType"
49-
placeholder="请选择数据库字段类型"
50-
clearable
51-
>
52-
<el-option
53-
v-for="item in dbfdOptions"
54-
:key="item.label"
55-
:label="item.label"
56-
:value="item.label"
57-
/>
58-
</el-select>
59-
</el-form-item>
60-
<el-form-item label="数据库字段长度" prop="dataTypeLong">
61-
<el-input v-model="middleDate.dataTypeLong" placeholder="自定义类型必须指定长度" :disabled="!middleDate.dataType" />
43+
<el-form-item label="类型长度" prop="dataTypeLong">
44+
<el-input v-model="middleDate.dataTypeLong" placeholder="数据库类型长度" />
6245
</el-form-item>
6346
<el-form-item label="Field查询条件" prop="fieldSearchType">
6447
<el-select
@@ -97,7 +80,6 @@
9780
</template>
9881

9982
<script>
100-
import { getDict } from '@/utils/dictionary'
10183
import { toLowerCase, toSQLLine } from '@/utils/stringFun'
10284
import { getSysDictionaryList } from '@/api/sysDictionary'
10385
import warningBar from '@/components/warningBar/warningBar.vue'
@@ -116,7 +98,6 @@ export default {
11698
data() {
11799
return {
118100
middleDate: {},
119-
dbfdOptions: [],
120101
dictOptions: [],
121102
typeSearchOptions: [
122103
{
@@ -189,25 +170,12 @@ export default {
189170
})
190171
191172
this.dictOptions = dictRes.data.list
192-
this.getDict()
193173
},
194174
methods: {
195175
autoFill() {
196176
this.middleDate.fieldJson = toLowerCase(this.middleDate.fieldName)
197177
this.middleDate.columnName = toSQLLine(this.middleDate.fieldJson)
198178
},
199-
async getDbfdOptions() {
200-
this.middleDate.dataType = ''
201-
this.middleDate.dataTypeLong = ''
202-
this.middleDate.fieldSearchType = ''
203-
this.middleDate.dictType = ''
204-
this.getDict()
205-
},
206-
async getDict() {
207-
if (this.middleDate.fieldType) {
208-
this.dbfdOptions = await getDict(this.middleDate.fieldType)
209-
}
210-
}
211179
}
212180
}
213181
</script>

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<el-input v-model="form.description" placeholder="中文描述作为自动api描述" />
6262
</el-form-item>
6363
<el-form-item label="文件名称" prop="packageName">
64-
<el-input v-model="form.packageName" placeholder="生成文件的默认名称(建议为驼峰格式,首字母小写,如sysXxxXxxx)" />
64+
<el-input v-model="form.packageName" placeholder="生成文件的默认名称(建议为驼峰格式,首字母小写,如sysXxxXxxx)" @blur="toLowerCase(form,'packageName')" />
6565
</el-form-item>
6666
<el-form-item>
6767
<template #label>
@@ -92,7 +92,6 @@
9292
<el-table-column align="left" prop="fieldDesc" label="中文名" />
9393
<el-table-column align="left" prop="fieldJson" label="FieldJson" />
9494
<el-table-column align="left" prop="fieldType" label="Field数据类型" width="130" />
95-
<el-table-column align="left" prop="dataType" label="数据库字段类型" width="130" />
9695
<el-table-column align="left" prop="dataTypeLong" label="数据库字段长度" width="130" />
9796
<el-table-column align="left" prop="columnName" label="数据库字段" width="130" />
9897
<el-table-column align="left" prop="comment" label="数据库字段描述" width="130" />
@@ -182,7 +181,7 @@ const fieldTemplate = {
182181
183182
import FieldDialog from '@/view/systemTools/autoCode/component/fieldDialog.vue'
184183
import PreviewCodeDialog from '@/view/systemTools/autoCode/component/previewCodeDialg.vue'
185-
import { toUpperCase, toHump, toSQLLine } from '@/utils/stringFun'
184+
import { toUpperCase, toHump, toSQLLine, toLowerCase } from '@/utils/stringFun'
186185
import { createTemp, getDB, getTable, getColumn, preview, getMeta } from '@/api/autoCode'
187186
import { getDict } from '@/utils/dictionary'
188187
@@ -247,6 +246,9 @@ export default {
247246
}
248247
},
249248
methods: {
249+
toLowerCase(form, key) {
250+
form[key] = toLowerCase(form[key])
251+
},
250252
selectText() {
251253
this.$refs.preview.selectText()
252254
},
@@ -324,6 +326,11 @@ export default {
324326
}
325327
this.$refs.autoCodeForm.validate(async valid => {
326328
if (valid) {
329+
for (const key in this.form) {
330+
if (typeof this.form[key] === 'string') {
331+
this.form[key] = this.form[key].trim()
332+
}
333+
}
327334
this.form.structName = toUpperCase(this.form.structName)
328335
if (this.form.tableName) { this.form.tableName = this.form.tableName.replace(' ', '') }
329336
if (this.form.structName === this.form.abbreviation) {
@@ -413,7 +420,7 @@ export default {
413420
fieldType: this.fdMap[item.dataType],
414421
dataType: item.dataType,
415422
fieldJson: fbHump,
416-
dataTypeLong: item.dataTypeLong,
423+
dataTypeLong: item.dataTypeLong && item.dataTypeLong.split(',')[0],
417424
columnName: item.columnName,
418425
comment: item.columnComment,
419426
fieldSearchType: '',

0 commit comments

Comments
 (0)