index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!--
  2. * @Descripttion: 此文件由SCUI生成,典型的VUE增删改列表页面组件
  3. * @version: 1.0
  4. * @Author: SCUI AutoCode 模板版本 1.0.0-beta.1
  5. * @Date: <%= createDate %>
  6. * @LastEditors: (最后更新作者)
  7. * @LastEditTime: (最后更新时间)
  8. -->
  9. <template>
  10. <el-container>
  11. <el-header>
  12. <div class="left-panel">
  13. <el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
  14. <el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length==0" @click="batch_del"></el-button>
  15. </div>
  16. <div class="right-panel">
  17. <div class="right-panel-search">
  18. <el-input v-model="search.keyword" placeholder="关键词搜索" clearable></el-input>
  19. <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
  20. </div>
  21. </div>
  22. </el-header>
  23. <el-main class="nopadding">
  24. <scTable ref="table" :apiObj="apiObj" row-key="<%= base.rowKey %>" @selection-change="selectionChange">
  25. <el-table-column type="selection" width="50"></el-table-column>
  26. <% column.forEach(function(item, index){ %>
  27. <el-table-column label="<%= item.label %>" prop="<%= item.prop %>" width="<%= item.width %>"></el-table-column>
  28. <% })%>
  29. <el-table-column label="操作" fixed="right" align="right" width="140">
  30. <template #default="scope">
  31. <el-button type="text" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
  32. <el-button type="text" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
  33. <el-popconfirm title="确定删除吗?" @confirm="table_del(scope.row, scope.$index)">
  34. <template #reference>
  35. <el-button type="text" size="small">删除</el-button>
  36. </template>
  37. </el-popconfirm>
  38. </template>
  39. </el-table-column>
  40. </scTable>
  41. </el-main>
  42. </el-container>
  43. <el-dialog :title="titleMap[saveMode]" v-model="saveDialogVisible" :width="500" destroy-on-close>
  44. <save-dialog ref="saveDialog" :mode="saveMode"></save-dialog>
  45. <template #footer>
  46. <el-button @click="saveDialogVisible=false" >取 消</el-button>
  47. <el-button v-if="saveMode!='show'" type="primary" @click="saveForm()" :loading="isSaveing">保 存</el-button>
  48. </template>
  49. </el-dialog>
  50. </template>
  51. <script>
  52. import saveDialog from './save'
  53. export default {
  54. name: '<%= base.name %>',
  55. components: {
  56. saveDialog
  57. },
  58. data() {
  59. return {
  60. apiObj: this.$API.<%= api.list %>,
  61. selection: [],
  62. search: {
  63. keyword: ""
  64. },
  65. saveDialogVisible: false,
  66. saveMode: 'add',
  67. titleMap: {
  68. add: "新增",
  69. edit: "编辑",
  70. show: "查看"
  71. },
  72. isSaveing: false,
  73. }
  74. },
  75. mounted(){
  76. },
  77. methods: {
  78. //添加
  79. add(){
  80. this.saveMode = 'add';
  81. this.saveDialogVisible = true;
  82. },
  83. //编辑
  84. table_edit(row){
  85. this.saveMode = 'edit';
  86. this.saveDialogVisible = true;
  87. this.$nextTick(() => {
  88. //这里可以再次根据ID查询详情接口
  89. this.$refs.saveDialog.setData(row)
  90. })
  91. },
  92. //查看
  93. table_show(row){
  94. this.saveMode = 'show';
  95. this.saveDialogVisible = true;
  96. this.$nextTick(() => {
  97. //这里可以再次根据ID查询详情接口
  98. this.$refs.saveDialog.setData(row)
  99. })
  100. },
  101. //删除
  102. async table_del(row, index){
  103. var reqData = {id: row.id}
  104. var res = await this.$API.<%= api.del %>.post(reqData);
  105. if(res.code == 200){
  106. //这里选择刷新整个表格 OR 插入/编辑现有表格数据
  107. this.$refs.table.tableData.splice(index, 1);
  108. this.$message.success("删除成功")
  109. }else{
  110. this.$alert(res.message, "提示", {type: 'error'})
  111. }
  112. },
  113. //批量删除
  114. async batch_del(){
  115. this.$confirm(`确定删除选中的 ${this.selection.length} 项吗?`, '提示', {
  116. type: 'warning'
  117. }).then(() => {
  118. const loading = this.$loading();
  119. this.selection.forEach(item => {
  120. this.$refs.table.tableData.forEach((itemI, indexI) => {
  121. if (item.id === itemI.id) {
  122. this.$refs.table.tableData.splice(indexI, 1)
  123. }
  124. })
  125. })
  126. loading.close();
  127. this.$message.success("操作成功")
  128. }).catch(() => {
  129. })
  130. },
  131. //提交
  132. saveForm(){
  133. this.$refs.saveDialog.submit(async (formData) => {
  134. this.isSaveing = true;
  135. var res = await this.$API.<%= api.save %>.post(formData);
  136. this.isSaveing = false;
  137. if(res.code == 200){
  138. //这里选择刷新整个表格 OR 插入/编辑现有表格数据
  139. this.saveDialogVisible = false;
  140. this.$message.success("操作成功")
  141. }else{
  142. this.$alert(res.message, "提示", {type: 'error'})
  143. }
  144. })
  145. },
  146. //表格选择后回调事件
  147. selectionChange(selection){
  148. this.selection = selection;
  149. },
  150. //搜索
  151. upsearch(){
  152. }
  153. }
  154. }
  155. </script>
  156. <style>
  157. </style>