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.

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