Commit cadb56f7 authored by liwei's avatar liwei

对接了点赞接口

parent fe9f2328
...@@ -20,10 +20,10 @@ export function publishArticle(data) { ...@@ -20,10 +20,10 @@ export function publishArticle(data) {
} }
// 点赞 // 点赞
export function praise(id) { export function like(data) {
return request({ return request({
url: '/opmarticle/likeAdd/'+id, url: '/app/opmArticle/like?articleId='+data.id+'&praiseType='+data.praiseType,
data:id, data: {},
method: 'POST', method: 'POST',
}) })
} }
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<text>{{info.commentCount}}</text> <text>{{info.commentCount}}</text>
</view> </view>
<view class="btn" @click="praise(info)"> <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> <image v-else :src="baseUrl+'/article/105-no.png'" mode=""></image>
<text>{{info.likeCount}}</text> <text>{{info.likeCount}}</text>
</view> </view>
...@@ -99,13 +99,14 @@ ...@@ -99,13 +99,14 @@
<!-- 右上角三个点的选项--> <!-- 右上角三个点的选项-->
<u-action-sheet :actions="list" :closeOnClickOverlay="true" :safeAreaInsetBottom="true" cancelText="取消" <u-action-sheet :actions="list" :closeOnClickOverlay="true" :safeAreaInsetBottom="true" cancelText="取消"
@select="selectClick" @close="show = false" :show="show"></u-action-sheet> @select="selectClick" @close="show = false" :show="show"></u-action-sheet>
<!-- 登录弹窗-->
<login @change="getToLogin" :isLoginPop="isLoginPop" class="my-select"></login>
</view> </view>
</template> </template>
<script> <script>
import imageAdaptation from '@/components/images-adaptation/imageAdaptation.vue' import imageAdaptation from '@/components/images-adaptation/imageAdaptation.vue'
import xzjReadMore from "@/components/xzj-readMore/xzj-readMore.vue" import xzjReadMore from "@/components/xzj-readMore/xzj-readMore.vue"
import {praise} from "../../../api/article";
export default { export default {
name:'ArticleItem', name:'ArticleItem',
options: { options: {
...@@ -144,6 +145,8 @@ ...@@ -144,6 +145,8 @@
}, },
data() { data() {
return { return {
//登录弹窗
isLoginPop: false,
//图片路径 //图片路径
baseUrl: this.$store.state.imgUrl, baseUrl: this.$store.state.imgUrl,
imgs: [], imgs: [],
...@@ -159,7 +162,6 @@ ...@@ -159,7 +162,6 @@
// name: "举报" // name: "举报"
// } // }
], ],
isConfirm: false
} }
}, },
methods: { methods: {
...@@ -180,9 +182,30 @@ ...@@ -180,9 +182,30 @@
}, },
// 点赞 // 点赞
praise(item) { 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) { selectClick(item) {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
</u-tabs> </u-tabs>
</view> </view>
<view v-for="(item,index) in dataList" :key="item.id"> <view v-for="(item,index) in dataList" :key="item.id">
<ItemVue :info="item"/> <ItemVue :info="item" @praise="praise"/>
</view> </view>
<empty v-if="firstLoaded && !dataList.length"/> <empty v-if="firstLoaded && !dataList.length"/>
</z-paging> </z-paging>
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
</template> </template>
<script> <script>
import ItemVue from './Item.vue' import ItemVue from './Item.vue';
import empty from '@/components/empty.vue' import empty from '@/components/empty.vue';
import {topicList} from "../../../api/topic"; import {topicList} from "../../../api/topic";
import {articleList} from "../../../api/article"; import {articleList, like} from "../../../api/article";
import {getCity, getValue} from "../../../common/options"; import {getCity, getValue} from "../../../common/options";
import {calculateAge, parseDate} from "../../../common"; import {calculateAge, parseDate} from "../../../common";
export default { export default {
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
}, },
data() { data() {
return { return {
//登录弹窗
isLoginPop:'',
//话题id //话题id
topicId: 0, topicId: 0,
//当前的tab //当前的tab
...@@ -226,6 +228,27 @@ ...@@ -226,6 +228,27 @@
// this.$refs.paging.complete(false); // 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> </script>
......
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
goMessage() { goMessage() {
}, },
// //登录弹窗
getToLogin(e) { getToLogin(e) {
if (e == 0) { 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