Commit 2e94cca6cced7a95293bec70f66eec3fa6fd48ec
1 parent
bf7244a8
Exists in
master
and in
1 other branch
完成Scheme组件删除逻辑
Showing
2 changed files
with
62 additions
and
9 deletions
Show diff stats
examples/views/page/test.vue
| @@ -6,7 +6,9 @@ | @@ -6,7 +6,9 @@ | ||
| 6 | :detailProps="{ span: 24, 'label-width': '50px' }" | 6 | :detailProps="{ span: 24, 'label-width': '50px' }" |
| 7 | :dialogProps="dialogProps" | 7 | :dialogProps="dialogProps" |
| 8 | @dialog-change="handleDialogChange" | 8 | @dialog-change="handleDialogChange" |
| 9 | - ></eagle-scheme> | 9 | + > |
| 10 | + <el-table-column type="selection" width="50"></el-table-column> | ||
| 11 | + </eagle-scheme> | ||
| 10 | </template> | 12 | </template> |
| 11 | 13 | ||
| 12 | <script> | 14 | <script> |
| @@ -75,6 +77,15 @@ export default { | @@ -75,6 +77,15 @@ export default { | ||
| 75 | return false; | 77 | return false; |
| 76 | }); | 78 | }); |
| 77 | }, | 79 | }, |
| 80 | + async deleteAPI(param) { | ||
| 81 | + return this.$axios.post('/dataDictionary/delete', param) | ||
| 82 | + .then((response) => { | ||
| 83 | + const { success = false } = response || {}; | ||
| 84 | + return success; | ||
| 85 | + }).catch(() => { | ||
| 86 | + return false; | ||
| 87 | + }); | ||
| 88 | + }, | ||
| 78 | handleDialogChange(type) { | 89 | handleDialogChange(type) { |
| 79 | this.dialogType = type; | 90 | this.dialogType = type; |
| 80 | } | 91 | } |
packages/scheme/index.vue
| @@ -332,8 +332,8 @@ export default { | @@ -332,8 +332,8 @@ export default { | ||
| 332 | }, | 332 | }, |
| 333 | // 查询单项数据详情 | 333 | // 查询单项数据详情 |
| 334 | async doDetail(param) { | 334 | async doDetail(param) { |
| 335 | - const { primaryKey = 'id', detailPrimaryKey } = this.option || {}; | ||
| 336 | - if (this.option.detailAPI) { // 配置了自定义查询API的情况 | 335 | + const { primaryKey = 'id', detailPrimaryKey, detailRow = false } = this.option || {}; |
| 336 | + if (this.option.detailAPI && !detailRow) { // 配置了自定义查询API的情况 | ||
| 337 | console.log('detailAPI'); | 337 | console.log('detailAPI'); |
| 338 | this.dialogLoading = true; | 338 | this.dialogLoading = true; |
| 339 | try { | 339 | try { |
| @@ -344,7 +344,7 @@ export default { | @@ -344,7 +344,7 @@ export default { | ||
| 344 | } finally { | 344 | } finally { |
| 345 | this.dialogLoading = false; | 345 | this.dialogLoading = false; |
| 346 | } | 346 | } |
| 347 | - } else if (_$http && this.option.url) { // 给定了http的情况 | 347 | + } else if (_$http && this.option.url && !detailRow) { // 给定了http的情况 |
| 348 | console.log('_$http detail'); | 348 | console.log('_$http detail'); |
| 349 | this.dialogLoading = true; | 349 | this.dialogLoading = true; |
| 350 | const defaultDetailMethod = `info/${detailPrimaryKey || primaryKey}/${param[detailPrimaryKey] || param[primaryKey]}`; | 350 | const defaultDetailMethod = `info/${detailPrimaryKey || primaryKey}/${param[detailPrimaryKey] || param[primaryKey]}`; |
| @@ -358,9 +358,7 @@ export default { | @@ -358,9 +358,7 @@ export default { | ||
| 358 | this.dialogLoading = false; | 358 | this.dialogLoading = false; |
| 359 | }); | 359 | }); |
| 360 | } else { | 360 | } else { |
| 361 | - this.dialogLoading = true; | ||
| 362 | this.setFormModel(param); | 361 | this.setFormModel(param); |
| 363 | - setTimeout(() => { this.dialogLoading = false; }, 1500); | ||
| 364 | } | 362 | } |
| 365 | }, | 363 | }, |
| 366 | // 新增按钮 | 364 | // 新增按钮 |
| @@ -420,9 +418,54 @@ export default { | @@ -420,9 +418,54 @@ export default { | ||
| 420 | // 删除按钮 | 418 | // 删除按钮 |
| 421 | handleDelete(type, scope) { | 419 | handleDelete(type, scope) { |
| 422 | if (type === 'one') { | 420 | if (type === 'one') { |
| 423 | - console.log(type, [scope.row]); | 421 | + this.doDelete([scope.row]); |
| 424 | } else if (type === 'more') { | 422 | } else if (type === 'more') { |
| 425 | - console.log(type, this.tableSelection); | 423 | + this.$confirm(`是否删除已选中的 [ ${this.tableSelection.length} ] 项`, '提示', { |
| 424 | + confirmButtonText: '确定', | ||
| 425 | + cancelButtonText: '取消', | ||
| 426 | + type: 'warning' | ||
| 427 | + }).then(() => { | ||
| 428 | + this.doDelete(this.tableSelection || []); | ||
| 429 | + }).catch(() => { | ||
| 430 | + // 取消的操作 | ||
| 431 | + }); | ||
| 432 | + } | ||
| 433 | + }, | ||
| 434 | + // 删除数据 | ||
| 435 | + async doDelete(selection) { | ||
| 436 | + const { primaryKey = 'id', deletePrimaryKey } = this.option || {}; | ||
| 437 | + const param = selection.map(item => item[deletePrimaryKey || primaryKey]); | ||
| 438 | + if (this.option.deleteAPI) { // 配置了自定义删除API的情况 | ||
| 439 | + console.log('deleteAPI'); | ||
| 440 | + this.dialogLoading = true; | ||
| 441 | + try { | ||
| 442 | + const success = await this.option.deleteAPI(param, selection); | ||
| 443 | + if (success) { | ||
| 444 | + this.hideDialog(); | ||
| 445 | + this.handleSearch(); | ||
| 446 | + if (this.$message) { this.$message({ message: '删除成功', type: 'success' }); } | ||
| 447 | + } | ||
| 448 | + } catch (error) { | ||
| 449 | + console.error(error); | ||
| 450 | + } finally { | ||
| 451 | + this.dialogLoading = false; | ||
| 452 | + } | ||
| 453 | + } else if (_$http && this.option.url) { // 给定了http的情况 | ||
| 454 | + console.log('_$http delete'); | ||
| 455 | + this.dialogLoading = true; | ||
| 456 | + const postData = param; | ||
| 457 | + _$http.post(`${this.option.url.trim('/')}/${this.option.newMethod || 'delete'}`, postData) | ||
| 458 | + .then(response => { | ||
| 459 | + const { success = false } = response || {}; | ||
| 460 | + if (success) { | ||
| 461 | + this.hideDialog(); | ||
| 462 | + this.handleSearch(); | ||
| 463 | + if (this.$message) { this.$message({ message: '删除成功', type: 'success' }); } | ||
| 464 | + } | ||
| 465 | + }) | ||
| 466 | + .finally(() => { | ||
| 467 | + this.dialogLoading = false; | ||
| 468 | + }); | ||
| 426 | } | 469 | } |
| 427 | }, | 470 | }, |
| 428 | // 设置表单值 | 471 | // 设置表单值 |
| @@ -533,7 +576,6 @@ export default { | @@ -533,7 +576,6 @@ export default { | ||
| 533 | // 表格选择 | 576 | // 表格选择 |
| 534 | handleTableSelectionChange(selection) { | 577 | handleTableSelectionChange(selection) { |
| 535 | this.tableSelection = selection; | 578 | this.tableSelection = selection; |
| 536 | - console.log(selection); | ||
| 537 | }, | 579 | }, |
| 538 | // 显示弹出框 | 580 | // 显示弹出框 |
| 539 | showDialog() { | 581 | showDialog() { |