开篇
因为没法提供平台对应的账号
特别细的地方大家可能不太理解
可以忽略参数的填写等问题,关注实际的代码思路
写的过程中发现有什么问题再进行查阅
正文
之前我们已经将课程保存到了vuex
这节课我们开始获取具体课程的详细信息
我们要获取的是视频信息
因为上边的课程介绍,视频课件等是动态的
所以我们需要先写代码
然后在写具体的视频video获取代码
export function GetVideoChapterId() {
return new Promise(async (resolve, reject) => {
let postdata = {
service: "alioth.study.course.listChapterTag",
tenantCode: store.state.UserInfo.bindUserList[0].tenantCode,
userName: store.state.UserInfo.bindUserList[0].userName,
courseId: store.state.CurrentLesson.courseId,
trainId: store.state.CurrentLesson.trainId,
trainCourseId: store.state.CurrentLesson.trainCourseId,
enrollmentId: store.state.CurrentLesson.enrollmentId,
courseVersionId: store.state.CurrentLesson.courseVersionId,
businessTenantCode: store.state.UserInfo.bindUserList[0].tenantCode,
businessUserName: store.state.UserInfo.bindUserList[0].userName,
};
post(
"https://xueqiplus.chinaedu.net/aliothprovider/router",
await GeneratePostData(postdata)
).then((response) => {
let RetObject = {
status: "error",
};
if (response.code === "0") {
let result = JSON.parse(response.data);
for (let index = 0; index < result.chapterTagList.length; index++) {
const item = result.chapterTagList[index];
if (item.chapterTagName === "视频课件") {
RetObject.id = item.chapterTagId;
RetObject.status = "success";
break;
}
if (item.chapterTagName === "在线课件") {
RetObject.id = item.chapterTagId;
RetObject.externalUrl =
item.externalUrlList.length !== 0
? item.externalUrlList[0].externalUrl
: undefined;
RetObject.status = "success";
break;
}
}
resolve(RetObject);
} else {
resolve(RetObject);
}
});
});
}
这里读取了章节的数据,并且寻找课程课件或者在线课件两个关键词
如果找到了就进行返回,接下来我们尝试调用上方的函数
let result = await GetLessonDetail(ChapterObject);
if (result.status === "error") {
alert("获取课程章节失败");
return;
}
if (result.attrs === "normal" && !result.detail.chapterList) {
alert("当前无课程!");
return;
}
接下来我们判断章节的获取情况,以及章节列表的读取
let result = await GetLessonDetail(ChapterObject);
if (result.status === "error") {
alert("获取课程章节失败");
return;
}
if (result.attrs === "normal" && !result.detail.chapterList) {
alert("当前无课程!");
return;
}
chapterList.value = [];
result.detail.chapterList.forEach((Chapter) => {
chapterList.value = chapterList.value.concat(Chapter.activityList);
});
根据对应的格式循环添加视频Activity数据即可
得到的Activity数据就是每一个视频的相应数据
chapterList是我声明的视频的数据存储对象
结语
撒花~