hookehuyr

feat(teacher): 新增教师作业设置功能及相关API接口

添加教师作业设置页面表单提交功能,包括作业名称、频次、目标总数等字段
实现获取作业设置参数和提交作业设置的API接口
移除未使用的活动和小组成员选择功能
根据API返回数据动态加载年级、班级、课程和章节信息
1 /* 1 /*
2 * @Date: 2025-06-23 11:46:21 2 * @Date: 2025-06-23 11:46:21
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-06-25 10:51:28 4 + * @LastEditTime: 2025-06-25 15:48:41
5 * @FilePath: /mlaj/src/api/teacher.js 5 * @FilePath: /mlaj/src/api/teacher.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -9,12 +9,37 @@ import { fn, fetch } from './fn' ...@@ -9,12 +9,37 @@ import { fn, fetch } from './fn'
9 9
10 const Api = { 10 const Api = {
11 TEACHER_GRADE_CLASS_LIST: '/srv/?a=user&t=teacher_grade_class_group_list', 11 TEACHER_GRADE_CLASS_LIST: '/srv/?a=user&t=teacher_grade_class_group_list',
12 + TEACHER_FIND_SETTINGS: '/srv/?a=task&t=teacher_find_settings',
13 + TEACHER_ADD_TASK: '/srv/?a=task&t=teacher_add',
12 } 14 }
13 15
14 /** 16 /**
15 * 获取老师的年级、班级、课程列表信息 17 * 获取老师的年级、班级、课程列表信息
16 * @param {*} grade_id 年级ID 用来缩小班级、课程的筛选范围 18 * @param {*} grade_id 年级ID 用来缩小班级、课程的筛选范围
17 * @param {*} class_id 班级ID 用来缩小课程的筛选范围 19 * @param {*} class_id 班级ID 用来缩小课程的筛选范围
18 - * @returns {Array} data { grade_list [{id, grade_name}], class_list [{id, class_name}], group_list [{id, title}] } 20 + * @returns {Object} data { grade_list [{id, grade_name}], class_list [{id, class_name}], group_list [{id, title}] }
19 */ 21 */
20 export const getTeacherGradeClassListAPI = (params) => fn(fetch.get(Api.TEACHER_GRADE_CLASS_LIST, params)) 22 export const getTeacherGradeClassListAPI = (params) => fn(fetch.get(Api.TEACHER_GRADE_CLASS_LIST, params))
23 +
24 +/**
25 + * 获取老师查询作业参数
26 + * @returns {Object} data { grade_list [{id, grade_name}], class_list [{id, class_name}], group_list [{id, title, schedule_list[{id, title}]}], task_type, task_frequency }
27 + */
28 +export const getTeacherFindSettingsAPI = (params) => fn(fetch.get(Api.TEACHER_FIND_SETTINGS, params))
29 +
30 +
31 +/**
32 + * 老师设置作业
33 + * @param {*} title 作业名称
34 + * @param {*} begin_date 开始日期
35 + * @param {*} end_date 结束日期
36 + * @param {*} target_number 目标总数
37 + * @param {*} class_id 班级ID
38 + * @param {*} group_id 年级ID
39 + * @param {*} lesson_id 课程ID
40 + * @param {*} task_type 任务类型
41 + * @param {*} frequency 任务频率
42 + * @param {*} schedule[{id, begin_date, end_date}] 批量设置课程章节的作业
43 + * @returns {Object} data { id }
44 + */
45 +export const setTeacherTaskAPI = (params) => fn(fetch.post(Api.TEACHER_ADD_TASK, params))
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
2 * @Author: hookehuyr hookehuyr@gmail.com 2 * @Author: hookehuyr hookehuyr@gmail.com
3 * @Date: 2025-01-20 10:00:00 3 * @Date: 2025-01-20 10:00:00
4 * @LastEditors: hookehuyr hookehuyr@gmail.com 4 * @LastEditors: hookehuyr hookehuyr@gmail.com
5 - * @LastEditTime: 2025-06-24 11:46:49 5 + * @LastEditTime: 2025-06-25 15:49:50
6 * @FilePath: /mlaj/src/views/teacher/formPage.vue 6 * @FilePath: /mlaj/src/views/teacher/formPage.vue
7 * @Description: 教师作业新增表单页面 7 * @Description: 教师作业新增表单页面
8 --> 8 -->
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 <!-- 作业名称输入框 --> 16 <!-- 作业名称输入框 -->
17 <div class="mb-6"> 17 <div class="mb-6">
18 <van-field 18 <van-field
19 - v-model="formData.homework_name" 19 + v-model="formData.title"
20 - name="homework_name" 20 + name="title"
21 :placeholder="`请输入${pageTitle === '设置作业' ? '作业' : '打卡'}名称(必填)`" 21 :placeholder="`请输入${pageTitle === '设置作业' ? '作业' : '打卡'}名称(必填)`"
22 required 22 required
23 :border="false" 23 :border="false"
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
28 <!-- 作业要求说明 --> 28 <!-- 作业要求说明 -->
29 <div class="mb-6"> 29 <div class="mb-6">
30 <van-field 30 <van-field
31 - v-model="formData.description" 31 + v-model="formData.note"
32 - name="description" 32 + name="note"
33 type="textarea" 33 type="textarea"
34 :placeholder="`请输入${pageTitle === '设置作业' ? '作业' : '打卡'}要求和说明`" 34 :placeholder="`请输入${pageTitle === '设置作业' ? '作业' : '打卡'}要求和说明`"
35 :border="false" 35 :border="false"
...@@ -45,11 +45,11 @@ ...@@ -45,11 +45,11 @@
45 <van-col span="12"> 45 <van-col span="12">
46 <label class="setting-label">{{ pageTitle === '设置作业' ? '作业' : '打卡' }}频次</label> 46 <label class="setting-label">{{ pageTitle === '设置作业' ? '作业' : '打卡' }}频次</label>
47 <van-field 47 <van-field
48 - v-model="formData.frequency" 48 + v-model="formData.frequency_text"
49 is-link 49 is-link
50 readonly 50 readonly
51 - name="frequency" 51 + name="frequency_text"
52 - placeholder="每天" 52 + placeholder="请选择频次"
53 :border="false" 53 :border="false"
54 @click="showFrequencyPicker = true" 54 @click="showFrequencyPicker = true"
55 class="frequency-field" 55 class="frequency-field"
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
59 <label class="setting-label">目标总数</label> 59 <label class="setting-label">目标总数</label>
60 <div class="target-count-container"> 60 <div class="target-count-container">
61 <van-stepper 61 <van-stepper
62 - v-model="formData.target_count" 62 + v-model="formData.target_number"
63 min="1" 63 min="1"
64 max="100" 64 max="100"
65 integer 65 integer
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
122 <van-icon name="arrow" class="arrow-icon" @click="showCoursePicker = true" /> 122 <van-icon name="arrow" class="arrow-icon" @click="showCoursePicker = true" />
123 </div> 123 </div>
124 </div> 124 </div>
125 - <div class="select-row" v-if="formData.course"> 125 + <div class="select-row" v-if="courseChapters[formData.course]?.length">
126 <div class="select-item"> 126 <div class="select-item">
127 <van-icon name="bookmark-o" class="select-icon" /> 127 <van-icon name="bookmark-o" class="select-icon" />
128 <span class="select-label">课程章节:</span> 128 <span class="select-label">课程章节:</span>
...@@ -170,11 +170,6 @@ ...@@ -170,11 +170,6 @@
170 </div> 170 </div>
171 </div> 171 </div>
172 172
173 - <!-- 类型选择器 -->
174 - <van-popup v-model:show="showTypePicker" position="bottom">
175 - <van-picker :columns="typeOptions" @confirm="onTypeConfirm" @cancel="showTypePicker = false" />
176 - </van-popup>
177 -
178 <!-- 频次选择器 --> 173 <!-- 频次选择器 -->
179 <van-popup v-model:show="showFrequencyPicker" position="bottom"> 174 <van-popup v-model:show="showFrequencyPicker" position="bottom">
180 <van-picker :columns="frequencyOptions" @confirm="onFrequencyConfirm" @cancel="showFrequencyPicker = false" /> 175 <van-picker :columns="frequencyOptions" @confirm="onFrequencyConfirm" @cancel="showFrequencyPicker = false" />
...@@ -269,7 +264,7 @@ ...@@ -269,7 +264,7 @@
269 </van-popup> 264 </van-popup>
270 265
271 <!-- 活动选择器 --> 266 <!-- 活动选择器 -->
272 - <van-popup v-model:show="showActivityPicker" position="bottom"> 267 + <!-- <van-popup v-model:show="showActivityPicker" position="bottom">
273 <div class="p-4"> 268 <div class="p-4">
274 <van-search v-model="activitySearchValue" placeholder="搜索活动" @search="searchActivity" /> 269 <van-search v-model="activitySearchValue" placeholder="搜索活动" @search="searchActivity" />
275 <van-list> 270 <van-list>
...@@ -277,7 +272,7 @@ ...@@ -277,7 +272,7 @@
277 :border="false" @click="onActivitySelect(activity)" /> 272 :border="false" @click="onActivitySelect(activity)" />
278 </van-list> 273 </van-list>
279 </div> 274 </div>
280 - </van-popup> 275 + </van-popup> -->
281 276
282 <!-- 年级选择器 --> 277 <!-- 年级选择器 -->
283 <van-popup v-model:show="showGradePicker" position="bottom"> 278 <van-popup v-model:show="showGradePicker" position="bottom">
...@@ -302,7 +297,7 @@ ...@@ -302,7 +297,7 @@
302 </van-popup> 297 </van-popup>
303 298
304 <!-- 小组选择器 --> 299 <!-- 小组选择器 -->
305 - <van-popup v-model:show="showGroupPicker" position="bottom"> 300 + <!-- <van-popup v-model:show="showGroupPicker" position="bottom">
306 <div class="p-4"> 301 <div class="p-4">
307 <van-search v-model="groupSearchValue" placeholder="搜索小组" @search="searchGroup" /> 302 <van-search v-model="groupSearchValue" placeholder="搜索小组" @search="searchGroup" />
308 <van-list> 303 <van-list>
...@@ -310,7 +305,7 @@ ...@@ -310,7 +305,7 @@
310 @click="onGroupSelect(group)" /> 305 @click="onGroupSelect(group)" />
311 </van-list> 306 </van-list>
312 </div> 307 </div>
313 - </van-popup> 308 + </van-popup> -->
314 </AppLayout> 309 </AppLayout>
315 </template> 310 </template>
316 311
...@@ -322,6 +317,8 @@ import AppLayout from '@/components/layout/AppLayout.vue'; ...@@ -322,6 +317,8 @@ import AppLayout from '@/components/layout/AppLayout.vue';
322 import FrostedGlass from '@/components/ui/FrostedGlass.vue'; 317 import FrostedGlass from '@/components/ui/FrostedGlass.vue';
323 import { useTitle } from '@vueuse/core'; 318 import { useTitle } from '@vueuse/core';
324 319
320 +import { getTeacherFindSettingsAPI, setTeacherTaskAPI } from "@/api/teacher";
321 +
325 const $route = useRoute(); 322 const $route = useRoute();
326 const $router = useRouter(); 323 const $router = useRouter();
327 324
...@@ -331,40 +328,41 @@ const pageTitle = computed(() => { ...@@ -331,40 +328,41 @@ const pageTitle = computed(() => {
331 328
332 useTitle(pageTitle); 329 useTitle(pageTitle);
333 330
334 -const type = ref('');
335 -
336 // 表单数据 331 // 表单数据
337 const formData = ref({ 332 const formData = ref({
338 - homework_name: '', 333 + title: '',
339 - description: '', 334 + note: '',
340 - type: $route.query.type === 'homework' ? '上传附件' : '签到', 335 + task_type: $route.query.type === 'homework' ? 'upload' : 'checkin',
336 + frequency_text: '',
341 frequency: '', 337 frequency: '',
342 - target_count: 1, 338 + target_number: 1,
343 start_time: new Date(), 339 start_time: new Date(),
344 end_time: new Date(), 340 end_time: new Date(),
345 course: '', 341 course: '',
342 + lesson_id: '',
346 chapter: '', 343 chapter: '',
347 - activity: '', 344 + // activity: '',
348 grade: '', 345 grade: '',
346 + grade_id: '',
349 class_name: '', 347 class_name: '',
350 - group_name: '' 348 + class_id: '',
349 + // group_name: ''
351 }); 350 });
352 351
353 // 加载状态 352 // 加载状态
354 const loading = ref(false); 353 const loading = ref(false);
355 354
356 // 弹窗显示状态 355 // 弹窗显示状态
357 -const showTypePicker = ref(false);
358 const showFrequencyPicker = ref(false); 356 const showFrequencyPicker = ref(false);
359 const showStartTimePicker = ref(false); 357 const showStartTimePicker = ref(false);
360 const showEndTimePicker = ref(false); 358 const showEndTimePicker = ref(false);
361 const showCoursePicker = ref(false); 359 const showCoursePicker = ref(false);
362 const showChapterPicker = ref(false); 360 const showChapterPicker = ref(false);
363 const showChapterTimePicker = ref(false); 361 const showChapterTimePicker = ref(false);
364 -const showActivityPicker = ref(false); 362 +// const showActivityPicker = ref(false);
365 const showGradePicker = ref(false); 363 const showGradePicker = ref(false);
366 const showClassPicker = ref(false); 364 const showClassPicker = ref(false);
367 -const showGroupPicker = ref(false); 365 +// const showGroupPicker = ref(false);
368 366
369 // 日期选择器相关 367 // 日期选择器相关
370 const startDate = ref(['2024', '01', '01']); 368 const startDate = ref(['2024', '01', '01']);
...@@ -372,67 +370,24 @@ const endDate = ref(['2024', '12', '31']); ...@@ -372,67 +370,24 @@ const endDate = ref(['2024', '12', '31']);
372 const minDate = new Date(2020, 0, 1); 370 const minDate = new Date(2020, 0, 1);
373 const maxDate = new Date(2035, 11, 31); 371 const maxDate = new Date(2035, 11, 31);
374 372
375 -// 选项数据 373 +const frequencyOptions = ref([]);
376 -const typeOptions = ref([
377 - { text: '签到', value: 'checkin' },
378 - { text: '作业', value: 'homework' },
379 - { text: '考试', value: 'exam' },
380 - { text: '活动', value: 'activity' }
381 -]);
382 -
383 -const frequencyOptions = ref([
384 - { text: '一次', value: 'once' },
385 - { text: '每日', value: 'daily' },
386 - { text: '每周', value: 'weekly' },
387 - { text: '每月', value: 'monthly' }
388 -]);
389 374
390 // 搜索值 375 // 搜索值
391 const courseSearchValue = ref(''); 376 const courseSearchValue = ref('');
392 const chapterSearchValue = ref(''); 377 const chapterSearchValue = ref('');
393 -const activitySearchValue = ref(''); 378 +// const activitySearchValue = ref('');
394 const gradeSearchValue = ref(''); 379 const gradeSearchValue = ref('');
395 const classSearchValue = ref(''); 380 const classSearchValue = ref('');
396 -const groupSearchValue = ref(''); 381 +// const groupSearchValue = ref('');
397 382
398 // 数据列表 383 // 数据列表
399 -const courses = ref([ 384 +const courses = ref([]);
400 - { id: 1, name: '数学课程' },
401 - { id: 2, name: '语文课程' },
402 - { id: 3, name: '英语课程' },
403 - { id: 4, name: '物理课程' }
404 -]);
405 385
406 // 章节数据 - 根据课程动态变化 386 // 章节数据 - 根据课程动态变化
407 const chapters = ref([]); 387 const chapters = ref([]);
408 388
409 // 各课程对应的章节数据 389 // 各课程对应的章节数据
410 -const courseChapters = { 390 +const courseChapters = ref({});
411 - '数学课程': [
412 - { id: 1, name: '第一章 数与代数', selected: false, startTime: '', endTime: '' },
413 - { id: 2, name: '第二章 几何图形', selected: false, startTime: '', endTime: '' },
414 - { id: 3, name: '第三章 统计与概率', selected: false, startTime: '', endTime: '' },
415 - { id: 4, name: '第四章 函数与方程', selected: false, startTime: '', endTime: '' }
416 - ],
417 - '语文课程': [
418 - { id: 5, name: '第一单元 现代文阅读', selected: false, startTime: '', endTime: '' },
419 - { id: 6, name: '第二单元 古诗文阅读', selected: false, startTime: '', endTime: '' },
420 - { id: 7, name: '第三单元 写作训练', selected: false, startTime: '', endTime: '' },
421 - { id: 8, name: '第四单元 口语交际', selected: false, startTime: '', endTime: '' }
422 - ],
423 - '英语课程': [
424 - { id: 9, name: 'Unit 1 Hello World', selected: false, startTime: '', endTime: '' },
425 - { id: 10, name: 'Unit 2 My Family', selected: false, startTime: '', endTime: '' },
426 - { id: 11, name: 'Unit 3 School Life', selected: false, startTime: '', endTime: '' },
427 - { id: 12, name: 'Unit 4 Hobbies', selected: false, startTime: '', endTime: '' }
428 - ],
429 - '物理课程': [
430 - { id: 13, name: '第一章 力学基础', selected: false, startTime: '', endTime: '' },
431 - { id: 14, name: '第二章 热学原理', selected: false, startTime: '', endTime: '' },
432 - { id: 15, name: '第三章 电磁学', selected: false, startTime: '', endTime: '' },
433 - { id: 16, name: '第四章 光学现象', selected: false, startTime: '', endTime: '' }
434 - ]
435 -};
436 391
437 // 已选择的章节列表 392 // 已选择的章节列表
438 const selectedChapters = ref([]); 393 const selectedChapters = ref([]);
...@@ -442,33 +397,23 @@ const currentChapterTime = ref(['2024', '01', '01']); ...@@ -442,33 +397,23 @@ const currentChapterTime = ref(['2024', '01', '01']);
442 const currentChapter = ref(null); 397 const currentChapter = ref(null);
443 const currentTimeType = ref(''); // 'start' or 'end' 398 const currentTimeType = ref(''); // 'start' or 'end'
444 399
445 -const activities = ref([ 400 +// const activities = ref([
446 - { id: 1, name: '春游活动' }, 401 +// { id: 1, name: '春游活动' },
447 - { id: 2, name: '运动会' }, 402 +// { id: 2, name: '运动会' },
448 - { id: 3, name: '文艺汇演' }, 403 +// { id: 3, name: '文艺汇演' },
449 - { id: 4, name: '科技节' } 404 +// { id: 4, name: '科技节' }
450 -]); 405 +// ]);
451 - 406 +
452 -const grades = ref([ 407 +const grades = ref([]);
453 - { id: 1, name: '一年级' }, 408 +
454 - { id: 2, name: '二年级' }, 409 +const classes = ref([]);
455 - { id: 3, name: '三年级' }, 410 +
456 - { id: 4, name: '四年级' } 411 +// const groups = ref([
457 -]); 412 +// { id: 1, name: '第一小组' },
458 - 413 +// { id: 2, name: '第二小组' },
459 -const classes = ref([ 414 +// { id: 3, name: '第三小组' },
460 - { id: 1, name: '一班' }, 415 +// { id: 4, name: '第四小组' }
461 - { id: 2, name: '二班' }, 416 +// ]);
462 - { id: 3, name: '三班' },
463 - { id: 4, name: '四班' }
464 -]);
465 -
466 -const groups = ref([
467 - { id: 1, name: '第一小组' },
468 - { id: 2, name: '第二小组' },
469 - { id: 3, name: '第三小组' },
470 - { id: 4, name: '第四小组' }
471 -]);
472 417
473 // 计算属性 - 时间显示格式 418 // 计算属性 - 时间显示格式
474 const startTimeDisplay = computed(() => { 419 const startTimeDisplay = computed(() => {
...@@ -517,12 +462,12 @@ const selectedChaptersCount = computed(() => { ...@@ -517,12 +462,12 @@ const selectedChaptersCount = computed(() => {
517 return chapters.value.filter(chapter => chapter.selected).length; 462 return chapters.value.filter(chapter => chapter.selected).length;
518 }); 463 });
519 464
520 -const filteredActivities = computed(() => { 465 +// const filteredActivities = computed(() => {
521 - if (!activitySearchValue.value) return activities.value; 466 +// if (!activitySearchValue.value) return activities.value;
522 - return activities.value.filter(activity => 467 +// return activities.value.filter(activity =>
523 - activity.name.toLowerCase().includes(activitySearchValue.value.toLowerCase()) 468 +// activity.name.toLowerCase().includes(activitySearchValue.value.toLowerCase())
524 - ); 469 +// );
525 -}); 470 +// });
526 471
527 const filteredGrades = computed(() => { 472 const filteredGrades = computed(() => {
528 if (!gradeSearchValue.value) return grades.value; 473 if (!gradeSearchValue.value) return grades.value;
...@@ -538,12 +483,12 @@ const filteredClasses = computed(() => { ...@@ -538,12 +483,12 @@ const filteredClasses = computed(() => {
538 ); 483 );
539 }); 484 });
540 485
541 -const filteredGroups = computed(() => { 486 +// const filteredGroups = computed(() => {
542 - if (!groupSearchValue.value) return groups.value; 487 +// if (!groupSearchValue.value) return groups.value;
543 - return groups.value.filter(group => 488 +// return groups.value.filter(group =>
544 - group.name.toLowerCase().includes(groupSearchValue.value.toLowerCase()) 489 +// group.name.toLowerCase().includes(groupSearchValue.value.toLowerCase())
545 - ); 490 +// );
546 -}); 491 +// });
547 492
548 /** 493 /**
549 * 格式化日期时间 494 * 格式化日期时间
...@@ -560,20 +505,12 @@ const formatDateTime = (date) => { ...@@ -560,20 +505,12 @@ const formatDateTime = (date) => {
560 }; 505 };
561 506
562 /** 507 /**
563 - * 类型选择确认
564 - * @param {Object} option - 选中的选项
565 - */
566 -const onTypeConfirm = (option) => {
567 - formData.value.type = option.selectedOptions[0].text;
568 - showTypePicker.value = false;
569 -};
570 -
571 -/**
572 * 频次选择确认 508 * 频次选择确认
573 * @param {Object} option - 选中的选项 509 * @param {Object} option - 选中的选项
574 */ 510 */
575 const onFrequencyConfirm = (option) => { 511 const onFrequencyConfirm = (option) => {
576 - formData.value.frequency = option.selectedOptions[0].text; 512 + formData.value.frequency_text = option.selectedOptions[0].text;
513 + formData.value.frequency = option.selectedOptions[0].value;
577 showFrequencyPicker.value = false; 514 showFrequencyPicker.value = false;
578 }; 515 };
579 516
...@@ -633,10 +570,11 @@ const onEndTimeConfirm = () => { ...@@ -633,10 +570,11 @@ const onEndTimeConfirm = () => {
633 */ 570 */
634 const onCourseSelect = (course) => { 571 const onCourseSelect = (course) => {
635 formData.value.course = course.name; 572 formData.value.course = course.name;
573 + formData.value.lesson_id = course.id;
636 // 清空之前选择的章节 574 // 清空之前选择的章节
637 selectedChapters.value = []; 575 selectedChapters.value = [];
638 // 根据选择的课程更新章节数据 576 // 根据选择的课程更新章节数据
639 - chapters.value = courseChapters[course.name] ? JSON.parse(JSON.stringify(courseChapters[course.name])) : []; 577 + chapters.value = courseChapters.value[course.name] ? JSON.parse(JSON.stringify(courseChapters.value[course.name])) : [];
640 showCoursePicker.value = false; 578 showCoursePicker.value = false;
641 courseSearchValue.value = ''; 579 courseSearchValue.value = '';
642 }; 580 };
...@@ -758,11 +696,11 @@ const confirmChapterSelection = () => { ...@@ -758,11 +696,11 @@ const confirmChapterSelection = () => {
758 * 活动选择 696 * 活动选择
759 * @param {Object} activity - 选中的活动 697 * @param {Object} activity - 选中的活动
760 */ 698 */
761 -const onActivitySelect = (activity) => { 699 +// const onActivitySelect = (activity) => {
762 - formData.value.activity = activity.name; 700 +// formData.value.activity = activity.name;
763 - showActivityPicker.value = false; 701 +// showActivityPicker.value = false;
764 - activitySearchValue.value = ''; 702 +// activitySearchValue.value = '';
765 -}; 703 +// };
766 704
767 /** 705 /**
768 * 年级选择 706 * 年级选择
...@@ -770,6 +708,7 @@ const onActivitySelect = (activity) => { ...@@ -770,6 +708,7 @@ const onActivitySelect = (activity) => {
770 */ 708 */
771 const onGradeSelect = (grade) => { 709 const onGradeSelect = (grade) => {
772 formData.value.grade = grade.name; 710 formData.value.grade = grade.name;
711 + formData.value.grade_id = grade.id;
773 showGradePicker.value = false; 712 showGradePicker.value = false;
774 gradeSearchValue.value = ''; 713 gradeSearchValue.value = '';
775 }; 714 };
...@@ -780,6 +719,7 @@ const onGradeSelect = (grade) => { ...@@ -780,6 +719,7 @@ const onGradeSelect = (grade) => {
780 */ 719 */
781 const onClassSelect = (classItem) => { 720 const onClassSelect = (classItem) => {
782 formData.value.class_name = classItem.name; 721 formData.value.class_name = classItem.name;
722 + formData.value.class_id = classItem.id;
783 showClassPicker.value = false; 723 showClassPicker.value = false;
784 classSearchValue.value = ''; 724 classSearchValue.value = '';
785 }; 725 };
...@@ -788,11 +728,11 @@ const onClassSelect = (classItem) => { ...@@ -788,11 +728,11 @@ const onClassSelect = (classItem) => {
788 * 小组选择 728 * 小组选择
789 * @param {Object} group - 选中的小组 729 * @param {Object} group - 选中的小组
790 */ 730 */
791 -const onGroupSelect = (group) => { 731 +// const onGroupSelect = (group) => {
792 - formData.value.group_name = group.name; 732 +// formData.value.group_name = group.name;
793 - showGroupPicker.value = false; 733 +// showGroupPicker.value = false;
794 - groupSearchValue.value = ''; 734 +// groupSearchValue.value = '';
795 -}; 735 +// };
796 736
797 /** 737 /**
798 * 搜索课程 738 * 搜索课程
...@@ -814,9 +754,9 @@ const searchChapter = (value) => { ...@@ -814,9 +754,9 @@ const searchChapter = (value) => {
814 * 搜索活动 754 * 搜索活动
815 * @param {string} value - 搜索值 755 * @param {string} value - 搜索值
816 */ 756 */
817 -const searchActivity = (value) => { 757 +// const searchActivity = (value) => {
818 - activitySearchValue.value = value; 758 +// activitySearchValue.value = value;
819 -}; 759 +// };
820 760
821 /** 761 /**
822 * 搜索年级 762 * 搜索年级
...@@ -838,9 +778,9 @@ const searchClass = (value) => { ...@@ -838,9 +778,9 @@ const searchClass = (value) => {
838 * 搜索小组 778 * 搜索小组
839 * @param {string} value - 搜索值 779 * @param {string} value - 搜索值
840 */ 780 */
841 -const searchGroup = (value) => { 781 +// const searchGroup = (value) => {
842 - groupSearchValue.value = value; 782 +// groupSearchValue.value = value;
843 -}; 783 +// };
844 784
845 /** 785 /**
846 * 表单提交处理 786 * 表单提交处理
...@@ -851,7 +791,7 @@ const handleSubmit = async (values) => { ...@@ -851,7 +791,7 @@ const handleSubmit = async (values) => {
851 loading.value = true; 791 loading.value = true;
852 792
853 // 验证必填项 793 // 验证必填项
854 - if (!formData.value.homework_name) { 794 + if (!formData.value.title) {
855 showToast('请输入作业名称'); 795 showToast('请输入作业名称');
856 return; 796 return;
857 } 797 }
...@@ -860,27 +800,24 @@ const handleSubmit = async (values) => { ...@@ -860,27 +800,24 @@ const handleSubmit = async (values) => {
860 const submitData = { 800 const submitData = {
861 ...formData.value, 801 ...formData.value,
862 // 格式化日期为YYYY-MM-DD格式 802 // 格式化日期为YYYY-MM-DD格式
863 - start_time: formatDateTime(formData.value.start_time), 803 + begin_date: formatDateTime(formData.value.start_time),
864 - end_time: formatDateTime(formData.value.end_time), 804 + end_date: formatDateTime(formData.value.end_time),
865 // 添加课程章节选择数据 805 // 添加课程章节选择数据
866 - selected_chapters: selectedChapters.value.map(chapter => ({ 806 + schedule: selectedChapters.value.map(chapter => ({
867 id: chapter.id, 807 id: chapter.id,
868 name: chapter.name, 808 name: chapter.name,
869 - start_time: formatDateTime(chapter.startTime), 809 + begin_date: formatDateTime(chapter.startTime),
870 - end_time: formatDateTime(chapter.endTime) 810 + end_date: formatDateTime(chapter.endTime)
871 })) 811 }))
872 }; 812 };
873 813
874 // 这里可以调用API提交数据 814 // 这里可以调用API提交数据
875 console.log('提交的表单数据:', submitData); 815 console.log('提交的表单数据:', submitData);
876 - 816 + const { code, data } = await setTeacherTaskAPI(submitData);
877 - // 模拟API调用 817 + if (code) {
878 - await new Promise(resolve => setTimeout(resolve, 1000)); 818 + showToast('保存成功');
879 - 819 + $router.back();
880 - showToast('保存成功'); 820 + }
881 -
882 - // 返回上一页或跳转到列表页
883 - // $router.back();
884 821
885 } catch (error) { 822 } catch (error) {
886 console.error('提交失败:', error); 823 console.error('提交失败:', error);
...@@ -893,9 +830,37 @@ const handleSubmit = async (values) => { ...@@ -893,9 +830,37 @@ const handleSubmit = async (values) => {
893 /** 830 /**
894 * 组件挂载时初始化数据 831 * 组件挂载时初始化数据
895 */ 832 */
896 -onMounted(() => { 833 +onMounted(async () => {
897 // 这里可以调用API获取课程、活动、年级、班级、小组等数据 834 // 这里可以调用API获取课程、活动、年级、班级、小组等数据
898 - console.log('页面初始化'); 835 + const { code, data } = await getTeacherFindSettingsAPI();
836 + if (code) {
837 + frequencyOptions.value = Object.entries(data.task_frequency).map(([value, text]) => ({
838 + text,
839 + value: String(value) // 确保值为字符串类型
840 + }));
841 + grades.value = data.grade_list.map(grade => ({
842 + name: grade.grade_name,
843 + id: String(grade.id)
844 + }));
845 + classes.value = data.class_list.map(classItem => ({
846 + name: classItem.class_name,
847 + id: String(classItem.id)
848 + }));
849 + courses.value = data.group_list.map(course => ({
850 + name: course.title,
851 + id: String(course.id),
852 + schedule_list: course.schedule_list
853 + }));
854 + data.group_list.forEach(course => {
855 + courseChapters.value[course.title] = course.schedule_list.map(chapter => ({
856 + id: chapter.id,
857 + name: chapter.title,
858 + selected: false,
859 + startTime: '',
860 + endTime: ''
861 + }));
862 + });
863 + }
899 }); 864 });
900 </script> 865 </script>
901 866
......