table.vue.tpl 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <div>
  3. <div class="search-term">
  4. <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
  5. {{- range .Fields}} {{- if .FieldSearchType}} {{- if eq .FieldType "bool" }}
  6. <el-form-item label="{{.FieldDesc}}" prop="{{.FieldJson}}">
  7. <el-select v-model="searchInfo.{{.FieldJson}}" clearable placeholder="请选择">
  8. <el-option
  9. key="true"
  10. label="是"
  11. value="true">
  12. </el-option>
  13. <el-option
  14. key="false"
  15. label="否"
  16. value="false">
  17. </el-option>
  18. </el-select>
  19. </el-form-item>
  20. {{- else }}
  21. <el-form-item label="{{.FieldDesc}}">
  22. <el-input v-model="searchInfo.{{.FieldJson}}" placeholder="搜索条件" />
  23. </el-form-item>{{ end }}{{ end }}{{ end }}
  24. <el-form-item>
  25. <el-button size="mini" type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
  26. <el-button size="mini" type="primary" icon="el-icon-plus" @click="openDialog">新增</el-button>
  27. <el-popover v-model:visible="deleteVisible" placement="top" width="160">
  28. <p>确定要删除吗?</p>
  29. <div style="text-align: right; margin: 0">
  30. <el-button size="mini" type="text" @click="deleteVisible = false">取消</el-button>
  31. <el-button size="mini" type="primary" @click="onDelete">确定</el-button>
  32. </div>
  33. <template #reference>
  34. <el-button icon="el-icon-delete" size="mini" type="danger" style="margin-left: 10px;">批量删除</el-button>
  35. </template>
  36. </el-popover>
  37. </el-form-item>
  38. </el-form>
  39. </div>
  40. <el-table
  41. ref="multipleTable"
  42. border
  43. stripe
  44. style="width: 100%"
  45. tooltip-effect="dark"
  46. :data="tableData"
  47. @selection-change="handleSelectionChange"
  48. >
  49. <el-table-column type="selection" width="55" />
  50. <el-table-column label="日期" width="180">
  51. <template #default="scope">{{ "{{ formatDate(scope.row.CreatedAt) }}" }}</template>
  52. </el-table-column>
  53. {{- range .Fields}}
  54. {{- if .DictType}}
  55. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
  56. <template #default="scope">
  57. {{"{{"}} filterDict(scope.row.{{.FieldJson}},"{{.DictType}}") {{"}}"}}
  58. </template>
  59. </el-table-column>
  60. {{- else if eq .FieldType "bool" }}
  61. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
  62. <template #default="scope">{{"{{"}} formatBoolean(scope.row.{{.FieldJson}}) {{"}}"}}</template>
  63. </el-table-column> {{- else }}
  64. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120" />
  65. {{- end }}
  66. {{- end }}
  67. <el-table-column label="按钮组">
  68. <template #default="scope">
  69. <el-button size="small" type="primary" icon="el-icon-edit" class="table-button" @click="update{{.StructName}}(scope.row)">变更</el-button>
  70. <el-button type="danger" icon="el-icon-delete" size="mini" @click="deleteRow(scope.row)">删除</el-button>
  71. </template>
  72. </el-table-column>
  73. </el-table>
  74. <el-pagination
  75. layout="total, sizes, prev, pager, next, jumper"
  76. :current-page="page"
  77. :page-size="pageSize"
  78. :page-sizes="[10, 30, 50, 100]"
  79. :style="{float:'right',padding:'20px'}"
  80. :total="total"
  81. @current-change="handleCurrentChange"
  82. @size-change="handleSizeChange"
  83. />
  84. <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
  85. <el-form :model="formData" label-position="right" label-width="80px">
  86. {{- range .Fields}}
  87. <el-form-item label="{{.FieldDesc}}:">
  88. {{- if eq .FieldType "bool" }}
  89. <el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch>
  90. {{- end }}
  91. {{- if eq .FieldType "string" }}
  92. <el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" />
  93. {{- end }}
  94. {{- if eq .FieldType "int" }}
  95. {{- if .DictType}}
  96. <el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
  97. <el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value" />
  98. </el-select>
  99. {{- else }}
  100. <el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入" />
  101. {{- end }}
  102. {{- end }}
  103. {{- if eq .FieldType "time.Time" }}
  104. <el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable />
  105. {{- end }}
  106. {{- if eq .FieldType "float64" }}
  107. <el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable />
  108. {{- end }}
  109. </el-form-item>
  110. {{- end }}
  111. </el-form>
  112. <template #footer>
  113. <div class="dialog-footer">
  114. <el-button @click="closeDialog">取 消</el-button>
  115. <el-button type="primary" @click="enterDialog">确 定</el-button>
  116. </div>
  117. </template>
  118. </el-dialog>
  119. </div>
  120. </template>
  121. <script>
  122. import {
  123. create{{.StructName}},
  124. delete{{.StructName}},
  125. delete{{.StructName}}ByIds,
  126. update{{.StructName}},
  127. find{{.StructName}},
  128. get{{.StructName}}List
  129. } from '@/api/{{.PackageName}}' // 此处请自行替换地址
  130. import { formatTimeToStr } from '@/utils/date'
  131. import infoList from '@/mixins/infoList'
  132. export default {
  133. name: '{{.StructName}}',
  134. mixins: [infoList],
  135. data() {
  136. return {
  137. listApi: get{{ .StructName }}List,
  138. dialogFormVisible: false,
  139. type: '',
  140. deleteVisible: false,
  141. multipleSelection: [],
  142. {{- range .Fields}}
  143. {{- if .DictType }}
  144. {{ .DictType }}Options: [],
  145. {{- end }}
  146. {{- end }}
  147. formData: {
  148. {{- range .Fields}}
  149. {{- if eq .FieldType "bool" }}
  150. {{.FieldJson}}: false,
  151. {{- end }}
  152. {{- if eq .FieldType "string" }}
  153. {{.FieldJson}}: '',
  154. {{- end }}
  155. {{- if eq .FieldType "int" }}
  156. {{.FieldJson}}: 0,
  157. {{- end }}
  158. {{- if eq .FieldType "time.Time" }}
  159. {{.FieldJson}}: new Date(),
  160. {{- end }}
  161. {{- if eq .FieldType "float64" }}
  162. {{.FieldJson}}: 0,
  163. {{- end }}
  164. {{- end }}
  165. }
  166. }
  167. },
  168. async created() {
  169. await this.getTableData()
  170. {{- range .Fields }}
  171. {{- if .DictType }}
  172. await this.getDict('{{.DictType}}')
  173. {{- end }}
  174. {{- end }}
  175. },
  176. methods: {
  177. // 条件搜索前端看此方法
  178. onSubmit() {
  179. this.page = 1
  180. this.pageSize = 10
  181. {{- range .Fields}}{{- if eq .FieldType "bool" }}
  182. if (this.searchInfo.{{.FieldJson}} === ""){
  183. this.searchInfo.{{.FieldJson}}=null
  184. }{{ end }}{{ end }}
  185. this.getTableData()
  186. },
  187. handleSelectionChange(val) {
  188. this.multipleSelection = val
  189. },
  190. deleteRow(row) {
  191. this.$confirm('确定要删除吗?', '提示', {
  192. confirmButtonText: '确定',
  193. cancelButtonText: '取消',
  194. type: 'warning'
  195. }).then(() => {
  196. this.delete{{.StructName}}(row)
  197. })
  198. },
  199. async onDelete() {
  200. const ids = []
  201. if (this.multipleSelection.length === 0) {
  202. this.$message({
  203. type: 'warning',
  204. message: '请选择要删除的数据'
  205. })
  206. return
  207. }
  208. this.multipleSelection &&
  209. this.multipleSelection.map(item => {
  210. ids.push(item.ID)
  211. })
  212. const res = await delete{{.StructName}}ByIds({ ids })
  213. if (res.code === 0) {
  214. this.$message({
  215. type: 'success',
  216. message: '删除成功'
  217. })
  218. if (this.tableData.length === ids.length && this.page > 1) {
  219. this.page--
  220. }
  221. this.deleteVisible = false
  222. this.getTableData()
  223. }
  224. },
  225. async update{{.StructName}}(row) {
  226. const res = await find{{.StructName}}({ ID: row.ID })
  227. this.type = 'update'
  228. if (res.code === 0) {
  229. this.formData = res.data.re{{.Abbreviation}}
  230. this.dialogFormVisible = true
  231. }
  232. },
  233. closeDialog() {
  234. this.dialogFormVisible = false
  235. this.formData = {
  236. {{- range .Fields}}
  237. {{- if eq .FieldType "bool" }}
  238. {{.FieldJson}}: false,
  239. {{- end }}
  240. {{- if eq .FieldType "string" }}
  241. {{.FieldJson}}: '',
  242. {{- end }}
  243. {{- if eq .FieldType "int" }}
  244. {{.FieldJson}}: 0,
  245. {{- end }}
  246. {{- if eq .FieldType "time.Time" }}
  247. {{.FieldJson}}: new Date(),
  248. {{- end }}
  249. {{- if eq .FieldType "float64" }}
  250. {{.FieldJson}}: 0,
  251. {{- end }}
  252. {{- end }}
  253. }
  254. },
  255. async delete{{.StructName}}(row) {
  256. const res = await delete{{.StructName}}({ ID: row.ID })
  257. if (res.code === 0) {
  258. this.$message({
  259. type: 'success',
  260. message: '删除成功'
  261. })
  262. if (this.tableData.length === 1 && this.page > 1) {
  263. this.page--
  264. }
  265. this.getTableData()
  266. }
  267. },
  268. async enterDialog() {
  269. let res
  270. switch (this.type) {
  271. case 'create':
  272. res = await create{{.StructName}}(this.formData)
  273. break
  274. case 'update':
  275. res = await update{{.StructName}}(this.formData)
  276. break
  277. default:
  278. res = await create{{.StructName}}(this.formData)
  279. break
  280. }
  281. if (res.code === 0) {
  282. this.$message({
  283. type: 'success',
  284. message: '创建/更改成功'
  285. })
  286. this.closeDialog()
  287. this.getTableData()
  288. }
  289. },
  290. openDialog() {
  291. this.type = 'create'
  292. this.dialogFormVisible = true
  293. }
  294. },
  295. }
  296. </script>
  297. <style>
  298. </style>