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.

307 lines
10 KiB

3 years ago
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="el-icon-search" @click="onSubmit">查询</el-button>
  26. <el-button size="mini" icon="el-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="el-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="el-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="el-icon-edit" size="small" class="table-button" @click="update{{.StructName}}(scope.row)">变更</el-button>
  73. <el-button type="text" icon="el-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 .Fields}}
  147. {{- if .DictType }}
  148. {{ .DictType }}Options: [],
  149. {{- end }}
  150. {{- end }}
  151. formData: {
  152. {{- range .Fields}}
  153. {{- if eq .FieldType "bool" }}
  154. {{.FieldJson}}: false,
  155. {{- end }}
  156. {{- if eq .FieldType "string" }}
  157. {{.FieldJson}}: '',
  158. {{- end }}
  159. {{- if eq .FieldType "int" }}
  160. {{.FieldJson}}: 0,
  161. {{- end }}
  162. {{- if eq .FieldType "time.Time" }}
  163. {{.FieldJson}}: new Date(),
  164. {{- end }}
  165. {{- if eq .FieldType "float64" }}
  166. {{.FieldJson}}: 0,
  167. {{- end }}
  168. {{- end }}
  169. }
  170. }
  171. },
  172. async created() {
  173. await this.getTableData()
  174. {{- range .Fields }}
  175. {{- if .DictType }}
  176. await this.getDict('{{.DictType}}')
  177. {{- end }}
  178. {{- end }}
  179. },
  180. methods: {
  181. onReset() {
  182. this.searchInfo = {}
  183. },
  184. // 条件搜索前端看此方法
  185. onSubmit() {
  186. this.page = 1
  187. this.pageSize = 10
  188. {{- range .Fields}}{{- if eq .FieldType "bool" }}
  189. if (this.searchInfo.{{.FieldJson}} === ""){
  190. this.searchInfo.{{.FieldJson}}=null
  191. }{{ end }}{{ end }}
  192. this.getTableData()
  193. },
  194. handleSelectionChange(val) {
  195. this.multipleSelection = val
  196. },
  197. deleteRow(row) {
  198. this.$confirm('确定要删除吗?', '提示', {
  199. confirmButtonText: '确定',
  200. cancelButtonText: '取消',
  201. type: 'warning'
  202. }).then(() => {
  203. this.delete{{.StructName}}(row)
  204. })
  205. },
  206. async onDelete() {
  207. const ids = []
  208. if (this.multipleSelection.length === 0) {
  209. this.$message({
  210. type: 'warning',
  211. message: '请选择要删除的数据'
  212. })
  213. return
  214. }
  215. this.multipleSelection &&
  216. this.multipleSelection.map(item => {
  217. ids.push(item.ID)
  218. })
  219. const res = await delete{{.StructName}}ByIds({ ids })
  220. if (res.code === 0) {
  221. this.$message({
  222. type: 'success',
  223. message: '删除成功'
  224. })
  225. if (this.tableData.length === ids.length && this.page > 1) {
  226. this.page--
  227. }
  228. this.deleteVisible = false
  229. this.getTableData()
  230. }
  231. },
  232. async update{{.StructName}}(row) {
  233. const res = await find{{.StructName}}({ ID: row.ID })
  234. this.type = 'update'
  235. if (res.code === 0) {
  236. this.formData = res.data.re{{.Abbreviation}}
  237. this.dialogFormVisible = true
  238. }
  239. },
  240. closeDialog() {
  241. this.dialogFormVisible = false
  242. this.formData = {
  243. {{- range .Fields}}
  244. {{- if eq .FieldType "bool" }}
  245. {{.FieldJson}}: false,
  246. {{- end }}
  247. {{- if eq .FieldType "string" }}
  248. {{.FieldJson}}: '',
  249. {{- end }}
  250. {{- if eq .FieldType "int" }}
  251. {{.FieldJson}}: 0,
  252. {{- end }}
  253. {{- if eq .FieldType "time.Time" }}
  254. {{.FieldJson}}: new Date(),
  255. {{- end }}
  256. {{- if eq .FieldType "float64" }}
  257. {{.FieldJson}}: 0,
  258. {{- end }}
  259. {{- end }}
  260. }
  261. },
  262. async delete{{.StructName}}(row) {
  263. const res = await delete{{.StructName}}({ ID: row.ID })
  264. if (res.code === 0) {
  265. this.$message({
  266. type: 'success',
  267. message: '删除成功'
  268. })
  269. if (this.tableData.length === 1 && this.page > 1) {
  270. this.page--
  271. }
  272. this.getTableData()
  273. }
  274. },
  275. async enterDialog() {
  276. let res
  277. switch (this.type) {
  278. case 'create':
  279. res = await create{{.StructName}}(this.formData)
  280. break
  281. case 'update':
  282. res = await update{{.StructName}}(this.formData)
  283. break
  284. default:
  285. res = await create{{.StructName}}(this.formData)
  286. break
  287. }
  288. if (res.code === 0) {
  289. this.$message({
  290. type: 'success',
  291. message: '创建/更改成功'
  292. })
  293. this.closeDialog()
  294. this.getTableData()
  295. }
  296. },
  297. openDialog() {
  298. this.type = 'create'
  299. this.dialogFormVisible = true
  300. }
  301. },
  302. }
  303. </script>
  304. <style>
  305. </style>