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.

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