+ {{- if .IsTree }}
+
+
+
+ {{- end }}
{{- range .Fields}}
{{- if .Form }}
-
+
{{- if .CheckDataSource}}
-
+
{{- else }}
{{- if eq .FieldType "bool" }}
-
+
{{- end }}
{{- if eq .FieldType "string" }}
{{- if .DictType}}
-
+
{{- else }}
-
+
{{- end }}
{{- end }}
{{- if eq .FieldType "richtext" }}
{{- end }}
{{- if eq .FieldType "int" }}
-
+
{{- end }}
{{- if eq .FieldType "time.Time" }}
-
+
{{- end }}
{{- if eq .FieldType "float64" }}
{{- end }}
{{- if eq .FieldType "enum" }}
-
+
{{- end }}
@@ -229,8 +240,8 @@ getDataSourceFunc()
{{- end }}
{{- end }}
- {{ "{{ t('general.save') }}" }}
- {{ "{{ t('general.back') }}" }}
+ 保存
+ 返回
@@ -242,6 +253,9 @@ import {
{{- if .HasDataSource }}
get{{.StructName}}DataSource,
{{- end }}
+ {{- if .IsTree }}
+ get{{.StructName}}List,
+ {{- end }}
create{{.StructName}},
update{{.StructName}},
find{{.StructName}}
@@ -256,8 +270,6 @@ import { getDictFunc } from '@/utils/format'
import { useRoute, useRouter } from "vue-router"
import { ElMessage } from 'element-plus'
import { ref, reactive } from 'vue'
-import { useI18n } from 'vue-i18n'
-const { t } = useI18n()
{{- if .HasPic }}
// 图片选择组件
import SelectImage from '@/components/selectImage/selectImage.vue'
@@ -278,15 +290,49 @@ import RichEdit from '@/components/richtext/rich-edit.vue'
import ArrayCtrl from '@/components/arrayCtrl/arrayCtrl.vue'
{{- end }}
+import { useI18n } from 'vue-i18n'
+const { t } = useI18n()
const route = useRoute()
const router = useRouter()
+{{- if .IsTree }}
+const tableData = ref([])
+
+const defaultProps = {
+ children: "children",
+ label: "{{ .TreeJson }}",
+ value: "{{ .PrimaryField.FieldJson }}"
+}
+
+const rootNode = {
+ {{ .PrimaryField.FieldJson }}: 0,
+ {{ .TreeJson }}: '根节点',
+ children: []
+}
+
+const getTableData = async() => {
+ const table = await get{{.StructName}}List()
+ if (table.code === 0) {
+ tableData.value = table.data || []
+ }
+}
+
+getTableData()
+
+{{- end }}
+
+// 提交按钮loading
+const btnLoading = ref(false)
+
const type = ref('')
{{- range $index, $element := .DictTypes}}
const {{ $element }}Options = ref([])
{{- end }}
const formData = ref({
+ {{- if .IsTree }}
+ parentID: undefined,
+ {{- end }}
{{- range .Fields}}
{{- if .Form }}
{{- if eq .FieldType "bool" }}
@@ -299,7 +345,7 @@ const formData = ref({
{{.FieldJson}}: '',
{{- end }}
{{- if eq .FieldType "int" }}
- {{.FieldJson}}: {{- if or .DictType .DataSource }} undefined{{ else }} 0{{- end }},
+ {{.FieldJson}}: {{- if or .DataSource }} undefined{{ else }} 0{{- end }},
{{- end }}
{{- if eq .FieldType "time.Time" }}
{{.FieldJson}}: new Date(),
@@ -328,27 +374,16 @@ const formData = ref({
{{- end }}
{{- end }}
})
-
// 验证规则
const rule = reactive({
{{- range .Fields }}
- {{- if .Form }}
{{- if eq .Require true }}
{{.FieldJson }} : [{
required: true,
message: '{{ .ErrorText }}',
trigger: ['input','blur'],
- },
- {{- if eq .FieldType "string" }}
- {
- whitespace: true,
- message: t('general.noOnlySpace'),
- trigger: ['input', 'blur'],
- }
- {{- end }}
- ],
+ }],
{{- end }}
- {{- end }}
{{- end }}
})
@@ -385,8 +420,9 @@ const init = async () => {
init()
// 保存按钮
const save = async() => {
+ btnLoading.value = true
elFormRef.value?.validate( async (valid) => {
- if (!valid) return
+ if (!valid) return btnLoading.value = false
let res
switch (type.value) {
case 'create':
@@ -399,10 +435,11 @@ const save = async() => {
res = await create{{.StructName}}(formData.value)
break
}
+ btnLoading.value = false
if (res.code === 0) {
ElMessage({
type: 'success',
- message: t('general.createUpdateSuccess')
+ message: '创建/更改成功'
})
}
})
@@ -426,5 +463,4 @@ const back = () => {
{{- end }}
-{{- end }}
-
+{{- end }}
\ No newline at end of file
diff --git a/server/resource/plugin/web/view/view.vue.template b/server/resource/plugin/web/view/view.vue.template
index 94bcd871f..03921822f 100644
--- a/server/resource/plugin/web/view/view.vue.template
+++ b/server/resource/plugin/web/view/view.vue.template
@@ -1,88 +1,91 @@
{{- $global := . }}
{{- $top := . -}}
{{- $templateID := printf "%s_%s" .Package .StructName }}
-
{{- if .IsAdd }}
// 请在搜索条件中增加如下代码
-{{- range .Fields}} {{- if .FieldSearchType}} {{- if not .FieldSearchHide }} {{- if eq .FieldType "bool" }}
-
-
-
-
-
-
-
-
-{{- else if .DictType}}
-
- {searchInfo.{{.FieldJson}}=undefined}">
-
-
-
- {{- else}}
-
-{{- if eq .FieldType "float64" "int"}}
- {{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
-
- —
-
- {{- else}}
- {{- if .DictType}}
-
-
-
+{{- range .Fields}} {{- if .FieldSearchType}} {{- if eq .FieldType "bool" }}
+
+
+
+
+
+
+
+
+ {{- else if .DictType}}
+
+ {searchInfo.{{.FieldJson}}=undefined}">
+
+
+
+ {{- else if .CheckDataSource}}
+
+
+
+
+
{{- else}}
-
- {{- end }}
- {{- end}}
-{{- else if eq .FieldType "time.Time"}}
- {{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
-
-
- {{"{{"}} t('{{$top.Package}}.{{$top.StructName}}.{{.FieldName}}') {{"}}"}}
-
-
-
-
-
-
- —
-
- {{- else}}
-
- {{- end}}
-{{- else}}
-
-{{- end}}
-{{ end }}{{ end }}{{ end }}{{ end }}
+
+ {{- if eq .FieldType "float64" "int"}}
+ {{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
+
+—
+
+ {{- else}}
+
+ {{- end}}
+ {{- else if eq .FieldType "time.Time"}}
+ {{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
+
+
+{{.FieldDesc}}
+
+
+
+
+
+
+—
+
+ {{- else}}
+
+ {{- end}}
+ {{- else}}
+
+ {{- end}}
+{{ end }}{{ end }}{{ end }}
// 表格增加如下列代码
{{- range .Fields}}
-{{- if .Table}}
-{{- if .CheckDataSource }}
-
-
- {{if eq .DataSource.Association 2}}
-
- {{ "{{ item }}" }}
-
- {{ else }}
- {{"{{"}} filterDataSource(dataSource.{{.FieldJson}},scope.row.{{.FieldJson}}) {{"}}"}}
- {{ end }}
-
-
-{{- else if .DictType}}
-
+ {{- if .Table}}
+ {{- if .CheckDataSource }}
+
+ {{- if eq .DataSource.Association 2}}
+
+ {{ "{{ item }}" }}
+
+ {{- else }}
+ {{"{{"}} filterDataSource(dataSource.{{.FieldJson}},scope.row.{{.FieldJson}}) {{"}}"}}
+ {{- end }}
+
+
+ {{- else if .DictType}}
+
+
+ {{if eq .FieldType "array"}}
+ {{"{{"}} filterDict(item,{{.DictType}}Options) {{"}}"}}
+ {{- else }}
{{"{{"}} filterDict(scope.row.{{.FieldJson}},{{.DictType}}Options) {{"}}"}}
+ {{end}}
{{- else if eq .FieldType "bool" }}
@@ -178,17 +181,23 @@
{{- if eq .FieldType "json" }}
// 此字段为json结构,可以前端自行控制展示和数据绑定模式 需绑定json的key为 formData.{{.FieldJson}} 后端会按照json的类型进行存取
{{"{{"}} formData.{{.FieldJson}} {{"}}"}}
-{{- end }}
- {{- if eq .FieldType "array" }}
+ {{- end }}
+ {{- if eq .FieldType "array" }}
+ {{- if .DictType}}
+
+
+
+ {{- else }}
- {{- end }}
-{{- if eq .FieldType "int" }}
-
-{{- end }}
-{{- if eq .FieldType "time.Time" }}
-
-{{- end }}
-{{- if eq .FieldType "float64" }}
+ {{- end }}
+ {{- end }}
+ {{- if eq .FieldType "int" }}
+
+ {{- end }}
+ {{- if eq .FieldType "time.Time" }}
+
+ {{- end }}
+ {{- if eq .FieldType "float64" }}
{{- end }}
{{- if eq .FieldType "enum" }}
@@ -226,32 +235,45 @@
// 查看抽屉中增加如下代码
{{- range .Fields}}
-{{- if .Desc }}
-
- {{- if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }}
- {{"{{"}} detailFrom.{{.FieldJson}} {{"}}"}}
- {{- else }}
- {{- if eq .FieldType "picture" }}
-
- {{- end }}
- {{- if eq .FieldType "array" }}
-
- {{- end }}
- {{- if eq .FieldType "pictures" }}
-
- {{- end }}
- {{- if eq .FieldType "file" }}
-
-
-
- {{"{{"}}item.name{{"}}"}}
-
-
- {{- end }}
- {{- end }}
-
-{{- end }}
-{{- end }}
+ {{- if .Desc }}
+
+{{- if .CheckDataSource }}
+
+ {{- if eq .DataSource.Association 2}}
+
+ {{ "{{ item }}" }}
+
+ {{- else }}
+ {{"{{"}} filterDataSource(dataSource.{{.FieldJson}},detailFrom.{{.FieldJson}}) {{"}}"}}
+ {{- end }}
+
+ {{- else if and (ne .FieldType "picture" ) (ne .FieldType "pictures" ) (ne .FieldType "file" ) (ne .FieldType "array" ) }}
+ {{"{{"}} detailFrom.{{.FieldJson}} {{"}}"}}
+ {{- else }}
+ {{- if eq .FieldType "picture" }}
+
+ {{- end }}
+ {{- if eq .FieldType "array" }}
+
+ {{- end }}
+ {{- if eq .FieldType "pictures" }}
+
+ {{- end }}
+ {{- if eq .FieldType "richtext" }}
+
+ {{- end }}
+ {{- if eq .FieldType "file" }}
+
+
+
+ {{"{{"}}item.name{{"}}"}}
+
+
+ {{- end }}
+ {{- end }}
+
+ {{- end }}
+ {{- end }}
// 字典增加如下代码
{{- range $index, $element := .DictTypes}}
@@ -277,7 +299,7 @@ const {{ $element }}Options = ref([])
{{.FieldJson}}: '',
{{- end }}
{{- if eq .FieldType "int" }}
-{{.FieldJson}}: {{- if or .DictType .DataSource}} undefined{{ else }} 0{{- end }},
+{{.FieldJson}}: {{- if .DataSource}} undefined{{ else }} 0{{- end }},
{{- end }}
{{- if eq .FieldType "time.Time" }}
{{.FieldJson}}: new Date(),
@@ -334,11 +356,11 @@ const {{ $element }}Options = ref([])
get{{.StructName}}DataSource,
// 获取数据源
-const dataSource = ref([])
+const dataSource = ref({})
const getDataSourceFunc = async()=>{
const res = await get{{.StructName}}DataSource()
if (res.code === 0) {
- dataSource.value = res.data
+ dataSource.value = res.data || []
}
}
getDataSourceFunc()
@@ -349,6 +371,7 @@ getDataSourceFunc()
{{- if not .OnlyTemplate}}
+ {{- if not .IsTree }}
{{- if .GvaModel }}
@@ -382,11 +405,17 @@ getDataSourceFunc()
{{- else if .DictType}}
-
- {searchInfo.{{.FieldJson}}=undefined}">
+
+ {searchInfo.{{.FieldJson}}=undefined}">
+ {{- else if .CheckDataSource}}
+
+
+
+
+
{{- else}}
{{- if eq .FieldType "float64" "int"}}
@@ -395,13 +424,7 @@ getDataSourceFunc()
—
{{- else}}
- {{- if .DictType}}
-
-
-
- {{- else}}
-
- {{- end }}
+
{{- end}}
{{- else if eq .FieldType "time.Time"}}
{{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
@@ -422,7 +445,6 @@ getDataSourceFunc()
{{- else}}
{{- end}}
-
{{ end }}{{ end }}{{ end }}{{ end }}
@@ -443,8 +465,8 @@ getDataSourceFunc()
{{- else if .DictType}}
-
- {searchInfo.{{.FieldJson}}=undefined}">
+
+ {searchInfo.{{.FieldJson}}=undefined}">
@@ -456,13 +478,7 @@ getDataSourceFunc()
—
{{- else}}
- {{- if .DictType}}
-
-
-
- {{- else}}
-
- {{- end }}
+
{{- end}}
{{- else if eq .FieldType "time.Time"}}
{{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
@@ -496,10 +512,11 @@ getDataSourceFunc()
+ {{- end }}
-
{{"{{"}}t('general.add'){{"}}"}}
-
{{"{{"}}t('general.delete'){{"}}"}}
+
新增
+
删除
{{ if .HasExcel -}}
@@ -519,7 +536,7 @@ getDataSourceFunc()
>
{{ if .GvaModel }}
-
+
{{ "{{ formatDate(scope.row.CreatedAt) }}" }}
{{ end }}
@@ -528,19 +545,23 @@ getDataSourceFunc()
{{- if .CheckDataSource }}
- {{if eq .DataSource.Association 2}}
+ {{- if eq .DataSource.Association 2}}
{{ "{{ item }}" }}
- {{ else }}
+ {{- else }}
{{"{{"}} filterDataSource(dataSource.{{.FieldJson}},scope.row.{{.FieldJson}}) {{"}}"}}
- {{ end }}
+ {{- end }}
{{- else if .DictType}}
- {{"{{"}} filterDict(scope.row.{{.FieldJson}},{{.DictType}}Options) {{"}}"}}
+ {{if eq .FieldType "array"}}
+ {{"{{"}} filterDict(item,{{.DictType}}Options) {{"}}"}}
+ {{- else }}
+ {{"{{"}} filterDict(scope.row.{{.FieldJson}},{{.DictType}}Options) {{"}}"}}
+ {{end}}
{{- else if eq .FieldType "bool" }}
@@ -598,22 +619,25 @@ getDataSourceFunc()
{{- else if eq .FieldType "array" }}
-
+
{{- else }}
-
+
{{- end }}
{{- end }}
{{- end }}
-
-
- {{"{{"}}t('general.desc'){{"}}"}}
- {{"{{"}}t('general.change'){{"}}"}}
- {{"{{"}}t('general.delete'){{"}}"}}
-
+
+
+ {{- if .IsTree }}
+ 新增子节点
+ {{- end }}
+ 查看
+ 编辑
+ 删除
+