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.

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