feat(教师表单): 优化时间选择器交互并完善表单提交逻辑
重构时间选择器点击事件为独立函数,提高代码可维护性 扩展最大可选日期至2035年 移除未使用的活动和小组成员选择代码 完善表单提交数据格式,包含章节选择和日期格式化
Showing
2 changed files
with
55 additions
and
8 deletions
src/api/teacher.js
0 → 100644
File mode changed
| ... | @@ -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-23 11:38:17 | 5 | + * @LastEditTime: 2025-06-23 11:54:22 |
| 6 | * @FilePath: /mlaj/src/views/teacher/formPage.vue | 6 | * @FilePath: /mlaj/src/views/teacher/formPage.vue |
| 7 | * @Description: 教师作业新增表单页面 | 7 | * @Description: 教师作业新增表单页面 |
| 8 | --> | 8 | --> |
| ... | @@ -78,7 +78,7 @@ | ... | @@ -78,7 +78,7 @@ |
| 78 | <div class="time-item"> | 78 | <div class="time-item"> |
| 79 | <van-icon name="calendar-o" class="time-icon" /> | 79 | <van-icon name="calendar-o" class="time-icon" /> |
| 80 | <span class="time-label">开始日期:</span> | 80 | <span class="time-label">开始日期:</span> |
| 81 | - <span class="time-value" @click="showStartTimePicker = true"> | 81 | + <span class="time-value" @click="openStartTimePicker"> |
| 82 | {{ startTimeDisplay || '2025-05-13' }} | 82 | {{ startTimeDisplay || '2025-05-13' }} |
| 83 | </span> | 83 | </span> |
| 84 | <van-icon name="arrow" class="arrow-icon" /> | 84 | <van-icon name="arrow" class="arrow-icon" /> |
| ... | @@ -88,7 +88,7 @@ | ... | @@ -88,7 +88,7 @@ |
| 88 | <div class="time-item"> | 88 | <div class="time-item"> |
| 89 | <van-icon name="calendar-o" class="time-icon" /> | 89 | <van-icon name="calendar-o" class="time-icon" /> |
| 90 | <span class="time-label">结束日期:</span> | 90 | <span class="time-label">结束日期:</span> |
| 91 | - <span class="time-value" @click="showEndTimePicker = true"> | 91 | + <span class="time-value" @click="openEndTimePicker"> |
| 92 | {{ endTimeDisplay || '2025-06-13' }} | 92 | {{ endTimeDisplay || '2025-06-13' }} |
| 93 | </span> | 93 | </span> |
| 94 | <van-icon name="arrow" class="arrow-icon" /> | 94 | <van-icon name="arrow" class="arrow-icon" /> |
| ... | @@ -132,7 +132,7 @@ | ... | @@ -132,7 +132,7 @@ |
| 132 | <van-icon name="arrow" class="arrow-icon" @click="showChapterPicker = true" /> | 132 | <van-icon name="arrow" class="arrow-icon" @click="showChapterPicker = true" /> |
| 133 | </div> | 133 | </div> |
| 134 | </div> | 134 | </div> |
| 135 | - <div class="select-row"> | 135 | + <!-- <div class="select-row"> |
| 136 | <div class="select-item"> | 136 | <div class="select-item"> |
| 137 | <van-icon name="fire-o" class="select-icon" /> | 137 | <van-icon name="fire-o" class="select-icon" /> |
| 138 | <span class="select-label">所在活动:</span> | 138 | <span class="select-label">所在活动:</span> |
| ... | @@ -147,7 +147,7 @@ | ... | @@ -147,7 +147,7 @@ |
| 147 | <span class="select-value" @click="showGroupPicker = true">{{ formData.group_name || '请选择小组' }}</span> | 147 | <span class="select-value" @click="showGroupPicker = true">{{ formData.group_name || '请选择小组' }}</span> |
| 148 | <van-icon name="arrow" class="arrow-icon" @click="showGroupPicker = true" /> | 148 | <van-icon name="arrow" class="arrow-icon" @click="showGroupPicker = true" /> |
| 149 | </div> | 149 | </div> |
| 150 | - </div> | 150 | + </div> --> |
| 151 | </div> | 151 | </div> |
| 152 | 152 | ||
| 153 | <!-- 提交按钮 --> | 153 | <!-- 提交按钮 --> |
| ... | @@ -365,7 +365,7 @@ const showGroupPicker = ref(false); | ... | @@ -365,7 +365,7 @@ const showGroupPicker = ref(false); |
| 365 | const startDate = ref(['2024', '01', '01']); | 365 | const startDate = ref(['2024', '01', '01']); |
| 366 | const endDate = ref(['2024', '12', '31']); | 366 | const endDate = ref(['2024', '12', '31']); |
| 367 | const minDate = new Date(2020, 0, 1); | 367 | const minDate = new Date(2020, 0, 1); |
| 368 | -const maxDate = new Date(2030, 11, 31); | 368 | +const maxDate = new Date(2035, 11, 31); |
| 369 | 369 | ||
| 370 | // 选项数据 | 370 | // 选项数据 |
| 371 | const typeOptions = ref([ | 371 | const typeOptions = ref([ |
| ... | @@ -573,6 +573,22 @@ const onFrequencyConfirm = (option) => { | ... | @@ -573,6 +573,22 @@ const onFrequencyConfirm = (option) => { |
| 573 | }; | 573 | }; |
| 574 | 574 | ||
| 575 | /** | 575 | /** |
| 576 | + * 打开开始时间选择器 | ||
| 577 | + */ | ||
| 578 | +const openStartTimePicker = () => { | ||
| 579 | + // 同步当前的开始时间到选择器 | ||
| 580 | + if (formData.value.start_time) { | ||
| 581 | + const date = new Date(formData.value.start_time); | ||
| 582 | + startDate.value = [ | ||
| 583 | + date.getFullYear().toString(), | ||
| 584 | + (date.getMonth() + 1).toString().padStart(2, '0'), | ||
| 585 | + date.getDate().toString().padStart(2, '0') | ||
| 586 | + ]; | ||
| 587 | + } | ||
| 588 | + showStartTimePicker.value = true; | ||
| 589 | +}; | ||
| 590 | + | ||
| 591 | +/** | ||
| 576 | * 开始时间确认 | 592 | * 开始时间确认 |
| 577 | */ | 593 | */ |
| 578 | const onStartTimeConfirm = () => { | 594 | const onStartTimeConfirm = () => { |
| ... | @@ -582,6 +598,22 @@ const onStartTimeConfirm = () => { | ... | @@ -582,6 +598,22 @@ const onStartTimeConfirm = () => { |
| 582 | }; | 598 | }; |
| 583 | 599 | ||
| 584 | /** | 600 | /** |
| 601 | + * 打开结束时间选择器 | ||
| 602 | + */ | ||
| 603 | +const openEndTimePicker = () => { | ||
| 604 | + // 同步当前的结束时间到选择器 | ||
| 605 | + if (formData.value.end_time) { | ||
| 606 | + const date = new Date(formData.value.end_time); | ||
| 607 | + endDate.value = [ | ||
| 608 | + date.getFullYear().toString(), | ||
| 609 | + (date.getMonth() + 1).toString().padStart(2, '0'), | ||
| 610 | + date.getDate().toString().padStart(2, '0') | ||
| 611 | + ]; | ||
| 612 | + } | ||
| 613 | + showEndTimePicker.value = true; | ||
| 614 | +}; | ||
| 615 | + | ||
| 616 | +/** | ||
| 585 | * 结束时间确认 | 617 | * 结束时间确认 |
| 586 | */ | 618 | */ |
| 587 | const onEndTimeConfirm = () => { | 619 | const onEndTimeConfirm = () => { |
| ... | @@ -813,8 +845,23 @@ const handleSubmit = async (values) => { | ... | @@ -813,8 +845,23 @@ const handleSubmit = async (values) => { |
| 813 | return; | 845 | return; |
| 814 | } | 846 | } |
| 815 | 847 | ||
| 848 | + // 准备提交的数据,包含课程章节选择和格式化的日期 | ||
| 849 | + const submitData = { | ||
| 850 | + ...formData.value, | ||
| 851 | + // 格式化日期为YYYY-MM-DD格式 | ||
| 852 | + start_time: formatDateTime(formData.value.start_time), | ||
| 853 | + end_time: formatDateTime(formData.value.end_time), | ||
| 854 | + // 添加课程章节选择数据 | ||
| 855 | + selected_chapters: selectedChapters.value.map(chapter => ({ | ||
| 856 | + id: chapter.id, | ||
| 857 | + name: chapter.name, | ||
| 858 | + start_time: formatDateTime(chapter.startTime), | ||
| 859 | + end_time: formatDateTime(chapter.endTime) | ||
| 860 | + })) | ||
| 861 | + }; | ||
| 862 | + | ||
| 816 | // 这里可以调用API提交数据 | 863 | // 这里可以调用API提交数据 |
| 817 | - console.log('提交的表单数据:', formData.value); | 864 | + console.log('提交的表单数据:', submitData); |
| 818 | 865 | ||
| 819 | // 模拟API调用 | 866 | // 模拟API调用 |
| 820 | await new Promise(resolve => setTimeout(resolve, 1000)); | 867 | await new Promise(resolve => setTimeout(resolve, 1000)); |
| ... | @@ -822,7 +869,7 @@ const handleSubmit = async (values) => { | ... | @@ -822,7 +869,7 @@ const handleSubmit = async (values) => { |
| 822 | showToast('保存成功'); | 869 | showToast('保存成功'); |
| 823 | 870 | ||
| 824 | // 返回上一页或跳转到列表页 | 871 | // 返回上一页或跳转到列表页 |
| 825 | - $router.back(); | 872 | + // $router.back(); |
| 826 | 873 | ||
| 827 | } catch (error) { | 874 | } catch (error) { |
| 828 | console.error('提交失败:', error); | 875 | console.error('提交失败:', error); | ... | ... |
-
Please register or login to post a comment