Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

接口

下面是核心的前端调用代码,具体页面效果根据自身模版的风格进行调整。

Tip

dataType是关注类型字典,前台在对接业务时需注意,请传递字典label值。

Tip

注意:大部分接口都需要会员登陆后才能调用,用户对该信息的关注,通过自定义dataType值来区分收藏、赞等类型,例如:dataType=文章点赞收藏dataType=商品关注赞等等,可以自定义多种类型,对应的取消、列表、统计接口dataType要保持一致。

前端对接

Tip

后台需要在自定义字典中增加字典值;找到关注类型,再添加新的字典,如(名称label:文章点赞,数据值value:contentLike)数据值作为数据保存,名称作为展示;

查看点赞或者关注数量

// VUE代码片段
    ...
    // 页面片段,具体业务样式,需自行开发
	<span>
            {{attentionTotal}}
	</span>
    ...
    attentionTotal: 0, //文章点赞数量
    dataId:'${field.id}',//文章id
    dataType: '文章点赞'   //业务类型
    ...
    
// 查询点赞总数量方法
attentionTotals: function (dataType) {
	var that = this;
    ms.http.post( ms.base + "/attention/collection/queryCollectionCount.do", {
	    dataIds: commentDataIds.toString(),
	    dataType: '关注点赞'
    }).then(function (res) {
	    that.attentionTotal = 0;
		if(res.result){
			that.attentionTotal = res.data[0].dataCount;
		}
	})
},

会员点赞、关注或者收藏

    // 页面片段,具体业务样式,需自行开发
    ...
    <div>
    	<i @click="saveAttention()"></i>
    	<span>
            {{attentionTotal}}
    	</span>
    </div>
    ...

// VUE代码片段
    ...
    attentionTotal: 0, //文章点赞数量
    dataId:'${field.id}',//文章id
    dataType: '文章点赞'   //业务类型
    collectionDataTitle: '${field.title}' // 文章标题
    contentLike: false, // 当前用户是否点赞此文章
    ...

// 文章点赞,重复点击会取消点赞
saveAttention: function () {
	var that = this
	ms.http.post( ms.base + "/people/attention/collection/save.do", {
		dataId: that.dataId,
		dataType: that.dataType
		collectionDataTitle: that.collectionDataTitle,
	}).then(function (res) {
		if (res.result) {
		    // 调用查询点赞数量
			that.attentionTotals(that.dataType)
		}
	});
},
// 查询点赞总数量方法
attentionTotals: function (dataType) {
	var that = this;
	ms.http.post("/people/attention/collectionLog/queryCollectionCount.do", {
		dataIds: that.dataId,
		dataType: that.dataType
	}).then(function (res) {
	    that.attentionTotal = 0;
		if(res.result){
		    // 获取文章点赞总数
			that.attentionTotal = res.data[0].dataCount;
			// 判断当前文章是否点赞
			that.contentLike = item.like;
		}
	})
},

Tip

注意: 只有请求people层接口且登录才能判断当前用户是否点赞或关注此业务

会员中心-列表

需要会员登陆后才能调用的接口,查询当前会员的关注信息或者点赞信息

代码片段

list: function () {
        ms.http.get("/people/attention/collectionLog/list.do",{
            pageSize: 999,
            dataType: "文章点赞",
            pageNo: 1,
        }).then(function (res){
            if (res.result) {
             //列表渲染
            }
        })
},

业务层开发

开发规范查看biz.CollectionBizImpl中的方法注释 下面以业务层saveOrDelete为例 attention.biz.impl中saveOrDelete方法代码片段,可以通过控制层直接调用biz方法实现更多的点赞或者关注业务场景,例如:商品关注、商品点赞

        //基本数据校验
...
        // 判断关注数据存在
        CollectionLogEntity collectionLog  = new CollectionLogEntity();
        collectionLog.setDataId(collectionEntity.getDataId());
        collectionLog.setDataType(collectionEntity.getDataType());
        // 重复点赞判断
        LambdaQueryWrapper<CollectionEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CollectionEntity::getDataId, collectionEntity.getDataId());
        wrapper.eq(CollectionEntity::getPeopleId, collectionEntity.getPeopleId());
        wrapper.eq(CollectionEntity::getDataType, collectionEntity.getDataType());
...
        collectionEntity.setCreateDate(new Date());
        // 插入一条数据
        collectionDao.insert(collectionEntity);
        return true;