diff --git a/src/views/group-management-view.jsx b/src/views/group-management-view.jsx index f6557e76..c62984b8 100644 --- a/src/views/group-management-view.jsx +++ b/src/views/group-management-view.jsx @@ -1199,12 +1199,21 @@ function MyNicknameEditor({topic, onToast}) { const [value, setValue] = React.useState(''); // getGroupMembers' list items never include group_nickname (confirmed live) -- only // GET .../members/me/profile actually returns it, same fix as GroupProfile's preview row above. + // 同一个 GET 实测确认真的带 version 字段(不是空字符串/undefined),但这里原来保存时 + // 一直硬编码 version:0——跟本文件其余"编辑单个字段+乐观锁"的写法(GroupNameEditor/ + // GroupDescriptionEditor 用 getGroup 拿到的真实 version,Governance/OwnerSelect 的 + // 注释更是明确写了"version<=0 时服务端会整个跳过乐观锁 WHERE 子句,两次并发写入会 + // 静默覆盖")不一致。实测验证过这里同样如此:明明真实 version 是 1,PUT 时传 0 依然 + // 200 成功且服务端自己把 version 推到了 2——多标签页/多端几乎同时改自己在本群的昵称 + // 时,后写入的会静默覆盖先写入的,没有任何冲突信号。跟其余几处一样,把已经拿到手的 + // 真实 version 存下来,保存时原样带上。 + const [version, setVersion] = React.useState(0); React.useEffect(() => { if (!topic) return; - getMyGroupProfile(topic).then(data => setValue(data.nickname || '')).catch(() => {}); + getMyGroupProfile(topic).then(data => { setValue(data.nickname || ''); setVersion(data.version || 0); }).catch(() => {}); }, [topic]); const save = () => { - updateMyGroupProfile(topic, value.trim(), 0).then(() => { + updateMyGroupProfile(topic, value.trim(), version).then(() => { onToast('保存成功'); window.setTimeout(() => navigate('group-settings', topic), 600); }).catch(err => onToast(err.message || '保存失败')); };