vue.go.template 21 KB

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