From b35beae5dfcec7130e11015423482583fc9fbeb3 Mon Sep 17 00:00:00 2001 From: zou Date: Wed, 2 Sep 2026 11:34:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(good):=20=E5=95=86=E5=93=81=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8/=E4=B8=8A=E4=B8=8B=E6=9E=B6/=E6=94=B9=E5=88=86?= =?UTF-8?q?=E7=B1=BB/=E5=88=A0=E9=99=A4=E8=AF=AF=E6=8A=A5=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=A4=B1=E8=B4=A5=E2=80=94=E2=80=94httpGet/httpPost?= =?UTF-8?q?=20=E5=B7=B2=E8=A7=A3=E5=8C=85=20data=EF=BC=8Cr=3F.code=3D=3D?= =?UTF-8?q?=3D0=20=E6=81=92=20false=EF=BC=9B=E6=94=B9=20isOk=20=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E5=AF=B9=E8=B1=A1/=E5=B8=83=E5=B0=94/null=EF=BC=88?= =?UTF-8?q?=E5=90=8C=E7=B1=BB=E4=BF=AE=E5=A4=8D=20CompanyAccountListView?= =?UTF-8?q?=20=E6=8E=A5=E7=AE=A1/=E8=A7=A3=E7=BB=91=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/openapi/CompanyAccountListView.vue | 10 ++++++++-- src/modules/supplier/good/GoodListView.vue | 14 ++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/modules/openapi/CompanyAccountListView.vue b/src/modules/openapi/CompanyAccountListView.vue index 9bd297b..b1fca35 100644 --- a/src/modules/openapi/CompanyAccountListView.vue +++ b/src/modules/openapi/CompanyAccountListView.vue @@ -49,6 +49,12 @@ const STATUS_MAP: Record = { 0: { label: '已停用', type: 'info' } } +// httpGet/httpPost 已解包 code===0 的业务 data(拦截器已 reject 非 0 code), +// 拿到值即为成功;兼容对象/布尔/null 返回(与 InquiryDetailView 修复同源) +function isOk(r: any) { + return !(r && typeof r === 'object' && 'code' in r && Number(r.code) !== 0) +} + const list = ref([]) const total = ref(0) const loading = ref(false) @@ -200,7 +206,7 @@ async function takeoverConfirm() { } try { const res = await httpPost('/sys/openapi/company/takeover', { ...takeoverForm }) - if (res?.code !== 0) { + if (!isOk(res)) { ElMessage.error(res?.msg || '接管失败') return } @@ -224,7 +230,7 @@ function unbindHandle(row: CompanyAccount) { id: Number(row.id), reason: '管理员解绑' }) - if (res?.code !== 0) { + if (!isOk(res)) { ElMessage.error(res?.msg || '解绑失败') return } diff --git a/src/modules/supplier/good/GoodListView.vue b/src/modules/supplier/good/GoodListView.vue index ff717be..eca9dc3 100644 --- a/src/modules/supplier/good/GoodListView.vue +++ b/src/modules/supplier/good/GoodListView.vue @@ -134,6 +134,12 @@ const batchCategoryDialogVisible = ref(false) const batchRejectDialogVisible = ref(false) const batchRejectForm = reactive({ reason: '' }) +// httpGet/httpPost 已解包 code===0 的业务 data(拦截器已 reject 非 0 code), +// 拿到值即为成功;兼容对象/布尔/null 返回(与 InquiryDetailView 修复同源) +function isOk(r: any) { + return !(r && typeof r === 'object' && 'code' in r && Number(r.code) !== 0) +} + const columns = [ { type: 'selection' as const, label: '', width: 50 }, { prop: 'supplierGoodId', label: '商品ID', width: 100 }, @@ -253,7 +259,7 @@ async function onSubmitCheck() { checkStatus: checkForm.checkStatus, checkOpinion: checkForm.checkOpinion || '' }) - if (r?.code === 0) { + if (isOk(r)) { ElMessage.success(checkForm.checkStatus === 2 ? '审核通过' : '已驳回') checkDialogVisible.value = false load() @@ -266,7 +272,7 @@ async function onOnShelf(row: Good) { try { await ElMessageBox.confirm(`确认${row.onShelf === 1 ? '下架' : '上架'}「${row.title}」?`, '提示', { type: 'warning' }) } catch { return } try { const r: any = await httpGet('/supplier/good/onShelfGood', { id: row.id }) - if (r?.code === 0) { ElMessage.success(row.onShelf === 1 ? '已下架' : '已上架'); load() } + if (isOk(r)) { ElMessage.success(row.onShelf === 1 ? '已下架' : '已上架'); load() } else ElMessage.error(r?.msg || '操作失败') } catch (e: any) { ElMessage.error(e?.msg || e?.message || '操作失败') } } @@ -279,7 +285,7 @@ async function onSubmitCategory() { secondCategoryId: categoryForm.secondCategoryId || undefined, thirdCategoryId: categoryForm.thirdCategoryId || undefined }) - if (r?.code === 0) { ElMessage.success('分类已修改'); categoryDialogVisible.value = false; load() } + if (isOk(r)) { ElMessage.success('分类已修改'); categoryDialogVisible.value = false; load() } else ElMessage.error(r?.msg || '操作失败') } catch (e: any) { ElMessage.error(e?.msg || e?.message || '操作失败') } } @@ -287,7 +293,7 @@ async function onDelete(row: Good) { try { await ElMessageBox.confirm(`确认删除「${row.title}」?`, '提示', { type: 'warning' }) } catch { return } try { const r: any = await httpGet('/supplier/good/delete', { id: row.id }) - if (r?.code === 0) { ElMessage.success('已删除'); load() } + if (isOk(r)) { ElMessage.success('已删除'); load() } else ElMessage.error(r?.msg || '操作失败') } catch (e: any) { ElMessage.error(e?.msg || e?.message || '操作失败') } }