RecommendCourse.js
3.55 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// 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();
this.asyncfindBeiSenSSOToken();
}
},
methods: {
async getCourseTaskPage() {
try {
wx.showLoading({
mask: true
});
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 || [])
});
}
wx.hideLoading();
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'
})
}
})
},
async asyncfindBeiSenSSOToken() {
try {
// 这里替换为实际的小程序API调用
const res = await this.mockBeisenApiCall();
// uni.$storage.set('beisenToken', res.data)
} catch (error) {
console.error('获取北森Token失败:', error);
}
},
// 模拟北森API调用
mockBeisenApiCall() {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
data: 'mock-beisen-token'
});
}, 300);
});
}
}
});