13518219792

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

创新互联百度小程序教程:one-stop-interaction一站式互动组件

one-stop-interaction 一站式互动组件

基础库 3.180.3 开始支持,低版本需做兼容处理。

十余年的乌尔禾网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网整合营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整乌尔禾建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“乌尔禾网站设计”,“乌尔禾网站推广”以来,每个客户项目都认真落实执行。

解释:一站式互动组件,为开发者提供一整套包含评论发布器、评论列表及详情、点赞、收藏、转发功能的互动 bar 能力,互动 bar 支持自定义,此外还提供数据存储、数据内容审核、用户接收百度 App 消息通知的一站式服务。

使用了原 smart-sc 动态库引入的方式,请迁移到如下新的动态库方式接入。

使用方式

1.在项目中声明引用 swan-interaction 动态库

在 app.json 文件配置的 dynamicLib 字段中增加对 swan-interaction 的引用,具体格式在使用动态库文档中查看。

 
 
 
  1. "dynamicLib": {
  2. // 'myDynamicLib' 是个可自定义的别名。
  3. "myDynamicLib": {
  4. // provider 是要引用的动态库的名字,在此为 'swan-interaction'。
  5. "provider": "swan-interaction"
  6. }
  7. }

2.创建一个带评论功能的页面,并在页面中声明引用 comment-list 组件
动态库中的组件与其他自定义组件类似,都需要在 page 中使用。所以首先需要创建一个 page,page 路径可自定义,推荐路径为 pages/list/index(即在小程序页面目录 pages 下创建 list 文件夹,并在文件夹下创建 index.js、index.swan、index.css、index.json 页面文件)。

页面中引用动态库组件的方式是:在页面的 json 配置的 usingSwanComponents 字段中声明组件引用。

 
 
 
  1. {
  2. "navigationBarTitleText": "评论列表",
  3. "usingSwanComponents": {
  4. "comment-list": "dynamicLib://myDynamicLib/comment-list"
  5. }
  6. }

在页面中放入列表组件,传入必要的参数,组件详情配置请参考 comment-list 评论列表组件。

 
 
 
  1. {{header.title}}
  2. {{header.author}}
  3. {{header.time}}
  4. {{item.data}}
  5. class="content-img"
  6. src="{{item.data.src}}"
  7. original-src="{{item.data.src}}"
  8. mode="widthFix"
  9. preview="true"
  10. lazy-load="true"/>
  11. 欢迎使用智能小程序动态库
  12. 欢迎使用智能小程序动态库
  13. 欢迎使用智能小程序动态库
  14. class="img">
  15. 欢迎使用智能小程序动态库
  16. 欢迎使用智能小程序动态库
  17. 欢迎使用智能小程序动态库
  18. comment-param="{{commentParam}}"
  19. detail-path="{{detailPath}}"
  20. toolbar-config="{{toolbarConfig}}"
  21. bindclickcomment="clickComment">
 
 
 
  1. Page({
  2. data: {
  3. commentParam: {},
  4. header: {
  5. title: '心疼!中国自行车女将卷入摔车事故 腹部扎入3厘米木刺坚持完赛',
  6. avatar: 'https://b.bdstatic.com/miniapp/images/demo-dog.png',
  7. author: '百度智能小程序',
  8. time: '2020年04月14日'
  9. },
  10. content: {
  11. items: [
  12. {
  13. type: 'text',
  14. data: '测试文字'
  15. }
  16. ]
  17. },
  18. detailPath: '/pages/detail/index?params1=abd',
  19. // 底部互动 bar 的配置
  20. toolbarConfig: {
  21. // 若 moduleList 中配置有 share 模块,默认是有,则该属性为必填,title 必传
  22. share: {
  23. title: '心疼!中国自行车女将卷入摔车事故 腹部扎入3厘米木刺坚持完赛'
  24. }
  25. }
  26. },
  27. onLoad(query) {
  28. this.setData({
  29. commentParam: {
  30. snid: '10070000311753961',
  31. path: '/pages/comment/index?snid=test_snid57',
  32. title: '测试文章标题',
  33. content: '测试文章内容',
  34. images: ['https://b.bdstatic.com/miniapp/images/demo-dog.png']
  35. }
  36. });
  37. },
  38. onReady() {
  39. // 用于实现页面间的跳转
  40. requireDynamicLib('myDynamicLib').listenEvent();
  41. },
  42. clickComment(e) {
  43. }
  44. });
 
 
 
  1. .article-header {
  2. padding: 0 17px;
  3. }
  4. .article-header .title {
  5. display: block;
  6. font-size: 24px;
  7. line-height: 1.5;
  8. font-weight: 700;
  9. }
  10. .article-header .source {
  11. margin-top: 24px;
  12. display: flex;
  13. align-items: flex-start;
  14. }
  15. .article-header .source image {
  16. width: 35px;
  17. height: 35px;
  18. border-radius: 100%;
  19. margin-right: 8px;
  20. background-color: #eef1f4;
  21. background-size: 16px 16px;
  22. background-repeat: no-repeat;
  23. background-position: center center;
  24. background-image: url(../common/assets/logo-default.png);
  25. }
  26. .article-header .info {
  27. display: flex;
  28. flex-direction: column;
  29. justify-content: center;
  30. height: 35px;
  31. }
  32. .article-header .info .author {
  33. font-size: 16px;
  34. line-height: 1;
  35. display: block;
  36. color: #000;
  37. margin-bottom: 7px;
  38. }
  39. .article-header .info .time {
  40. display: block;
  41. color: #999;
  42. font-size: 12px;
  43. line-height: 1;
  44. }
  45. .article-content {
  46. color: #000;
  47. font-size: 19px;
  48. line-height: 1.58;
  49. letter-spacing: 2.84;
  50. margin-bottom: 30px;
  51. }
  52. .article-content .content-img {
  53. width: 100%;
  54. margin-top: 30px;
  55. vertical-align: bottom;
  56. background-color: #eef1f4;
  57. background-size: 32px 32px;
  58. background-repeat: no-repeat;
  59. background-position: center center;
  60. background-image: url(../common/assets/logo-default.png);
  61. }
  62. .article-content .content-p {
  63. margin: 24.5px 17px -5.5px 17px;
  64. text-align: justify;
  65. word-break: break-all;
  66. }

3.创建一个评论详情页面,并在页面中声明引用 comment-detail 组件
动态库中的组件与其他自定义组件类似,都需要在 page 中使用。所以首先需要创建一个 page,page 路径可自定义,推荐路径为 pages/detail/index(即在小程序页面目录 pages 下创建 detail 文件夹,并在文件夹下创建 index.js、index.swan、index.css、index.json 页面文件)。

页面中引用动态库组件的方式是:在页面的 json 配置的 usingSwanComponents 字段中声明组件引用。

  • JSON
 
 
 
  1. {
  2. "navigationBarTitleText": "评论详情",
  3. "usingSwanComponents": {
  4. "comment-detail": "dynamicLib://myDynamicLib/comment-detail"
  5. }
  6. }

在页面中放入详情组件,传入必要的参数,组件详情配置请参考 comment-detail 评论详情组件。

  • SWAN
  • JS
 
 
 
  1. comment-param="{{commentParam}}"
  2. srid="{{srid}}"
  3. need-like-btn="{{true}}"
  4. binddelete="detailDelete">
 
 
 
  1. Page({
  2. data: {
  3. srid: '',
  4. commentParam: {}
  5. },
  6. onLoad(options) {
  7. if (options) {
  8. this.setData({
  9. srid: options.srid
  10. });
  11. }
  12. const param = getApp().globalData.commentParam;
  13. if (param && Object.keys(param).length) {
  14. this.setData({
  15. 'commentParam': param
  16. });
  17. }
  18. else {
  19. this.setData({
  20. commentParam: {
  21. snid: '10070000311753961',
  22. path: '/pages/comment/index?snid=test_snid57',
  23. title: '测试文章标题'
  24. }
  25. });
  26. }
  27. }
  28. });

图片示例

评论列表支持折叠

对于部分开发者,在评论列表下方希望放入广告等推荐区域,故评论列表支持折叠使用。

使用方式

1.创建一个带评论功能的页面,并在页面中声明引用 comment-list 组件
在页面中放入列表组件,传入必要的可折叠参数,组件详情配置请参考 comment-list 评论列表组件。

  • SWAN
  • JS
  • JSON
  • CSS
 
 
 
  1. {{header.title}}
  2. {{header.author}}
  3. {{header.time}}
  4. {{item.data}}
  5. class="content-img"
  6. src="{{item.data.src}}"
  7. original-src="{{item.data.src}}"
  8. mode="widthFix"
  9. preview="true"
  10. lazy-load="true"/>
  11. comment-param="{{commentParam}}"
  12. detail-path="{{detailPath}}"
  13. is-folded="{{true}}"
  14. fold-num="{{foldNum}}"
  15. toolbar-config="{{toolbarConfig}}"
  16. view-more-path="{{viewMorePath}}"
  17. bindclickcomment="clickComment"
  18. bindviewmore="viewMore">
  19. 欢迎使用智能小程序动态库
  20. 欢迎使用智能小程序动态库
  21. 欢迎使用智能小程序动态库
  22. class="img">
  23. 欢迎使用智能小程序动态库
  24. 欢迎使用智能小程序动态库
  25. 欢迎使用智能小程序动态库
 
 
 
  1. Page({
  2. data: {
  3. commentParam: {},
  4. header: {
  5. title: '心疼!中国自行车女将卷入摔车事故 腹部扎入3厘米木刺坚持完赛',
  6. avatar: 'https://b.bdstatic.com/miniapp/images/demo-dog.png',
  7. author: '百度智能小程序',
  8. time: '2020年04月14日'
  9. },
  10. content: {
  11. items: [
  12. {
  13. type: 'image',
  14. data: {
  15. src: 'https://b.bdstatic.com/miniapp/images/demo-dog.png'
  16. }
  17. },
  18. {
  19. type: 'text',
  20. data: '测试文字'
  21. }
  22. ]
  23. },
  24. // 评论详情页面路径
  25. detailPath: '/pages/detail/index?params1=abd',
  26. // 全部评论页面路径
  27. viewMorePath: '/pages/all-list/index',
  28. // 折叠展示最大评论条数
  29. foldNum: 5,
  30. // 底部互动 bar 的配置
  31. toolbarConfig: {
  32. // 若 moduleList 中配置有 share 模块,默认是有,则该属性为必填,title 必传
  33. share: {
  34. title: '心疼!中国自行车女将卷入摔车事故 腹部扎入3厘米木刺坚持完赛'
  35. }
  36. }
  37. },
  38. onLoad(query) {
  39. this.setData({
  40. commentParam: {
  41. snid: '10070000311753961',
  42. path: '/pages/comment/index?snid=test_snid57',
  43. title: '测试文章标题',
  44. content: '测试文章内容',
  45. images: ['https://b.bdstatic.com/miniapp/images/demo-dog.png']
  46. }
  47. });
  48. },
  49. onReady() {
  50. // 用于实现页面间的跳转
  51. requireDynamicLib('myDynamicLib').listenEvent();
  52. },
  53. clickComment(e) {
  54. },
  55. viewMore() {
  56. swan.showToast({
  57. title: 'click success'
  58. });
  59. }
  60. });
 
 
 
  1. {
  2. "navigationBarTitleText": "折叠列表页",
  3. "usingSwanComponents": {
  4. "comment-list": "dynamicLib://myDynamicLib/comment-list"
  5. }
  6. }
 
 
 
  1. .article-header {
  2. padding: 0 39.8rpx;
  3. }
  4. .article-header .title {
  5. display: block;
  6. font-size: 56rpx;
  7. line-height: 1.5;
  8. font-weight: 700;
  9. }
  10. .article-header .source {
  11. margin-top: 56rpx;
  12. display: flex;
  13. align-items: flex-start;
  14. }
  15. .article-header .source image {
  16. width: 82rpx;
  17. height: 82rpx;
  18. border-radius: 100%;
  19. margin-right: 18.7rpx;
  20. background-color: #eef1f4;
  21. background-size: 37.4rpx 37.4rpx;
  22. background-repeat: no-repeat;
  23. background-position: center center;
  24. background-image: url(../common/assets/logo-default.png);
  25. }
  26. .article-header .info {
  27. display: flex;
  28. flex-direction: column;
  29. justify-content: center;
  30. height: 82rpx;
  31. }
  32. .article-header .info .author {
  33. font-size: 37.4rpx;
  34. line-height: 1;
  35. display: block;
  36. color: #000;
  37. margin-bottom: 16.4rpx;
  38. }
  39. .article-header .info .time {
  40. display: block;
  41. color: #999;
  42. font-size: 28rpx;
  43. line-height: 1;
  44. }
  45. .article-content {
  46. color: #000;
  47. font-size: 44.5rpx;
  48. line-height: 1.58;
  49. letter-spacing: 2.84;
  50. margin-bottom: 70.2rpx;
  51. }
  52. .article-content .content-img {
  53. width: 100%;
  54. margin-top: 70.2rpx;
  55. vertical-align: bottom;
  56. background-color: #eef1f4;
  57. background-size: 74.9rpx 74.9rpx;
  58. background-repeat: no-repeat;
  59. background-position: center center;
  60. background-image: url(../common/assets/logo-default.png);
  61. }
  62. .article-content .content-p {
  63. margin: 57.3rpx 39.8rpx -12.9rpx 39.8rpx;
  64. text-align: justify;
  65. word-break: break-all;
  66. }
  67. .list-after {
  68. padding: 30rpx 18rpx 90rpx;
  69. }
  70. .comment-list-folded-bottom-margin {
  71. height: 14.4rpx;
  72. background-color: #f5f5f5;
  73. }

2.创建一个展示全部评论的页面,并在页面中声明引用 comment-list 组件
我们建议全部评论的页面,互动 bar 仅保留评论发布。组件配置请参考 comment-list 评论列表组件。

  • SWAN
  • JS
  • JSON
 
 
 
  1. comment-param="{{commentParam}}"
  2. detail-path="{{detailPath}}"
  3. toolbar-config="{{toolbarConfig}}"
  4. bindclickcomment="clickComment">
 
 
 
  1. Page({
  2. data: {
  3. commentParam: {},
  4. toolbarConfig: {
  5. moduleList: []
  6. },
  7. detailPath: '/pages/detail/index?params1=abd'
  8. },
  9. onInit() {
  10. this.isOnInitCalled = true;
  11. this.init();
  12. },
  13. onLoad() {
  14. // 兼容不支持 onInit 的版本
  15. if (!this.isOnInitCalled) {
  16. this.init();
  17. }
  18. },
  19. init() {
  20. const commentParam = getApp().globalData.commentParam;
  21. if (commentParam && Object.keys(commentParam).length) {
  22. this.setData({
  23. commentParam
  24. });
  25. }
  26. else {
  27. this.setData({
  28. commentParam: {
  29. snid: '10070000311753961',
  30. path: '/pages/comment/index?snid=test_snid57',
  31. title: '测试文章标题'
  32. }
  33. });
  34. }
  35. },
  36. onReady() {
  37. // 用于实现页面间的跳转
  38. requireDynamicLib('myDynamicLib').listenEvent();
  39. },
  40. clickComment(e) {
  41. }
  42. });
 
 
 
  1. {
  2. "navigationBarTitleText": "全部评论",
  3. "usingSwanComponents": {
  4. "comment-list": "dynamicLib://myDynamicLib/comment-list"
  5. }
  6. }

3.创建一个评论详情页面,并在页面中声明引用 comment-detail 组件

Bug & Tip

  • Tip:使用 Mars 等第三方框架开发小程序时,可能存在 setData 的异步延时,如在评论详情页 srid 作为单独参数传入没有生效,可作为 commentParam 中的字段传入。
  • Tip:原有一站式互动组件 smart-sc 因性能问题,对用户流量产生影响,为避免影响线上已接入用户,本次新的一站式互动组件采用新的动态库。
  • Tip:原有一站式互动组件的部分 bug ,如点赞状态失效等,已在新一站式组件中修复。
  • Tip:新的一站式互动组件,通用性更强,除了页面级别,也支持浮层的使用。
  • Tip:在 onLoad 和 onReady 生命周期内引入requireDynamicLib('myDynamicLib').listenEvent()来实现页面的跳转。

网站栏目:创新互联百度小程序教程:one-stop-interaction一站式互动组件
标题链接:http://cdbrznjsb.com/article/cohisje.html
  • 网站建设专属方案

  • 网站定制化设计

  • 7X24小时服务

  • N对管家服务

让你的专属顾问为你服务