添加loading

master
xcw 2023-03-28 14:09:31 +08:00
parent ce5e3b7d80
commit 4e6e74c462
3 changed files with 69 additions and 11 deletions

View File

@ -106,13 +106,15 @@ const request = (method, url, options) => {
break; break;
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log(`${url}的参数===>`,options); uni.showLoading({title: '加载中',mask:true});
uni.request({ uni.request({
url: `${getApp().globalData.hostapi}${url}`, url: `${getApp().globalData.hostapi}${url}`,
method: methods, method: methods,
data: options, data: options,
header: headers, header: headers,
success: res => { success: res => {
uni.hideLoading();
console.log(`${url}的参数===>`,options);
if (res.statusCode == 200) { if (res.statusCode == 200) {
if (res.data.code == 0) { if (res.data.code == 0) {
// 接口调用成功 // 接口调用成功
@ -123,11 +125,13 @@ const request = (method, url, options) => {
checkError(res); checkError(res);
} }
} else { } else {
uni.hideLoading();
// 接口返回错误信息 // 接口返回错误信息
checkError(res); checkError(res);
} }
}, },
fail: e => { fail: e => {
uni.hideLoading();
// 接口请求错误 // 接口请求错误
checkError(e, reject); checkError(e, reject);
}, },

View File

@ -1,14 +1,14 @@
<template> <template>
<view> <view>
<status-container titlet="观记录" returnc="#FFFFFF"> <status-container titlet="观记录" returnc="#FFFFFF">
<view slot="content" style="margin-top: -20rpx;"> <view slot="content" style="margin-top: -20rpx;">
<view class="pad-zy30 bacf pad-x30" v-if="total"> <view class="pad-zy30 bacf pad-x30" v-if="total">
<view class="pad-sx30 disac fon24 bbot" v-for="(item,index) in dataList" :key="index"> <view class="pad-sx30 disac fon24 bbot" v-for="(item,index) in dataList" :key="index">
<image class="flexs" :src="hostapi + item.course_video_cover" mode="aspectFill" style="width: 228rpx;height: 160rpx;"></image> <image class="flexs" :src="hostapi + item.course_video_cover" mode="aspectFill" style="width: 228rpx;height: 160rpx;"></image>
<view class="disjbac fc width100 mar-z20" style="height: 160rpx;"> <view class="disjbac fc width100 mar-z20" style="height: 160rpx;">
<view class="fon26 col26 width100"> <view class="fon28 col26 width100">
<view class="clips2">{{item.course_video_title}}</view> <view class="clips2">{{item.course_video_title}}</view>
<view class="fon20 mar-s10" style="color: #7f7f7f;">{{item.course_video_summary}}</view> <view class="fon24 mar-s10" style="color: #7f7f7f;">观看时长{{item.duration}}</view>
</view> </view>
<view class="disjbac width100"> <view class="disjbac width100">
<view class="fon24"></view> <view class="fon24"></view>
@ -64,13 +64,19 @@
size:this.size size:this.size
} }
this.$requst.post('/api/course/course-browse-records',params).then(res=>{ this.$requst.post('/api/course/course-browse-records',params).then(res=>{
if(res.code == 0) {
this.total = res.data.total; this.total = res.data.total;
if(this.page==1){this.dataList=[];} if(this.page==1){this.dataList=[];}
this.dataList = [...this.dataList,...res.data.list]; this.dataList = [...this.dataList,...res.data.list];
this.dataList.forEach((item,index)=>{
item.duration = this.formatSeconds(item.duration)
})
if(this.total==this.dataList.length && this.page!=1){ if(this.total==this.dataList.length && this.page!=1){
this.noMore = true; this.noMore = true;
} }
this.loading = true; this.loading = true;
}
}) })
}, },
@ -89,6 +95,52 @@
} }
}) })
},
//
formatSeconds(value) {
//
let second = parseInt(value)
//
let minute = 0
//
let hour = 0
//
// let day = 0
// 60
if (second > 60) {
// 60
minute = parseInt(second / 60)
//
second = parseInt(second % 60)
// 60
if (minute > 60) {
// 60
hour = parseInt(minute / 60)
// 60
minute = parseInt(minute % 60)
// 24
// if (hour > 23) {
// // 24
// day = parseInt(hour / 24)
// // 24
// hour = parseInt(hour % 24)
// }
}
}
let result = '' + parseInt(second) + '秒'
if (minute > 0) {
result = '' + parseInt(minute) + '分' + result
}
if (hour > 0) {
result = '' + parseInt(hour) + '小时' + result
}
// if (day > 0) {
// result = '' + parseInt(day) + '' + result
// }
console.log('result', result)
return result
} }
} }
} }

View File

@ -216,4 +216,6 @@
} }
</script> </script>
<style></style> <style>
.rich-text [alt]{width: 100%;}
</style>