fix(expert): 编辑保存失败 Updates:0 + 错误 toast 弹两次
两个根因:
1. 后端 Updates: 0
- ExpertNew.vue (admin+manager) onSave 编辑分支里 delete payload.expertId
- 后端 BizExpertMapper.updateByPrimaryKey 是 where expert_id = #{expertId}
- 没有 expertId → WHERE 不匹配 → 0 updates → 抛 "操作失败" 500
- 修复: 不再 delete expertId (后端 insert/update 都依赖该字段)
2. 前端操作失败弹两次
- request.js 响应拦截器在 code != 200 时自动 ElMessage.error
- onSave 的 catch 又 ElMessage.error 一次
- 修复: 加 __silentError 请求配置项, 拦截器遇此 flag 不自动 toast
- api/public.js bizAdd/bizUpdate 加第 3 参数 opts 透传给 request
- ExpertNew.vue onSave 调用时传 __silentError: true, 由 catch 块按业务语义
决定 黄警 (手机号重复) 还是 红错 (其它)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -272,18 +272,19 @@ async function onSave() {
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = { ...form }
|
||||
if (isEdit) {
|
||||
delete payload.expertId
|
||||
} else {
|
||||
// manager 创建专家: 自动通过审核, 状态正常
|
||||
if (!isEdit) {
|
||||
// 新建: manager 创建专家, 自动通过审核, 状态正常
|
||||
// 注意: 不要把 expertId 也删掉, 后端 updateByPrimaryKey / insert 都依赖 expert_id
|
||||
payload.auditStatus = '2'
|
||||
payload.auditBy = userStore.user?.userName || userStore.user?.nickName || 'manager'
|
||||
payload.auditTime = new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
payload.status = 'Y'
|
||||
}
|
||||
// __silentError: 拦截器不自动 toast, 由本组件根据业务语义选择 黄警 (重复) / 红错 (其它)
|
||||
const opts = { __silentError: true }
|
||||
const res = isEdit
|
||||
? await bizUpdate('expert', payload)
|
||||
: await bizAdd('expert', payload)
|
||||
? await bizUpdate('expert', payload, opts)
|
||||
: await bizAdd('expert', payload, opts)
|
||||
if (res?.code === 200) {
|
||||
if (!isEdit && res.data) {
|
||||
const u = res.data
|
||||
|
||||
Reference in New Issue
Block a user