vue-view.go.template 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. {{$tableComment:=.TableComment}}
  2. <script setup lang="ts" name="{{.BBusinessName}}">
  3. import apis from "@a"
  4. import message from "@@/utils/message"
  5. import dayjs from "dayjs"
  6. {{ range .Columns -}}
  7. {{- if ne .FkTableName "" }}
  8. const {{.JsonField}}Options = ref<any[]>([])
  9. {{- else if (ne .DictType "") }}
  10. {{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox") }}
  11. const {{.JsonField}}Options = computed(() => {
  12. return [
  13. { label: "请选择", value: "" },
  14. { label: "", value: "" }
  15. ]
  16. })
  17. {{- end -}}
  18. {{- end }}
  19. const tableRef = ref()
  20. const modalRef = ref()
  21. const opts = reactive<any>({
  22. columns: [
  23. {{- range .Columns -}}
  24. {{$sort := eq .IsSort "1"}}
  25. {{- if (eq .IsPk "1") }}
  26. { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: 100, visible: false, isSort: {{ $sort }}, tooltip: true},
  27. {{- else if (eq .IsList "1") }}
  28. {{- if ne .DictType ""}}
  29. { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: 100, isSort: {{ $sort }}, visible: true},
  30. {{- else if eq .HtmlType "datetime"}}
  31. { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: 185, isSort: {{ $sort }}, visible: true},
  32. {{- else }}
  33. { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: "auto", isSort: {{ $sort }}, visible: true},
  34. {{- end -}}
  35. {{- else if (eq .JsonField "createdAt") }}
  36. { field: "{{.JsonField}}", name: "{{.ColumnComment}}", width: 185, isSort: true, visible: true},
  37. {{- end -}}
  38. {{- end }}
  39. { field: "actions", name: `操作`, width: 150 }
  40. ],
  41. queryParams: {
  42. {{- range .Columns -}}
  43. {{- if (eq .GoField "CreatedAt") }}
  44. dateRange:[]
  45. {{- else if (eq .IsQuery "1") }}
  46. {{- if eq .HtmlType "datetime"}}
  47. dateRange{{.BJsonField}}: [],
  48. {{- else }}
  49. {{.JsonField}}: undefined,
  50. {{- end -}}
  51. {{- end -}}
  52. {{- end }}
  53. },
  54. searchFormItems: [
  55. {{- range .Columns -}}
  56. {{- if eq .GoField "CreatedAt"}}
  57. {
  58. field: "dateRange",
  59. label: "{{.ColumnComment}}",
  60. class: "w-100",
  61. component: "D",
  62. placeholder: "请选择{{.ColumnComment }}",
  63. props: {
  64. type: "daterange",
  65. valueFormat: "YYYY-MM-DD",
  66. rangeSeparator: "-",
  67. startPlaceholder: "开始日期",
  68. endPlaceholder: "结束日期"
  69. },
  70. listeners: {
  71. change: (v: any) => {
  72. queryParams.value.dateRange = v
  73. }
  74. },
  75. },
  76. {{- else if (eq .IsQuery "1") -}}
  77. {{ $required := eq .IsRequired "1" }}
  78. {{- if ne .FkTableName ""}}
  79. {
  80. field: "{{.JsonField}}",
  81. label: "{{.ColumnComment}}",
  82. class: "w-100",
  83. component: "VS",
  84. data: () => {{.JsonField}}Options.value,
  85. props: {
  86. {{- if eq .HtmlType "radio"}}
  87. type: "radio",
  88. {{- else if eq .HtmlType "checkbox"}}
  89. type: "checkbox",
  90. {{- else }}
  91. type: "select",
  92. {{- end }}
  93. clearable: true,
  94. placeholder: "请选择{{.ColumnComment }}",
  95. props:{
  96. label:{{.FkLabelName}},
  97. value:{{.FkLabelId}},
  98. }
  99. }
  100. },
  101. {{- else if ne .DictType ""}}
  102. {
  103. field: "{{.JsonField}}",
  104. label: "{{.ColumnComment}}",
  105. class: "w-100",
  106. component: "Dict",
  107. props: {
  108. {{- if eq .HtmlType "radio"}}
  109. type: "radio",
  110. {{- else if eq .HtmlType "checkbox"}}
  111. type: "checkbox",
  112. {{- else }}
  113. type: "select",
  114. clearable: true,
  115. {{- end }}
  116. placeholder: "请选择{{.ColumnComment }}",
  117. dictType: "{{.DictType}}"
  118. {{- if or (eq .GoType "int") (eq .GoType "int64") }}
  119. valueIsNumber: true,
  120. {{- end }}
  121. }
  122. },
  123. {{- else if eq .HtmlType "datetime"}}
  124. {
  125. field: "dateRange{{.BJsonField}}",
  126. label: "{{.ColumnComment}}",
  127. class: "w-100",
  128. component: "D",
  129. placeholder: "请选择{{.ColumnComment }}",
  130. props: {
  131. type: "daterange",
  132. valueFormat: "YYYY-MM-DD",
  133. rangeSeparator: "-",
  134. startPlaceholder: "开始日期",
  135. endPlaceholder: "结束日期"
  136. },
  137. listeners: {
  138. change: (v: any) => {
  139. queryParams.value.dateRange{{.BJsonField}} = v
  140. }
  141. },
  142. },
  143. {{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox") }}
  144. {
  145. field: "{{.JsonField}}",
  146. label: "{{.ColumnComment}}",
  147. class: "w-100",
  148. component: "VS",
  149. placeholder: "请选择{{.ColumnComment }}",
  150. data: () => {{.JsonField}}Options.value,
  151. props: {
  152. type: "{{.HtmlType}}",
  153. clearable: true,
  154. {{- if or (eq .GoType "int") (eq .GoType "int64") }}
  155. valueIsNumber: true,
  156. {{- end }}
  157. },
  158. },
  159. {{- else }}
  160. {
  161. field: "{{.JsonField}}",
  162. label: "{{.ColumnComment}}",
  163. class: "w-100",
  164. component: "I",
  165. listeners:{
  166. keyup: (e: any) => {
  167. if (e.code == "Enter") {
  168. handleQuery()
  169. }
  170. }
  171. }
  172. },
  173. {{- end -}}
  174. {{- end -}}
  175. {{- end }}
  176. ] as any,
  177. permission: "{{.PackageName}}:{{.BusinessName}}",
  178. handleFuns: {},
  179. customBtns: [],
  180. tableListFun: apis.{{.PackageName}}.{{.BusinessName}}Api.list{{.BBusinessName}},
  181. getEntityFun: apis.{{.PackageName}}.{{.BusinessName}}Api.get{{.BBusinessName}},
  182. deleteEntityFun: apis.{{.PackageName}}.{{.BusinessName}}Api.del{{.BBusinessName}},
  183. formItems:[
  184. {{- range .Columns -}}
  185. {{- if (eq .IsInsert "1") -}}
  186. {{ $required := eq .IsRequired "1" }}
  187. {{- if (.Pk) }}
  188. {{- else if or (eq .GoField "CreatedAt") (eq .GoField "UpdatedAt") (eq .GoField "DeletedAt") (eq .GoField "UpdateBy") (eq .GoField "CreateBy") -}}
  189. {{- else if ne .FkTableName ""}}
  190. {
  191. field: "{{.JsonField}}",
  192. label: "{{.ColumnComment}}",
  193. class: "w-100",
  194. required: {{$required}},
  195. component: "VS",
  196. data: () => {{.JsonField}}Options.value,
  197. props: {
  198. {{- if eq .HtmlType "radio"}}
  199. type: "radio",
  200. {{- else if eq .HtmlType "checkbox"}}
  201. type: "checkbox",
  202. {{- else }}
  203. type: "select",
  204. {{- end }}
  205. clearable: true,
  206. placeholder: "请选择{{.ColumnComment }}",
  207. props:{
  208. label:{{.FkLabelName}},
  209. value:{{.FkLabelId}},
  210. }
  211. }
  212. },
  213. {{- else if ne .DictType ""}}
  214. {
  215. field: "{{.JsonField}}",
  216. label: "{{.ColumnComment}}",
  217. class: "w-100",
  218. required: {{$required}},
  219. component: "Dict",
  220. props: {
  221. {{- if eq .HtmlType "radio"}}
  222. type: "radio",
  223. {{- else if eq .HtmlType "checkbox"}}
  224. type: "checkbox",
  225. {{- else }}
  226. type: "select",
  227. {{- end }}
  228. clearable: true,
  229. placeholder: "请选择{{.ColumnComment }}",
  230. dictType: "{{.DictType}}"
  231. }
  232. },
  233. {{- else if eq .HtmlType "datetime"}}
  234. {
  235. field: "{{.JsonField}}",
  236. label: "{{.ColumnComment}}",
  237. class: "w-100",
  238. required: {{$required}},
  239. component: "D",
  240. placeholder: "请选择{{.ColumnComment }}",
  241. props: {
  242. type: "date",
  243. valueFormat: "YYYY-MM-DD",
  244. },
  245. },
  246. {{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox") }}
  247. {
  248. field: "{{.JsonField}}",
  249. label: "{{.ColumnComment}}",
  250. class: "w-100",
  251. required: {{$required}},
  252. component: "VS",
  253. placeholder: "请选择{{.ColumnComment }}",
  254. data: () => {{.JsonField}}Options.value,
  255. props: {
  256. type: "{{.HtmlType}}",
  257. clearable: true,
  258. {{- if or (eq .GoType "int") (eq .GoType "int64") }}
  259. valueIsNumber: true,
  260. {{- end }}
  261. },
  262. },
  263. {{- else }}
  264. {
  265. field: "{{.JsonField}}",
  266. label: "{{.ColumnComment}}",
  267. class: "w-100",
  268. {{- if eq .HtmlType "file"}}
  269. component: "VU",
  270. {{- else if eq .HtmlType "textarea"}}
  271. component: "VE",
  272. {{- else }}
  273. component: "I",
  274. {{- end }}
  275. {{- if or (eq .GoType "int") (eq .GoType "int64") }}
  276. type: "number",
  277. {{- end }}
  278. required: {{ $required }}
  279. },
  280. {{- end -}}
  281. {{- end -}}
  282. {{- end }}
  283. ] as any,
  284. resetForm: () => {
  285. form.value = emptyFormData.value
  286. },
  287. emptyFormData: {
  288. {{- range .Columns -}}
  289. {{- if (eq .IsPk "1") }}
  290. {{.JsonField}}: undefined,
  291. {{- else if or (eq .GoField "CreatedAt") (eq .GoField "UpdatedAt") (eq .GoField "DeletedAt") (eq .GoField "UpdateBy") (eq .GoField "CreateBy") -}}
  292. {{- else if (eq .IsInsert "1") }}
  293. {{.JsonField}}: undefined,
  294. {{- end -}}
  295. {{- end }}
  296. }
  297. })
  298. const { queryParams, emptyFormData } = toRefs(opts)
  299. const form = ref<any>(emptyFormData.value)
  300. /** 修改按钮操作 */
  301. function handleUpdate(row: any) {
  302. tableRef.value.defaultHandleFuns.handleUpdate("", row)
  303. }
  304. /** 删除按钮操作 */
  305. function handleDelete(rows: any[]) {
  306. tableRef.value.defaultHandleFuns.handleDelete("", rows)
  307. }
  308. /** 提交按钮 */
  309. function submitForm() {
  310. if (form.value.{{.PkJsonField}} != undefined) {
  311. apis.{{.PackageName}}.{{.BusinessName}}Api.update{{.BBusinessName}}(form.value).then(() => {
  312. message.msgSuccess("修改成功")
  313. handleQuery()
  314. })
  315. } else {
  316. apis.{{.PackageName}}.{{.BusinessName}}Api.add{{.BBusinessName}}(form.value).then(() => {
  317. message.msgSuccess("新增成功")
  318. handleQuery()
  319. })
  320. }
  321. }
  322. /** 查询按钮 */
  323. function handleQuery() {
  324. {{- range .Columns -}}
  325. {{- if ( eq .GoField "CreatedAt")}}
  326. addDateRange(queryParams.value, queryParams.value.dateRange)
  327. {{- else if and (eq .IsQuery "1") (eq .HtmlType "datetime")}}
  328. addDateRange(queryParams.value, queryParams.value.dateRange{{.BJsonField}})
  329. {{- end -}}
  330. {{- end }}
  331. tableRef.value?.search()
  332. }
  333. /** 查询重置按钮 */
  334. function resetQuery() {
  335. {{- range .Columns -}}
  336. {{- if ( eq .GoField "CreatedAt")}}
  337. queryParams.value.dateRange = []
  338. addDateRange(queryParams.value, queryParams.value.dateRange)
  339. {{- else if and (eq .IsQuery "1") (eq .HtmlType "datetime")}}
  340. queryParams.value.dateRange{{.BJsonField}} = []
  341. addDateRange(queryParams.value, queryParams.value.dateRange{{.BJsonField}})
  342. {{- end -}}
  343. {{- end }}
  344. }
  345. function init(){
  346. {{ range .Columns -}}
  347. {{- if ne .FkTableName "" -}}
  348. apis.{{.FkTableNamePackage}}.{{.FkTableNameBusiness}}Api.list{{.BFkTableNameBusiness}}({pageSize:10000,pageIndex:1}).then((res)=>{
  349. {{.JsonField}}Options.value = res.data.rows
  350. })
  351. {{- end -}}
  352. {{- end }}
  353. }
  354. onMounted(init)
  355. </script>
  356. <template>
  357. <div class="app-container">
  358. <VbDataTable
  359. ref="tableRef"
  360. :handle-perm="opts.permission"
  361. :handle-funs="opts.handleFuns"
  362. :search-form-items="opts.searchFormItems"
  363. :columns="opts.columns"
  364. :custom-btns="opts.customBtns"
  365. :remote-fun="opts.tableListFun"
  366. :get-entity-fun="opts.getEntityFun"
  367. :delete-entity-fun="opts.deleteEntityFun"
  368. {{- range .Columns -}}
  369. {{- if (eq .JsonField "createdAt") }}
  370. sortField="createdAt"
  371. sort-order="desc"
  372. {{- end -}}
  373. {{- end }}
  374. :modal="modalRef"
  375. :reset-form-fun="opts.resetForm"
  376. v-model:form-data="form"
  377. :query-params="queryParams"
  378. :check-multiple="true"
  379. :has-checkbox="true"
  380. :reset-search-form-fun="resetQuery"
  381. :custom-search-fun="handleQuery">
  382. {{ range .Columns -}}
  383. {{- if (eq .IsList "1") -}}
  384. {{- if (ne .FkTableName "") -}}
  385. <template #{{.JsonField}}="{ row }">
  386. <vb-tag :value="row.{{.JsonField}}" :data="{{.JsonField}}Options"></vb-tag>
  387. </template>
  388. {{- else if (ne .DictType "") -}}
  389. <template #{{.JsonField}}="{ row }">
  390. {{- if or (eq .GoType "int") (eq .GoType "int64")}}
  391. <DictTag valueIsNumber :value="row.{{.JsonField}}" type="{{.DictType}}"></DictTag>
  392. {{- else }}
  393. <DictTag :value="row.{{.JsonField}}" type="{{.DictType}}"></DictTag>
  394. {{- end}}
  395. </template>
  396. {{- else if (eq .HtmlType "datetime") -}}
  397. <template #{{.JsonField}}="{ row }">
  398. <span>{{"{{"}} {{"dayjs"}}(row.{{.JsonField}}).format("YYYY-MM-DD HH:mm:ss") {{"}}"}}</span>
  399. </template>
  400. {{- else if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox") -}}
  401. <template #{{.JsonField}}="{ row }">
  402. {{- if or (eq .GoType "int") (eq .GoType "int64")}}
  403. <vb-tag valueIsNumber :value="row.{{.JsonField}}" :data="{{.JsonField}}Options"></vb-tag>
  404. {{- else }}
  405. <vb-tag :value="row.{{.JsonField}}" :data="[]"></vb-tag>
  406. {{- end}}
  407. </template>
  408. {{- end}}
  409. {{- else if (eq .JsonField "createdAt") }}
  410. <template #{{.JsonField}}="{ row }">
  411. <span>{{"{{"}} {{"dayjs"}}(row.{{.JsonField}}).format("YYYY-MM-DD HH:mm:ss") {{"}}"}}</span>
  412. </template>
  413. {{- end -}}
  414. {{- end }}
  415. <template #actions="{ row }">
  416. <vb-tooltip content="修改" placement="top">
  417. <el-button
  418. link
  419. type="primary"
  420. @click="handleUpdate(row)"
  421. v-hasPermission="'{{.PackageName}}:{{.BusinessName}}:edit'">
  422. <template #icon>
  423. <VbIcon icon-name="notepad-edit" icon-type="duotone" class="fs-3"></VbIcon>
  424. </template>
  425. </el-button>
  426. </vb-tooltip>
  427. <vb-tooltip content="删除" placement="top">
  428. <el-button
  429. link
  430. type="primary"
  431. @click="handleDelete([row])"
  432. v-hasPermission="'{{.PackageName}}:{{.BusinessName}}:remove'">
  433. <template #icon>
  434. <VbIcon icon-name="trash-square" icon-type="duotone" class="fs-3"></VbIcon>
  435. </template>
  436. </el-button>
  437. </vb-tooltip>
  438. </template>
  439. </VbDataTable>
  440. <VbModal
  441. v-model:modal="modalRef"
  442. :title="opts.modalTitle"
  443. :form-items="opts.formItems as any"
  444. :form-data="form"
  445. @confirm="submitForm"
  446. append-to-body></VbModal>
  447. </div>
  448. </template>