mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 18:19:03 +08:00
ALPHA: 未完成
This commit is contained in:
@@ -26,7 +26,7 @@ interface AutoScoreRule {
|
||||
name: string
|
||||
studentNames: string[]
|
||||
lastExecuted?: string
|
||||
triggers?: { event: string; value?: string }[]
|
||||
triggers?: { event: string; value?: string; relation?: 'AND' | 'OR' }[]
|
||||
actions?: { event: string; value?: string; reason?: string }[]
|
||||
}
|
||||
|
||||
@@ -108,7 +108,11 @@ export const AutoScoreManager: React.FC = () => {
|
||||
|
||||
const studentNames = Array.isArray(values.studentNames) ? values.studentNames : []
|
||||
|
||||
const triggersPayload = triggerList.map((t) => ({ event: t.eventName, value: t.value }))
|
||||
const triggersPayload = triggerList.map((t) => ({
|
||||
event: t.eventName,
|
||||
value: t.value,
|
||||
relation: t.relation
|
||||
}))
|
||||
const actionsPayload = actionList.map((a) => ({
|
||||
event: a.eventName,
|
||||
value: a.value,
|
||||
@@ -175,7 +179,8 @@ export const AutoScoreManager: React.FC = () => {
|
||||
const mapped = rule.triggers.map((t, idx) => ({
|
||||
id: idx + 1,
|
||||
eventName: t.event,
|
||||
value: t.value ?? ''
|
||||
value: t.value ?? '',
|
||||
relation: t.relation ?? 'AND'
|
||||
}))
|
||||
setTriggerList(mapped)
|
||||
} else {
|
||||
@@ -268,7 +273,8 @@ export const AutoScoreManager: React.FC = () => {
|
||||
{
|
||||
id: nextId,
|
||||
eventName: defaultTrigger.eventName,
|
||||
value: ''
|
||||
value: '',
|
||||
relation: 'AND'
|
||||
}
|
||||
])
|
||||
}
|
||||
@@ -285,6 +291,10 @@ export const AutoScoreManager: React.FC = () => {
|
||||
setTriggerList((prev) => prev.map((t) => (t.id === id ? { ...t, value } : t)))
|
||||
}
|
||||
|
||||
const handleTriggerRelationChange = (id: number, relation: 'AND' | 'OR') => {
|
||||
setTriggerList((prev) => prev.map((t) => (t.id === id ? { ...t, relation } : t)))
|
||||
}
|
||||
|
||||
const handleAddAction = () => {
|
||||
const nextId = actionList.length ? Math.max(...actionList.map((a) => a.id)) + 1 : 1
|
||||
const defaultAction = allActions.list[0]
|
||||
@@ -447,6 +457,7 @@ export const AutoScoreManager: React.FC = () => {
|
||||
onDelete={handleDeleteTrigger}
|
||||
onChange={handleTriggerChange}
|
||||
onValueChange={handleTriggerValueChange}
|
||||
onRelationChange={handleTriggerRelationChange}
|
||||
isFirst={idx === 0}
|
||||
/>
|
||||
))
|
||||
@@ -566,7 +577,8 @@ export const AutoScoreManager: React.FC = () => {
|
||||
const studentNames = Array.isArray(values.studentNames) ? values.studentNames : []
|
||||
const triggersPayload = triggerList.map((t) => ({
|
||||
event: t.eventName,
|
||||
value: t.value
|
||||
value: t.value,
|
||||
relation: t.relation
|
||||
}))
|
||||
const actionsPayload = actionList.map((a) => ({
|
||||
event: a.eventName,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useState } from 'react'
|
||||
import { Button, Select } from 'tdesign-react'
|
||||
import { Delete1Icon } from 'tdesign-icons-react'
|
||||
import { triggerRegistry, allTriggers } from './registry'
|
||||
@@ -9,6 +8,7 @@ interface TriggerItemProps {
|
||||
onDelete: (id: number) => void
|
||||
onChange: (id: number, eventName: string) => void
|
||||
onValueChange: (id: number, value: string) => void
|
||||
onRelationChange?: (id: number, relation: 'AND' | 'OR') => void
|
||||
isFirst?: boolean
|
||||
}
|
||||
|
||||
@@ -17,21 +17,22 @@ const TriggerItem: React.FC<TriggerItemProps> = ({
|
||||
onDelete,
|
||||
onChange,
|
||||
onValueChange,
|
||||
onRelationChange,
|
||||
isFirst = false
|
||||
}) => {
|
||||
const definition = triggerRegistry.get(item.eventName)
|
||||
const Component = definition?.component
|
||||
const [andFilled, setAndFilled] = useState(false)
|
||||
const relation = item.relation || 'AND'
|
||||
|
||||
return (
|
||||
<div style={{ display: 'flex', gap: 5 }}>
|
||||
{!isFirst && (
|
||||
<Button
|
||||
theme="primary"
|
||||
variant={andFilled ? 'base' : 'outline'}
|
||||
onClick={() => setAndFilled((v) => !v)}
|
||||
theme={relation === 'AND' ? 'primary' : 'warning'}
|
||||
variant={relation === 'AND' ? 'base' : 'outline'}
|
||||
onClick={() => onRelationChange?.(item.id, relation === 'AND' ? 'OR' : 'AND')}
|
||||
>
|
||||
并
|
||||
{relation === 'AND' ? '并' : '或'}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Select } from 'tdesign-react'
|
||||
import type { ActionComponentProps } from '../types'
|
||||
|
||||
export const eventName = 'set_student_status'
|
||||
export const label = '设置学生状态'
|
||||
export const description = '设置学生的状态'
|
||||
export const hasReason = false
|
||||
|
||||
const statusOptions = [
|
||||
{ label: '活跃', value: 'active' },
|
||||
{ label: '不活跃', value: 'inactive' },
|
||||
{ label: '请假', value: 'leave' }
|
||||
]
|
||||
|
||||
const SetStudentStatusAction: React.FC<ActionComponentProps> = ({ value, onChange }) => {
|
||||
return (
|
||||
<Select
|
||||
placeholder="请选择状态"
|
||||
style={{ width: '150px' }}
|
||||
value={value ?? ''}
|
||||
onChange={(v: any) => onChange(v ? String(v) : '')}
|
||||
options={statusOptions}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default SetStudentStatusAction
|
||||
@@ -22,13 +22,6 @@ import SendNotificationAction, {
|
||||
hasReason as sendNotificationHasReason
|
||||
} from './SendNotificationAction'
|
||||
|
||||
import SetStudentStatusAction, {
|
||||
eventName as setStudentStatusEventName,
|
||||
label as setStudentStatusLabel,
|
||||
description as setStudentStatusDescription,
|
||||
hasReason as setStudentStatusHasReason
|
||||
} from './SetStudentStatusAction'
|
||||
|
||||
const actionDefinitions: ActionDefinition[] = [
|
||||
{
|
||||
eventName: addScoreEventName,
|
||||
@@ -51,15 +44,8 @@ const actionDefinitions: ActionDefinition[] = [
|
||||
component: SendNotificationAction,
|
||||
hasReason: sendNotificationHasReason
|
||||
},
|
||||
{
|
||||
eventName: setStudentStatusEventName,
|
||||
label: setStudentStatusLabel,
|
||||
description: setStudentStatusDescription,
|
||||
component: SetStudentStatusAction,
|
||||
hasReason: setStudentStatusHasReason
|
||||
}
|
||||
]
|
||||
|
||||
actionDefinitions.forEach((def) => actionRegistry.register(def))
|
||||
|
||||
export { AddScoreAction, AddTagAction, SendNotificationAction, SetStudentStatusAction }
|
||||
export { AddScoreAction, AddTagAction, SendNotificationAction }
|
||||
|
||||
@@ -18,5 +18,4 @@ export {
|
||||
AddScoreAction,
|
||||
AddTagAction,
|
||||
SendNotificationAction,
|
||||
SetStudentStatusAction
|
||||
} from './actions'
|
||||
|
||||
@@ -45,6 +45,7 @@ export interface TriggerItem {
|
||||
id: number
|
||||
eventName: string
|
||||
value: string
|
||||
relation?: 'AND' | 'OR'
|
||||
}
|
||||
|
||||
export interface ActionItem {
|
||||
|
||||
Reference in New Issue
Block a user