vue.template 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. {{$tableComment:=.table.TableComment}}
  2. <template>
  3. <div class="app-container">
  4. <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px" >
  5. {{range $index, $column := .table.Columns}}
  6. {{ $x := $column.IsQuery }}
  7. {{ if eq $x "1"}}
  8. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.GoField}}">
  9. <el-input v-model="queryParams.{{$column.GoField}}" placeholder="请输入{{$column.ColumnComment}}" clearable size="small" @keyup.enter.native="handleQuery" />
  10. </el-form-item>
  11. {{end}}
  12. {{ end }}
  13. <el-form-item>
  14. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-row :gutter="10" class="mb8">
  19. <el-col :span="1.5">
  20. <el-button
  21. type="primary"
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. >新增</el-button>
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button
  29. type="success"
  30. icon="el-icon-edit"
  31. size="mini"
  32. :disabled="single"
  33. @click="handleUpdate"
  34. >修改</el-button>
  35. </el-col>
  36. <el-col :span="1.5">
  37. <el-button
  38. type="danger"
  39. icon="el-icon-delete"
  40. size="mini"
  41. :disabled="multiple"
  42. @click="handleDelete"
  43. >删除</el-button>
  44. </el-col>
  45. </el-row>
  46. {{if eq .table.TplCategory "crud"}}
  47. <!--单表-->
  48. <el-table v-loading="loading" :data="{{.table.ModuleName}}List" @selection-change="handleSelectionChange">
  49. <el-table-column type="selection" width="55" align="center" />
  50. {{range $index,$column:=.table.Columns}}
  51. {{ $x := $column.IsList }}
  52. {{ if eq $x "1"}}
  53. <el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.GoField}}" :show-overflow-tooltip="true" />
  54. {{end }}
  55. {{end }}
  56. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  57. <template slot-scope="scope">
  58. <el-button
  59. size="mini"
  60. type="text"
  61. icon="el-icon-edit"
  62. @click="handleUpdate(scope.row)"
  63. >修改</el-button>
  64. <el-button
  65. size="mini"
  66. type="text"
  67. icon="el-icon-delete"
  68. @click="handleDelete(scope.row)"
  69. >删除</el-button>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. <pagination
  74. v-show="total>0"
  75. :total="total"
  76. :page.sync="queryParams.pageIndex"
  77. :limit.sync="queryParams.pageSize"
  78. @pagination="getList"
  79. />
  80. {{else}}
  81. <!--树形菜单-->
  82. <el-table
  83. v-loading="loading"
  84. :data="deptList"
  85. row-key="deptId"
  86. default-expand-all
  87. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  88. >
  89. {{range $index,$column:=.table.Columns}}
  90. {{ $x := $column.IsList }}
  91. {{ if eq $x "1"}}
  92. <el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.GoField}}" :show-overflow-tooltip="true" />
  93. {{ end }}
  94. {{ end }}
  95. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  96. <template slot-scope="scope">
  97. <el-button
  98. size="mini"
  99. type="text"
  100. icon="el-icon-edit"
  101. @click="handleUpdate(scope.row)"
  102. >修改</el-button>
  103. <el-button
  104. size="mini"
  105. type="text"
  106. icon="el-icon-plus"
  107. @click="handleAdd(scope.row)"
  108. >新增</el-button>
  109. <el-button
  110. v-if="scope.row.parentId != 0"
  111. size="mini"
  112. type="text"
  113. icon="el-icon-delete"
  114. @click="handleDelete(scope.row)"
  115. >删除</el-button>
  116. </template>
  117. </el-table-column>
  118. </el-table>
  119. {{end}}
  120. <!-- 添加或修改对话框 -->
  121. <el-dialog :title="title" :visible.sync="open" width="500px">
  122. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  123. {{ range $index,$column:=.table.Columns }}
  124. {{ $x := $column.IsInsert }}
  125. {{ if eq $x "1"}}
  126. {{ if eq $column.IsPk "1" }}
  127. {{else if eq $column.GoField "CreatedAt" }}
  128. {{else if eq $column.GoField "UpdatedAt" }}
  129. {{else if eq $column.GoField "DeletedAt" }}
  130. {{else if eq $column.GoField "UpdateBy" }}
  131. {{else if eq $column.GoField "CreateBy" }}
  132. {{else }}
  133. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.GoField}}" >
  134. {{ if eq "input" $column.HtmlType }}
  135. <el-input v-model="form.{{$column.GoField}}" placeholder="{{$column.ColumnComment}}" {{if eq $column.IsEdit "false" }}:disabled="isEdit" {{ end}}/>
  136. {{ else if eq "select" $column.HtmlType }}
  137. <el-select v-model="form.{{$column.GoField}}" {{if eq $column.IsEdit "false" }} :disabled="isEdit" {{end }}>
  138. <el-option label="demo1" value="demo1" />
  139. <el-option label="demo2" value="demo2" />
  140. </el-select>
  141. {{else if eq "radio" $column.HtmlType }}
  142. <el-radio-group v-model="form.{{$column.GoField}}">
  143. <el-radio
  144. v-for="dict in {{$column.GoField}}Options"
  145. :key="dict.dictValue"
  146. :label="dict.dictValue"
  147. >{{"{{"}} dict.dictLabel {{"}}"}}</el-radio>
  148. </el-radio-group>
  149. {{ end }}
  150. </el-form-item>
  151. {{ end }}
  152. {{ end }}
  153. {{ end }}
  154. </el-form>
  155. <div slot="footer" class="dialog-footer">
  156. <el-button type="primary" @click="submitForm">确 定</el-button>
  157. <el-button @click="cancel">取 消</el-button>
  158. </div>
  159. </el-dialog>
  160. </div>
  161. </template>
  162. <script>
  163. import { list{{.table.BusinessName|UcFirst}}, get{{.table.BusinessName|UcFirst}}, del{{.table.BusinessName|UcFirst}}, add{{.table.BusinessName|UcFirst}}, update{{.table.BusinessName|UcFirst}} } from '@/api/{{.table.ModuleName}}/{{.table.BusinessName}}'
  164. export default {
  165. name: '{{.table.BusinessName|UcFirst}}',
  166. data() {
  167. return {
  168. // 遮罩层
  169. loading: true,
  170. // 选中数组
  171. ids: [],
  172. // 非单个禁用
  173. single: true,
  174. // 非多个禁用
  175. multiple: true,
  176. // 总条数
  177. total: 0,
  178. // 弹出层标题
  179. title: '',
  180. // 是否显示弹出层
  181. open: false,
  182. isEdit: false,
  183. // 类型数据字典
  184. typeOptions: [],
  185. // 查询参数
  186. queryParams: {
  187. pageIndex: 1,
  188. pageSize: 10,
  189. {{ range $index,$column:=.table.Columns }}
  190. {{if eq $column.IsQuery "1"}}
  191. {{$column.GoField}}:undefined,
  192. {{ end }}
  193. {{ end }}
  194. },
  195. // 表单参数
  196. form: {
  197. },
  198. // 表单校验
  199. rules: {
  200. {{range $index,$column :=.table.Columns }}
  201. {{ $x := $column.IsQuery }}
  202. {{ if eq $x "1"}}
  203. {{$column.GoField}}:
  204. [
  205. {required: true, message: '{{$column.ColumnComment}}不能为空', trigger: 'blur'}
  206. ],
  207. {{ end }}
  208. {{ end }}
  209. }
  210. }
  211. },
  212. created() {
  213. this.getList()
  214. {{range $index,$column:=.table.Columns}}
  215. {{ if ne $column.DictType "" }}
  216. this.getDicts('{{$column.DictType}}').then(response => {
  217. this.{{$column.GoField}}Options = response.data
  218. })
  219. {{ end }}
  220. {{ end }}
  221. },
  222. methods: {
  223. /** 查询参数列表 */
  224. getList() {
  225. this.loading = true
  226. list{{.table.BusinessName|UcFirst}}(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  227. this.{{.table.ModuleName}}List = response.data.list
  228. this.total = response.data.count
  229. this.loading = false
  230. }
  231. )
  232. },
  233. // 取消按钮
  234. cancel() {
  235. this.open = false
  236. this.reset()
  237. },
  238. // 表单重置
  239. reset() {
  240. this.form = {
  241. {{ range $index,$column:=.table.Columns}}
  242. {{ $x := $column.IsInsert }}
  243. {{ if eq $x "1"}}
  244. {{if eq $column.GoField "CreatedAt" }}
  245. {{else if eq $column.GoField "UpdatedAt" }}
  246. {{else if eq $column.GoField "DeletedAt" }}
  247. {{else if eq $column.GoField "UpdateBy" }}
  248. {{else if eq $column.GoField "CreateBy" }}
  249. {{else }}
  250. {{$column.GoField}}: undefined,
  251. {{ end }}
  252. {{ end }}
  253. {{ end }}
  254. }
  255. this.resetForm('form')
  256. },
  257. {{$pk:=""}}
  258. {{ range $index,$column:=.table.Columns}}
  259. {{if eq $column.IsPk "1"}}
  260. {{$pk =$column.GoField}}
  261. {{end}}
  262. {{ if ne $column.DictType "" }}
  263. {{$column.GoField}}Format(row) {
  264. return this.selectDictLabel(this.{{$column.GoField}}Options, row.{{$column.GoField}})
  265. },
  266. {{ end }}
  267. {{ end }}
  268. /** 搜索按钮操作 */
  269. handleQuery() {
  270. this.queryParams.pageIndex = 1
  271. this.getList()
  272. },
  273. /** 重置按钮操作 */
  274. resetQuery() {
  275. this.dateRange = []
  276. this.resetForm('queryForm')
  277. this.handleQuery()
  278. },
  279. /** 新增按钮操作 */
  280. handleAdd() {
  281. this.reset()
  282. this.open = true
  283. this.title = '添加{{.table.TableComment}}'
  284. this.isEdit = false
  285. },
  286. // 多选框选中数据
  287. handleSelectionChange(selection) {
  288. this.ids = selection.map(item => item.{{$pk}})
  289. this.single = selection.length !== 1
  290. this.multiple = !selection.length
  291. },
  292. /** 修改按钮操作 */
  293. handleUpdate(row) {
  294. this.reset()
  295. const {{$pk}} = row.{{$pk}} || this.ids
  296. get{{.table.BusinessName|UcFirst}}({{$pk}}).then(response => {
  297. this.form = response.data
  298. this.open = true
  299. this.title = '修改{{.table.TableComment}}'
  300. this.isEdit = true
  301. })
  302. },
  303. /** 提交按钮 */
  304. submitForm: function() {
  305. this.$refs['form'].validate(valid => {
  306. if (valid) {
  307. if (this.form.{{$pk}} !== undefined) {
  308. update{{.table.BusinessName|UcFirst}}(this.form).then(response => {
  309. if (response.code === 200) {
  310. this.msgSuccess('修改成功')
  311. this.open = false
  312. this.getList()
  313. } else {
  314. this.msgError(response.msg)
  315. }
  316. })
  317. } else {
  318. add{{.table.BusinessName|UcFirst}}(this.form).then(response => {
  319. if (response.code === 200) {
  320. this.msgSuccess('新增成功')
  321. this.open = false
  322. this.getList()
  323. } else {
  324. this.msgError(response.msg)
  325. }
  326. })
  327. }
  328. }
  329. })
  330. },
  331. /** 删除按钮操作 */
  332. handleDelete(row) {
  333. const Ids = row.{{$pk}} || this.ids
  334. this.$confirm('是否确认删除编号为"' + Ids + '"的数据项?', '警告', {
  335. confirmButtonText: '确定',
  336. cancelButtonText: '取消',
  337. type: 'warning'
  338. }).then(function() {
  339. return del{{.table.BusinessName|UcFirst}}(Ids)
  340. }).then(() => {
  341. this.getList()
  342. this.msgSuccess('删除成功')
  343. }).catch(function() {})
  344. }
  345. }
  346. }
  347. </script>