课程搜索

This commit is contained in:
zhaofang
2022-07-21 15:45:19 +08:00
parent 826bd86e17
commit c61b435b6a

View File

@@ -90,11 +90,11 @@
</div>
<!-- </el-tooltip> -->
<div class="course-author">
<div class="course-author-left" v-if="cinfo.authorInfo">
{{cinfo.authorInfo.name}}
<div class="course-author-left" v-if="cinfo.teacher">
{{cinfo.teacher}}
</div>
<div style="flex:1;text-align: center;">
<span class="study-num">{{cinfo.studys}}人学习</span>
<span class="study-num">{{cinfo.studies}}人学习</span>
</div>
<div style="padding-left:15px">
<div v-if="cinfo.score">
@@ -218,10 +218,9 @@ import apiUser from "@/api/system/user.js";
import scene from "@/api/modules/scene.js";
import interactBar from "@/components/Portal/interactBar.vue";
import courseImage from "@/components/Course/courseImage.vue";
import { courseType, getType, toScore } from "@/utils/tools.js";
import { courseType, getType, toScore,formatDate } from "@/utils/tools.js";
import { deepClone, param } from "../../../utils";
import apiSearchterm from "@/api/modules/searchterm.js";
import { Promise } from "q";
export default {
name: "index",
components: {
@@ -239,6 +238,7 @@ export default {
},
data() {
return {
formatDate,
couretitle: "",
toScore,
noPageList: true, //判断接口是否还有数据
@@ -294,8 +294,7 @@ export default {
};
},
mounted() {
let screenWidth = window.screen.availHeight;
//console.log("screenWidth", screenWidth);
let screenWidth = window.screen.availWidth;
if (screenWidth < 1280) {
this.course.pageSize = 9;
this.columns = 3;
@@ -306,8 +305,6 @@ export default {
this.course.pageSize = 15;
this.columns = 5;
}
//var hasNum=12;
//console.log(parseInt(hasNum/this.columns)*this.columns,'this.columns');
let el_top = document.querySelector("#searchbar");
let el_search = document.querySelector("#searchbar");
@@ -524,18 +521,8 @@ export default {
if (this.course.keyword) {
apiSearchterm.save({ keyword: this.course.keyword, type: 1 });
}
this.isFind = true;
if (this.category === 0) {
this.course.type = null;
} else if (this.category === 2) {
// if (this.categorySub === "") {
// this.course.type = "20";
// } else {
// this.course.type = this.categorySub;
// }
} else {
this.course.type = this.category;
}
this.isFind = true;
this.course.type = this.category;
if (this.types.sysTypes == 0 || this.types.sysTypes == null) {
this.course.sysType1 = "";
this.course.sysType2 = "";
@@ -553,78 +540,11 @@ export default {
}
this.course.device = 1;
this.getTags();
//从新课程库中取10条从老库中取10条
let oldPageIndex = 0;
let oldCateName = "";
let oldParamsType = "";
if (this.course.sysType1) {
//cateName
let courseSysType = this.course.sysType1;
let curName = this.optionsList.find(item => {
return item.id === courseSysType;
});
if (curName) {
oldCateName = curName.name;
}
}
if (this.category == 20) {
oldParamsType = "online-course";
} else if (this.category == 30) {
oldParamsType = "face-course";
} else if (this.category == 40) {
oldParamsType = "project";
}
//if(oldParamsType == '' && oldCateName == '' && this.course.keyword == '') {
if (this.searchTags.length == 0) {
oldPageIndex = this.course.pageIndex - 3;
} else {
oldPageIndex = this.course.pageIndex;
}
let oldParams = {
type: oldParamsType,
page: oldPageIndex,
size: this.course.pageSize,
keyword: this.course.keyword,
sort: "new",
cateName: oldCateName
};
if (this.course.orderField == "id") {
//最新
oldParams.sort = "new";
}
if (this.course.orderField == "studys") {
//最热
oldParams.sort = "hot";
if(this.course.pageIndex == 1) {
this.courseList = [];
}
let data = [];
let isTopList = [];
if (this.course.pageIndex > this.totalPages) {
//console.log(this.course.pageIndex, this.totalPages, "1");
this.noDataList = true;
if (this.searchTags.length == 0) {
oldParams.page = this.course.pageIndex - this.totalPages;
}
} else {
//console.log(this.course.pageIndex, this.totalPages, "2");
if (this.searchTags.length == 0) {
if (this.totalPages > 3) {
if (this.course.pageIndex <= 3) {
this.noDataList = false;
} else {
this.noDataList = true;
}
}
}
// if(this.totalPages == 1 && this.course.pageIndex ==1){
// this.noDataList = true;
// }
}
if (this.course.type == 30 || this.course.type == 40) {
this.noPageList = false;
}
//console.log(this.noDataList, this.totalPages, "this.noDataList");
// 隐藏loadMore
this.moreState = 2;
await apiCoursePortal
@@ -634,130 +554,18 @@ export default {
this.totalPages = res.result.totalPages;
let courseIds = [];
res.result.list.forEach(item => {
item.name = this.$keywordActiveShow(
item.name,
this.course.keyword
);
item.couretitle = this.$keywordActiveShow(
item.name,
this.course.keyword
)
.replace(/<[^>]+>|&[^>]+;/g, "")
.trim(); //去掉所有的html标签和&nbsp;之类的特殊符合
item.authorInfo = {
aid: "",
name: "",
orgInfo: "",
avatar: "",
code: ""
};
courseIds.push(item.id);
if (item.isTop) {
isTopList.push(item);
} else {
data.push(item);
}
data.push(item);
});
that.loadCouserTeacher(res.result.list, courseIds);
that.moreState = 1;
} else {
that.noPageList = false;
this.moreState = 3;
}
})
.catch(err => {
that.noPageList = false;
this.moreState = 3;
});
if (this.course.orderField == "id") {
//最新
data.sort(this.pcompare("publishTime", false));
}
if (this.course.orderField == "studys") {
//最热
data.sort(this.pcompare("studys", false));
}
this.courseList.push(...isTopList, ...data);
if (this.noDataList == false && this.noPageList == false) {
this.moreState = 3;
}
},
pcompare(prop, rev) {
if (rev === undefined) {
rev = 1;
} else {
rev = rev ? 1 : -1;
}
return function(obj1, obj2) {
let val1 = obj1[prop],
val2 = obj2[prop];
return val1 < val2 ? rev * -1 : rev * 1;
};
},
filterConversion(data) {
let list = [];
data.forEach((item, index) => {
list.push({
coverImg: item.cover[0].url,
name: item.title,
type: item.type,
id: item.id,
studys: Number(item.enrollSuccess), // Number(), //学习人数
score: item.score,
publishTime: item.releaseDate,
authorInfo: {
avatar: "",
name: ""
}
});
});
return list;
},
loadCouserTeacher(list, ids) {
let that = this;
// 先查课程关联教师iD
apiCourse.getTeacherByCourseIDs(ids).then(cres => {
if (cres.status == 200) {
let userIds = [];
list.forEach((item, index) => {
cres.result.some(courseTeahcer => {
if (courseTeahcer.courseId == item.id) {
if (courseTeahcer.teacherIds) {
userIds.push(courseTeahcer.teacherIds[0]);
item.authorInfo.aid = courseTeahcer.teacherIds[0];
item.authorInfo.name = courseTeahcer.names[0];
}
return true;
} else {
return false;
}
});
});
//that.loadCourseAuthorInfo(list,userIds);
}
});
},
loadCourseAuthorInfo(list, ids) {
//加载作者信息,头像,机构信息
if (ids.length == 0) {
return;
}
const noReapetIds = [...new Set(ids)];
apiUser.getByIds(ids).then(res => {
if (res.status == 200) {
list.forEach((item, index) => {
res.result.some(author => {
if (author.aid == item.authorInfo.aid) {
item.authorInfo = author;
return true;
} else {
return false;
}
});
});
} else {
console.log("加载课程信息失败:" + res.error);
//this.$message.error(res.message);
}
});
this.courseList.push(...data);
},
getTags() {
this.searchTags = [];