掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流
解釋:評論列表,評論的相關數(shù)據(jù)為托管數(shù)據(jù)。
Web 態(tài)說明:由于瀏覽器的限制,在 Web 態(tài)內(nèi)暫不支持發(fā)布評論、收藏、分享等功能。

| 屬性名 | 類型 | 必填 | 默認值 | 說明 |
|---|---|---|---|---|
| comment-param | Object | 是 | 評論核心參數(shù) | |
| toolbar-config | Object | 否 | 底部 toolbar 的相關配置 | |
| is-page-scroll | Boolean | 否 | true | 滾動方式為頁面滾動,若組件作為浮層使用,該參數(shù)需設為 false |
| need-toolbar | Boolean | 否 | true | 是否需要底部 toolbar ,若使用開發(fā)者自定義的底部 toolbar ,該參數(shù)需設為 false |
| add-comment | Boolean | 否 | false | 用于調起評論發(fā)布器發(fā)布評論 |
| detail-path | String | 否 | 點擊單條評論跳轉的詳情頁頁面 path ,若沒有配置則不會發(fā)生跳轉;配置的前提是列表與詳情均是頁面級 | |
| is-folded | Boolean | 否 | false | 是否折疊列表,默認全展示 |
| fold-num | Number | 否 | 3 | 折疊后列表展示最大條數(shù),默認 3 條,最多 10 條 |
| view-more-path | String | 否 | 傳入放置評論組件的頁面路徑,如‘/pages/list/index’,組件內(nèi)部會觸發(fā)跳轉邏輯 | |
| view-more-style | Object | 否 | 『全部 xx 條』的樣式,目前只支持開發(fā)者自定義字體顏色 | |
| bindclickcomment | EventHandler | 否 | 綁定點擊單條評論的事件,點擊單條評論時觸發(fā),返回數(shù)據(jù)為{status, data:{srid}} | |
| bindviewmore | EventHandle | 否 | 綁定點擊更多事件,若除了頁面跳轉還需要其他操作,可通過該回調執(zhí)行;若為浮層,也可使用該回調自定義交互邏輯 |
| 屬性名 | 類型 | 必填 | 默認值 | 說明 | 示例值 |
|---|---|---|---|---|---|
| snid | String | 是 | 文章的唯一標識,與 path 參數(shù)一一對應 | ‘20200101’ | |
| title | String | 是 | 文章標題 | ||
| path | String | 是 | 智能小程序內(nèi)頁鏈接,最長不能超過 194 字符。如該文章需要入信息流投放,需保證該參數(shù)與信息流投放提交的 path 一致,否則將會影響流量 | “path”:”/pages/index/index” | |
| images | Array | 否 | 數(shù)組第一項用于收藏功能的展示圖片 | [‘https://b.bdstatic.com/miniapp/images/demo-dog.png‘] |
| 屬性名 | 類型 | 必填 | 默認值 | 說明 |
|---|---|---|---|---|
| placeholder | String | 否 | 輸入框提示文字 | |
| moduleList | Array | 否 | [‘comment’, ‘like’, ‘favor’, ‘share’] | 顯示的互動模塊,對應默認值分別是:評論數(shù)、點贊、收藏、分享 |
| share | Object | 否 | 若 moduleList 里配置了 share 模塊,該參數(shù)為必填 | |
| share.title | String | 是 | 分享標題 | |
| share.content | String | 否 | 分享內(nèi)容 | |
| share.imageUrl | String | 否 | 分享圖標 | |
| share.path | String | 否 | 頁面 path ,必須是以 / 開頭的完整路徑,如果 path 中參數(shù)包含中文字符,需對中文字符進行編碼 |
| 屬性名 | 類型 | 必填 | 默認值 | 說明 |
|---|---|---|---|---|
| color | String | 否 | ‘#3388ff’ | 『全部 xx 條』的字體顏色,默認為視覺提供色號,開發(fā)者可傳入自定義色號 |
頁面中引用動態(tài)庫組件的方式是:在頁面的 json 配置的 usingSwanComponents 字段中聲明組件引用。
{"navigationBarTitleText": "評論列表","usingSwanComponents": {"comment-list": "dynamicLib://myDynamicLib/comment-list"}}
在頁面中放入列表組件,傳入必要的參數(shù)。
comment-param="{{commentParam}}"detail-path="{{detailPath}}"toolbar-config="{{toolbarConfig}}"bindclickcomment="clickComment">
Page({data: {commentParam: {},detailPath: '/pages/detail/index?params1=abd',// 底部互動 bar 的配置toolbarConfig: {// 若 moduleList 中配置有 share 模塊,默認是有,則該屬性為必填,title 必傳share: {title: '測試文章標題'}}},onLoad(query) {this.setData({commentParam: {snid: '10070000311753961',path: '/pages/comment/index?snid=test_snid57',title: '測試文章標題',content: '測試文章內(nèi)容'}});},onReady() {requireDynamicLib('myDynamicLib').listenEvent();},clickComment(e) {}});
{{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">歡迎使用智能小程序動態(tài)庫 歡迎使用智能小程序動態(tài)庫歡迎使用智能小程序動態(tài)庫class="img">歡迎使用智能小程序動態(tài)庫 歡迎使用智能小程序動態(tài)庫歡迎使用智能小程序動態(tài)庫
Page({data: {commentParam: {},header: {title: '心疼!中國自行車女將卷入摔車事故 腹部扎入3厘米木刺堅持完賽',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: '測試文字'}]},// 折疊展示最大評論條數(shù)foldNum: 5,// 底部互動 bar 的配置toolbarConfig: {// 若 moduleList 中配置有 share 模塊,默認是有,則該屬性為必填,title 必傳share: {title: '心疼!中國自行車女將卷入摔車事故 腹部扎入3厘米木刺堅持完賽'}}},onLoad(query) {this.setData({commentParam: {snid: '10070000311753961',path: '/pages/comment/index?snid=test_snid57',title: '測試文章標題',content: '測試文章內(nèi)容'}});},onReady() {requireDynamicLib('myDynamicLib').listenEvent();},clickComment(e) {swan.showToast({title: 'click comment success'});},viewMore() {// swan.showToast({// title: 'click viewmore success'// });}});
{"navigationBarTitleText": "折疊列表頁","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;}
若開發(fā)者希望調起評論發(fā)布器,且與組件內(nèi)的評論發(fā)布邏輯保持一致(發(fā)布成功插入列表第一條,且滾動到列表頂部),可使用如下方法:
在 js 文件中,將 add-comment 屬性設為 true ,即可調起評論發(fā)布器。
前提是評論列表組件已渲染。
class="img">這是背景 全部評論 class="float-list-component"add-comment="{{addComment}}"is-page-scroll="{{false}}"comment-param="{{commentParam}}"need-toolbar="{{false}}"bindclickcomment="clickComment">關閉 評論詳情 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: '測試文章標題','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}, () => {// 需要設為 false 的原因:因為調起發(fā)布監(jiān)聽 addComment 的變化,如果一直為 true,無法再次調起this.setData({'addComment': false});});}else {this.setData({showList: false,publishComment: true}, () => {// 需要設為 false 的原因:因為調起發(fā)布監(jiān)聽 addComment 的變化,如果一直為 true,無法再次調起this.setData({'publishComment': false});});}},/*** 詳情刪除后的回調** @param {Object} options 返回的相關數(shù)據(jù),{status, data}* @property {string} srid 評論 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 有多高,這里就設多少 */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 {/* 因為浮層塊高度為800rpx */0% {height: 0;}25% {height: 200rpx;}50% {height: 400rpx;}75% {height: 600rpx;}100% {height: 900rpx;}}

我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流