From e045626b5c3daff565b3db687faf76d11b42c594 Mon Sep 17 00:00:00 2001 From: Harry Yang Date: Wed, 4 Jan 2023 20:08:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B7=B2=E5=8A=9E=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/business/process-completed.ftl | 110 +++++++++++------- 1 file changed, 70 insertions(+), 40 deletions(-) diff --git a/src/main/resources/templates/admin/business/process-completed.ftl b/src/main/resources/templates/admin/business/process-completed.ftl index 3c5541a..0d789b6 100644 --- a/src/main/resources/templates/admin/business/process-completed.ftl +++ b/src/main/resources/templates/admin/business/process-completed.ftl @@ -189,6 +189,21 @@ return !isBlank(obj) } + function checkStatus(response) { + if (response.status >= 200 && response.status < 300) { + return response + } + else { + const error = new Error(response.statusText); + error.response = response + throw error + } + } + + function parseJSON(response) { + return response.json() + } + const data = () => { return { auditForm: { @@ -228,22 +243,23 @@ fetch("${base}/process/" + row.id, { method: 'DELETE', // or 'PUT' - }).then(response => { - if (response.ok) { - this.queryTable() - this.$message({ - showClose: true, - message: '删除成功', - type: 'success' - }) + }).then(checkStatus).then(response => { + this.queryTable() + this.$message({ + showClose: true, + message: '删除成功', + type: 'success' + }) + }).catch(({ response }) => { + if (response) { + parseJSON(response) + .then(json => { + this.$message.error(json.message || "删除失败") + }) } else { - return Promise.reject(response) + this.$message.error("删除失败") } - }).catch(res => { - res.json().then(json => { - this.$message.error(json.message || "删除失败"); - }) }).finally(() => loading.close()) }).catch(() => { this.$message({ @@ -267,20 +283,23 @@ fetch("${base}/process/revoke/" + row.id, { method: 'POST', // or 'PUT' - }).then(response => { - if (response.ok) { - this.queryTable() - this.$message({ - showClose: true, - message: '撤销成功', - type: 'success' - }) + }).then(checkStatus).then(response => { + this.queryTable() + this.$message({ + showClose: true, + message: '撤销成功', + type: 'success' + }) + }).catch(({ response }) => { + if (response) { + parseJSON(response) + .then(json => { + this.$message.error(json.message || "撤销失败") + }) } else { - return Promise.reject(response) + this.$message.error("撤销失败") } - }).catch(err => { - this.$message.error("撤销失败"); }).finally(() => loading.close()) }).catch(() => { this.$message({ @@ -297,22 +316,25 @@ background: 'rgba(0, 0, 0, 0.7)' }) - fetch("${base}/process/audits/" + row.id).then(response => { - if (response.ok) { - // 展示弹窗 - response.json().then(json => { + fetch("${base}/process/audits/" + row.id) + .then(checkStatus) + .then(parseJSON) + .then(json => { + // 展示弹窗 this.auditDetailVisible = true this.auditDetails = json }) - } - else { - return Promise.reject(response) - } - }).catch(res => { - res.json().then(json => { - this.$message.error(json.message || "数据获取失败"); - }) - }).finally(() => loading.close()) + .catch(({ response }) => { + if (response) { + parseJSON(response) + .then(json => { + this.$message.error(json.message || "数据获取失败") + }) + } + else { + this.$message.error("数据获取失败") + } + }).finally(() => loading.close()) }, @@ -334,7 +356,7 @@ 'Content-Type': 'application/json', }, body: JSON.stringify(form), - }).then(response => { + }).then(checkStatus).then(response => { this.$message({ showClose: true, message: '审核成功', @@ -342,8 +364,16 @@ }) // 关闭对话框 this.auditFormVisible = false - }).catch(err => { - this.$message.error("审核失败"); + }).catch(({ response }) => { + if (response) { + parseJSON(response) + .then(json => { + this.$message.error(json.message || "审核失败") + }) + } + else { + this.$message.error("审核失败") + } }).finally(() => loading.close()) } else {