From 10e167c5f52ed5bca965df27f8076092850834e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?piexlMax=28=E5=A5=87=E6=B7=BC?= Date: Mon, 18 Nov 2024 18:32:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=91=E5=BD=A2=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=8F=AF=E5=AE=9A=E4=B9=89=E5=B1=95=E7=A4=BAkey=E5=92=8C?= =?UTF-8?q?=E5=A1=AB=E5=85=85key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/model/system/request/sys_auto_code.go | 1 + .../package/server/service/service.go.tpl | 2 ++ server/resource/package/web/view/form.vue.tpl | 13 +++++-- .../resource/package/web/view/table.vue.tpl | 20 ++++++++--- web/src/view/systemTools/autoCode/index.vue | 35 +++++++++++++------ 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/server/model/system/request/sys_auto_code.go b/server/model/system/request/sys_auto_code.go index 9fb943759f..bea6b751c4 100644 --- a/server/model/system/request/sys_auto_code.go +++ b/server/model/system/request/sys_auto_code.go @@ -28,6 +28,7 @@ type AutoCode struct { AutoCreateBtnAuth bool `json:"autoCreateBtnAuth" example:"false"` // 是否自动创建按钮权限 OnlyTemplate bool `json:"onlyTemplate" example:"false"` // 是否只生成模板 IsTree bool `json:"isTree" example:"false"` // 是否树形结构 + TreeJson string `json:"treeJson" example:"展示的树json字段"` // 展示的树json字段 IsAdd bool `json:"isAdd" example:"false"` // 是否新增 Fields []*AutoCodeField `json:"fields"` Module string `json:"-"` diff --git a/server/resource/package/server/service/service.go.tpl b/server/resource/package/server/service/service.go.tpl index 58e0bd00b1..6a84d0bebd 100644 --- a/server/resource/package/server/service/service.go.tpl +++ b/server/resource/package/server/service/service.go.tpl @@ -60,7 +60,9 @@ import ( {{- if not .OnlyTemplate }} "{{.Module}}/global" "{{.Module}}/model/{{.Package}}" + {{- if not .IsTree}} {{.Package}}Req "{{.Module}}/model/{{.Package}}/request" + {{- end }} {{- if .AutoCreateResource }} "gorm.io/gorm" {{- end}} diff --git a/server/resource/package/web/view/form.vue.tpl b/server/resource/package/web/view/form.vue.tpl index 7a70a42923..a49f27edac 100644 --- a/server/resource/package/web/view/form.vue.tpl +++ b/server/resource/package/web/view/form.vue.tpl @@ -172,9 +172,10 @@ getDataSourceFunc() :data="tableData" check-strictly :render-after-expand="false" - show-checkbox + :props="defaultProps" + clearable style="width: 240px" - placeholder="为空默认为根节点" + placeholder="根节点" /> {{- end }} @@ -293,6 +294,12 @@ const router = useRouter() {{- if .IsTree }} const tableData = ref([]) +const defaultProps = { + children: "children", + label: "{{ .TreeJson }}", + value: "{{ .PrimaryField.FieldJson }}" +} + const getTableData = async() => { const table = await get{{.StructName}}List() if (table.code === 0) { @@ -313,7 +320,7 @@ const {{ $element }}Options = ref([]) {{- end }} const formData = ref({ {{- if .IsTree }} - parentID:0, + parentID: undefined, {{- end }} {{- range .Fields}} {{- if .Form }} diff --git a/server/resource/package/web/view/table.vue.tpl b/server/resource/package/web/view/table.vue.tpl index 0758fd80b1..2cf95a6db0 100644 --- a/server/resource/package/web/view/table.vue.tpl +++ b/server/resource/package/web/view/table.vue.tpl @@ -671,8 +671,10 @@ getDataSourceFunc() :data="tableData" check-strictly :render-after-expand="false" - show-checkbox + :props="defaultProps" + clearable style="width: 240px" + placeholder="根节点" /> {{- end }} @@ -759,9 +761,10 @@ getDataSourceFunc() check-strictly disabled :render-after-expand="false" - show-checkbox + :props="defaultProps" + clearable style="width: 240px" - placeholder="为空默认为根节点" + placeholder="根节点" /> {{- end }} @@ -884,7 +887,7 @@ const {{ $element }}Options = ref([]) {{- end }} const formData = ref({ {{- if .IsTree }} - parentID:0, + parentID:undefined, {{- end }} {{- range .Fields}} {{- if .Form}} @@ -1076,6 +1079,13 @@ const getTableData = async() => { } } {{- else }} +// 树选择器配置 +const defaultProps = { + children: "children", + label: "{{ .TreeJson }}", + value: "{{ .PrimaryField.FieldJson }}" +} + // 查询 const getTableData = async() => { const table = await get{{.StructName}}List() @@ -1187,7 +1197,7 @@ const dialogFormVisible = ref(false) const openDialog = ({{- if .IsTree -}}row{{- end -}}) => { type.value = 'create' {{- if .IsTree }} - formData.value.parentID = row ? row.{{.PrimaryField.FieldJson}} : 0 + formData.value.parentID = row ? row.{{.PrimaryField.FieldJson}} : undefined {{- end }} dialogFormVisible.value = true } diff --git a/web/src/view/systemTools/autoCode/index.vue b/web/src/view/systemTools/autoCode/index.vue index 6c0df6e514..0ef657561b 100644 --- a/web/src/view/systemTools/autoCode/index.vue +++ b/web/src/view/systemTools/autoCode/index.vue @@ -404,34 +404,38 @@ - + - + - +
+ + +
+ @@ -1041,6 +1045,7 @@ autoCreateResource: false, onlyTemplate: false, isTree: false, + treeJson: "", fields: [] }) const rules = ref({ @@ -1154,6 +1159,13 @@ } const autoCodeForm = ref(null) const enterForm = async (isPreview) => { + if (form.value.isTree && !form.value.treeJson){ + ElMessage({ + type: 'error', + message: '请填写树型结构的前端展示json属性' + }) + return false + } if (!form.value.onlyTemplate) { if (form.value.fields.length <= 0) { ElMessage({ @@ -1463,6 +1475,7 @@ autoCreateResource: false, onlyTemplate: false, isTree: false, + treeJson: "", fields: [] } await nextTick()