Skip to content

Commit 52e7f93

Browse files
tknsnail
authored andcommitted
fix: 🐛 scTable dataChanged
1 parent 81ac00d commit 52e7f93

File tree

1 file changed

+40
-37
lines changed
  • src/frontend/admin/src/components/scTable

1 file changed

+40
-37
lines changed

src/frontend/admin/src/components/scTable/index.vue

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ export default {
325325
}
326326
//判断是否静态数据
327327
if (this.queryApi) {
328-
const res = await this.getData()
329-
this.$emit('dataChange', res, this.tableData)
328+
await this.getData()
330329
} else if (this.data) {
331330
this.tableData = this.data
332331
this.total = this.tableData.length
@@ -460,44 +459,48 @@ export default {
460459
},
461460
//获取数据
462461
async getData() {
463-
this.loading = true
462+
const ret = await (async () => {
463+
this.loading = true
464464
465-
let res
466-
let response
467-
try {
468-
const reqData = this.getQueryParams()
469-
if (!this.beforePost || this.beforePost(reqData)) res = await this.queryApi.post(reqData)
470-
} catch (error) {
471-
this._clearData()
472-
this.loading = false
473-
this.emptyText = error.statusText
474-
return false
475-
}
476-
try {
477-
response = config.parseData(res)
478-
} catch (error) {
479-
this._clearData()
480-
this.loading = false
481-
this.emptyText = '数据格式错误'
482-
return false
483-
}
484-
if (response.code !== config.successCode) {
485-
this._clearData()
486-
this.loading = false
487-
this.emptyText = response.msg
488-
} else {
489-
this.emptyText = '暂无数据'
490-
if (this.hidePagination) {
491-
this.tableData = response.data || []
465+
let res
466+
let response
467+
try {
468+
const reqData = this.getQueryParams()
469+
if (!this.beforePost || this.beforePost(reqData)) res = await this.queryApi.post(reqData)
470+
} catch (error) {
471+
this._clearData()
472+
this.loading = false
473+
this.emptyText = error.statusText
474+
return false
475+
}
476+
try {
477+
response = config.parseData(res)
478+
} catch (error) {
479+
this._clearData()
480+
this.loading = false
481+
this.emptyText = '数据格式错误'
482+
return false
483+
}
484+
if (response.code !== config.successCode) {
485+
this._clearData()
486+
this.loading = false
487+
this.emptyText = response.msg
492488
} else {
493-
this.tableData = response.rows || []
489+
this.emptyText = '暂无数据'
490+
if (this.hidePagination) {
491+
this.tableData = response.data || []
492+
} else {
493+
this.tableData = response.rows || []
494+
}
495+
this.total = response.total || 0
496+
this.summary = response.summary || {}
497+
this.loading = false
494498
}
495-
this.total = response.total || 0
496-
this.summary = response.summary || {}
497-
this.loading = false
498-
}
499-
this.$refs.scTable?.setScrollTop(0)
500-
return res
499+
this.$refs.scTable?.setScrollTop(0)
500+
return res
501+
})()
502+
503+
this.$emit('dataChange', ret, this.tableData)
501504
},
502505
//清空数据
503506
_clearData() {

0 commit comments

Comments
 (0)