6
0
Fork 0

对接文章相关接口

hui.zhou
h30830569 2022-05-19 11:30:13 +08:00
parent 063b3d68e3
commit b29e554e20
3 changed files with 32 additions and 115 deletions

View File

@ -627,7 +627,7 @@
"iconPath": "static/tabbar/healthy.png",
"selectedIconPath": "static/tabbar/healthy_sel.png",
"pagePath": "pages/healthy/index",
"text": "健康"
"text": "文章"
},
{
"iconPath": "static/tabbar/my.png",

View File

@ -33,20 +33,11 @@
<view class="px-36rpx mt-15rpx text-md text-txBase">{{info.subtitle}}</view>
<view class="px-36rpx flex items-center justify-between text-md text-txGray">
<view class="">{{info.created_at}}</view>
<view @tap="getThumbs" class="flex items-center">
<u-icon :color="info.like_status ? '#378264' : ''" size="48"
:name="info.like_status ? 'thumb-up-fill' : 'thumb-up'"></u-icon>
<view class="ml-base">{{info.likes}}</view>
</view>
</view>
<view class="mx-base mt-base h-2rpx bg-txBorder"></view>
<view class="px-36rpx mt-30rpx text-md text-txBase leading-60rpx">
<u-parse :tag-style="style" :html="info.content"></u-parse>
</view>
<!-- 倒计时 -->
<view v-if="isShow"
class="w-100rpx text-center borders text-lg text-txBase fixed right-0 z-8 top-500rpx bg-primary bg-opacity-60 ">
{{Time}}</view>
</view>
</template>
@ -56,11 +47,7 @@
return {
swiperList: [], //
info: {},
Time: 15,
val: '',
isShow: false,
style: {
// img:'width:100% !important',
table: 'width:100% !important',
p: 'text-indent:20px'
},
@ -68,21 +55,12 @@
audioCtx:''
};
},
computed: {},
async onLoad({
id
}) {
async onLoad({id}) {
await this.getDate(id)
await this.getDown()
},
onReady() {
this.audioCtx = uni.createAudioContext('myAudio')
},
onUnload() {
clearInterval(this.val)
this.Time = 15,
this.isShow = false
},
methods: {
audioClick(){
this.isPlaying=!this.isPlaying
@ -98,49 +76,13 @@
if (resDate.media_type == 1) {
this.getSwiper(resDate.media_content)
}
if (resDate.points > 0 && !resDate.has_read) {
this.isShow = true
}
this.info = resDate
},
getSwiper(val) {
let arr = val.split(',')
this.swiperList = arr
},
//
async getThumbs() {
await this.$api.post(`/v1/articles/${this.info.id}/like`, {}, {
custom: {
loading: true
}
});
this.info.like_status = true;
this.info.likes += 1
this.$u.toast('点赞成功');
uni.$emit('isUp', {
id: this.info.id
})
},
//
getDown() {
if (this.isShow && !this.info.has_read) {
this.val = setInterval(() => {
this.Time--
if (this.Time == 0) {
this.Time = 15
clearInterval(this.val)
this.isShow = false
this.$api.post(`/v1/articles/${this.info.id}/read`).then(({
points
}) => {
this.$store.dispatch('user/getUserInfo')
this.$u.toast(`阅读成功,+${points}积分`);
})
}
}, 1000)
}
}
}
},
}
</script>

View File

@ -2,8 +2,8 @@
<view>
<loading-view v-if="isFirstLoading"></loading-view>
<!-- 顶部tabbar -->
<view class="bg-white sticky top-0 z-9999">
<u-tabs :list="list" active-color="#378264" inactive-color="#808080" :current="id" @change="change"></u-tabs>
<view class="bg-white sticky w-full top-0 z-9999">
<u-tabs :list="tabbarList" :is-scroll="isScroll" active-color="#378264" inactive-color="#808080" :current="current" @change="change"></u-tabs>
</view>
<mescroll-body :height="height" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
:down="downOption" :up="upOption">
@ -17,18 +17,10 @@
<block v-if="item.cover">
<u-image border-radius="15rpx" width="250rpx" height="187rpx" :src="item.cover" :lazy-load="true"></u-image>
</block>
<view class="ml-base flex-1">
<view class="text-txBase w-full h-80rpx leading-40rpx text-30rpx two-ellipsis font-bold">{{item.title}}
</view>
<view class="text-txGray text-md mt-10rpx">{{item.created_at}}</view>
<view class="flex items-center justify-between mt-10rpx text-txGray text-md">
<view>积分: {{item.points}}</view>
<view class="flex items-center">
<u-icon :color="item.like_status ? '#378264' : ''" size="48"
:name="item.like_status ? 'thumb-up-fill' : 'thumb-up'"></u-icon>
<view class="ml-10rpx h-30rpx">{{item.likes}}</view>
</view>
<view class="ml-base flex-1 h-187rpx flex items-start justify-between flex-col">
<view class="text-txBase w-full leading-40rpx text-30rpx three-ellipsis font-bold">{{item.title}}
</view>
<view class="text-txGray text-md text-right w-full">{{item.created_at}}</view>
</view>
</view>
</mescroll-body>
@ -42,28 +34,9 @@
mixins: [MescrollMixin, CartMixin],
data() {
return {
list: [{
name: '待收货'
}, {
name: '待付款'
}, {
name: '待评价',
}, {
name: '待收货'
}, {
name: '待付款'
}, {
name: '待评价',
}, {
name: '待收货'
}, {
name: '待付款'
}, {
name: '待评价',
}],
tabbarList: [],
isFirstLoading: true,
article_banner: [], //广
searchText: '',
downOption: {
auto: false,
},
@ -74,10 +47,13 @@
noMoreSize: 1
},
dataList: [], //
id: 0
current: 0
};
},
computed: {
isScroll(){
return this.tabbarList.length>5?true:false
},
height() {
const {
windowHeight,
@ -87,30 +63,23 @@
},
cpaceImage() {
return this.article_banner.length > 0 ? this.article_banner[0] : {}
},
chooseItem(){
return this.tabbarList[this.current]
}
},
onLoad({
id
}) {
this.id = id
onLoad() {
setTimeout(() => {
this.isFirstLoading = false
}, 300)
this.getCpace()
uni.$on('isUp', ({
id
}) => {
this.dataList.forEach((item) => {
if (item.id == id) {
item.like_status = true;
item.likes += 1
}
})
})
this.getDate()
},
methods: {
change(e) {
this.id = e
if(e==this.current) return
this.current=e
this.downCallback()
},
//广
async getCpace() {
@ -121,8 +90,14 @@
}
})
this.article_banner = resDate.article_banner
} catch (err) {} finally {}
} catch (err) {}
},
//
async getDate(){
const resData=await this.$api.get('/v1/articles/category')
this.tabbarList=resData
this.downCallback()
},
downCallback() {
this.mescroll.resetUpScroll();
this.dataList = []
@ -135,12 +110,12 @@
size
}) {
let obj = {
category: this.id,
key: this.searchText,
cate: this.chooseItem?.id,
key:'',
page: num,
per_page: size
}
this.$api.get(`/v1/articles/by-category/${ this.id}`, {
this.$api.get(`/v1/articles`, {
params: obj
}).then(res => {
this.mescroll.endSuccess(res.data.length)
@ -159,7 +134,7 @@
}
}
},
}
},
}
</script>