Commit cadb56f7 authored by liwei's avatar liwei

对接了点赞接口

parent fe9f2328
......@@ -20,10 +20,10 @@ export function publishArticle(data) {
}
// 点赞
export function praise(id) {
export function like(data) {
return request({
url: '/opmarticle/likeAdd/'+id,
data:id,
url: '/app/opmArticle/like?articleId='+data.id+'&praiseType='+data.praiseType,
data: {},
method: 'POST',
})
}
......
......@@ -81,7 +81,7 @@
<text>{{info.commentCount}}</text>
</view>
<view class="btn" @click="praise(info)">
<image v-if="!info.isLike" :src="baseUrl+'/article/105.png'" mode=""></image>
<image v-if="info.isLike == '0'" :src="baseUrl+'/article/105.png'" mode=""></image>
<image v-else :src="baseUrl+'/article/105-no.png'" mode=""></image>
<text>{{info.likeCount}}</text>
</view>
......@@ -99,13 +99,14 @@
<!-- 右上角三个点的选项-->
<u-action-sheet :actions="list" :closeOnClickOverlay="true" :safeAreaInsetBottom="true" cancelText="取消"
@select="selectClick" @close="show = false" :show="show"></u-action-sheet>
<!-- 登录弹窗-->
<login @change="getToLogin" :isLoginPop="isLoginPop" class="my-select"></login>
</view>
</template>
<script>
import imageAdaptation from '@/components/images-adaptation/imageAdaptation.vue'
import xzjReadMore from "@/components/xzj-readMore/xzj-readMore.vue"
import {praise} from "../../../api/article";
export default {
name:'ArticleItem',
options: {
......@@ -144,6 +145,8 @@
},
data() {
return {
//登录弹窗
isLoginPop: false,
//图片路径
baseUrl: this.$store.state.imgUrl,
imgs: [],
......@@ -159,7 +162,6 @@
// name: "举报"
// }
],
isConfirm: false
}
},
methods: {
......@@ -180,10 +182,31 @@
},
// 点赞
praise(item) {
praise(item.businessId).then(res=>{
})
const token = uni.getStorageSync('token')
//校验token 如果没有token,跳到登录页进行登录
if (token && token !== '' && token != null){
//已登录
//0:取消点赞/未点赞 1:点赞
item.isLike = item.isLike == '0' ? '1' : '0'
this.$emit('praise', item)
} else {
//未登录
this.isLoginPop = true
}
},
//登录弹窗
getToLogin(e) {
if (e == 0) {
//取消登录
this.isLoginPop = false;
} else {
this.isLoginPop = false;
//立即登录
uni.navigateTo({
url: '/pageslogin/index'
})
}
},
// 删除
selectClick(item) {
......
......@@ -26,7 +26,7 @@
</u-tabs>
</view>
<view v-for="(item,index) in dataList" :key="item.id">
<ItemVue :info="item"/>
<ItemVue :info="item" @praise="praise"/>
</view>
<empty v-if="firstLoaded && !dataList.length"/>
</z-paging>
......@@ -34,10 +34,10 @@
</template>
<script>
import ItemVue from './Item.vue'
import empty from '@/components/empty.vue'
import ItemVue from './Item.vue';
import empty from '@/components/empty.vue';
import {topicList} from "../../../api/topic";
import {articleList} from "../../../api/article";
import {articleList, like} from "../../../api/article";
import {getCity, getValue} from "../../../common/options";
import {calculateAge, parseDate} from "../../../common";
export default {
......@@ -48,6 +48,8 @@
},
data() {
return {
//登录弹窗
isLoginPop:'',
//话题id
topicId: 0,
//当前的tab
......@@ -226,6 +228,27 @@
// this.$refs.paging.complete(false);
// })
},
// 点赞
praise(item) {
var type = ''
if (item.isLike == '0') {
//取消点赞
type = 'cancel'
item.likeCount -= 1
} else {
//点赞
type = 'praise'
item.likeCount += 1
}
const params = {
id: item.businessId,
praiseType: type
}
like(params).then( res => {
let idx = this.dataList.findIndex(obj => obj.businessId == item.businessId)
this.dataList.splice(idx, 1, item)
})
},
}
}
</script>
......
......@@ -107,7 +107,7 @@
goMessage() {
},
//
//登录弹窗
getToLogin(e) {
if (e == 0) {
//取消登录
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment