@@ -79,7 +234,7 @@ import {
create{{.StructName}},
update{{.StructName}},
find{{.StructName}}
-} from '@/plugin/{{.Package}}/api/{{.PackageName}}'
+} from '@/api/{{.Package}}/{{.PackageName}}'
defineOptions({
name: '{{.StructName}}Form'
@@ -112,6 +267,7 @@ import RichEdit from '@/components/richtext/rich-edit.vue'
import ArrayCtrl from '@/components/arrayCtrl/arrayCtrl.vue'
{{- end }}
+
const route = useRoute()
const router = useRouter()
@@ -161,18 +317,27 @@ const formData = ref({
{{- end }}
{{- end }}
})
+
// 验证规则
const rule = reactive({
{{- range .Fields }}
- {{- if .Form }}
+ {{- 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 }}
{{- end }}
})
@@ -250,3 +415,4 @@ const back = () => {
{{- end }}
+{{- end }}
diff --git a/server/resource/plugin/web/view/view.vue.template b/server/resource/plugin/web/view/view.vue.template
index 4276647242..b51a10704f 100644
--- a/server/resource/plugin/web/view/view.vue.template
+++ b/server/resource/plugin/web/view/view.vue.template
@@ -1,6 +1,351 @@
{{- $global := . }}
-{{- $templateID := printf "%s_%s" .Package .StructName }}
{{- $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}}
+
+
+
+ {{- 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 }}
+
+
+// 表格增加如下列代码
+
+{{- range .Fields}}
+{{- if .Table}}
+{{- if .CheckDataSource }}
+
+
+ {{if eq .DataSource.Association 2}}
+
+ {{ "{{ item }}" }}
+
+ {{ else }}
+ {{"{{"}} filterDataSource(dataSource.{{.FieldJson}},scope.row.{{.FieldJson}}) {{"}}"}}
+ {{ end }}
+
+
+{{- else if .DictType}}
+
+
+ {{"{{"}} filterDict(scope.row.{{.FieldJson}},{{.DictType}}Options) {{"}}"}}
+
+
+{{- else if eq .FieldType "bool" }}
+
+ {{"{{"}} formatBoolean(scope.row.{{.FieldJson}}) {{"}}"}}
+
+ {{- else if eq .FieldType "time.Time" }}
+
+ {{"{{"}} formatDate(scope.row.{{.FieldJson}}) {{"}}"}}
+
+ {{- else if eq .FieldType "picture" }}
+
+
+
+
+
+ {{- else if eq .FieldType "pictures" }}
+
+
+
+
+
+
+
+ {{- else if eq .FieldType "video" }}
+
+
+
+
+
+ {{- else if eq .FieldType "richtext" }}
+
+
+ [RichText]
+
+
+ {{- else if eq .FieldType "file" }}
+
+
+
+ {{"{{"}}file.name{{"}}"}}
+
+
+
+ {{- else if eq .FieldType "json" }}
+
+
+ [JSON]
+
+
+ {{- else if eq .FieldType "array" }}
+
+
+
+
+
+ {{- else }}
+
+ {{- end }}
+{{- end }}
+{{- 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 "json" }}
+ // 此字段为json结构,可以前端自行控制展示和数据绑定模式 需绑定json的key为 formData.{{.FieldJson}} 后端会按照json的类型进行存取
+ {{"{{"}} formData.{{.FieldJson}} {{"}}"}}
+{{- end }}
+ {{- if eq .FieldType "array" }}
+
+ {{- end }}
+{{- if eq .FieldType "int" }}
+
+{{- end }}
+{{- if eq .FieldType "time.Time" }}
+
+{{- end }}
+{{- if eq .FieldType "float64" }}
+
+{{- end }}
+{{- if eq .FieldType "enum" }}
+
+
+
+{{- end }}
+{{- if eq .FieldType "picture" }}
+
+{{- end }}
+{{- if eq .FieldType "pictures" }}
+
+{{- end }}
+{{- if eq .FieldType "video" }}
+
+ {{- end }}
+{{- if eq .FieldType "file" }}
+
+{{- end }}
+{{- end }}
+
+{{- end }}
+{{- end }}
+
+// 查看抽屉中增加如下代码
+
+{{- 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 }}
+
+// 字典增加如下代码
+ {{- range $index, $element := .DictTypes}}
+const {{ $element }}Options = ref([])
+ {{- end }}
+
+// setOptions方法中增加如下调用
+
+{{- range $index, $element := .DictTypes }}
+ {{ $element }}Options.value = await getDictFunc('{{$element}}')
+{{- end }}
+
+// 基础formData结构(变量处和关闭表单处)增加如下字段
+{{- range .Fields}}
+ {{- if .Form}}
+ {{- if eq .FieldType "bool" }}
+{{.FieldJson}}: false,
+ {{- end }}
+ {{- if eq .FieldType "string" }}
+{{.FieldJson}}: '',
+ {{- end }}
+ {{- if eq .FieldType "richtext" }}
+{{.FieldJson}}: '',
+ {{- end }}
+ {{- if eq .FieldType "int" }}
+{{.FieldJson}}: {{- if or .DictType .DataSource}} undefined{{ else }} 0{{- end }},
+ {{- end }}
+ {{- if eq .FieldType "time.Time" }}
+{{.FieldJson}}: new Date(),
+ {{- end }}
+ {{- if eq .FieldType "float64" }}
+{{.FieldJson}}: 0,
+ {{- end }}
+ {{- if eq .FieldType "picture" }}
+{{.FieldJson}}: "",
+ {{- end }}
+ {{- if eq .FieldType "video" }}
+{{.FieldJson}}: "",
+ {{- end }}
+ {{- if eq .FieldType "pictures" }}
+{{.FieldJson}}: [],
+ {{- end }}
+ {{- if eq .FieldType "file" }}
+{{.FieldJson}}: [],
+ {{- end }}
+ {{- if eq .FieldType "json" }}
+{{.FieldJson}}: {},
+ {{- end }}
+ {{- if eq .FieldType "array" }}
+{{.FieldJson}}: [],
+ {{- end }}
+ {{- end }}
+ {{- end }}
+// 验证规则中增加如下字段
+
+{{- 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 }}
+
+
+
+{{- if .HasDataSource }}
+// 请引用
+get{{.StructName}}DataSource,
+
+// 获取数据源
+const dataSource = ref([])
+const getDataSourceFunc = async()=>{
+ const res = await get{{.StructName}}DataSource()
+ if (res.code === 0) {
+ dataSource.value = res.data
+ }
+}
+getDataSourceFunc()
+{{- end }}
+
+{{- else }}
+
{{- if not .OnlyTemplate}}
@@ -31,7 +376,7 @@
@@ -62,7 +407,7 @@
{{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
- {{"{{"}}t({{$top.Package}}.{{$top.StructName}}.{{.FieldDesc}}){{"}}"}}
+ {{"{{"}} t('{{$top.Package}}.{{$top.StructName}}.{{.FieldName}}') {{"}}"}}
@@ -123,7 +468,7 @@
{{if eq .FieldSearchType "BETWEEN" "NOT BETWEEN"}}
- {{"{{"}}t({{$top.Package}}.{{$top.StructName}}.{{.FieldDesc}}){{"}}"}}
+ {{"{{"}} t('{{$top.Package}}.{{$top.StructName}}.{{.FieldName}}') {{"}}"}}
@@ -133,7 +478,7 @@
—
{{- else}}
-
+
{{- end}}
{{- else}}
@@ -252,23 +597,23 @@
[JSON]
- {{- else if eq .FieldType "array" }}
-
-
+ {{- else if eq .FieldType "array" }}
+
+
-
-
- {{- else }}
+
+
+ {{- else }}
- {{- end }}
+ {{- end }}
{{- end }}
{{- end }}
-
+
{{"{{"}}t('general.desc'){{"}}"}}
{{"{{"}}t('general.change'){{"}}"}}
{{"{{"}}t('general.delete'){{"}}"}}
-
+
@@ -416,7 +759,7 @@ import {
update{{.StructName}},
find{{.StructName}},
get{{.StructName}}List
-} from '@/plugin/{{.Package}}/api/{{.PackageName}}'
+} from '@/api/{{.Package}}/{{.PackageName}}'
{{- if or .HasPic .HasFile}}
import { getUrl } from '@/utils/image'
@@ -431,7 +774,6 @@ import SelectImage from '@/components/selectImage/selectImage.vue'
import RichEdit from '@/components/richtext/rich-edit.vue'
{{- end }}
-
{{- if .HasFile }}
// 文件选择组件
import SelectFile from '@/components/selectFile/selectFile.vue'
@@ -446,6 +788,9 @@ import ArrayCtrl from '@/components/arrayCtrl/arrayCtrl.vue'
import { getDictFunc, formatDate, formatBoolean, filterDict ,filterDataSource, returnArrImg, onDownloadFile } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive } from 'vue'
+import { useI18n } from 'vue-i18n'
+const { t } = useI18n()
+
{{- if .AutoCreateBtnAuth }}
// 引入按钮权限标识
import { useBtnAuth } from '@/utils/btnAuth'
@@ -460,9 +805,6 @@ import ImportExcel from '@/components/exportExcel/importExcel.vue'
import ExportTemplate from '@/components/exportExcel/exportTemplate.vue'
{{- end}}
-import { useI18n } from 'vue-i18n'
-const { t } = useI18n()
-
defineOptions({
name: '{{.StructName}}'
})
@@ -538,7 +880,7 @@ const formData = ref({
// 验证规则
const rule = reactive({
{{- range .Fields }}
- {{- if .Form }}
+ {{- if .Form }}
{{- if eq .Require true }}
{{.FieldJson }} : [{
required: true,
@@ -554,7 +896,7 @@ const rule = reactive({
{{- end }}
],
{{- end }}
- {{- end }}
+ {{- end }}
{{- end }}
})
@@ -606,13 +948,13 @@ const searchInfo = ref({})
const sortChange = ({ prop, order }) => {
const sortMap = {
{{- range .Fields}}
- {{- if .Table}}
- {{- if and .Sort}}
- {{- if not (eq .ColumnName "")}}
- {{.FieldJson}}: '{{.ColumnName}}',
- {{- end}}
+ {{- if .Table}}
+ {{- if and .Sort}}
+ {{- if not (eq .ColumnName "")}}
+ {{.FieldJson}}: '{{.ColumnName}}',
{{- end}}
{{- end}}
+ {{- end}}
{{- end}}
}
@@ -852,7 +1194,6 @@ const downloadFile = (url) => {
}
{{end}}
-
const detailFrom = ref({})
// 查看详情控制标记
@@ -913,4 +1254,6 @@ defineOptions({
-{{- end}}
\ No newline at end of file
+{{- end}}
+
+{{- end }}