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:
@@ -88,8 +88,9 @@ export const markMessageRead = (msgId) => request.put(`/business/message/read/${
|
||||
export const markAllMessagesRead = () => request.put('/business/message/readAll')
|
||||
|
||||
export const bizGet = (entity, id) => request.get(`/business/${entity}/${id}`)
|
||||
export const bizAdd = (entity, data) => request.post(`/business/${entity}`, data)
|
||||
export const bizUpdate = (entity, data) => request.put(`/business/${entity}`, data)
|
||||
// opts 透传给 request (例如 { __silentError: true } 让拦截器不自动 toast, 由调用方控制)
|
||||
export const bizAdd = (entity, data, opts) => request.post(`/business/${entity}`, data, opts)
|
||||
export const bizUpdate = (entity, data, opts) => request.put(`/business/${entity}`, data, opts)
|
||||
export const bizDelete = (entity, ids) => request.delete(`/business/${entity}/${ids}`)
|
||||
|
||||
// 人员批量导入 (unitType: 'sponsor' | 'executor')
|
||||
|
||||
@@ -34,11 +34,16 @@ request.interceptors.response.use(
|
||||
localStorage.removeItem('ry_user')
|
||||
window.location.href = '/#/login'
|
||||
}
|
||||
ElMessage.error(data?.msg || '请求失败')
|
||||
return Promise.reject(new Error(data?.msg || '请求失败'))
|
||||
// __silentError: 调用方已经接管错误 toast (如把红错改成黄警), 拦截器不再重复弹
|
||||
if (!res.config?.__silentError) {
|
||||
ElMessage.error(data?.msg || '请求失败')
|
||||
}
|
||||
return Promise.reject(Object.assign(new Error(data?.msg || '请求失败'), { msg: data?.msg, code: data?.code, silentError: !!res.config?.__silentError }))
|
||||
},
|
||||
(err) => {
|
||||
ElMessage.error(err.message || '网络错误')
|
||||
if (!err.config?.__silentError) {
|
||||
ElMessage.error(err.message || '网络错误')
|
||||
}
|
||||
return Promise.reject(err)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -289,19 +289,19 @@ async function onSave() {
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = { ...form }
|
||||
if (isEdit) {
|
||||
// 编辑: 不改 expertId 主键, 也不重置 auditStatus
|
||||
delete payload.expertId
|
||||
} else {
|
||||
if (!isEdit) {
|
||||
// 新建: admin 创建, 自动通过审核 (BizAuditStatusEnum.APPROVED='2'), 状态正常
|
||||
// 注意: 不要把 expertId 也删掉, 后端 updateByPrimaryKey / insert 都依赖 expert_id
|
||||
payload.auditStatus = '2'
|
||||
payload.auditBy = userStore.user?.userName || userStore.user?.nickName || 'admin'
|
||||
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) {
|
||||
// 新建成功: 后端同时创建 sys_user, 提示账号信息
|
||||
|
||||
@@ -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