diff --git a/src/main/db/migrations/AddTagsSchema2026020600000.ts b/src/main/db/migrations/AddTagsSchema2026020600000.ts deleted file mode 100644 index 7a3275f..0000000 --- a/src/main/db/migrations/AddTagsSchema2026020600000.ts +++ /dev/null @@ -1,53 +0,0 @@ -import type { MigrationInterface, QueryRunner } from 'typeorm' - -export class AddTagsSchema2026020600000 implements MigrationInterface { - name = 'AddTagsSchema2026020600000' - - async up(queryRunner: QueryRunner): Promise { - if (!(await queryRunner.hasTable('tags'))) { - await queryRunner.query(` - CREATE TABLE "tags" ( - "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, - "name" text NOT NULL UNIQUE, - "created_at" text NOT NULL DEFAULT (CURRENT_TIMESTAMP), - "updated_at" text NOT NULL DEFAULT (CURRENT_TIMESTAMP) - ) - `) - } - - if (!(await queryRunner.hasTable('student_tags'))) { - await queryRunner.query(` - CREATE TABLE "student_tags" ( - "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, - "student_id" integer NOT NULL, - "tag_id" integer NOT NULL, - "created_at" text NOT NULL DEFAULT (CURRENT_TIMESTAMP), - FOREIGN KEY ("student_id") REFERENCES "students"("id") ON DELETE CASCADE, - FOREIGN KEY ("tag_id") REFERENCES "tags"("id") ON DELETE CASCADE, - UNIQUE("student_id", "tag_id") - ) - `) - } - - await queryRunner.query( - `CREATE INDEX IF NOT EXISTS "IDX_student_tags_student_id" ON "student_tags" ("student_id")` - ) - await queryRunner.query( - `CREATE INDEX IF NOT EXISTS "IDX_student_tags_tag_id" ON "student_tags" ("tag_id")` - ) - - await queryRunner.query(` - INSERT OR IGNORE INTO "tags" ("name") VALUES - ('优秀生'), - ('班干部'), - ('勤奋'), - ('活跃'), - ('进步快') - `) - } - - async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE IF EXISTS "student_tags"`) - await queryRunner.query(`DROP TABLE IF EXISTS "tags"`) - } -} diff --git a/src/main/db/migrations/InitSchema2026011800000.ts b/src/main/db/migrations/InitSchema2026011800000.ts index 5fa149d..05cd578 100644 --- a/src/main/db/migrations/InitSchema2026011800000.ts +++ b/src/main/db/migrations/InitSchema2026011800000.ts @@ -81,6 +81,47 @@ export class InitSchema2026011800000 implements MigrationInterface { ('迟到','纪律',-1,1,CURRENT_TIMESTAMP), ('未交作业','作业情况',-2,1,CURRENT_TIMESTAMP) `) + + if (!(await queryRunner.hasTable('tags'))) { + await queryRunner.query(` + CREATE TABLE "tags" ( + "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, + "name" text NOT NULL UNIQUE, + "created_at" text NOT NULL DEFAULT (CURRENT_TIMESTAMP), + "updated_at" text NOT NULL DEFAULT (CURRENT_TIMESTAMP) + ) + `) + } + + if (!(await queryRunner.hasTable('student_tags'))) { + await queryRunner.query(` + CREATE TABLE "student_tags" ( + "id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, + "student_id" integer NOT NULL, + "tag_id" integer NOT NULL, + "created_at" text NOT NULL DEFAULT (CURRENT_TIMESTAMP), + FOREIGN KEY ("student_id") REFERENCES "students"("id") ON DELETE CASCADE, + FOREIGN KEY ("tag_id") REFERENCES "tags"("id") ON DELETE CASCADE, + UNIQUE("student_id", "tag_id") + ) + `) + } + + await queryRunner.query( + `CREATE INDEX IF NOT EXISTS "IDX_student_tags_student_id" ON "student_tags" ("student_id")` + ) + await queryRunner.query( + `CREATE INDEX IF NOT EXISTS "IDX_student_tags_tag_id" ON "student_tags" ("tag_id")` + ) + + await queryRunner.query(` + INSERT OR IGNORE INTO "tags" ("name") VALUES + ('优秀生'), + ('班干部'), + ('勤奋'), + ('活跃'), + ('进步快') + `) } async down(queryRunner: QueryRunner): Promise { @@ -89,5 +130,7 @@ export class InitSchema2026011800000 implements MigrationInterface { await queryRunner.query(`DROP TABLE IF EXISTS "students"`) await queryRunner.query(`DROP TABLE IF EXISTS "reasons"`) await queryRunner.query(`DROP TABLE IF EXISTS "settings"`) + await queryRunner.query(`DROP TABLE IF EXISTS "student_tags"`) + await queryRunner.query(`DROP TABLE IF EXISTS "tags"`) } } diff --git a/src/main/db/migrations/index.ts b/src/main/db/migrations/index.ts index 9dcd328..fbb3197 100644 --- a/src/main/db/migrations/index.ts +++ b/src/main/db/migrations/index.ts @@ -1,4 +1,3 @@ import { InitSchema2026011800000 } from './InitSchema2026011800000' -import { AddTagsSchema2026020600000 } from './AddTagsSchema2026020600000' -export const migrations = [InitSchema2026011800000, AddTagsSchema2026020600000] +export const migrations = [InitSchema2026011800000] diff --git a/src/renderer/src/components/AutoScoreManager.tsx b/src/renderer/src/components/AutoScoreManager.tsx index 832b412..63b1bea 100644 --- a/src/renderer/src/components/AutoScoreManager.tsx +++ b/src/renderer/src/components/AutoScoreManager.tsx @@ -440,13 +440,14 @@ export const AutoScoreManager: React.FC = () => { const triggerItems = triggerList .filter((t) => t.eventName !== null) - .map((item) => ( + .map((item, idx) => ( )) @@ -498,25 +499,6 @@ export const AutoScoreManager: React.FC = () => { - - setCurrentPage(pageInfo.current), - onPageSizeChange: (size) => setPageSize(size) - }} - style={{ color: 'var(--ss-text-main)' }} - /> - { + + +
setCurrentPage(pageInfo.current), + onPageSizeChange: (size) => setPageSize(size) + }} + style={{ color: 'var(--ss-text-main)' }} + /> + + { diff --git a/src/renderer/src/components/com.automatically/ActionItem.tsx b/src/renderer/src/components/com.automatically/ActionItem.tsx index 2ee06d4..ec51ef9 100644 --- a/src/renderer/src/components/com.automatically/ActionItem.tsx +++ b/src/renderer/src/components/com.automatically/ActionItem.tsx @@ -31,7 +31,7 @@ const ActionItem: React.FC = ({ /> onChange(item.id, value as string)} diff --git a/src/renderer/src/components/com.automatically/triggers/IntervalTimeTrigger.tsx b/src/renderer/src/components/com.automatically/triggers/IntervalTimeTrigger.tsx index 3ec2dfc..1bc62f6 100644 --- a/src/renderer/src/components/com.automatically/triggers/IntervalTimeTrigger.tsx +++ b/src/renderer/src/components/com.automatically/triggers/IntervalTimeTrigger.tsx @@ -1,4 +1,5 @@ -import { InputNumber } from 'tdesign-react' +import { useState } from 'react' +import { InputNumber, Space, Radio, Form } from 'tdesign-react' import type { TriggerComponentProps } from '../types' export const eventName = 'interval_time_passed' @@ -19,21 +20,59 @@ export const triggerLogic = { const IntervalTimeTrigger: React.FC = ({ value, onChange }) => { const numValue = value ? parseInt(value, 10) : undefined + const [unit, setUnit] = useState<'minutes' | 'days'>('minutes') const handleChange = (v: any) => { const numV = typeof v === 'number' ? v : v ? Number(v) : undefined - onChange(numV !== undefined && numV !== null && !isNaN(numV) ? String(numV) : '') + if (numV === undefined || numV === null || isNaN(numV)) { + onChange('') + return + } + const minutes = unit === 'minutes' ? numV : numV * 1440 + onChange(String(Math.round(minutes))) } + const displayValue = + numValue === undefined || isNaN(numValue) + ? undefined + : unit === 'minutes' + ? numValue + : Math.max(1, Math.round(numValue / 1440)) + return ( - + + + + + + setUnit(String(v) as 'minutes' | 'days')} + > + + 分钟 + + + ) } diff --git a/src/renderer/src/components/com.automatically/triggers/RandomTimeTrigger.tsx b/src/renderer/src/components/com.automatically/triggers/RandomTimeTrigger.tsx index e27ab32..36d9801 100644 --- a/src/renderer/src/components/com.automatically/triggers/RandomTimeTrigger.tsx +++ b/src/renderer/src/components/com.automatically/triggers/RandomTimeTrigger.tsx @@ -1,7 +1,7 @@ import { InputNumber, Row, Col } from 'tdesign-react' import type { TriggerComponentProps } from '../types' -export const eventName = 'random_time' +export const eventName = 'random_time_reached' export const label = '随机时间触发' export const description = '在指定时间范围内随机触发自动化' export const triggerLogic = { diff --git a/src/renderer/src/components/com.automatically/triggers/StudentTagTrigger.tsx b/src/renderer/src/components/com.automatically/triggers/StudentTagTrigger.tsx index 1c66ef6..8e4752e 100644 --- a/src/renderer/src/components/com.automatically/triggers/StudentTagTrigger.tsx +++ b/src/renderer/src/components/com.automatically/triggers/StudentTagTrigger.tsx @@ -1,10 +1,9 @@ import { useState, useEffect } from 'react' import { Select } from 'tdesign-react' import type { TriggerComponentProps } from '../types' - -export const eventName = 'student_tag_added' -export const label = '当学生添加标签时触发' -export const description = '当学生添加特定标签时触发自动化' +export const eventName = 'student_tag_matched' +export const label = '当学生匹配标签时触发' +export const description = '当学生匹配特定标签时触发自动化' export const triggerLogic = { eventName, label, @@ -23,7 +22,7 @@ const StudentTagTrigger: React.FC = ({ value, onChange }) useEffect(() => { const fetchTags = async () => { try { - const res = await (window as any).api.invoke('tag:getAll', {}) + const res = await (window as any).api.tagsGetAll() if (res.success && res.data) { setTags(res.data.map((tag: any) => ({ label: tag.name, value: tag.name }))) } diff --git a/src/shared/triggers/index.ts b/src/shared/triggers/index.ts index 52f5b2f..bcb1cf6 100644 --- a/src/shared/triggers/index.ts +++ b/src/shared/triggers/index.ts @@ -13,5 +13,15 @@ export const allTriggerLogics: TriggerLogic[] = [ ] export function getTriggerLogic(eventName: string): TriggerLogic | undefined { - return allTriggerLogics.find((t) => t.eventName === eventName) + const direct = allTriggerLogics.find((t) => t.eventName === eventName) + if (direct) return direct + const aliasMap: Record = { + random_time: 'random_time_reached', + student_tag_added: 'student_tag_matched' + } + const mapped = aliasMap[eventName] + if (mapped) { + return allTriggerLogics.find((t) => t.eventName === mapped) + } + return undefined }