diff --git a/controllers/task.go b/controllers/task.go index 4d6b6c7..6b40085 100644 --- a/controllers/task.go +++ b/controllers/task.go @@ -16,9 +16,9 @@ func (p *ProjectController) GetSectionTasks() { sid := p.GetString(":sid") tasks, err := models.GetSectionTasks(sid) if err != nil { - p.Data["json"] = map[string][]models.Task{"tasks": nil} + p.Data["json"] = map[string][]models.TaskDetail{"tasks": nil} } else { - p.Data["json"] = map[string][]models.Task{"tasks": tasks} + p.Data["json"] = map[string][]models.TaskDetail{"tasks": tasks} } p.ServeJSON() } diff --git a/models/survey.go b/models/survey.go index bc19e6b..ea91224 100644 --- a/models/survey.go +++ b/models/survey.go @@ -21,7 +21,7 @@ type Question struct { QuestionCount string `json:"question" xorm:"text"` } type SurveyDetail struct { - Survey `xorm:"extends"` + Survey `json:"survey" xorm:"extends"` Questions []Question `json:"questions" xorm:"extends"` } diff --git a/models/task.go b/models/task.go index f6432a3..9b67b5d 100644 --- a/models/task.go +++ b/models/task.go @@ -14,6 +14,12 @@ type Task struct { TaskType string `json:"taskType" xorm:"index"` } +type TaskDetail struct { + Task `xorm:"extends"` + SurveyDetail `xorm:"extends"` + +} + func (t *Task) GetEngine() *xorm.Session { return adapter.Engine.Table(t) } @@ -40,11 +46,26 @@ func (t *Task) Delete() (err error) { return } -func GetSectionTasks(sid string) (t []Task, err error) { +func GetSectionTasks(sid string) (t []TaskDetail, err error) { err = (&Task{}).GetEngine(). Where("section_id = ?", sid). Asc("task_order"). Find(&t) + var s Survey + var qs []Question + for i := 0; i < len(t); i ++ { + if t[i].TaskType == "survey" { + _, err = (&Survey{}).GetEngine(). + Where("task_id = ?", t[i].Id). + Get(&s) + err = (&Question{}).GetEngine(). + Where("survey_id = ?", s.Id). + Asc("question_order"). + Find(&qs) + t[i].Survey = s + t[i].Questions = qs + } + } return } diff --git a/openpbl-landing/package.json b/openpbl-landing/package.json index d084c36..8839a1c 100644 --- a/openpbl-landing/package.json +++ b/openpbl-landing/package.json @@ -39,8 +39,9 @@ "web-vitals": "^1.0.1" }, "scripts": { + "analyze": "source-map-explorer 'build/static/js/*.js'", "start": "craco start", - "build": "craco --max_old_space_size=2048 build", + "build": "craco build", "test": "craco test", "eject": "react-scripts eject" }, diff --git a/openpbl-landing/src/pages/Project/CreateProject/PreviewResource.jsx b/openpbl-landing/src/pages/Project/CreateProject/PreviewResource.jsx index c21a33f..a0f1d72 100644 --- a/openpbl-landing/src/pages/Project/CreateProject/PreviewResource.jsx +++ b/openpbl-landing/src/pages/Project/CreateProject/PreviewResource.jsx @@ -1,26 +1,72 @@ import React, {useEffect, useState} from "react"; -import {Card, PageHeader} from "antd"; +import {Card, PageHeader, Input, Upload, message, Button, Collapse, Spin, Radio, Divider} from "antd"; import DocumentTitle from 'react-document-title'; - +import {InboxOutlined} from '@ant-design/icons' import SectionApi from "../../../api/SectionApi"; import "./section-edit.less" +import "./preview.less" +import TaskApi from "../../../api/TaskApi"; +import FillSurvey from "./component/FillSurvey"; + function PreviewResource(obj) { const sid = obj.match.params.sid const pid = obj.match.params.pid const [section, setSection] = useState({resource:{}}) + const [tasks, setTasks] = useState([]) + useEffect(()=>{ + getSectionResource() + getTasks() + }, []) + const getSectionResource = () => { SectionApi.getSectionDetail(sid) .then(res=>{ setSection(res.data.section) }) .catch(e=>{console.log(e)}) - }, []) - + } + const getTasks = () => { + TaskApi.getSectionTasks(sid) + .then(res=>{ + if (res.data.tasks === null) { + setTasks([]) + } else { + let t = res.data.tasks + for (let i = 0; i < t.length; i++) { + if (t[i].questions !== undefined && t[i].questions != null) { + for (let j = 0; j < t[i].questions.length; j++) { + t[i].questions[j].questionOptions = t[i].questions[j].questionOptions.split(",") + } + } + } + setTasks(t) + } + }) + .catch(e=>{console.log(e)}) + } const back = e => { window.location.href = '/project/edit/section/' + pid + '/' + sid } - + const props = { + name: 'file', + multiple: true, + action: '', + onChange(info) { + const { status } = info.file; + if (status !== 'uploading') { + console.log(info.file, info.fileList); + } + if (status === 'done') { + message.success(`${info.file.name} 上传成功`); + } else if (status === 'error') { + message.error(`${info.file.name} 上传失败`); + } + }, + onDrop(e) { + console.log('Dropped files', e.dataTransfer.files); + }, + }; return ( @@ -31,7 +77,7 @@ function PreviewResource(obj) { title="返回" subTitle="我的项目" /> -
+

{section.sectionName}

@@ -39,18 +85,45 @@ function PreviewResource(obj) {
-

文件

+

文件资源

{section.resource.fileTitle}

{section.resource.fileIntroduce}

- {section.resource.hasHomeWork ? - + {tasks.map((item, index)=>( +

学生任务

-

{section.resource.homeWorkTitle}

-

{section.resource.homeWorkIntroduce}

+

{item.taskTitle}

+

{item.taskIntroduce}

+ {item.taskType === 'file' ? +
+ +

+ +

+

点击或拖动文件上传

+

hint +

+
+
+ : null + } + {item.taskType === 'comment' ? +
+ + +
+ : null + } + {item.taskType === 'survey' ? + + : null + }
- : null} -
+ )) + } +

) diff --git a/openpbl-landing/src/pages/Project/CreateProject/component/FillSurvey.jsx b/openpbl-landing/src/pages/Project/CreateProject/component/FillSurvey.jsx new file mode 100644 index 0000000..5dd37a0 --- /dev/null +++ b/openpbl-landing/src/pages/Project/CreateProject/component/FillSurvey.jsx @@ -0,0 +1,80 @@ +import React from "react"; +import {Button, Checkbox, Divider, Input, Radio} from "antd"; + +import Question from "../Question" +import "../preview.less" +import "../section-edit.less" + +const blank = Question.blank + +function FillSurvey(obj) { + + const submitSurvey = e => { + + } + return ( +
+

{obj.item.survey.surveyTitle}

+ +
+ {obj.item.questions.map((subItem, subIndex)=>( +
+ {subItem.questionType==='singleChoice' ? +
+

{subItem.questionTitle}

+ + {subItem.questionOptions.map((optItem, optIndex) => ( +
+ + {optItem} + +
+ ))} +
+
+ : null} + {subItem.questionType==='multipleChoice' ? +
+

{subItem.questionTitle}

+ {subItem.questionOptions.map((optItem, optIndex) => ( +
+ + {optItem} + +
+ ))} +
+ : null} + {subItem.questionType==='blankFill' ? +
+

{subItem.questionTitle}

+ {subItem.questionOptions.map((optItem, optIndex) => ( +
+ {optItem === blank ? + + + + : + {optItem}} +
+ ))} +
+ : null} + + {subItem.questionType==='briefAnswer' ? +
+

{subItem.questionOptions[0]}

+ +
+ : null} + + +
+ ))} +
+ +
+ ) +} + +export default FillSurvey \ No newline at end of file diff --git a/openpbl-landing/src/pages/Project/CreateProject/preview.less b/openpbl-landing/src/pages/Project/CreateProject/preview.less new file mode 100644 index 0000000..d906411 --- /dev/null +++ b/openpbl-landing/src/pages/Project/CreateProject/preview.less @@ -0,0 +1,7 @@ +.survey{ + max-width: 1200px; + padding: 20px; + margin: auto; + background-color: rgba(244, 231, 174, 0.07); + border-radius: 10px; +} \ No newline at end of file diff --git a/openpbl-landing/src/pages/Project/CreateProject/section-edit.less b/openpbl-landing/src/pages/Project/CreateProject/section-edit.less index 2e77083..ed56bb6 100644 --- a/openpbl-landing/src/pages/Project/CreateProject/section-edit.less +++ b/openpbl-landing/src/pages/Project/CreateProject/section-edit.less @@ -9,5 +9,6 @@ } .task-title{ text-align: left; - font-weight: bold; + font-size: 16px; } + diff --git a/openpbl-landing/src/pages/Project/component/MultipleChoice.jsx b/openpbl-landing/src/pages/Project/component/MultipleChoice.jsx index cc4e099..b2803d2 100644 --- a/openpbl-landing/src/pages/Project/component/MultipleChoice.jsx +++ b/openpbl-landing/src/pages/Project/component/MultipleChoice.jsx @@ -88,9 +88,9 @@ function MultipleChoice(obj) { {obj.item.questionOptions.map((subItem, subIndex) => (
- + {subItem} - +
))}