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.

299 lines
9.7 KiB

  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>
  25. <div class="gva-btn-list">
  26. <el-button size="mini" type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
  27. <el-button size="mini" type="primary" icon="el-icon-plus" @click="openDialog">新增</el-button>
  28. <el-popover v-model:visible="deleteVisible" placement="top" width="160">
  29. <p>确定要删除吗?</p>
  30. <div style="text-align: right; margin: 0">
  31. <el-button size="mini" type="text" @click="deleteVisible = false">取消</el-button>
  32. <el-button size="mini" type="primary" @click="onDelete">确定</el-button>
  33. </div>
  34. <template #reference>
  35. <el-button icon="el-icon-delete" size="mini" type="danger" style="margin-left: 10px;">批量删除</el-button>
  36. </template>
  37. </el-popover>
  38. </div>
  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 v-model="dialogFormVisible" :before-close="closeDialog" 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 v-model="formData.{{.FieldJson}}" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" 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 v-model="formData.{{ .FieldJson }}" type="date" placeholder="选择日期" 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 infoList from '@/mixins/infoList'
  131. export default {
  132. name: '{{.StructName}}',
  133. mixins: [infoList],
  134. data() {
  135. return {
  136. listApi: get{{ .StructName }}List,
  137. dialogFormVisible: false,
  138. type: '',
  139. deleteVisible: false,
  140. multipleSelection: [],
  141. {{- range .Fields}}
  142. {{- if .DictType }}
  143. {{ .DictType }}Options: [],
  144. {{- end }}
  145. {{- end }}
  146. formData: {
  147. {{- range .Fields}}
  148. {{- if eq .FieldType "bool" }}
  149. {{.FieldJson}}: false,
  150. {{- end }}
  151. {{- if eq .FieldType "string" }}
  152. {{.FieldJson}}: '',
  153. {{- end }}
  154. {{- if eq .FieldType "int" }}
  155. {{.FieldJson}}: 0,
  156. {{- end }}
  157. {{- if eq .FieldType "time.Time" }}
  158. {{.FieldJson}}: new Date(),
  159. {{- end }}
  160. {{- if eq .FieldType "float64" }}
  161. {{.FieldJson}}: 0,
  162. {{- end }}
  163. {{- end }}
  164. }
  165. }
  166. },
  167. async created() {
  168. await this.getTableData()
  169. {{- range .Fields }}
  170. {{- if .DictType }}
  171. await this.getDict('{{.DictType}}')
  172. {{- end }}
  173. {{- end }}
  174. },
  175. methods: {
  176. // 条件搜索前端看此方法
  177. onSubmit() {
  178. this.page = 1
  179. this.pageSize = 10
  180. {{- range .Fields}}{{- if eq .FieldType "bool" }}
  181. if (this.searchInfo.{{.FieldJson}} === ""){
  182. this.searchInfo.{{.FieldJson}}=null
  183. }{{ end }}{{ end }}
  184. this.getTableData()
  185. },
  186. handleSelectionChange(val) {
  187. this.multipleSelection = val
  188. },
  189. deleteRow(row) {
  190. this.$confirm('确定要删除吗?', '提示', {
  191. confirmButtonText: '确定',
  192. cancelButtonText: '取消',
  193. type: 'warning'
  194. }).then(() => {
  195. this.delete{{.StructName}}(row)
  196. })
  197. },
  198. async onDelete() {
  199. const ids = []
  200. if (this.multipleSelection.length === 0) {
  201. this.$message({
  202. type: 'warning',
  203. message: '请选择要删除的数据'
  204. })
  205. return
  206. }
  207. this.multipleSelection &&
  208. this.multipleSelection.map(item => {
  209. ids.push(item.ID)
  210. })
  211. const res = await delete{{.StructName}}ByIds({ ids })
  212. if (res.code === 0) {
  213. this.$message({
  214. type: 'success',
  215. message: '删除成功'
  216. })
  217. if (this.tableData.length === ids.length && this.page > 1) {
  218. this.page--
  219. }
  220. this.deleteVisible = false
  221. this.getTableData()
  222. }
  223. },
  224. async update{{.StructName}}(row) {
  225. const res = await find{{.StructName}}({ ID: row.ID })
  226. this.type = 'update'
  227. if (res.code === 0) {
  228. this.formData = res.data.re{{.Abbreviation}}
  229. this.dialogFormVisible = true
  230. }
  231. },
  232. closeDialog() {
  233. this.dialogFormVisible = false
  234. this.formData = {
  235. {{- range .Fields}}
  236. {{- if eq .FieldType "bool" }}
  237. {{.FieldJson}}: false,
  238. {{- end }}
  239. {{- if eq .FieldType "string" }}
  240. {{.FieldJson}}: '',
  241. {{- end }}
  242. {{- if eq .FieldType "int" }}
  243. {{.FieldJson}}: 0,
  244. {{- end }}
  245. {{- if eq .FieldType "time.Time" }}
  246. {{.FieldJson}}: new Date(),
  247. {{- end }}
  248. {{- if eq .FieldType "float64" }}
  249. {{.FieldJson}}: 0,
  250. {{- end }}
  251. {{- end }}
  252. }
  253. },
  254. async delete{{.StructName}}(row) {
  255. const res = await delete{{.StructName}}({ ID: row.ID })
  256. if (res.code === 0) {
  257. this.$message({
  258. type: 'success',
  259. message: '删除成功'
  260. })
  261. if (this.tableData.length === 1 && this.page > 1) {
  262. this.page--
  263. }
  264. this.getTableData()
  265. }
  266. },
  267. async enterDialog() {
  268. let res
  269. switch (this.type) {
  270. case 'create':
  271. res = await create{{.StructName}}(this.formData)
  272. break
  273. case 'update':
  274. res = await update{{.StructName}}(this.formData)
  275. break
  276. default:
  277. res = await create{{.StructName}}(this.formData)
  278. break
  279. }
  280. if (res.code === 0) {
  281. this.$message({
  282. type: 'success',
  283. message: '创建/更改成功'
  284. })
  285. this.closeDialog()
  286. this.getTableData()
  287. }
  288. },
  289. openDialog() {
  290. this.type = 'create'
  291. this.dialogFormVisible = true
  292. }
  293. },
  294. }
  295. </script>
  296. <style>
  297. </style>