feat: add project view num

This commit is contained in:
lbaf23 2021-08-14 14:23:33 +08:00
parent aa1aee2fc9
commit 73c7e91891
6 changed files with 56 additions and 9 deletions

View File

@ -4,7 +4,6 @@ import (
"OpenPBL/models" "OpenPBL/models"
"OpenPBL/util" "OpenPBL/util"
"encoding/json" "encoding/json"
"fmt"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/casdoor/casdoor-go-sdk/auth" "github.com/casdoor/casdoor-go-sdk/auth"
"strings" "strings"
@ -90,8 +89,8 @@ func (p *ProjectController) CreateProject() {
uid := util.GetUserId(user) uid := util.GetUserId(user)
project := &models.Project{ project := &models.Project{
TeacherId: uid, TeacherId: uid,
LearnMinuteWeight: 100,
} }
fmt.Println(project)
err := project.Create() err := project.Create()
if err != nil { if err != nil {
resp = Response{ resp = Response{
@ -539,3 +538,27 @@ func (p *ProjectController) GetProjectSubjectsAndSkills() {
} }
p.ServeJSON() p.ServeJSON()
} }
// ViewProject
// @Title
// @Description create project
// @Success 200 {object} Response
// @Failure 401
// @Failure 400
// @Failure 403
// @router /:id/view [post]
func (p *ProjectController) ViewProject() {
pid := p.GetString(":id")
err := models.ViewProject(pid)
if err != nil {
p.Data["json"] = Response{
Code: 400,
Msg: err.Error(),
}
} else {
p.Data["json"] = Response{
Code: 200,
}
}
p.ServeJSON()
}

View File

@ -225,3 +225,9 @@ func GetSkills() (skills []string, err error) {
Find(&skills) Find(&skills)
return return
} }
func ViewProject(pid string) (err error) {
_, err = adapter.Engine.
Exec("update project set read_num = read_num + 1 where id = ?", pid)
return
}

View File

@ -91,6 +91,12 @@ const ProjectApi = {
url: `/project/${pid}/subjects-skills`, url: `/project/${pid}/subjects-skills`,
method: 'get' method: 'get'
}) })
},
viewProject(pid) {
return request({
url: `/project/${pid}/view`,
method: 'post'
})
} }
} }

View File

@ -48,10 +48,12 @@ function SectionEditPage(obj) {
<FileResource section={section}/> <FileResource section={section}/>
<StudentTask section={section} pid={pid}/> <StudentTask section={section} pid={pid}/>
</div> </div>
<div style={{textAlign: 'center'}}>
<Link to={`/project/${pid}/section/${sid}/preview?back=/project/${pid}/section/${sid}/edit`}> <Link to={`/project/${pid}/section/${sid}/preview?back=/project/${pid}/section/${sid}/edit`}>
<Button style={{marginBottom: '20px'}}>预览</Button> <Button style={{marginBottom: '20px'}}>预览</Button>
</Link> </Link>
</div> </div>
</div>
</DocumentTitle> </DocumentTitle>
) )
} }

View File

@ -100,7 +100,8 @@ function StudentTask(obj) {
}) })
} }
} }
const gotoSurvey = item => { const gotoSurvey = (item, index) => {
saveContent(item, index)
window.location.href = `/project/${pid}/section/${obj.section.id}/task/${item.id}/survey/edit` window.location.href = `/project/${pid}/section/${obj.section.id}/task/${item.id}/survey/edit`
} }
@ -129,7 +130,7 @@ function StudentTask(obj) {
<Input.TextArea placeholder="任务描述" value={item.taskIntroduce} onChange={e => changeIntroduce(e, index)} <Input.TextArea placeholder="任务描述" value={item.taskIntroduce} onChange={e => changeIntroduce(e, index)}
style={{marginTop: '20px'}}/> style={{marginTop: '20px'}}/>
{item.taskType === 'survey' ? {item.taskType === 'survey' ?
<Button style={{marginTop: '10px'}} onClick={e => gotoSurvey(item)}>查看问卷</Button> <Button style={{marginTop: '10px'}} onClick={e => gotoSurvey(item, index)}>查看问卷</Button>
: null : null
} }

View File

@ -112,6 +112,16 @@ function ProjectList(obj) {
setSelectedSkills(selected) setSelectedSkills(selected)
updateProjectList(page, size, selectedSubjects.toString(), selected.toString(), value) updateProjectList(page, size, selectedSubjects.toString(), selected.toString(), value)
} }
const viewProject = (item) => {
if (item.published && !item.closed) {
ProjectApi.viewProject(item.id)
.then(res => {
})
.catch(e => {
})
}
window.location.href = `/project/${item.id}/info`
}
const onSearch = (v) => { const onSearch = (v) => {
setValue(v) setValue(v)
@ -176,10 +186,10 @@ function ProjectList(obj) {
{ {
learningProjectList.map((item, index) => ( learningProjectList.map((item, index) => (
<Col key={index.toString()} {...topColResponsiveProps}> <Col key={index.toString()} {...topColResponsiveProps}>
<Link to={`/project/${item.id}/info`}>
<Card <Card
hoverable hoverable
bordered={false} bordered={false}
onClick={e=>viewProject(item)}
style={{ style={{
borderRadius: '10px', borderRadius: '10px',
}} }}
@ -239,7 +249,6 @@ function ProjectList(obj) {
{util.FilterMoment(item.createAt)} {util.FilterMoment(item.createAt)}
</span> </span>
</Card> </Card>
</Link>
</Col> </Col>
)) ))
} }