index.vue.stub 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="app-container">
  3. <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
  4. <el-form-item>
  5. <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
  6. </el-form-item>
  7. <el-form-item>
  8. <el-button @click="getDataList()">查询</el-button>
  9. <el-button v-if="isAuth('{%moduleName%}:{%className%}:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
  10. <el-button v-if="isAuth('{%moduleName%}:{%className%}:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
  11. </el-form-item>
  12. </el-form>
  13. <el-table
  14. :data="dataList"
  15. border
  16. v-loading="dataListLoading"
  17. @selection-change="selectionChangeHandle"
  18. style="width: 100%;">
  19. <el-table-column
  20. type="selection"
  21. header-align="center"
  22. align="center"
  23. width="50">
  24. </el-table-column>
  25. {%schemas%}
  26. <el-table-column
  27. fixed="right"
  28. header-align="center"
  29. align="center"
  30. width="150"
  31. label="操作">
  32. <template slot-scope="scope">
  33. <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.{%primarykey%})">修改</el-button>
  34. <el-button type="text" size="small" @click="deleteHandle(scope.row.{%primarykey%})">删除</el-button>
  35. </template>
  36. </el-table-column>
  37. </el-table>
  38. <el-pagination
  39. @size-change="sizeChangeHandle"
  40. @current-change="currentChangeHandle"
  41. :current-page="pageIndex"
  42. :page-sizes="[10, 20, 50, 100]"
  43. :page-size="pageSize"
  44. :total="totalPage"
  45. layout="total, sizes, prev, pager, next, jumper">
  46. </el-pagination>
  47. <!-- 弹窗, 新增 / 修改 -->
  48. <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  49. </div>
  50. </template>
  51. <script>
  52. import AddOrUpdate from './{%className%}-add-or-update'
  53. export default {
  54. data () {
  55. return {
  56. dataForm: {
  57. key: ''
  58. },
  59. dataList: [],
  60. pageIndex: 1,
  61. pageSize: 10,
  62. totalPage: 0,
  63. dataListLoading: false,
  64. dataListSelections: [],
  65. addOrUpdateVisible: false
  66. }
  67. },
  68. components: {
  69. AddOrUpdate
  70. },
  71. activated () {
  72. this.getDataList()
  73. },
  74. methods: {
  75. // 获取数据列表
  76. getDataList () {
  77. this.dataListLoading = true
  78. this.$http({
  79. url: this.$http.adornUrl('/{%moduleName%}/{%className%}/index'),
  80. method: 'get',
  81. params: this.$http.adornParams({
  82. 'page': this.pageIndex,
  83. 'limit': this.pageSize,
  84. 'key': this.dataForm.key
  85. })
  86. }).then(({res}) => {
  87. if (res && res.code === 0) {
  88. this.dataList = res.data.data
  89. this.totalPage = res.data.total
  90. } else {
  91. this.dataList = []
  92. this.totalPage = 0
  93. }
  94. this.dataListLoading = false
  95. })
  96. },
  97. // 每页数
  98. sizeChangeHandle (val) {
  99. this.pageSize = val
  100. this.pageIndex = 1
  101. this.getDataList()
  102. },
  103. // 当前页
  104. currentChangeHandle (val) {
  105. this.pageIndex = val
  106. this.getDataList()
  107. },
  108. // 多选
  109. selectionChangeHandle (val) {
  110. this.dataListSelections = val
  111. },
  112. // 新增 / 修改
  113. addOrUpdateHandle (id) {
  114. this.addOrUpdateVisible = true
  115. this.$nextTick(() => {
  116. this.$refs.addOrUpdate.init(id)
  117. })
  118. },
  119. // 删除
  120. deleteHandle (id) {
  121. var ids = id ? [id] : this.dataListSelections.map(item => {
  122. return item.{%primarykey%}
  123. })
  124. this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
  125. confirmButtonText: '确定',
  126. cancelButtonText: '取消',
  127. type: 'warning'
  128. }).then(() => {
  129. this.$http({
  130. url: this.$http.adornUrl('/{%moduleName%}/{%className%}/delete'),
  131. method: 'post',
  132. data: this.$http.adornData(ids, false)
  133. }).then(({data}) => {
  134. if (data && data.code === 0) {
  135. this.$message({
  136. message: '操作成功',
  137. type: 'success',
  138. duration: 1500,
  139. onClose: () => {
  140. this.getDataList()
  141. }
  142. })
  143. } else {
  144. this.$message.error(data.msg)
  145. }
  146. })
  147. }).catch(() => {})
  148. }
  149. }
  150. }
  151. </script>