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

升级V3接口

上级 76e6d010
...@@ -40,7 +40,7 @@ export default class CourseAction extends BaseACTION { ...@@ -40,7 +40,7 @@ export default class CourseAction extends BaseACTION {
const cur = data[i] const cur = data[i]
const _cur = data[i].curriculum 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') const str1 = _type === 1 ? _vIn.$t('action.courseAction.mustLearn')
: (_type === 2 ? _vIn.$t('action.courseAction.changeLearn') : (_type === 2 ? _vIn.$t('action.courseAction.changeLearn')
: (_type === 3 ? _vIn.$t('action.courseAction.repeatLearn') : '')) : (_type === 3 ? _vIn.$t('action.courseAction.repeatLearn') : ''))
......
...@@ -8,7 +8,7 @@ const httpRequest = new BaseAPI(webConf) ...@@ -8,7 +8,7 @@ const httpRequest = new BaseAPI(webConf)
* @param {string} courseId 课程ID * @param {string} courseId 课程ID
*/ */
export function getCourse(semesterId, courseId) { 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 { ...@@ -10,7 +10,7 @@ export default class CourseAPI extends BaseAPI {
* @param {[string]} isMy * @param {[string]} isMy
* @param {[object]} param * @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 * @param {[string]} id
......
...@@ -8,7 +8,7 @@ const httpRequest = new BaseAPI(webConf) ...@@ -8,7 +8,7 @@ const httpRequest = new BaseAPI(webConf)
* @param {string} courseId 课程ID * @param {string} courseId 课程ID
*/ */
export function getCourse(semesterId, courseId) { 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) { ...@@ -53,6 +53,14 @@ export function updateChapterVideoProgress(params) {
return httpRequest.get('/api/lms/v2/analytics/upload-video', 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 * @param {string} semesterId 学期ID
...@@ -60,7 +68,7 @@ export function updateChapterVideoProgress(params) { ...@@ -60,7 +68,7 @@ export function updateChapterVideoProgress(params) {
* @param {string} resourseId 章节的资源ID * @param {string} resourseId 章节的资源ID
*/ */
export function getChapterHomework(semesterId, courseId, resourseId) { 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 @@ ...@@ -9,6 +9,7 @@
// components // components
import Container from '../common/container.vue' import Container from '../common/container.vue'
import FileList from './fileList.vue' import FileList from './fileList.vue'
import * as api from '../../api'
// 章节阅读资料 // 章节阅读资料
export default { export default {
...@@ -30,15 +31,30 @@ export default { ...@@ -30,15 +31,30 @@ export default {
} }
} }
}, },
data() {
return {
files: []
}
},
computed: { computed: {
files() { // 资源ID
const reading = this.chapter.reading resourceId() {
const file = { return this.chapter.resource_id
file_name: reading.reading_content,
file_url: reading.reading_attachment
}
return [file]
} }
},
methods: {
getChapterReading() {
api.getChapterReading(this.resourceId).then(response => {
const file = {
file_name: response.reading_content,
file_url: response.reading_attachment
}
this.files = [file]
})
}
},
beforeMount() {
this.getChapterReading()
} }
} }
</script> </script>
...@@ -39,12 +39,8 @@ export default { ...@@ -39,12 +39,8 @@ export default {
components: { Container, ExamItem }, components: { Container, ExamItem },
props: { props: {
// 当前选中的章节 // 当前选中的章节
chapter: { chapter: { type: Object, default: () => ({}) },
type: Object, homework: { type: Object, default: () => ({}) }
default() {
return {}
}
}
}, },
data() { data() {
return { return {
...@@ -57,11 +53,16 @@ export default { ...@@ -57,11 +53,16 @@ export default {
} }
}, },
watch: { watch: {
chapter: { homework: {
immediate: true, immediate: true,
handler(data) { handler(data) {
if (!this.questions.length) { const { questions = [], answer = {} } = data
this.questions = data.homework ? this.genQuestions(data.homework.questions) : [] 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 { ...@@ -99,34 +100,6 @@ export default {
} }
}, },
methods: { 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) { genQuestions(list) {
if (!list) { if (!list) {
...@@ -165,6 +138,22 @@ export default { ...@@ -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() { checkSubmit() {
const questions = this.questions const questions = this.questions
...@@ -245,7 +234,7 @@ export default { ...@@ -245,7 +234,7 @@ export default {
.sbumitChapterHomework(params) .sbumitChapterHomework(params)
.then(response => { .then(response => {
if (response.status) { if (response.status) {
this.getDetail() this.$emit('update')
} else { } else {
this.$message.error(response.data.error) this.$message.error(response.data.error)
} }
...@@ -257,9 +246,6 @@ export default { ...@@ -257,9 +246,6 @@ export default {
this.submitLoading = false this.submitLoading = false
}) })
} }
},
beforeMount() {
this.getDetail()
} }
} }
</script> </script>
......
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
<chapter-work-comment <chapter-work-comment
:endDate="commentEndDate" :endDate="commentEndDate"
:status="detail.status2" :status="detail.status2"
@update="getDetail" v-on="$listeners"
v-if="showComment" v-if="showComment"
id="comment" id="comment"
/> />
...@@ -132,19 +132,10 @@ export default { ...@@ -132,19 +132,10 @@ export default {
components: { Container, ExamItem, ChapterWorkComment }, components: { Container, ExamItem, ChapterWorkComment },
props: { props: {
// 当前选中的 // 当前选中的
chapter: { chapter: { type: Object, default: () => ({}) },
type: Object,
default() {
return {}
}
},
// 课程详情接口返回的数据 // 课程详情接口返回的数据
data: { data: { type: Object, default: () => ({}) },
type: Object, homework: { type: Object, default: () => ({}) }
default() {
return {}
}
}
}, },
data() { data() {
return { return {
...@@ -167,11 +158,22 @@ export default { ...@@ -167,11 +158,22 @@ export default {
} }
}, },
watch: { watch: {
chapter: { homework: {
immediate: true, immediate: true,
handler(data) { handler(data) {
if (!this.questions.length) { const { questions = [], answer = {} } = data
this.questions = data.homework ? this.genQuestions(data.homework.questions) : [] 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 { ...@@ -251,37 +253,6 @@ export default {
this.commentEndDate = response.comment_end 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) { genQuestions(list) {
if (!list) { if (!list) {
...@@ -320,6 +291,19 @@ export default { ...@@ -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() { checkSubmit() {
let result = true let result = true
...@@ -385,7 +369,7 @@ export default { ...@@ -385,7 +369,7 @@ export default {
.then(response => { .then(response => {
if (response.status) { if (response.status) {
this.$message.success(this.$t('viewerWork.examSubmitSuccess')) this.$message.success(this.$t('viewerWork.examSubmitSuccess'))
this.getDetail() this.$emit('update')
} else { } else {
this.$message.error(response.data.error) this.$message.error(response.data.error)
} }
...@@ -410,7 +394,6 @@ export default { ...@@ -410,7 +394,6 @@ export default {
} }
}, },
beforeMount() { beforeMount() {
this.getDetail()
this.getDeadline() this.getDeadline()
} }
} }
......
<template> <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> </template>
<script> <script>
// componets // componets
import ChapterWork from './chapterWork.vue' import ChapterWork from './chapterWork.vue'
import ChapterTest from './chapterTest.vue' import ChapterTest from './chapterTest.vue'
import * as api from '../../api'
export default { export default {
name: 'ViewerWork', name: 'ViewerWork',
...@@ -26,15 +37,54 @@ export default { ...@@ -26,15 +37,54 @@ export default {
} }
} }
}, },
data() {
return {
loading: false,
homework: {}
}
},
computed: { computed: {
currentCompoent() { currentCompoent() {
const componentNames = { const componentNames = {
1: 'ChapterTest', // 课后测验 1: 'ChapterTest', // 课后测验
2: 'ChapterWork' // 作业 2: 'ChapterWork' // 作业
} }
const homework = this.chapter.homework const homework = this.homework
return homework ? componentNames[homework.work_type] : '' 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> </script>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论