import { useState } from 'react' import { Dialog, Toast } from 'antd-mobile' import { projectApi } from '../../api/task.js' import { useAuth } from '../../auth/AuthContext.jsx' // 项目成员 (T-PJ-06/07, T-AS-06, T-PM-02) export default function ProjectMembers({ project, onClose, onChanged }) { const { user } = useAuth() const meId = user?.id const [members, setMembers] = useState(project.members || []) const [adding, setAdding] = useState(false) const [email, setEmail] = useState('') async function add() { const e = email.trim() if (!e) return try { await projectApi.addMember(project.id, { email: e }) setEmail('') setAdding(false) Toast.show({ content: '已添加' }) onChanged?.() onClose?.() } catch (err) { Toast.show({ content: err.message }) } } async function remove(m, isSelf) { const ok = await Dialog.confirm({ content: isSelf ? '退出该项目?退出后将不再可见。' : `移除成员「${m.name}」?`, confirmText: isSelf ? '退出' : '移除', }) if (!ok) return try { await projectApi.removeMember(project.id, m.userId) setMembers((prev) => prev.filter((x) => x.userId !== m.userId)) Toast.show({ content: isSelf ? '已退出' : '已移除' }) onChanged?.() if (isSelf) onClose?.() } catch (err) { Toast.show({ content: err.message }) } } return (