RecommendCourse.js
2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// packageStudyCenter/pages/myTask/components/RecommendCourse/RecommendCourse.js
import api from "~/packageStudyCenter/api"
import commonApi from '~/api/api'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
Component({
properties: {
// 可以添加需要的属性
},
data: {
IMG_URL,
recommendCourseList: [],
nothing: false,
total: 0,
pageNum: 1,
pageSize: 10,
scrollTop: 0,
},
lifetimes: {
attached() {
this.getCourseTaskPage()
}
},
methods: {
async getCourseTaskPage() {
try {
const { pageNum, pageSize } = this.data;
const params = {
recommendStatus: 1, // 推荐状态 0=无推荐 1=推荐课程
pageNum,
pageSize
};
const res = await api.getCourseTaskPage(params);
if (pageNum == 1) {
this.setData({
recommendCourseList: res.data?.list || []
});
} else {
this.setData({
recommendCourseList: this.data.recommendCourseList.concat(res.data?.list || [])
});
}
this.setData({
total: res.data?.total || 0,
nothing: (res.data?.list || []).length > 0 ? false : true
});
} catch (error) {
wx.showToast({
title: error.message || '请求失败',
icon: "none",
});
}
},
pageonReachBottom() {
const { pageNum, total, pageSize } = this.data;
if (Math.ceil(total / pageSize) > pageNum) {
this.setData({
pageNum: pageNum + 1
});
this.getCourseTaskPage();
} else {
this.setData({ nothing: true });
}
},
startStudy(e) {
const item = e.currentTarget.dataset.item
let userInfo = wx.$util.getUserInfo()
// 埋点 推荐课程
wx.$track.setTrackData(0, 'recommend_course', {}, '', userInfo?.sceneType)
commonApi.findBeiSenSSOToken({}).then(res => {
const beisenToken = res.data;
if (beisenToken) {
const COURSE_ID = item?.courseId;
const baseUrl = 'https://cloud.italent.cn/PageHome/Index';
const params = {
product: 'Learning',
keyName: 'Nusion',
pageCode: 'LearningCourseTraineeDetailPage',
appCode: 'Learning',
id: COURSE_ID
};
this.jumpUrl = ''
const queryString = Object.entries(params)
.map(([key, value]) => `${key}=${value}`)
.join('&');
// this.setWebviewStyle()
const url = encodeURIComponent(`${baseUrl}?${queryString}#/viewDynamic?1=1`);
const tokenUrl = beisenToken
wx.$router.jumpH5(`${tokenUrl}&return_url=${url}`)
} else {
wx.showToast({
title: '培训账号未创建',
icon: 'none'
})
}
})
}
}
});