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/util"
"encoding/json"
"fmt"
"github.com/astaxie/beego"
"github.com/casdoor/casdoor-go-sdk/auth"
"strings"
@ -90,8 +89,8 @@ func (p *ProjectController) CreateProject() {
uid := util.GetUserId(user)
project := &models.Project{
TeacherId: uid,
LearnMinuteWeight: 100,
}
fmt.Println(project)
err := project.Create()
if err != nil {
resp = Response{
@ -538,4 +537,28 @@ func (p *ProjectController) GetProjectSubjectsAndSkills() {
}
}
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

@ -224,4 +224,10 @@ func GetSkills() (skills []string, err error) {
Distinct("skill").
Find(&skills)
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`,
method: 'get'
})
},
viewProject(pid) {
return request({
url: `/project/${pid}/view`,
method: 'post'
})
}
}

View File

@ -48,9 +48,11 @@ function SectionEditPage(obj) {
<FileResource section={section}/>
<StudentTask section={section} pid={pid}/>
</div>
<Link to={`/project/${pid}/section/${sid}/preview?back=/project/${pid}/section/${sid}/edit`}>
<Button style={{marginBottom: '20px'}}>预览</Button>
</Link>
<div style={{textAlign: 'center'}}>
<Link to={`/project/${pid}/section/${sid}/preview?back=/project/${pid}/section/${sid}/edit`}>
<Button style={{marginBottom: '20px'}}>预览</Button>
</Link>
</div>
</div>
</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`
}
@ -129,7 +130,7 @@ function StudentTask(obj) {
<Input.TextArea placeholder="任务描述" value={item.taskIntroduce} onChange={e => changeIntroduce(e, index)}
style={{marginTop: '20px'}}/>
{item.taskType === 'survey' ?
<Button style={{marginTop: '10px'}} onClick={e => gotoSurvey(item)}>查看问卷</Button>
<Button style={{marginTop: '10px'}} onClick={e => gotoSurvey(item, index)}>查看问卷</Button>
: null
}

View File

@ -112,6 +112,16 @@ function ProjectList(obj) {
setSelectedSkills(selected)
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) => {
setValue(v)
@ -176,10 +186,10 @@ function ProjectList(obj) {
{
learningProjectList.map((item, index) => (
<Col key={index.toString()} {...topColResponsiveProps}>
<Link to={`/project/${item.id}/info`}>
<Card
hoverable
bordered={false}
onClick={e=>viewProject(item)}
style={{
borderRadius: '10px',
}}
@ -239,7 +249,6 @@ function ProjectList(obj) {
{util.FilterMoment(item.createAt)}
</span>
</Card>
</Link>
</Col>
))
}