新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)百度小程序教程:comment-list 評(píng)論列表組件
- comment-list 評(píng)論列表組件
- 屬性說(shuō)明
- comment-param 服務(wù)參數(shù)說(shuō)明
- toolbar-config 參數(shù)說(shuō)明
- view-more-style 參數(shù)說(shuō)明
- 代碼示例 1:列表組件放入頁(yè)面
- 代碼示例 2:列表支持折疊
- 調(diào)起評(píng)論發(fā)布功能
- 代碼示例:列表組件放入浮層且自定義底部 toolbar
- Bug & Tip
- 屬性說(shuō)明
comment-list 評(píng)論列表組件
解釋:評(píng)論列表,評(píng)論的相關(guān)數(shù)據(jù)為托管數(shù)據(jù)。
Web 態(tài)說(shuō)明:由于瀏覽器的限制,在 Web 態(tài)內(nèi)暫不支持發(fā)布評(píng)論、收藏、分享等功能。

屬性說(shuō)明
| 屬性名 | 類型 | 必填 | 默認(rèn)值 | 說(shuō)明 |
|---|---|---|---|---|
| comment-param | Object | 是 | 評(píng)論核心參數(shù) | |
| toolbar-config | Object | 否 | 底部 toolbar 的相關(guān)配置 | |
| is-page-scroll | Boolean | 否 | true | 滾動(dòng)方式為頁(yè)面滾動(dòng),若組件作為浮層使用,該參數(shù)需設(shè)為 false |
| need-toolbar | Boolean | 否 | true | 是否需要底部 toolbar ,若使用開(kāi)發(fā)者自定義的底部 toolbar ,該參數(shù)需設(shè)為 false |
| add-comment | Boolean | 否 | false | 用于調(diào)起評(píng)論發(fā)布器發(fā)布評(píng)論 |
| detail-path | String | 否 | 點(diǎn)擊單條評(píng)論跳轉(zhuǎn)的詳情頁(yè)頁(yè)面 path ,若沒(méi)有配置則不會(huì)發(fā)生跳轉(zhuǎn);配置的前提是列表與詳情均是頁(yè)面級(jí) | |
| is-folded | Boolean | 否 | false | 是否折疊列表,默認(rèn)全展示 |
| fold-num | Number | 否 | 3 | 折疊后列表展示最大條數(shù),默認(rèn) 3 條,最多 10 條 |
| view-more-path | String | 否 | 傳入放置評(píng)論組件的頁(yè)面路徑,如‘/pages/list/index’,組件內(nèi)部會(huì)觸發(fā)跳轉(zhuǎn)邏輯 | |
| view-more-style | Object | 否 | 『全部 xx 條』的樣式,目前只支持開(kāi)發(fā)者自定義字體顏色 | |
| bindclickcomment | EventHandler | 否 | 綁定點(diǎn)擊單條評(píng)論的事件,點(diǎn)擊單條評(píng)論時(shí)觸發(fā),返回?cái)?shù)據(jù)為{status, data:{srid}} | |
| bindviewmore | EventHandle | 否 | 綁定點(diǎn)擊更多事件,若除了頁(yè)面跳轉(zhuǎn)還需要其他操作,可通過(guò)該回調(diào)執(zhí)行;若為浮層,也可使用該回調(diào)自定義交互邏輯 |
comment-param 服務(wù)參數(shù)說(shuō)明
| 屬性名 | 類型 | 必填 | 默認(rèn)值 | 說(shuō)明 | 示例值 |
|---|---|---|---|---|---|
| snid | String | 是 | 文章的唯一標(biāo)識(shí),與 path 參數(shù)一一對(duì)應(yīng) | ‘20200101’ | |
| title | String | 是 | 文章標(biāo)題 | ||
| path | String | 是 | 智能小程序內(nèi)頁(yè)鏈接,最長(zhǎng)不能超過(guò) 194 字符。如該文章需要入信息流投放,需保證該參數(shù)與信息流投放提交的 path 一致,否則將會(huì)影響流量 | “path”:”/pages/index/index” | |
| images | Array | 否 | 數(shù)組第一項(xiàng)用于收藏功能的展示圖片 | [‘https://b.bdstatic.com/miniapp/images/demo-dog.png‘] |
toolbar-config 參數(shù)說(shuō)明
| 屬性名 | 類型 | 必填 | 默認(rèn)值 | 說(shuō)明 |
|---|---|---|---|---|
| placeholder | String | 否 | 輸入框提示文字 | |
| moduleList | Array | 否 | [‘comment’, ‘like’, ‘favor’, ‘share’] | 顯示的互動(dòng)模塊,對(duì)應(yīng)默認(rèn)值分別是:評(píng)論數(shù)、點(diǎn)贊、收藏、分享 |
| share | Object | 否 | 若 moduleList 里配置了 share 模塊,該參數(shù)為必填 | |
| share.title | String | 是 | 分享標(biāo)題 | |
| share.content | String | 否 | 分享內(nèi)容 | |
| share.imageUrl | String | 否 | 分享圖標(biāo) | |
| share.path | String | 否 | 頁(yè)面 path ,必須是以 / 開(kāi)頭的完整路徑,如果 path 中參數(shù)包含中文字符,需對(duì)中文字符進(jìn)行編碼 |
view-more-style 參數(shù)說(shuō)明
| 屬性名 | 類型 | 必填 | 默認(rèn)值 | 說(shuō)明 |
|---|---|---|---|---|
| color | String | 否 | ‘#3388ff’ | 『全部 xx 條』的字體顏色,默認(rèn)為視覺(jué)提供色號(hào),開(kāi)發(fā)者可傳入自定義色號(hào) |
代碼示例 1:列表組件放入頁(yè)面
頁(yè)面中引用動(dòng)態(tài)庫(kù)組件的方式是:在頁(yè)面的 json 配置的 usingSwanComponents 字段中聲明組件引用。
- JSON
{"navigationBarTitleText": "評(píng)論列表","usingSwanComponents": {"comment-list": "dynamicLib://myDynamicLib/comment-list"}}
在頁(yè)面中放入列表組件,傳入必要的參數(shù)。
- SWAN
- JS
comment-param="{{commentParam}}"detail-path="{{detailPath}}"toolbar-config="{{toolbarConfig}}"bindclickcomment="clickComment">
Page({data: {commentParam: {},detailPath: '/pages/detail/index?params1=abd',// 底部互動(dòng) bar 的配置toolbarConfig: {// 若 moduleList 中配置有 share 模塊,默認(rèn)是有,則該屬性為必填,title 必傳share: {title: '測(cè)試文章標(biāo)題'}}},onLoad(query) {this.setData({commentParam: {snid: '10070000311753961',path: '/pages/comment/index?snid=test_snid57',title: '測(cè)試文章標(biāo)題',content: '測(cè)試文章內(nèi)容'}});},onReady() {requireDynamicLib('myDynamicLib').listenEvent();},clickComment(e) {}});
代碼示例 2:列表支持折疊
- SWAN
- JS
- JSON
- CSS
{{header.title}} {{header.author}} {{header.time}} {{item.data}} class="content-img"src="{{item.data.src}}"original-src="{{item.data.src}}"mode="widthFix"preview="true"lazy-load="true"/>comment-param="{{commentParam}}"is-folded="{{true}}"fold-num="{{foldNum}}"toolbar-config="{{toolbarConfig}}"bindclickcomment="clickComment"bindviewmore="viewMore">歡迎使用智能小程序動(dòng)態(tài)庫(kù) 歡迎使用智能小程序動(dòng)態(tài)庫(kù)歡迎使用智能小程序動(dòng)態(tài)庫(kù)class="img">歡迎使用智能小程序動(dòng)態(tài)庫(kù) 歡迎使用智能小程序動(dòng)態(tài)庫(kù)歡迎使用智能小程序動(dòng)態(tài)庫(kù)
Page({data: {commentParam: {},header: {title: '心疼!中國(guó)自行車女將卷入摔車事故 腹部扎入3厘米木刺堅(jiān)持完賽',avatar: 'https://b.bdstatic.com/miniapp/images/demo-dog.png',author: '百度智能小程序',time: '2020年04月14日'},content: {items: [{type: 'image',data: {src: 'https://b.bdstatic.com/miniapp/images/demo-dog.png'}},{type: 'text',data: '測(cè)試文字'}]},// 折疊展示最大評(píng)論條數(shù)foldNum: 5,// 底部互動(dòng) bar 的配置toolbarConfig: {// 若 moduleList 中配置有 share 模塊,默認(rèn)是有,則該屬性為必填,title 必傳share: {title: '心疼!中國(guó)自行車女將卷入摔車事故 腹部扎入3厘米木刺堅(jiān)持完賽'}}},onLoad(query) {this.setData({commentParam: {snid: '10070000311753961',path: '/pages/comment/index?snid=test_snid57',title: '測(cè)試文章標(biāo)題',content: '測(cè)試文章內(nèi)容'}});},onReady() {requireDynamicLib('myDynamicLib').listenEvent();},clickComment(e) {swan.showToast({title: 'click comment success'});},viewMore() {// swan.showToast({// title: 'click viewmore success'// });}});
{"navigationBarTitleText": "折疊列表頁(yè)","usingSwanComponents": {"comment-list": "dynamicLib://myDynamicLib/comment-list"}}
.article-header {padding: 0 39.8rpx;}.article-header .title {display: block;font-size: 56rpx;line-height: 1.5;font-weight: 700;}.article-header .source {margin-top: 56rpx;display: flex;align-items: flex-start;}.article-header .source image {width: 82rpx;height: 82rpx;border-radius: 100%;margin-right: 18.7rpx;background-color: #eef1f4;background-size: 37.4rpx 37.4rpx;background-repeat: no-repeat;background-position: center center;background-image: url(../common/assets/logo-default.png);}.article-header .info {display: flex;flex-direction: column;justify-content: center;height: 82rpx;}.article-header .info .author {font-size: 37.4rpx;line-height: 1;display: block;color: #000;margin-bottom: 16.4rpx;}.article-header .info .time {display: block;color: #999;font-size: 28rpx;line-height: 1;}.article-content {color: #000;font-size: 44.5rpx;line-height: 1.58;letter-spacing: 2.84;margin-bottom: 70.2rpx;}.article-content .content-img {width: 100%;margin-top: 70.2rpx;vertical-align: bottom;background-color: #eef1f4;background-size: 74.9rpx 74.9rpx;background-repeat: no-repeat;background-position: center center;background-image: url(../common/assets/logo-default.png);}.article-content .content-p {margin: 57.3rpx 39.8rpx -12.9rpx 39.8rpx;text-align: justify;word-break: break-all;}.list-after {padding: 30rpx 18rpx 90rpx;}.comment-list-folded-bottom-margin {height: 14.4rpx;background-color: #f5f5f5;}
調(diào)起評(píng)論發(fā)布功能
若開(kāi)發(fā)者希望調(diào)起評(píng)論發(fā)布器,且與組件內(nèi)的評(píng)論發(fā)布邏輯保持一致(發(fā)布成功插入列表第一條,且滾動(dòng)到列表頂部),可使用如下方法:
在 js 文件中,將 add-comment 屬性設(shè)為 true ,即可調(diào)起評(píng)論發(fā)布器。
前提是評(píng)論列表組件已渲染。
代碼示例:列表組件放入浮層且自定義底部 toolbar
- SWAN
- JS
- JSON
- CSS
class="img">這是背景 全部評(píng)論 class="float-list-component"add-comment="{{addComment}}"is-page-scroll="{{false}}"comment-param="{{commentParam}}"need-toolbar="{{false}}"bindclickcomment="clickComment">關(guān)閉 評(píng)論詳情 class="float-detail-component"add-comment="{{publishComment}}"srid="{{srid}}"is-page-scroll="{{false}}"comment-param="{{commentParam}}"need-toolbar="{{false}}"back-list-after-delete="{{false}}"binddelete="detailDelete">
Page({data: {commentParam: {},addComment: {},showList: false,showDetail: false,srid: ''},onLoad() {this.setData({commentParam: {snid: '10070000311753961',path: '/pages/comment/index',title: '測(cè)試文章標(biāo)題','snid_type': ''}});},clickComment(e) {this.setData({srid: e.data.srid,showDetail: true,showList: false});},addComment() {const showDetail = this.data.showDetail;if (!showDetail) {this.setData({showList: true,addComment: true}, () => {// 需要設(shè)為 false 的原因:因?yàn)檎{(diào)起發(fā)布監(jiān)聽(tīng) addComment 的變化,如果一直為 true,無(wú)法再次調(diào)起this.setData({'addComment': false});});}else {this.setData({showList: false,publishComment: true}, () => {// 需要設(shè)為 false 的原因:因?yàn)檎{(diào)起發(fā)布監(jiān)聽(tīng) addComment 的變化,如果一直為 true,無(wú)法再次調(diào)起this.setData({'publishComment': false});});}},/*** 詳情刪除后的回調(diào)** @param {Object} options 返回的相關(guān)數(shù)據(jù),{status, data}* @property {string} srid 評(píng)論 id*/detailDelete(options) {if (options.data.srid) {this.setData({showDetail: false,showList: true});}},closeDetail() {this.setData({showDetail: false,showList: true});}});
{"navigationBarTitleText": "智能小程序示例","usingSwanComponents": {"comment-list": "dynamicLib://myDynamicLib/comment-list","comment-detail": "dynamicLib://myDynamicLib/comment-detail"}}
page {height: 100%;}.container {display: flex;flex-direction: column;min-height: 100%;}.img {width: 100%;position: relative;z-index: -1;-webkit-overflow: visible;}.bg {flex: 1;}.float-list-wrap,.float-detail-wrap {background-color: #fff;position: fixed;bottom: 0;left: 0;display: block;height: 900rpx;animation: climbup .5s;width: 100%;z-index: 99;border-top: 1px solid #666;border-radius: 10rpx;}.float-title {text-align: center;padding: 20rpx 0;}.float-list-component,.float-detail-component {height: 100%;}.float-list,.float-detail {overflow-y: scroll;height: 700rpx;/* my-toolbar 有多高,這里就設(shè)多少 */margin-bottom: 90rpx;}.float-detail-close {float: right;padding: 20rpx;}.my-toolbar {position: fixed;bottom: 0;width: 100%;height: 90rpx;background-color: #fff;z-index: 999;font-size: 28.99rpx;}@keyframes climbup {/* 因?yàn)楦訅K高度為800rpx */0% {height: 0;}25% {height: 200rpx;}50% {height: 400rpx;}75% {height: 600rpx;}100% {height: 900rpx;}}
Bug & Tip
- Tip:評(píng)論列表數(shù)據(jù)開(kāi)發(fā)者無(wú)法單獨(dú)獲取,也無(wú)需配置,評(píng)論列表會(huì)托管給組件,開(kāi)發(fā)者接入組件之后,用戶評(píng)論發(fā)布后會(huì)展現(xiàn)在評(píng)論列表上(自己可見(jiàn)),審核通過(guò)后會(huì)全體用戶可見(jiàn)。
- Tip:openid 和百度 App 登錄狀態(tài)(合稱登錄狀態(tài))會(huì)影響用戶的發(fā)布評(píng)論、舉報(bào)、刪除、消息提醒、跳轉(zhuǎn)個(gè)人主頁(yè)和頁(yè)面收藏(合稱互動(dòng)行為),未登錄用戶僅可以瀏覽評(píng)論和點(diǎn)贊。
- Tip:收藏功能在基礎(chǔ)庫(kù) 3.190.1 以上可用。
- Tip:由于 swan.login API 的非兼容改造,一站式互動(dòng)組件統(tǒng)一改為在組件內(nèi)強(qiáng)登錄。
網(wǎng)頁(yè)名稱:創(chuàng)新互聯(lián)百度小程序教程:comment-list 評(píng)論列表組件
網(wǎng)頁(yè)網(wǎng)址:http://www.dlmjj.cn/article/cojgdci.html


咨詢
建站咨詢
