vue.go.template 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. {{$tableComment:=.TableComment}}
  2. <template>
  3. <BasicLayout>
  4. <template #wrapper>
  5. <el-card class="box-card">
  6. <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
  7. {{range .Columns}}
  8. {{- $x := .IsQuery -}}
  9. {{- if (eq $x "1") -}}
  10. <el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
  11. {{- if ne .FkTableName "" -}}
  12. <el-select v-model="queryParams.{{.JsonField}}"
  13. placeholder="请选择" clearable size="small" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
  14. <el-option
  15. v-for="dict in {{.JsonField}}Options"
  16. :key="dict.key"
  17. :label="dict.value"
  18. :value="dict.key"
  19. />
  20. </el-select>
  21. {{- else -}}
  22. {{if eq .DictType "" -}}
  23. <el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable
  24. size="small" @keyup.enter.native="handleQuery"/>
  25. {{- else -}}
  26. <el-select v-model="queryParams.{{.JsonField}}"
  27. placeholder="{{$tableComment}}{{.ColumnComment}}" clearable size="small">
  28. <el-option
  29. v-for="dict in {{.JsonField}}Options"
  30. :key="dict.value"
  31. :label="dict.label"
  32. :value="dict.value"
  33. />
  34. </el-select>
  35. {{- end}}
  36. {{- end}}
  37. </el-form-item>
  38. {{end}}
  39. {{- end }}
  40. <el-form-item>
  41. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  42. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  43. </el-form-item>
  44. </el-form>
  45. <el-row :gutter="10" class="mb8">
  46. <el-col :span="1.5">
  47. <el-button
  48. v-permisaction="['{{.PackageName}}:{{.BusinessName}}:add']"
  49. type="primary"
  50. icon="el-icon-plus"
  51. size="mini"
  52. @click="handleAdd"
  53. >新增
  54. </el-button>
  55. </el-col>
  56. <el-col :span="1.5">
  57. <el-button
  58. v-permisaction="['{{.PackageName}}:{{.BusinessName}}:edit']"
  59. type="success"
  60. icon="el-icon-edit"
  61. size="mini"
  62. :disabled="single"
  63. @click="handleUpdate"
  64. >修改
  65. </el-button>
  66. </el-col>
  67. <el-col :span="1.5">
  68. <el-button
  69. v-permisaction="['{{.PackageName}}:{{.BusinessName}}:remove']"
  70. type="danger"
  71. icon="el-icon-delete"
  72. size="mini"
  73. :disabled="multiple"
  74. @click="handleDelete"
  75. >删除
  76. </el-button>
  77. </el-col>
  78. </el-row>
  79. <el-table v-loading="loading" :data="{{.BusinessName}}List" @selection-change="handleSelectionChange">
  80. <el-table-column type="selection" width="55" align="center"/>
  81. {{- range .Columns -}}
  82. {{- $x := .IsList -}}
  83. {{- if (eq $x "1") }}
  84. {{- if ne .FkTableName "" -}}
  85. <el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :formatter="{{.JsonField}}Format" width="100">
  86. <template slot-scope="scope">
  87. {{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
  88. </template>
  89. </el-table-column>
  90. {{- else -}}
  91. {{- if ne .DictType "" -}}
  92. <el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
  93. :formatter="{{.JsonField}}Format" width="100">
  94. <template slot-scope="scope">
  95. {{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
  96. </template>
  97. </el-table-column>
  98. {{- end -}}
  99. {{- if eq .DictType "" -}}
  100. {{- if eq .HtmlType "datetime" -}}
  101. <el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
  102. :show-overflow-tooltip="true">
  103. <template slot-scope="scope">
  104. <span>{{ "{{" }} parseTime(scope.row.{{.JsonField}}) {{"}}"}}</span>
  105. </template>
  106. </el-table-column>
  107. {{- else -}}
  108. <el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
  109. :show-overflow-tooltip="true"/>
  110. {{- end -}}
  111. {{- end -}}
  112. {{- end -}}
  113. {{- end }}
  114. {{- end }}
  115. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  116. <template slot-scope="scope">
  117. <el-popconfirm
  118. class="delete-popconfirm"
  119. title="确认要修改吗?"
  120. confirm-button-text="修改"
  121. @onConfirm="handleUpdate(scope.row)"
  122. >
  123. <el-button
  124. slot="reference"
  125. v-permisaction="['{{.PackageName}}:{{.BusinessName}}:edit']"
  126. size="mini"
  127. type="text"
  128. icon="el-icon-edit"
  129. >修改
  130. </el-button>
  131. </el-popconfirm>
  132. <el-popconfirm
  133. class="delete-popconfirm"
  134. title="确认要删除吗?"
  135. confirm-button-text="删除"
  136. @onConfirm="handleDelete(scope.row)"
  137. >
  138. <el-button
  139. slot="reference"
  140. v-permisaction="['{{.PackageName}}:{{.BusinessName}}:remove']"
  141. size="mini"
  142. type="text"
  143. icon="el-icon-delete"
  144. >删除
  145. </el-button>
  146. </el-popconfirm>
  147. </template>
  148. </el-table-column>
  149. </el-table>
  150. <pagination
  151. v-show="total>0"
  152. :total="total"
  153. :page.sync="queryParams.pageIndex"
  154. :limit.sync="queryParams.pageSize"
  155. @pagination="getList"
  156. />
  157. <!-- 添加或修改对话框 -->
  158. <el-dialog :title="title" :visible.sync="open" width="500px">
  159. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  160. {{ range .Columns }}
  161. {{- $x := .IsInsert -}}
  162. {{- if (eq $x "1") -}}
  163. {{- if (.Pk) }}
  164. {{- else if eq .GoField "CreatedAt" -}}
  165. {{- else if eq .GoField "UpdatedAt" -}}
  166. {{- else if eq .GoField "DeletedAt" -}}
  167. {{- else if eq .GoField "UpdateBy" -}}
  168. {{- else if eq .GoField "CreateBy" -}}
  169. {{- else }}
  170. <el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
  171. {{ if eq "input" .HtmlType -}}
  172. <el-input v-model="form.{{.JsonField}}" placeholder="{{.ColumnComment}}"
  173. {{if eq .IsEdit "false" -}}:disabled="isEdit" {{- end}}/>
  174. {{- else if eq "select" .HtmlType -}}
  175. {{- if ne .FkTableName "" -}}
  176. <el-select v-model="form.{{.JsonField}}"
  177. placeholder="请选择" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
  178. <el-option
  179. v-for="dict in {{.JsonField}}Options"
  180. :key="dict.key"
  181. :label="dict.value"
  182. :value="dict.key"
  183. />
  184. </el-select>
  185. {{- else -}}
  186. <el-select v-model="form.{{.JsonField}}"
  187. placeholder="请选择" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
  188. <el-option
  189. v-for="dict in {{.JsonField}}Options"
  190. :key="dict.value"
  191. :label="dict.label"
  192. :value="dict.value"
  193. />
  194. </el-select>
  195. {{- end -}}
  196. {{- else if eq "radio" .HtmlType -}}
  197. <el-radio-group v-model="form.{{.JsonField}}">
  198. <el-radio
  199. v-for="dict in {{.JsonField}}Options"
  200. :key="dict.value"
  201. :label="dict.value"
  202. >{{"{{"}} dict.label {{"}}"}}</el-radio>
  203. </el-radio-group>
  204. {{- else if eq "file" .HtmlType -}}
  205. <el-input
  206. v-model="form.{{.JsonField}}"
  207. placeholder="图片"
  208. />
  209. <el-button type="primary" @click="fileShow{{.GoField}}">选择文件</el-button>
  210. {{- else if eq "datetime" .HtmlType -}}
  211. <el-date-picker
  212. v-model="form.{{.JsonField}}"
  213. type="datetime"
  214. placeholder="选择日期">
  215. </el-date-picker>
  216. {{- else if eq "textarea" .HtmlType -}}
  217. <el-input
  218. v-model="form.{{.JsonField}}"
  219. type="textarea"
  220. :rows="2"
  221. placeholder="请输入内容">
  222. </el-input>
  223. {{- end }}
  224. </el-form-item>
  225. {{- end }}
  226. {{- end }}
  227. {{- end }}
  228. </el-form>
  229. <div slot="footer" class="dialog-footer">
  230. <el-button type="primary" @click="submitForm">确 定</el-button>
  231. <el-button @click="cancel">取 消</el-button>
  232. </div>
  233. </el-dialog>
  234. </el-card>
  235. </template>
  236. </BasicLayout>
  237. </template>
  238. <script>
  239. import {add{{.ClassName}}, del{{.ClassName}}, get{{.ClassName}}, list{{.ClassName}}, update{{.ClassName}}} from '@/api/{{ .PackageName}}/{{ .MLTBName}}'
  240. {{ $package:=.PackageName }}
  241. {{range .Columns}}
  242. {{- if ne .FkTableName "" -}}
  243. import {list{{.FkTableNameClass}} } from '@/api/{{ $package }}/{{ .FkTableNamePackage}}'
  244. {{ end -}}
  245. {{- end -}}
  246. export default {
  247. name: '{{.ClassName}}',
  248. components: {
  249. },
  250. data() {
  251. return {
  252. // 遮罩层
  253. loading: true,
  254. // 选中数组
  255. ids: [],
  256. // 非单个禁用
  257. single: true,
  258. // 非多个禁用
  259. multiple: true,
  260. // 总条数
  261. total: 0,
  262. // 弹出层标题
  263. title: '',
  264. // 是否显示弹出层
  265. open: false,
  266. isEdit: false,
  267. // 类型数据字典
  268. typeOptions: [],
  269. {{.BusinessName}}List: [],
  270. {{range .Columns}}
  271. {{- if ne .DictType "" -}}
  272. {{.JsonField}}Options: [],
  273. {{- end -}}
  274. {{- end }}
  275. // 关系表类型
  276. {{range .Columns}}
  277. {{- if ne .FkTableName "" -}}
  278. {{.JsonField}}Options :[],
  279. {{ end -}}
  280. {{- end }}
  281. // 查询参数
  282. queryParams: {
  283. pageIndex: 1,
  284. pageSize: 10,
  285. {{ range .Columns }}
  286. {{- if (.IsQuery) -}}
  287. {{.JsonField}}:undefined,
  288. {{ end -}}
  289. {{- end }}
  290. },
  291. // 表单参数
  292. form: {
  293. },
  294. // 表单校验
  295. rules: {
  296. {{- range .Columns -}}
  297. {{- $x := .IsQuery -}}
  298. {{- if (eq $x "1") -}}
  299. {{.JsonField}}: [ {required: true, message: '{{.ColumnComment}}不能为空', trigger: 'blur'} ],
  300. {{ end }}
  301. {{- end -}}
  302. }
  303. }
  304. },
  305. created() {
  306. this.getList()
  307. {{range .Columns}}
  308. {{- if ne .DictType "" -}}
  309. this.getDicts('{{.DictType}}').then(response => {
  310. this.{{.JsonField}}Options = response.data
  311. })
  312. {{ end -}}
  313. {{- if ne .FkTableName "" -}}
  314. this.get{{.FkTableNameClass}}Items()
  315. {{ end -}}
  316. {{- end -}}
  317. },
  318. methods: {
  319. /** 查询参数列表 */
  320. getList() {
  321. this.loading = true
  322. list{{.ClassName}}(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  323. this.{{.BusinessName}}List = response.data.list
  324. this.total = response.data.count
  325. this.loading = false
  326. }
  327. )
  328. },
  329. // 取消按钮
  330. cancel() {
  331. this.open = false
  332. this.reset()
  333. },
  334. // 表单重置
  335. reset() {
  336. this.form = {
  337. {{ range .Columns}}
  338. {{- $x := .IsInsert -}}
  339. {{- if (eq $x "1") -}}
  340. {{- if eq .GoField "CreatedAt" -}}
  341. {{- else if eq .GoField "UpdatedAt" -}}
  342. {{- else if eq .GoField "DeletedAt" -}}
  343. {{- else if eq .GoField "UpdateBy" -}}
  344. {{- else if eq .GoField "CreateBy" -}}
  345. {{- else }}
  346. {{.JsonField}}: undefined,
  347. {{- end }}
  348. {{- end -}}
  349. {{- end }}
  350. }
  351. this.resetForm('form')
  352. },
  353. getImgList: function() {
  354. this.form[this.fileIndex] = this.$refs['fileChoose'].resultList[0].fullUrl
  355. },
  356. fileClose: function() {
  357. this.fileOpen = false
  358. },
  359. {{range .Columns}}
  360. {{- if ne .DictType "" -}}
  361. {{.JsonField}}Format(row) {
  362. return this.selectDictLabel(this.{{.JsonField}}Options, row.{{.JsonField}})
  363. },
  364. {{ end -}}
  365. {{- if ne .FkTableName "" -}}
  366. {{.JsonField}}Format(row) {
  367. return this.selectItemsLabel(this.{{.JsonField}}Options, row.{{.JsonField}})
  368. },
  369. {{ end -}}
  370. {{- end -}}
  371. // 关系
  372. {{range .Columns}}
  373. {{- if ne .FkTableName "" -}}
  374. get{{.FkTableNameClass}}Items() {
  375. this.getItems(list{{.FkTableNameClass}}, undefined).then(res => {
  376. this.{{.JsonField}}Options = this.setItems(res, '{{.FkLabelId}}', '{{.FkLabelName}}')
  377. })
  378. },
  379. {{ end -}}
  380. {{- end -}}
  381. // 文件
  382. {{range .Columns}}
  383. {{- if eq .HtmlType "file" -}}
  384. fileShow{{.GoField}}: function() {
  385. this.fileOpen = true
  386. this.fileIndex = '{{.JsonField}}'
  387. },
  388. {{ end -}}
  389. {{- end -}}
  390. /** 搜索按钮操作 */
  391. handleQuery() {
  392. this.queryParams.pageIndex = 1
  393. this.getList()
  394. },
  395. /** 重置按钮操作 */
  396. resetQuery() {
  397. this.dateRange = []
  398. this.resetForm('queryForm')
  399. this.handleQuery()
  400. },
  401. /** 新增按钮操作 */
  402. handleAdd() {
  403. this.reset()
  404. this.open = true
  405. this.title = '添加{{.TableComment}}'
  406. this.isEdit = false
  407. },
  408. // 多选框选中数据
  409. handleSelectionChange(selection) {
  410. this.ids = selection.map(item => item.{{.PkJsonField}})
  411. this.single = selection.length !== 1
  412. this.multiple = !selection.length
  413. },
  414. /** 修改按钮操作 */
  415. handleUpdate(row) {
  416. this.reset()
  417. const {{.PkJsonField}} =
  418. row.{{.PkJsonField}} || this.ids
  419. get{{.ClassName}}({{.PkJsonField}}).then(response => {
  420. this.form = response.data
  421. this.open = true
  422. this.title = '修改{{.TableComment}}'
  423. this.isEdit = true
  424. })
  425. },
  426. /** 提交按钮 */
  427. submitForm: function () {
  428. this.$refs['form'].validate(valid => {
  429. if (valid) {
  430. if (this.form.{{.PkJsonField}} !== undefined) {
  431. update{{.ClassName}}(this.form).then(response => {
  432. if (response.code === 200) {
  433. this.msgSuccess(response.msg)
  434. this.open = false
  435. this.getList()
  436. } else {
  437. this.msgError(response.msg)
  438. }
  439. })
  440. } else {
  441. add{{.ClassName}}(this.form).then(response => {
  442. if (response.code === 200) {
  443. this.msgSuccess(response.msg)
  444. this.open = false
  445. this.getList()
  446. } else {
  447. this.msgError(response.msg)
  448. }
  449. })
  450. }
  451. }
  452. })
  453. },
  454. /** 删除按钮操作 */
  455. handleDelete(row) {
  456. var Ids = (row.{{.PkJsonField}} && [row.{{.PkJsonField}}]) || this.ids
  457. this.$confirm('是否确认删除编号为"' + Ids + '"的数据项?', '警告', {
  458. confirmButtonText: '确定',
  459. cancelButtonText: '取消',
  460. type: 'warning'
  461. }).then(function () {
  462. return del{{.ClassName}}( { 'ids': Ids })
  463. }).then((response) => {
  464. if (response.code === 200) {
  465. this.msgSuccess(response.msg)
  466. this.open = false
  467. this.getList()
  468. } else {
  469. this.msgError(response.msg)
  470. }
  471. }).catch(function () {
  472. })
  473. }
  474. }
  475. }
  476. </script>