Skip to content

Commit 0a64a90

Browse files
committed
加了一些注释
1 parent b8eb2ef commit 0a64a90

File tree

7 files changed

+85
-8
lines changed

7 files changed

+85
-8
lines changed

src/core/classIslandLoader.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
// 导入Profile类
12
import { Profile } from "./models/classisland/Profile";
23

4+
// 定义一个函数mapToObject,用于将Map对象转换为Object对象
35
function mapToObject<TKey, TValue>(map: Map<TKey, TValue>): Map<TKey, TValue> {
6+
// 创建一个新对象
47
const obj = Object.create(null);
8+
// 遍历Map对象,将每一项赋值给新对象
59
map.forEach((v, k) => {
610
obj[k] = v;
711
})
12+
// 返回新对象
813
return obj;
914
}
1015

16+
// 定义一个函数saveClassIslandProfile,用于保存ClassIsland中的Profile
1117
export function saveClassIslandProfile(profile: Profile): string {
18+
// 创建一个新的Profile对象
1219
const profileNew = Object.create(profile);
20+
// 将Profile中的ClassPlans、TimeLayouts和Subjects转换为Object对象
1321
profileNew.ClassPlans = mapToObject(profile.ClassPlans);
1422
profileNew.TimeLayouts = mapToObject(profile.TimeLayouts);
1523
profileNew.Subjects = mapToObject(profile.Subjects);
24+
// 返回新的Profile对象作为字符串
1625
return JSON.stringify(profileNew);
1726
}

src/core/ecs/converting.ts

+37-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ function generateGuid(): string {
1818

1919

2020

21+
// 函数matchTimeSpan用于匹配字符串中的时间跨度
2122
function matchTimeSpan(s: string): TimeSpan {
23+
// 定义正则表达式,匹配字符串中的数字
2224
const regex = /\d+/gi;
25+
// 获取字符串中匹配到的数字
2326
const nums = s.match(regex);
27+
// 判断匹配到的数字是否为4个,不是则抛出错误
2428
if (nums == null || nums.length != 4){
2529
throw new Error("无效的时间格式:" + s);
2630
}
31+
// 定义开始时间和结束时间
2732
const start = new Date();
2833
start.setUTCHours(+nums[0]);
2934
start.setUTCMinutes(+nums[1]);
@@ -34,20 +39,27 @@ function matchTimeSpan(s: string): TimeSpan {
3439
end.setUTCMinutes(+nums[3]);
3540
end.setUTCSeconds(0);
3641
end.setUTCMilliseconds(0);
42+
// 返回开始时间和结束时间
3743
return {
3844
start: start,
3945
end: end
4046
}
4147
}
4248

4349
export function convertEcsToClassIsland(profile: Schedule): Profile {
50+
// 创建一个Profile实例
4451
const classIsland = new Profile();
52+
// 创建一个Map,用于存储学科的guid
4553
const subjectMapping = new Map<string, string>();
54+
// 创建一个Map,用于存储时间表的guid
4655
const timeTableMapping = new Map<string, string>();
4756
// 处理科目
4857
profile.subject_name.forEach((v, k) => {
58+
// 生成一个guid
4959
const guid = generateGuid();
60+
// 将subject_name和guid存入subjectMapping
5061
subjectMapping.set(k, guid);
62+
// 将guid和subject信息存入classIsland.Subjects
5163
classIsland.Subjects.set(guid, {
5264
Name: v,
5365
Initial: k,
@@ -56,30 +68,48 @@ export function convertEcsToClassIsland(profile: Schedule): Profile {
5668
});
5769
})
5870
// 处理时间表
59-
profile.timetable.forEach((v, k) => {
71+
// 为profile的timetable循环
72+
profile.timetable.forEach((v, k) => {
73+
// 生成GUID
6074
const guid = generateGuid();
75+
// 存储GUID到timeTableMapping
6176
timeTableMapping.set(k, guid);
77+
// 创建TimeLayout实例
6278
const tl = new TimeLayout();
79+
// 如果v.size小于等于0,返回
6380
if (v.size <= 0) {
6481
return;
6582
}
83+
// 设置TimeLayout的name
6684
tl.Name = k;
85+
// 初始化last为undefined
6786
let last: TimeLayoutItem | undefined;
87+
// 获取dividers
6888
const dividers = profile.divider.get(k);
89+
// 遍历v
6990
v.forEach((v, k) => {
91+
// 创建TimeLayoutItem实例
7092
const tp = new TimeLayoutItem();
93+
// 获取时间段
7194
const ts = matchTimeSpan(k);
7295
console.debug("匹配时间段:", ts);
96+
// 设置TimeLayoutItem的startSecond
7397
tp.StartSecond = ts.start;
98+
// 设置TimeLayoutItem的endSecond
7499
tp.EndSecond = ts.end;
100+
// 如果last不为undefined,设置last的endSecond为tp的startSecond
75101
if (last != undefined) {
76102
last.EndSecond = tp.StartSecond;
77103
}
104+
// 如果v的类型为string,设置tp的timetype为1
78105
if (typeof(v) == "string") {
79106
tp.TimeType = 1;
80107
}
108+
// 设置last为tp
81109
last = tp
110+
// 将tp添加到tl的layouts数组中
82111
tl.Layouts.push(tp);
112+
// 如果v的类型为number,并且dividers包含v,创建TimeLayoutItem实例tpd,设置tpd的startSecond和endSecond,将tpd添加到tl的layouts数组中
83113
if (typeof(v) == "number" && dividers != undefined && dividers.includes(v as number)) {
84114
const startDivider = new Date(ts.end.getTime() + 120);
85115
const tpd = new TimeLayoutItem();
@@ -88,17 +118,23 @@ export function convertEcsToClassIsland(profile: Schedule): Profile {
88118
tl.Layouts.push(tpd)
89119
}
90120
});
121+
// 获取tl的layouts数组中的第一个元素
91122
const first = tl.Layouts[0];
123+
// 获取tl的layouts数组中的最后一个元素
92124
const end = tl.Layouts[tl.Layouts.length - 1];
125+
// 如果first的startSecond的时为0,且分为为0,将first从tl的layouts数组中移除
93126
if (first.StartSecond.getUTCHours() == 0 && first.StartSecond.getUTCMinutes() == 0) {
94127
tl.Layouts.shift();
95128
}
129+
// 如果end的endSecond的时为23,且分为59,将end从tl的layouts数组中移除
96130
if (end != undefined && end.EndSecond.getUTCHours() == 23 && end.EndSecond.getUTCMinutes() == 59) {
97131
tl.Layouts.pop();
98132
}
133+
// 对tl的layouts数组排序,根据startSecond
99134
tl.Layouts.sort((x, y) => {
100135
return x.StartSecond.getUTCSeconds() - y.EndSecond.getUTCSeconds();
101136
});
137+
// 将tl添加到classIsland的TimeLayouts中
102138
classIsland.TimeLayouts.set(guid, tl);
103139
})
104140

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1+
// 导出ClassInfo类
12
export class ClassInfo {
3+
// 课程ID
24
SubjectId: string = "";
35
}
46

7+
// 导出TimeRule类
58
export class TimeRule {
9+
// 课程周期
610
WeekDay: number = 0;
11+
// 课程周期
712
WeekCountDiv: number = 0;
813
}
914

15+
// 导出ClassPlan类
1016
export class ClassPlan{
17+
// 时间布局ID
1118
TimeLayoutId: string = "";
19+
// 课程信息
1220
Classes: Array<ClassInfo> = [];
21+
// 班级名称
1322
Name: string = "";
23+
// 课程周期
1424
TimeRule: TimeRule = new TimeRule();
25+
// 是否允许覆盖
1526
IsOverlay: boolean = false;
27+
// 是否启用
1628
IsEnabled: boolean = true;
29+
// 设置时间
1730
OverlaySetupTime: Date = new Date();
18-
}
31+
}
+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
// 导出类Subject
12
export class Subject {
3+
// 课程名称
24
Name: string = "";
5+
// 课程缩写
36
Initial: string = "";
7+
// 教师名称
48
TeacherName: string = "";
9+
// 是否为室外课程
510
IsOutDoor: boolean = false;
6-
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
// 导出TimeLayoutItem类
12
export class TimeLayoutItem {
3+
// 开始时间
24
StartSecond: Date = new Date();
5+
// 结束时间
36
EndSecond: Date = new Date();
7+
// 时间类型
48
TimeType: number = 0;
9+
// 是否隐藏默认
510
IsHideDefault: boolean = false;
6-
}
11+
}

src/core/models/ecs/Schedule.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
// 导入 DailyClass 类
12
import { DailyClass } from "./DailyClass";
23

4+
// 定义 Schedule 类
35
export class Schedule {
6+
// 设置倒计时目标时间
47
countdown_target: Date = new Date();
8+
// 定义每日课程数组
59
daily_class: Array<DailyClass> = [];
10+
// 定义科目名称映射
611
subject_name: Map<string, string> = new Map<string, string>();
12+
// 定义时间表
713
timetable: Map<string, Map<string, string | number>> = new Map<string, Map<string, string | number>>();
14+
// 定义分隔线
815
divider: Map<string, Array<number>> = new Map<string, Array<number>>();
16+
// 设置是否显示星期
917
week_display: boolean = true;
18+
// 定义样式
1019
css_style: Map<string, string> = new Map<string, string>();
11-
}
20+
}

src/pages/ecs.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<script lang="ts" setup>
1616
import { convertEcsToClassIsland } from "../core/ecs/converting";
17-
import { ref, reactive } from "vue";
17+
import { ref } from "vue";
1818
import { loadEcsSchedule } from "../core/ecs/ecsLoader";
1919
import { saveClassIslandProfile } from "../core/classIslandLoader";
2020
@@ -29,7 +29,7 @@ function loadFile() {
2929
if (file.value) {
3030
const reader = new FileReader();
3131
reader.onload = (event) => {
32-
fileContent.value = event.target?.result;
32+
fileContent.value = event.target?.result as string;
3333
};
3434
reader.readAsText(file.value);
3535
}
@@ -41,7 +41,7 @@ function downloadJson(fileName, json) {
4141
4242
const url = window.URL || window.webkitURL || window;
4343
const blob = new Blob([jsonStr]);
44-
const saveLink = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
44+
const saveLink = document.createElement('a');
4545
saveLink.href = url.createObjectURL(blob);
4646
saveLink.download = fileName;
4747
saveLink.click();

0 commit comments

Comments
 (0)