RecommendCourse.vue
5.38 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<template>
<view class="recommend-course">
<scroll-view scroll-y ref="scrollViewRef" :scroll-top="scrollTop" @scrolltolower="pageonReachBottom"
:class="getScrollHeight">
<template v-if="recommendCourseList.length">
<view class="recommend-course-list">
<view class="recommend-course-item" v-for="(item, index) in recommendCourseList" :key="index" @click="startStudy(item, index)">
<image
class="recommend-course-item-img"
src="../../../../assets/images/common/recommend-course-default.webp"
mode="scaleToFill"
/>
<view class="recommend-course-content">
<view class="recommend-course-item-title">
{{ item.courseName }}
</view>
<view class="recommend-course-item-text">{{ (item.totalDuration || item.totalDuration === 0) ? `${item.totalDuration}min` : '-' }}</view>
</view>
</view>
</view>
</template>
<template v-else>
<view class="nothing flex">
<image class="icon" src="../../../../assets/images/boutique/nothing.png" />
暂无数据
</view>
</template>
<template v-if="nothing">
<view class="end-text">到底了!</view>
</template>
</scroll-view>
</view>
</template>
<script>
export default {
name: 'RecommendCourse',
data() {
return {
recommendCourseList: [],
nothing: false,
total: 0,
pageNum: 1,
pageSize: 12,
scrollTop: 0,
}
},
computed: {
getScrollHeight() {
const list = this.recommendCourseList;
if (!list || list.length === 0) {
return '';
}
return 'scroll-view'
}
},
mounted() {
this.getCourseTaskPage()
this.asyncfindBeiSenSSOToken()
},
methods: {
// 获取我的任务接口, completeStatus: 完成状态 0=待完成 1=已完成, courseType: 课程类型 1=短课程 2=长课程
async getCourseTaskPage() {
try {
uni.showLoading({
mask: true
})
const { pageNum, pageSize } = this
const params = {
recommendStatus: 1, // 推荐状态 0=无推荐 1=推荐课程
pageNum,
pageSize
}
const res = await uni.$api.commonApi.getCourseTaskPage(params)
if (pageNum == 1) {
this.recommendCourseList = res.list
} else {
this.recommendCourseList = this.recommendCourseList.concat(res.list)
}
uni.hideLoading()
this.total = res.total
this.nothing = res.length ? true : false
} catch (error) {
uni.showToast({
title: error,
icon: "none",
});
}
},
pageonReachBottom() {
console.log('到底了');
// 解构赋值,设置 nothing 的默认值
let { pageNum, total, nothing = 'nothing', pageSize } = this;
if (Math.ceil(total / pageSize) > pageNum) {
this.pageNum += 1;
this.getCourseTaskPage()
} else {
this.nothing = true;
}
},
startStudy(item, index) {
let { pageNum, total, nothing = 'nothing', pageSize } = this;
uni.$track.add({eventCode: 'app_recommend_course', businessId: item.id, pagePath: '/pages/equity/index'})
uni.navigateTo({
url: `/pages/common/studyDetail/detail?type=recommendation&index=${index}&recommendCourseList=${encodeURIComponent(JSON.stringify(this.recommendCourseList))}&pageNum=${pageNum}&pageSize=${pageSize}&total=${total}`
})
},
async asyncfindBeiSenSSOToken () {
const res = await uni.$api.commonApi.findBeiSenSSOToken({})
uni.$storage.set('beisenToken', res.data)
},
}
}
</script>
<style lang="scss" scoped>
.recommend-course {
height: calc(100% - #{toRpx(100)});
.scroll-view {
margin-top: toRpx(40);
height: calc(100% - #{toRpx(70)});
.recommend-course-list {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: toRpx(32);
padding: 0 toRpx(40) toRpx(32);
.recommend-course-item {
width: 100%;
height: toRpx(376);
box-shadow: 0 toRpx(8) toRpx(24) 0 #2a61eb1a;
border-radius: toRpx(24);
.recommend-course-item-img {
width: 100%;
height: toRpx(180);
border-radius: toRpx(16) toRpx(16) 0 0;
}
.recommend-course-content {
padding: toRpx(32);
.recommend-course-item-title {
font-size: toRpx(30);
color: #292D33;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
margin-bottom: toRpx(16);
height: calc(2 * 1.2em); // 固定两行高度,1.4为行高倍数,可根据实际调整
line-height: 1.2;
}
.recommend-course-item-text {
font-size: toRpx(24);
color: #999EA8;
}
}
}
}
}
}
.nothing {
width: 100%;
flex-direction: column;
margin-top: toRpx(380);
font-size: toRpx(28);
color: #999999;
.icon {
width: toRpx(678);
height: toRpx(284);
margin-bottom: toRpx(24);
}
}
.end-text {
color: #999;
text-align: center;
padding: toRpx(30) 0;
font-size: toRpx(24);
}
/deep/ {
.uni-scroll-view-content {
height: calc(100% - #{toRpx(20)});
}
}
</style>