提交 a6fb699d authored 作者: 王鹏飞's avatar 王鹏飞

升级V3接口

上级 76e6d010
......@@ -40,7 +40,7 @@ export default class CourseAction extends BaseACTION {
const cur = data[i]
const _cur = data[i].curriculum
/* 课程类型 */
const _type = cur.course_type
const _type = parseInt(cur.course_type)
const str1 = _type === 1 ? _vIn.$t('action.courseAction.mustLearn')
: (_type === 2 ? _vIn.$t('action.courseAction.changeLearn')
: (_type === 3 ? _vIn.$t('action.courseAction.repeatLearn') : ''))
......
......@@ -8,7 +8,7 @@ const httpRequest = new BaseAPI(webConf)
* @param {string} courseId 课程ID
*/
export function getCourse(semesterId, courseId) {
return httpRequest.get(`/api/lms/v2/education/courses/${semesterId}/${courseId}`)
return httpRequest.get(`/api/lms/v3/education/courses/${semesterId}/${courseId}`)
}
/**
......
......@@ -10,7 +10,7 @@ export default class CourseAPI extends BaseAPI {
* @param {[string]} isMy
* @param {[object]} param
*/
getCourseList = (isMy, param) => this.get('/api/lms/v2/education/courses' + (isMy ? '/my' : ''), param)
getCourseList = (isMy, param) => this.get('/api/lms/v3/education/courses' + (isMy ? '/my' : ''), param)
/**
* 获取某个课程详细信息 - 课程考核 和 课程讨论单独获取
* @param {[string]} id
......
......@@ -8,7 +8,7 @@ const httpRequest = new BaseAPI(webConf)
* @param {string} courseId 课程ID
*/
export function getCourse(semesterId, courseId) {
return httpRequest.get(`/api/lms/v2/education/courses/${semesterId}/${courseId}`)
return httpRequest.get(`/api/lms/v3/education/courses/${semesterId}/${courseId}`)
}
/**
......@@ -53,6 +53,14 @@ export function updateChapterVideoProgress(params) {
return httpRequest.get('/api/lms/v2/analytics/upload-video', params)
}
/**
* 获取章节阅读资料
* @param {string} resourseId 章节的资源ID
*/
export function getChapterReading(resourseId) {
return httpRequest.get(`/api/lms/v3/education/reading/${resourseId}`)
}
/**
* 获取章节作业
* @param {string} semesterId 学期ID
......@@ -60,7 +68,7 @@ export function updateChapterVideoProgress(params) {
* @param {string} resourseId 章节的资源ID
*/
export function getChapterHomework(semesterId, courseId, resourseId) {
return httpRequest.get(`/api/lms/v2/education/homeworks/${semesterId}/${courseId}/${resourseId}`)
return httpRequest.get(`/api/lms/v3/education/homeworks/${semesterId}/${courseId}/${resourseId}`)
}
/**
......
......@@ -9,6 +9,7 @@
// components
import Container from '../common/container.vue'
import FileList from './fileList.vue'
import * as api from '../../api'
// 章节阅读资料
export default {
......@@ -30,15 +31,30 @@ export default {
}
}
},
data() {
return {
files: []
}
},
computed: {
files() {
const reading = this.chapter.reading
// 资源ID
resourceId() {
return this.chapter.resource_id
}
},
methods: {
getChapterReading() {
api.getChapterReading(this.resourceId).then(response => {
const file = {
file_name: reading.reading_content,
file_url: reading.reading_attachment
file_name: response.reading_content,
file_url: response.reading_attachment
}
return [file]
this.files = [file]
})
}
},
beforeMount() {
this.getChapterReading()
}
}
</script>
......@@ -39,12 +39,8 @@ export default {
components: { Container, ExamItem },
props: {
// 当前选中的章节
chapter: {
type: Object,
default() {
return {}
}
}
chapter: { type: Object, default: () => ({}) },
homework: { type: Object, default: () => ({}) }
},
data() {
return {
......@@ -57,11 +53,16 @@ export default {
}
},
watch: {
chapter: {
homework: {
immediate: true,
handler(data) {
if (!this.questions.length) {
this.questions = data.homework ? this.genQuestions(data.homework.questions) : []
const { questions = [], answer = {} } = data
this.detail = answer
this.questions = this.genQuestions(questions)
// 答案处理
const parseAnswers = answer.work_contents ? JSON.parse(answer.work_contents) : []
if (parseAnswers && parseAnswers.length) {
this.setAnswers(parseAnswers)
}
}
}
......@@ -99,34 +100,6 @@ export default {
}
},
methods: {
// 获取测试答题详情
getDetail() {
this.loading = true
api
.getChapterHomework(this.sid, this.cid, this.resourceId)
.then(response => {
this.detail = Array.isArray(response) ? null : response
if (this.detail) {
const parseAnswers = JSON.parse(this.detail.work_contents)
// 设置答案
this.questions = this.questions.map(item => {
const found = parseAnswers.find(answer => answer.question_id === item.id)
if (found) {
const selectedIds = found.options.reduce((result, item) => {
item.selected && result.push(item.id)
return result
}, [])
item.user_answer = item.question_type === 2 ? selectedIds : selectedIds[0]
}
return item
})
this.questions = this.genQuestions(this.questions)
}
})
.finally(() => {
this.loading = false
})
},
// 组装问题数据
genQuestions(list) {
if (!list) {
......@@ -165,6 +138,22 @@ export default {
)
})
},
// 设置答案
setAnswers(parseAnswers) {
this.questions = this.questions.map(item => {
const found = parseAnswers.find(answer => answer.question_id === item.id)
if (found) {
const selectedIds = found.options.reduce((result, item) => {
item.selected && result.push(item.id)
return result
}, [])
item.user_answer = item.question_type === 2 ? selectedIds : selectedIds[0]
}
return item
})
// 重新组装
this.questions = this.genQuestions(this.questions)
},
// 提交校验
checkSubmit() {
const questions = this.questions
......@@ -245,7 +234,7 @@ export default {
.sbumitChapterHomework(params)
.then(response => {
if (response.status) {
this.getDetail()
this.$emit('update')
} else {
this.$message.error(response.data.error)
}
......@@ -257,9 +246,6 @@ export default {
this.submitLoading = false
})
}
},
beforeMount() {
this.getDetail()
}
}
</script>
......
......@@ -89,7 +89,7 @@
<chapter-work-comment
:endDate="commentEndDate"
:status="detail.status2"
@update="getDetail"
v-on="$listeners"
v-if="showComment"
id="comment"
/>
......@@ -132,19 +132,10 @@ export default {
components: { Container, ExamItem, ChapterWorkComment },
props: {
// 当前选中的
chapter: {
type: Object,
default() {
return {}
}
},
chapter: { type: Object, default: () => ({}) },
// 课程详情接口返回的数据
data: {
type: Object,
default() {
return {}
}
}
data: { type: Object, default: () => ({}) },
homework: { type: Object, default: () => ({}) }
},
data() {
return {
......@@ -167,11 +158,22 @@ export default {
}
},
watch: {
chapter: {
homework: {
immediate: true,
handler(data) {
if (!this.questions.length) {
this.questions = data.homework ? this.genQuestions(data.homework.questions) : []
const { questions = [], answer = {} } = data
this.questions = this.genQuestions(questions)
this.detail = Array.isArray(answer) ? {} : answer
if (
(this.detail.status === 1 || this.detail.status2 === 1) &&
!([-1, -2].includes(this.detail.status) || [-1, -2].includes(this.detail.status2))
) {
this.dialogVisible = true
}
// 答案处理
const parseAnswers = answer.work_contents ? JSON.parse(answer.work_contents) : []
if (parseAnswers && parseAnswers.length) {
this.setAnswers(parseAnswers)
}
}
}
......@@ -251,37 +253,6 @@ export default {
this.commentEndDate = response.comment_end
})
},
// 获取详情
getDetail() {
this.loading = true
api
.getChapterHomework(this.sid, this.cid, this.resourceId)
.then(response => {
this.detail = Array.isArray(response) ? {} : response
if (
(this.detail.status === 1 || this.detail.status2 === 1) &&
!([-1, -2].includes(this.detail.status) || [-1, -2].includes(this.detail.status2))
) {
this.dialogVisible = true
}
if (this.detail.id) {
const parseAnswers = JSON.parse(this.detail.work_contents)
// 设置答案
this.questions = this.questions.map(item => {
const found = parseAnswers.find(answer => answer.question_id === item.id)
if (found) {
item.user_answer = found.descreption
item.attachments = found.file_url
}
return item
})
this.questions = this.genQuestions(this.questions)
}
})
.finally(() => {
this.loading = false
})
},
// 组装问题数据
genQuestions(list) {
if (!list) {
......@@ -320,6 +291,19 @@ export default {
)
})
},
// 设置答案
setAnswers(parseAnswers) {
this.questions = this.questions.map(item => {
const found = parseAnswers.find(answer => answer.question_id === item.id)
if (found) {
item.user_answer = found.descreption
item.attachments = found.file_url
}
return item
})
// 重新组装数据
this.questions = this.genQuestions(this.questions)
},
// 提交校验
checkSubmit() {
let result = true
......@@ -385,7 +369,7 @@ export default {
.then(response => {
if (response.status) {
this.$message.success(this.$t('viewerWork.examSubmitSuccess'))
this.getDetail()
this.$emit('update')
} else {
this.$message.error(response.data.error)
}
......@@ -410,7 +394,6 @@ export default {
}
},
beforeMount() {
this.getDetail()
this.getDeadline()
}
}
......
<template>
<component :is="currentCompoent" :chapter="chapter" :data="data" v-bind="$attrs" v-on="$listeners" v-if="chapter" />
<component
:is="currentCompoent"
:chapter="chapter"
:data="data"
:homework="homework"
@update="getHomework"
v-bind="$attrs"
v-on="$listeners"
v-if="chapter"
v-loading="loading"
/>
</template>
<script>
// componets
import ChapterWork from './chapterWork.vue'
import ChapterTest from './chapterTest.vue'
import * as api from '../../api'
export default {
name: 'ViewerWork',
......@@ -26,15 +37,54 @@ export default {
}
}
},
data() {
return {
loading: false,
homework: {}
}
},
computed: {
currentCompoent() {
const componentNames = {
1: 'ChapterTest', // 课后测验
2: 'ChapterWork' // 作业
}
const homework = this.chapter.homework
const homework = this.homework
return homework ? componentNames[homework.work_type] : ''
},
// 学期ID
sid() {
return this.$route.params.sid
},
// 课程ID
cid() {
return this.$route.params.cid
},
// 当前页面的ID
pid() {
return this.$route.params.id
},
// 资源ID
resourceId() {
return this.chapter.resource_id
}
},
methods: {
getHomework() {
this.loading = true
api
.getChapterHomework(this.sid, this.cid, this.resourceId)
.then(response => {
const { answer, question } = response
this.homework = { answer, ...question }
})
.finally(() => {
this.loading = false
})
}
},
beforeMount() {
this.getHomework()
}
}
</script>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论