You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
10 KiB

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