mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 21:14:21 +08:00
feat: 设置小组支持一键添加到已有小组
This commit is contained in:
@@ -54,6 +54,8 @@ export const StudentManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
const [form] = Form.useForm()
|
const [form] = Form.useForm()
|
||||||
const [groupForm] = Form.useForm()
|
const [groupForm] = Form.useForm()
|
||||||
const [messageApi, contextHolder] = message.useMessage()
|
const [messageApi, contextHolder] = message.useMessage()
|
||||||
|
const addFormGroupName = Form.useWatch("group_name", form)
|
||||||
|
const editFormGroupName = Form.useWatch("group_name", groupForm)
|
||||||
const isMobile = useIsMobile()
|
const isMobile = useIsMobile()
|
||||||
const isTablet = useIsTablet()
|
const isTablet = useIsTablet()
|
||||||
const breakpoint = useResponsive()
|
const breakpoint = useResponsive()
|
||||||
@@ -666,6 +668,22 @@ export const StudentManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
return baseColumns
|
return baseColumns
|
||||||
}, [t, canEdit, isMobile, isTablet, breakpoint])
|
}, [t, canEdit, isMobile, isTablet, breakpoint])
|
||||||
|
|
||||||
|
const existingGroupNames = useMemo(() => {
|
||||||
|
const groups = new Set<string>()
|
||||||
|
data.forEach((student) => {
|
||||||
|
const normalized = student.group_name?.trim()
|
||||||
|
if (normalized) groups.add(normalized)
|
||||||
|
})
|
||||||
|
return Array.from(groups).sort((a, b) => a.localeCompare(b, "zh-CN"))
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
const normalizedAddFormGroupName =
|
||||||
|
typeof addFormGroupName === "string" && addFormGroupName.trim() ? addFormGroupName.trim() : ""
|
||||||
|
const normalizedEditFormGroupName =
|
||||||
|
typeof editFormGroupName === "string" && editFormGroupName.trim()
|
||||||
|
? editFormGroupName.trim()
|
||||||
|
: ""
|
||||||
|
|
||||||
const paginatedData = data.slice((currentPage - 1) * pageSize, currentPage * pageSize)
|
const paginatedData = data.slice((currentPage - 1) * pageSize, currentPage * pageSize)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -725,6 +743,32 @@ export const StudentManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
<Form.Item label={t("students.group")} name="group_name">
|
<Form.Item label={t("students.group")} name="group_name">
|
||||||
<Input placeholder={t("students.groupPlaceholder")} />
|
<Input placeholder={t("students.groupPlaceholder")} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<div style={{ marginTop: 8 }}>
|
||||||
|
<div style={{ color: "var(--ss-text-secondary)", marginBottom: 8, fontSize: 12 }}>
|
||||||
|
{t("students.existingGroups")}
|
||||||
|
</div>
|
||||||
|
{existingGroupNames.length > 0 ? (
|
||||||
|
<Space wrap size={[8, 8]}>
|
||||||
|
{existingGroupNames.map((group) => {
|
||||||
|
const active = normalizedAddFormGroupName === group
|
||||||
|
return (
|
||||||
|
<Tag
|
||||||
|
key={`add-group-${group}`}
|
||||||
|
color={active ? "processing" : undefined}
|
||||||
|
style={{ cursor: "pointer", userSelect: "none", marginInlineEnd: 0 }}
|
||||||
|
onClick={() => form.setFieldValue("group_name", group)}
|
||||||
|
>
|
||||||
|
{group}
|
||||||
|
</Tag>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<div style={{ color: "var(--ss-text-secondary)", fontSize: 12 }}>
|
||||||
|
{t("students.noExistingGroups")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
@@ -746,6 +790,32 @@ export const StudentManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
|||||||
<Form.Item label={t("students.group")} name="group_name">
|
<Form.Item label={t("students.group")} name="group_name">
|
||||||
<Input placeholder={t("students.groupPlaceholder")} />
|
<Input placeholder={t("students.groupPlaceholder")} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<div style={{ marginTop: 8 }}>
|
||||||
|
<div style={{ color: "var(--ss-text-secondary)", marginBottom: 8, fontSize: 12 }}>
|
||||||
|
{t("students.existingGroups")}
|
||||||
|
</div>
|
||||||
|
{existingGroupNames.length > 0 ? (
|
||||||
|
<Space wrap size={[8, 8]}>
|
||||||
|
{existingGroupNames.map((group) => {
|
||||||
|
const active = normalizedEditFormGroupName === group
|
||||||
|
return (
|
||||||
|
<Tag
|
||||||
|
key={`edit-group-${group}`}
|
||||||
|
color={active ? "processing" : undefined}
|
||||||
|
style={{ cursor: "pointer", userSelect: "none", marginInlineEnd: 0 }}
|
||||||
|
onClick={() => groupForm.setFieldValue("group_name", group)}
|
||||||
|
>
|
||||||
|
{group}
|
||||||
|
</Tag>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<div style={{ color: "var(--ss-text-secondary)", fontSize: 12 }}>
|
||||||
|
{t("students.noExistingGroups")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
|||||||
@@ -488,6 +488,8 @@
|
|||||||
"editGroupTitle": "Set Group - {{name}}",
|
"editGroupTitle": "Set Group - {{name}}",
|
||||||
"groupSaveSuccess": "Group saved",
|
"groupSaveSuccess": "Group saved",
|
||||||
"groupSaveFailed": "Failed to save group",
|
"groupSaveFailed": "Failed to save group",
|
||||||
|
"existingGroups": "Existing groups (click to fill)",
|
||||||
|
"noExistingGroups": "No existing groups yet",
|
||||||
"noGroup": "Ungrouped",
|
"noGroup": "Ungrouped",
|
||||||
"editAvatarTitle": "Set Avatar - {{name}}",
|
"editAvatarTitle": "Set Avatar - {{name}}",
|
||||||
"avatarUpload": "Upload Image",
|
"avatarUpload": "Upload Image",
|
||||||
|
|||||||
@@ -488,6 +488,8 @@
|
|||||||
"editGroupTitle": "设置小组 - {{name}}",
|
"editGroupTitle": "设置小组 - {{name}}",
|
||||||
"groupSaveSuccess": "小组保存成功",
|
"groupSaveSuccess": "小组保存成功",
|
||||||
"groupSaveFailed": "小组保存失败",
|
"groupSaveFailed": "小组保存失败",
|
||||||
|
"existingGroups": "已有小组(点击一键填入)",
|
||||||
|
"noExistingGroups": "暂无可用的小组",
|
||||||
"noGroup": "未分组",
|
"noGroup": "未分组",
|
||||||
"editAvatarTitle": "设置头像 - {{name}}",
|
"editAvatarTitle": "设置头像 - {{name}}",
|
||||||
"avatarUpload": "上传图片",
|
"avatarUpload": "上传图片",
|
||||||
|
|||||||
Reference in New Issue
Block a user