| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- {{$tableComment:=.TableComment}}
- <script setup lang="ts" name="{{.BBusinessName}}">
- import apis from "@a"
- import message from "@@/utils/message"
- import dayjs from "dayjs"
- {{ range .Columns -}}
- {{- if ne .FkTableName "" }}
- const {{.JsonField}}Options = ref<any[]>([])
- {{- else if (ne .DictType "") }}
- {{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox") }}
- const {{.JsonField}}Options = computed(() => {
- return [
- { label: "请选择", value: "" },
- { label: "", value: "" }
- ]
- })
- {{- end -}}
- {{- end }}
- const tableRef = ref()
- const modalRef = ref()
- const opts = reactive<any>({
- columns: [
- {{- range .Columns -}}
- {{$sort := eq .IsSort "1"}}
- {{- if (eq .IsPk "1") }}
- { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: 100, visible: false, isSort: {{ $sort }}, tooltip: true},
- {{- else if (eq .IsList "1") }}
- {{- if ne .DictType ""}}
- { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: 100, isSort: {{ $sort }}, visible: true},
- {{- else if eq .HtmlType "datetime"}}
- { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: 185, isSort: {{ $sort }}, visible: true},
- {{- else }}
- { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: "auto", isSort: {{ $sort }}, visible: true},
- {{- end -}}
- {{- else if (eq .JsonField "createdAt") }}
- { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: 185, isSort: true, visible: true},
- {{- end -}}
- {{- end }}
- { field: "actions", name: `操作`, width: 150 }
- ],
- queryParams: {
- {{- range .Columns -}}
- {{- if (eq .GoField "CreatedAt") }}
- dateRange:[]
- {{- else if (eq .IsQuery "1") }}
- {{- if eq .HtmlType "datetime"}}
- dateRange{{.BJsonField}}: [],
- {{- else }}
- {{.JsonField}}: undefined,
- {{- end -}}
- {{- end -}}
- {{- end }}
- },
- searchFormItems: [
- {{- range .Columns -}}
- {{- if eq .GoField "CreatedAt"}}
- {
- field: "dateRange",
- label: "{{.ColumnComment}}",
- class: "w-100",
- component: "D",
- placeholder: "请选择{{.ColumnComment }}",
- props: {
- type: "daterange",
- valueFormat: "YYYY-MM-DD",
- rangeSeparator: "-",
- startPlaceholder: "开始日期",
- endPlaceholder: "结束日期"
- },
- listeners: {
- change: (v: any) => {
- queryParams.value.dateRange = v
- }
- },
- },
- {{- else if (eq .IsQuery "1") -}}
- {{ $required := eq .IsRequired "1" }}
- {{- if ne .FkTableName ""}}
- {
- field: "{{.JsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- component: "VS",
- data: () => {{.JsonField}}Options.value,
- props: {
- {{- if eq .HtmlType "radio"}}
- type: "radio",
- {{- else if eq .HtmlType "checkbox"}}
- type: "checkbox",
- {{- else }}
- type: "select",
- {{- end }}
- clearable: true,
- placeholder: "请选择{{.ColumnComment }}",
- props:{
- label:'{{.FkLabelName}}',
- value:'{{.FkLabelId}}',
- }
- }
- },
- {{- else if ne .DictType ""}}
- {
- field: "{{.JsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- component: "Dict",
- props: {
- {{- if eq .HtmlType "radio"}}
- type: "radio",
- {{- else if eq .HtmlType "checkbox"}}
- type: "checkbox",
- {{- else }}
- type: "select",
- clearable: true,
- {{- end }}
- placeholder: "请选择{{.ColumnComment }}",
- dictType: "{{.DictType}}",
- {{- if or (eq .GoType "int") (eq .GoType "int64") }}
- valueIsNumber: true,
- {{- end }}
- }
- },
- {{- else if eq .HtmlType "datetime"}}
- {
- field: "dateRange{{.BJsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- component: "D",
- placeholder: "请选择{{.ColumnComment }}",
- props: {
- type: "daterange",
- valueFormat: "YYYY-MM-DD",
- rangeSeparator: "-",
- startPlaceholder: "开始日期",
- endPlaceholder: "结束日期"
- },
- listeners: {
- change: (v: any) => {
- queryParams.value.dateRange{{.BJsonField}} = v
- }
- },
- },
- {{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox") }}
- {
- field: "{{.JsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- component: "VS",
- placeholder: "请选择{{.ColumnComment }}",
- data: () => {{.JsonField}}Options.value,
- props: {
- type: "{{.HtmlType}}",
- clearable: true,
- {{- if or (eq .GoType "int") (eq .GoType "int64") }}
- valueIsNumber: true,
- {{- end }}
- },
- },
- {{- else }}
- {
- field: "{{.JsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- component: "I",
- listeners:{
- keyup: (e: any) => {
- if (e.code == "Enter") {
- handleQuery()
- }
- }
- }
- },
- {{- end -}}
- {{- end -}}
- {{- end }}
- ] as any,
- permission: "{{.PackageName}}:{{.BusinessName}}",
- handleFuns: {},
- customBtns: [],
- tableListFun: apis.{{.PackageName}}.{{.BusinessName}}Api.list{{.BBusinessName}},
- getEntityFun: apis.{{.PackageName}}.{{.BusinessName}}Api.get{{.BBusinessName}},
- deleteEntityFun: apis.{{.PackageName}}.{{.BusinessName}}Api.del{{.BBusinessName}},
- formItems:[
- {{- range .Columns -}}
- {{- if (eq .IsInsert "1") -}}
- {{ $required := eq .IsRequired "1" }}
- {{- if (.Pk) }}
- {{- else if or (eq .GoField "CreatedAt") (eq .GoField "UpdatedAt") (eq .GoField "DeletedAt") (eq .GoField "UpdateBy") (eq .GoField "CreateBy") -}}
- {{- else if ne .FkTableName ""}}
- {
- field: "{{.JsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- required: {{$required}},
- component: "VS",
- data: () => {{.JsonField}}Options.value,
- props: {
- {{- if eq .HtmlType "radio"}}
- type: "radio",
- {{- else if eq .HtmlType "checkbox"}}
- type: "checkbox",
- {{- else }}
- type: "select",
- {{- end }}
- {{- if or (eq .GoType "int") (eq .GoType "int64") }}
- valueIsNumber: true,
- {{- end }}
- clearable: true,
- placeholder: "请选择{{.ColumnComment }}",
- props:{
- label:'{{.FkLabelName}}',
- value:'{{.FkLabelId}}',
- }
- }
- },
- {{- else if ne .DictType ""}}
- {
- field: "{{.JsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- required: {{$required}},
- component: "Dict",
- props: {
- {{- if eq .HtmlType "radio"}}
- type: "radio",
- {{- else if eq .HtmlType "checkbox"}}
- type: "checkbox",
- {{- else }}
- type: "select",
- {{- end }}
- {{- if or (eq .GoType "int") (eq .GoType "int64") }}
- valueIsNumber: true,
- {{- end }}
- clearable: true,
- placeholder: "请选择{{.ColumnComment }}",
- dictType: "{{.DictType}}"
- }
- },
- {{- else if eq .HtmlType "datetime"}}
- {
- field: "{{.JsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- required: {{$required}},
- component: "D",
- placeholder: "请选择{{.ColumnComment }}",
- props: {
- type: "date",
- valueFormat: "YYYY-MM-DD",
- },
- },
- {{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox") }}
- {
- field: "{{.JsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- required: {{$required}},
- component: "VS",
- placeholder: "请选择{{.ColumnComment }}",
- data: () => {{.JsonField}}Options.value,
- props: {
- type: "{{.HtmlType}}",
- clearable: true,
- {{- if or (eq .GoType "int") (eq .GoType "int64") }}
- valueIsNumber: true,
- {{- end }}
- },
- },
- {{- else }}
- {
- field: "{{.JsonField}}",
- label: "{{.ColumnComment}}",
- class: "w-100",
- {{- if eq .HtmlType "file"}}
- component: "VU",
- {{- else if eq .HtmlType "textarea"}}
- component: "VE",
- {{- else }}
- component: "I",
- {{- end }}
- {{- if or (eq .GoType "int") (eq .GoType "int64") }}
- type: "number",
- {{- end }}
- required: {{ $required }}
- },
- {{- end -}}
- {{- end -}}
- {{- end }}
- ] as any,
- modalTitle: "{{.FunctionName}}",
- resetForm: () => {
- form.value = emptyFormData.value
- },
- emptyFormData: {
- {{- range .Columns -}}
- {{- if (eq .IsPk "1") }}
- {{.JsonField}}: undefined,
- {{- else if or (eq .GoField "CreatedAt") (eq .GoField "UpdatedAt") (eq .GoField "DeletedAt") (eq .GoField "UpdateBy") (eq .GoField "CreateBy") -}}
- {{- else if (eq .IsInsert "1") }}
- {{.JsonField}}: undefined,
- {{- end -}}
- {{- end }}
- }
- })
- const { queryParams, emptyFormData } = toRefs(opts)
- const form = ref<any>(emptyFormData.value)
- /** 修改按钮操作 */
- function handleUpdate(row: any) {
- tableRef.value.defaultHandleFuns.handleUpdate("", row)
- }
- /** 删除按钮操作 */
- function handleDelete(rows: any[]) {
- tableRef.value.defaultHandleFuns.handleDelete("", rows)
- }
- /** 提交按钮 */
- function submitForm() {
- if (form.value.{{.PkJsonField}} != undefined) {
- apis.{{.PackageName}}.{{.BusinessName}}Api.update{{.BBusinessName}}(form.value).then(() => {
- message.msgSuccess("修改成功")
- handleQuery()
- })
- } else {
- apis.{{.PackageName}}.{{.BusinessName}}Api.add{{.BBusinessName}}(form.value).then(() => {
- message.msgSuccess("新增成功")
- handleQuery()
- })
- }
- }
- /** 查询按钮 */
- function handleQuery(query?: any) {
- query = query || tableRef.value?.getQueryParams() || queryParams.value
- {{- range .Columns -}}
- {{- if ( eq .GoField "CreatedAt")}}
- addDateRange(query, query.dateRange)
- {{- else if and (eq .IsQuery "1") (eq .HtmlType "datetime")}}
- addDateRange(query, query.dateRange{{.BJsonField}})
- {{- end -}}
- {{- end }}
- tableRef.value?.query(query)
- }
- /** 查询重置按钮 */
- function resetQuery(query?: any) {
- {{- range .Columns -}}
- {{- if ( eq .GoField "CreatedAt")}}
- query.dateRange = []
- addDateRange(query, query.dateRange)
- {{- else if and (eq .IsQuery "1") (eq .HtmlType "datetime")}}
- query.dateRange{{.BJsonField}} = []
- addDateRange(query, query.dateRange{{.BJsonField}})
- {{- end -}}
- {{- end }}
- }
- function init(){
- {{ range .Columns -}}
- {{- if ne .FkTableName "" -}}
- apis.{{.FkTableNamePackage}}.{{.FkTableNameBusiness}}Api.list{{.BFkTableNameBusiness}}({pageSize:10000,pageIndex:1}).then((res)=>{
- {{.JsonField}}Options.value = res.data.rows
- })
- {{- end -}}
- {{- end }}
- }
- onMounted(init)
- </script>
- <template>
- <div class="app-container">
- <VbDataTable
- ref="tableRef"
- :handle-perm="opts.permission"
- :handle-funs="opts.handleFuns"
- :search-form-items="opts.searchFormItems"
- :columns="opts.columns"
- :custom-btns="opts.customBtns"
- :remote-fun="opts.tableListFun"
- :get-entity-fun="opts.getEntityFun"
- :delete-entity-fun="opts.deleteEntityFun"
- {{- range .Columns -}}
- {{- if (eq .JsonField "createdAt") }}
- sortField="createdAt"
- sort-order="desc"
- {{- end -}}
- {{- end }}
- :modal="modalRef"
- :reset-form-fun="opts.resetForm"
- v-model:form-data="form"
- :query-params="queryParams"
- :check-multiple="true"
- :has-checkbox="true"
- :reset-search-form-fun="resetQuery"
- :custom-search-fun="handleQuery">
- {{ range .Columns -}}
- {{- if (eq .IsList "1") -}}
- {{- if (ne .FkTableName "") -}}
- <template #{{.JsonField}}="{ row }">
- <vb-tag :value="row.{{.JsonField}}" :data="{{.JsonField}}Options"></vb-tag>
- </template>
- {{- else if (ne .DictType "") -}}
- <template #{{.JsonField}}="{ row }">
- {{- if or (eq .GoType "int") (eq .GoType "int64")}}
- <DictTag valueIsNumber :value="row.{{.JsonField}}" type="{{.DictType}}"></DictTag>
- {{- else }}
- <DictTag :value="row.{{.JsonField}}" type="{{.DictType}}"></DictTag>
- {{- end}}
- </template>
- {{- else if (eq .HtmlType "datetime") -}}
- <template #{{.JsonField}}="{ row }">
- <span>{{"{{"}} {{"dayjs"}}(row.{{.JsonField}}).format("YYYY-MM-DD HH:mm:ss") {{"}}"}}</span>
- </template>
- {{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox") -}}
- <template #{{.JsonField}}="{ row }">
- {{- if or (eq .GoType "int") (eq .GoType "int64")}}
- <vb-tag valueIsNumber :value="row.{{.JsonField}}" :data="{{.JsonField}}Options"></vb-tag>
- {{- else }}
- <vb-tag :value="row.{{.JsonField}}" :data="[]"></vb-tag>
- {{- end}}
- </template>
- {{- end}}
- {{- else if (eq .JsonField "createdAt") }}
- <template #{{.JsonField}}="{ row }">
- <span>{{"{{"}} {{"dayjs"}}(row.{{.JsonField}}).format("YYYY-MM-DD HH:mm:ss") {{"}}"}}</span>
- </template>
- {{- end -}}
- {{- end }}
- <template #actions="{ row }">
- <vb-tooltip content="修改" placement="top">
- <el-button
- link
- type="primary"
- @click="handleUpdate(row)"
- v-hasPermission="'{{.PackageName}}:{{.BusinessName}}:edit'">
- <template #icon>
- <VbIcon icon-name="notepad-edit" icon-type="duotone" class="fs-3"></VbIcon>
- </template>
- </el-button>
- </vb-tooltip>
- <vb-tooltip content="删除" placement="top">
- <el-button
- link
- type="primary"
- @click="handleDelete([row])"
- v-hasPermission="'{{.PackageName}}:{{.BusinessName}}:remove'">
- <template #icon>
- <VbIcon icon-name="trash-square" icon-type="duotone" class="fs-3"></VbIcon>
- </template>
- </el-button>
- </vb-tooltip>
- </template>
- </VbDataTable>
- <VbModal
- v-model:modal="modalRef"
- :title="opts.modalTitle"
- :form-items="opts.formItems as any"
- :form-data="form"
- @confirm="submitForm"
- append-to-body></VbModal>
- </div>
- </template>
|