优化代码

This commit is contained in:
dengjie
2023-01-29 14:15:43 +08:00
parent 161f23f2c3
commit 09bbce1780
3 changed files with 32 additions and 15 deletions

View File

@@ -89,6 +89,7 @@
}, },
onLoad() { onLoad() {
this.getIdeasAndNeeds() this.getIdeasAndNeeds()
console.log(uni.getStorageSync('loginToken'));
if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) { if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) {
this.isLoad = false this.isLoad = false
// uni.navigateTo({ // uni.navigateTo({
@@ -102,7 +103,7 @@
//获取创意发布 //获取创意发布
getIdeasAndNeeds() { getIdeasAndNeeds() {
this.$apiServe.getIdeasAndNeeds(this.type).then(res => { this.$apiServe.getIdeasAndNeeds(this.type).then(res => {
// console.log('获取创意发布&需求发布', res.data.data); console.log('获取创意发布&需求发布', res.data.data);
let data = res.data.data let data = res.data.data
for (const item of data) { for (const item of data) {
item.pub_time = dateFormatXwDetail(item.pub_time) item.pub_time = dateFormatXwDetail(item.pub_time)

View File

@@ -5,8 +5,8 @@
</u-image> </u-image>
<view class="collect" @click="starTap"> <view class="collect" @click="starTap">
<view class="star"> <view class="star">
<u-image v-if="detailList.is_fav==0" src="/static/detail/xp_icon_wstar.png" width="28rpx" <u-image v-if="detailList.is_fav==0||!detailList.is_fav" src="/static/detail/xp_icon_wstar.png"
height="28rpx"> width="28rpx" height="28rpx">
</u-image> </u-image>
<u-image v-if="detailList.is_fav==1" src="/static/detail/xp_icon_star.png" width="28rpx" <u-image v-if="detailList.is_fav==1" src="/static/detail/xp_icon_star.png" width="28rpx"
height="28rpx"> height="28rpx">
@@ -100,10 +100,13 @@
//获取详情信息 //获取详情信息
getProductDetail() { getProductDetail() {
this.$apiServe.getProductDetail(this.id).then(res => { this.$apiServe.getProductDetail(this.id).then(res => {
// console.log('产品详情页', res.data) console.log('产品详情页', res.data)
if (res.data.data.thumb) { if (res.data.data.thumb) {
this.isThumb = true this.isThumb = true
} }
if (res.data.code == 0) {
this.$toast.warn('没有权限访问')
}
if (res.data.data) { if (res.data.data) {
let detail = res.data.data let detail = res.data.data
detail.pub_time = dateFormatDetail(detail.pub_time) detail.pub_time = dateFormatDetail(detail.pub_time)
@@ -118,19 +121,32 @@
}, },
//收藏按钮 //收藏按钮
starTap() { starTap() {
this.$apiServe.collect(this.id).then(res => { if (this.detailList.is_fav === 1) {
// console.log('收藏成功', res.data) this.$toast.warn('已收藏')
if (res.data.code == 1) { } else if (this.detailList.is_fav === 0) {
this.detailList.is_fav = 1 this.$apiServe.collect(this.id).then(res => {
this.$toast.warn('收藏成功') // console.log('收藏成功', res.data)
} else { if (res.data.code == 1) {
this.$toast.warn('收藏失败') this.detailList.is_fav = 1
} this.$toast.warn('收藏成功')
}).finally(_ => {}) } else {
this.$toast.warn('收藏失败')
}
}).finally(_ => {})
}
}, },
//点赞按钮 //点赞按钮
heartTap() { heartTap() {
this.showHeart = !this.showHeart // this.showHeart = !this.showHeart
this.$apiServe.thumb(this.id).then(res => {
console.log('点赞成功', res.data)
if (res.data.code == 1) {
this.showHeart = 1
this.$toast.warn('点赞成功')
} else {
this.$toast.warn('点赞失败')
}
}).finally(_ => {})
}, },
reOnLoad() { reOnLoad() {
if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) { if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) {

View File

@@ -8,7 +8,7 @@ function isOutTime(res) {
}) })
}, 1000) }, 1000)
uni.removeStorageSync('userInfo') uni.removeStorageSync('userInfo')
uni.removeStorageSync('loginToken') uni.removeStorageSync('token')
} else { } else {
// uni.showToast(res.data.message); // uni.showToast(res.data.message);
} }