feat: 自动化加上学生分数大于或小于的trigger

feat: 自动化表格tyle统一
This commit is contained in:
NanGua-QWQ
2026-04-10 22:35:42 +08:00
parent eef6b703f7
commit f2c062f904
7 changed files with 177 additions and 8 deletions
+54 -1
View File
@@ -75,9 +75,13 @@ export type ActionDraftError = "action_required" | "score_required" | "tag_requi
const TRIGGER_FIELD_INTERVAL = "interval_minutes"
const TRIGGER_FIELD_TAG = "student_tag"
const TRIGGER_FIELD_SQL = "student_sql"
const TRIGGER_FIELD_SCORE = "student_score"
const TRIGGER_FIELD_SCORE_GT = "student_score_gt"
const TRIGGER_TYPE_INTERVAL = "interval_duration"
const TRIGGER_WIDGET_INTERVAL = "interval_duration"
const OP_EQUAL = "equal"
const OP_GREATER = "greater"
const OP_LESS = "less"
const OP_MULTISELECT_CONTAINS = "multiselect_contains"
const buildEmptyGroup = (): JsonGroup => ({
@@ -188,11 +192,26 @@ const ruleFromTrigger = (trigger: AutoScoreTrigger): JsonRule | null => {
}
}
if (trigger.event === "student_score_gt" || trigger.event === "student_score_lt") {
const score = toFiniteNumber(trigger.value)
if (score === null) return null
return {
id: QbUtils.uuid(),
type: "rule",
properties: {
field: TRIGGER_FIELD_SCORE,
operator: trigger.event === "student_score_lt" ? OP_LESS : OP_GREATER,
value: [score],
},
}
}
return null
}
const triggerFromRule = (rule: JsonRule): AutoScoreTrigger | null => {
const field = typeof rule.properties?.field === "string" ? rule.properties.field : ""
const operator = typeof rule.properties?.operator === "string" ? rule.properties.operator : ""
const value = Array.isArray(rule.properties?.value) ? rule.properties.value[0] : undefined
if (field === TRIGGER_FIELD_INTERVAL) {
@@ -226,6 +245,15 @@ const triggerFromRule = (rule: JsonRule): AutoScoreTrigger | null => {
}
}
if (field === TRIGGER_FIELD_SCORE || field === TRIGGER_FIELD_SCORE_GT) {
const score = toFiniteNumber(value)
if (score === null) return null
return {
event: operator === OP_LESS ? "student_score_lt" : "student_score_gt",
value: String(score),
}
}
return null
}
@@ -261,6 +289,16 @@ export const createTriggerQueryConfig = (t: TFunction, tagOptions: AutoScoreTagO
},
operators: {
...AntdConfig.operators,
[OP_GREATER]: {
...AntdConfig.operators[OP_GREATER],
label: ">",
labelForFormat: ">",
},
[OP_LESS]: {
...AntdConfig.operators[OP_LESS],
label: "<",
labelForFormat: "<",
},
[OP_MULTISELECT_CONTAINS]: {
...AntdConfig.operators[OP_MULTISELECT_CONTAINS],
label: t("autoScore.operatorContains"),
@@ -329,6 +367,13 @@ export const createTriggerQueryConfig = (t: TFunction, tagOptions: AutoScoreTagO
placeholder: t("autoScore.triggerStudentSqlPlaceholder"),
},
},
[TRIGGER_FIELD_SCORE]: {
label: t("autoScore.triggerStudentScore"),
type: "number",
defaultOperator: OP_GREATER,
operators: [OP_GREATER, OP_LESS],
valueSources: ["value"],
},
},
settings: {
...AntdConfig.settings,
@@ -341,6 +386,7 @@ export const createTriggerQueryConfig = (t: TFunction, tagOptions: AutoScoreTagO
canLeaveEmptyGroup: false,
canReorder: true,
canRegroup: true,
setOpOnChangeField: ["default"],
},
}) as Config
@@ -401,7 +447,14 @@ const hydrateTriggerTreeNode = (
fallbackIndex.current += 1
const parsed = triggerFromRule(node)
if (parsed) {
return node
const normalizedRule = ruleFromTrigger(parsed)
if (!normalizedRule) {
return node
}
return {
...node,
properties: normalizedRule.properties,
}
}
if (!fallbackTrigger) {
+27 -1
View File
@@ -96,6 +96,8 @@ function AutoScoreManager({ canEdit }: AutoScoreManagerProps): React.JSX.Element
const [editingRuleId, setEditingRuleId] = useState<number | null>(null)
const [currentPage, setCurrentPage] = useState(1)
const [pageSize, setPageSize] = useState(10)
const [batchCurrentPage, setBatchCurrentPage] = useState(1)
const [batchPageSize, setBatchPageSize] = useState(10)
useEffect(() => {
const maxPage = Math.max(1, Math.ceil(rules.length / pageSize))
@@ -104,6 +106,13 @@ function AutoScoreManager({ canEdit }: AutoScoreManagerProps): React.JSX.Element
}
}, [currentPage, pageSize, rules.length])
useEffect(() => {
const maxPage = Math.max(1, Math.ceil(batches.length / batchPageSize))
if (batchCurrentPage > maxPage) {
setBatchCurrentPage(maxPage)
}
}, [batchCurrentPage, batchPageSize, batches.length])
useEffect(() => {
setTriggerTree((prevTree) => normalizeTriggerTree(prevTree, triggerConfig))
}, [triggerConfig])
@@ -584,6 +593,10 @@ function AutoScoreManager({ canEdit }: AutoScoreManagerProps): React.JSX.Element
]
const pagedRules = rules.slice((currentPage - 1) * pageSize, currentPage * pageSize)
const pagedBatches = batches.slice(
(batchCurrentPage - 1) * batchPageSize,
batchCurrentPage * batchPageSize
)
return (
<div style={{ padding: "24px" }}>
@@ -701,11 +714,24 @@ function AutoScoreManager({ canEdit }: AutoScoreManagerProps): React.JSX.Element
<Table
rowKey="id"
columns={batchColumns}
dataSource={batches.slice(0, 50)}
dataSource={pagedBatches}
pagination={false}
tableLayout="fixed"
scroll={{ x: 860 }}
/>
<div style={{ marginTop: 16, textAlign: "right" }}>
<Pagination
current={batchCurrentPage}
pageSize={batchPageSize}
total={batches.length}
showSizeChanger
showTotal={(total) => t("common.total", { count: total })}
onChange={(page, size) => {
setBatchCurrentPage(page)
setBatchPageSize(size)
}}
/>
</div>
</Card>
</div>
)
+27 -6
View File
@@ -84,12 +84,21 @@ export const ScoreManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
const [students, setStudents] = useState<student[]>([])
const [reasons, setReasons] = useState<reason[]>([])
const [events, setEvents] = useState<scoreEvent[]>([])
const [recordCurrentPage, setRecordCurrentPage] = useState(1)
const [recordPageSize, setRecordPageSize] = useState(10)
const [loading, setLoading] = useState(false)
const [submitLoading, setSubmitLoading] = useState(false)
const [form] = Form.useForm()
const [messageApi, contextHolder] = message.useMessage()
const selectedStudentNames = Form.useWatch("student_name", form) as string[] | undefined
useEffect(() => {
const maxPage = Math.max(1, Math.ceil(events.length / recordPageSize))
if (recordCurrentPage > maxPage) {
setRecordCurrentPage(maxPage)
}
}, [events.length, recordCurrentPage, recordPageSize])
const emitDataUpdated = (category: "events" | "students" | "reasons" | "all") => {
window.dispatchEvent(new CustomEvent("ss:data-updated", { detail: { category } }))
}
@@ -102,7 +111,7 @@ export const ScoreManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
const [stuRes, reaRes, eveRes] = await Promise.all([
(window as any).api.queryStudents({}),
(window as any).api.queryReasons(),
(window as any).api.queryEvents({ limit: 10 }),
(window as any).api.queryEvents({ limit: 100 }),
])
if (stuRes.success) setStudents(stuRes.data)
@@ -231,12 +240,12 @@ export const ScoreManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
}
const columns: ColumnsType<scoreEvent> = [
{ title: t("score.student"), dataIndex: "student_name", key: "student_name", width: 100 },
{ title: t("score.student"), dataIndex: "student_name", key: "student_name", width: 120 },
{
title: t("score.change"),
dataIndex: "delta",
key: "delta",
width: 80,
width: 92,
render: (delta: number) => (
<Tag color={delta > 0 ? "success" : "error"}>{delta > 0 ? `+${delta}` : delta}</Tag>
),
@@ -245,6 +254,7 @@ export const ScoreManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
title: t("score.reason"),
dataIndex: "reason_content",
key: "reason_content",
width: 280,
ellipsis: true,
},
{
@@ -257,7 +267,7 @@ export const ScoreManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
{
title: t("common.operation"),
key: "operation",
width: 80,
width: 96,
render: (_, row) => (
<Popconfirm title={t("score.undoConfirm")} onConfirm={() => handleUndo(row.uuid)}>
<Button type="link" danger disabled={!canEdit} icon={<UndoOutlined />}>
@@ -388,8 +398,19 @@ export const ScoreManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
columns={columns}
rowKey="uuid"
loading={loading}
size="small"
pagination={{ pageSize: 5, total: events.length, defaultCurrent: 1 }}
pagination={{
current: recordCurrentPage,
pageSize: recordPageSize,
total: events.length,
showSizeChanger: true,
showTotal: (total) => t("common.total", { count: total }),
onChange: (page, size) => {
setRecordCurrentPage(page)
setRecordPageSize(size)
},
}}
tableLayout="fixed"
scroll={{ x: 860 }}
style={{ color: "var(--ss-text-main)" }}
/>
</Card>