13518219792

建站动态

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

创新互联百度小程序教程:page-video短视频详情页模板

page-video 短视频详情页模板

从开发者工具 v2.25.1-rc 版本、基础库版本 3.190.1 版本开始支持。

纳雍网站建设公司成都创新互联,纳雍网站设计制作,有大型网站制作公司丰富经验。已为纳雍近千家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的纳雍做网站的公司定做!

解释:本模版适用于快速搭建视频片花、预告、短视频等视频类详情页。模版在保证用户交互体验的基础上,提供了不同模块,配合使用加入书架、预约和引导关注组件,实现兴趣激发,充分发挥短视频带长视频消费的种草价值,拉动二次重访。

示例

扫码体验

代码示例

请使用百度APP扫码

页面内容

模板包含两个页面:短视频详情页、评论详情页。

短视频详情页

默认配置为导航栏、视频播放器、短视频标题及辅助信息区、长视频信息区一站式互动区等模块。

包含导航栏、引导关注组件、视频播放器(含自动连播逻辑)、短视频标题及辅助信息区、长视频信息区、活动运营位、百青藤广告区、推荐短视频区和一站式互动区等模块,分为默认配置模块和可选配置模块。开发者可根据自身业务形态选择合适的模块进行自定义配置。

页面路径:pages/index

代码示例

 
 
 
  1. Page({
  2. ...
  3. attr: {
  4. // 请求的 url,请替换为真实的请求地址,该值仅做为示例,值为 defaultData 为默认配置示例,其他值为全配置示例
  5. url: '/index',
  6. // onLoad参数
  7. options: {}
  8. },
  9. onLoad(options) {
  10. this.getPageData();
  11. ...
  12. },
  13. getPageData() {
  14. const url = this.attr.url;
  15. // 模拟请求,请进行替换
  16. getIndexData({
  17. url
  18. }).then(
  19. res => {
  20. res.playVideoList.forEach(item => {
  21. // 格式化播放数量
  22. item.playNum = this.formatPlayNum(item.playNum);
  23. item.nextInfo = false;
  24. // 过滤出长视频
  25. if (item.type === 1) {
  26. this.attr.feedList.push(item);
  27. }
  28. });
  29. let {
  30. showFeed,
  31. feedMore,
  32. feedShowList,
  33. toolbarConfig
  34. } = this.data;
  35. let feedList = this.attr.feedList;
  36. if (!feedList.length) {
  37. showFeed = false;
  38. }
  39. // feed 少于5条不展示查看更多
  40. if (feedList.length <= 5) {
  41. feedMore = false;
  42. feedShowList = feedList;
  43. } else {
  44. // 多于5条时,先展示前5条
  45. feedShowList = feedList.slice(0, 5);
  46. }
  47. toolbarConfig.title = res.longVideoInfo.name;
  48. res.longVideoInfo = this.formatVideoInfo(res.longVideoInfo);
  49. this.setData({
  50. playVideoList: res.playVideoList,
  51. feedShowList: feedShowList,
  52. longVideoInfo: res.longVideoInfo,
  53. operateInfo: res.operateInfo,
  54. feedMore: feedMore,
  55. toolbarConfig: toolbarConfig,
  56. showFeed: showFeed,
  57. commentParam: {
  58. // 文章的唯一标识
  59. snid: this.attr.options.snid,
  60. path: `/@smt-ui-template-page-video/pages/index/index?snid=${this.attr.options.snid}`,
  61. title: res.longVideoInfo.name
  62. },
  63. loading: false,
  64. // code 0: 正常获取数据 99999: 无网络 其他: 服务异常
  65. statusType: res.code === 99999 ? 'noNetwork' : res.code !== 0 ? 'warning' : ''
  66. });
  67. }
  68. );
  69. }
  70. })
 
 
 
  1. Page({
  2. ...
  3. attr: {
  4. // 页面展示时是否显示关注引导tip
  5. showFavorite: true
  6. },
  7. onShow() {
  8. if (this.attr.showFavorite) {
  9. // 页面展示时显示关注引导
  10. this.showFavoriteGuide();
  11. }
  12. }
  13. })
  1. 当前用户退出小程序后,即删除已观看记录,下次进入小程序短视频落地页,重新执行去重逻辑。
  2. 蒙层展示下一条播放的视频信息并提供重播、观看正片、立即播放等功能。
 
 
 
  1. id="myVideo"
  2. class="video-header-player"
  3. src="{{playVideoList[playIndex] && playVideoList[playIndex].src}}"
  4. title="{{playVideoList[playIndex].title}}"
  5. autoplay="true"
  6. objectFit="fill"
  7. direction="true"
  8. muted="true"
  9. show-mute-btn="true"
  10. show-center-play-btn="false"
  11. bindtimeupdate="videoTimeUpdateHandler"
  12. bindplay="videoPlayHandler"
  13. bindended="videoEndedHandler"
  14. >
  15. 接下来播放
  16. {{remainingTime}}s后播放
  17. {{playVideoList[nextIndex].title}}
  18. {{playVideoList[nextIndex].playNum}}次播放
  19. 立即播放
  20. 重播
  21. 观看正片
  22. 重播
  23. <
  24. 即将播放:{{playVideoList[nextIndex].title}}
 
 
 
  1. Page({
  2. ...
  3. /**
  4. * 播放下一条视频
  5. */
  6. playVideo() {
  7. this.setData({
  8. isMonitoring: false,
  9. isPlaying: true,
  10. playIndex: this.data.nextIndex
  11. });
  12. },
  13. /**
  14. * 重播
  15. */
  16. replayVideo() {
  17. this.attr.videoContext.play();
  18. this.setData({
  19. isMonitoring: false,
  20. isPlaying: true
  21. });
  22. },
  23. /**
  24. * 监听播放开始事件
  25. */
  26. videoPlayHandler() {
  27. const {
  28. timer,
  29. playVideoList,
  30. playIndex
  31. } = this.data;
  32. // 开始播放清除倒计时器
  33. if (timer) {
  34. clearInterval(timer);
  35. this.setData({
  36. timer: null
  37. });
  38. }
  39. if (!playVideoList[playIndex].nextInfo) {
  40. playVideoList[playIndex].nextInfo = true;
  41. // 根据已播列表获取下一条视频 index
  42. for (let i = playIndex + 1; i < playVideoList.length; i++) {
  43. if (this.attr.playedList.indexOf(playVideoList[i].id) === -1) {
  44. this.setData({
  45. nextIndex: i
  46. });
  47. break;
  48. }
  49. }
  50. }
  51. this.setData({
  52. isMonitoring: false
  53. });
  54. },
  55. /**
  56. * 监听播放结束事件
  57. */
  58. videoEndedHandler() {
  59. // 短视频去重
  60. if (this.data.playVideoList[this.data.playIndex].type === 1) {
  61. this.attr.playedList.push(this.data.playVideoList[this.data.playIndex].id);
  62. }
  63. // 没有可播放的视频
  64. if (this.data.nextIndex === this.data.playIndex) {
  65. // 存在长视频落地页时跳转长视频落地页
  66. if (this.data.longVideoInfo.path) {
  67. swan.navigateTo({
  68. url: this.data.longVideoInfo.path
  69. });
  70. } else {
  71. // 显示重播按钮
  72. this.setData({
  73. playIndex: this.data.nextIndex,
  74. isPlaying: false
  75. });
  76. this.attr.videoContext.stop();
  77. return;
  78. }
  79. }
  80. // 播下一条视频时页面不在顶部
  81. if (this.attr.scrollTop !== 0) {
  82. // 取消自动连播
  83. this.attr.videoContext.stop();
  84. this.setData({
  85. isPlaying: false
  86. });
  87. // 开启计时器
  88. this.onTimer();
  89. } else {
  90. // 不被打断则直接播放下一条视频
  91. this.setData({
  92. playIndex: this.data.nextIndex
  93. });
  94. }
  95. },
  96. /**
  97. * 监听播放进度变化
  98. * @param {*} e 事件对象
  99. */
  100. videoTimeUpdateHandler(e) {
  101. if (this.data.nextIndex === this.data.playIndex) {
  102. return;
  103. }
  104. const {
  105. duration,
  106. currentTime
  107. } = e.detail;
  108. // 剩余5s 时进行自动播放提示
  109. if (duration !== 0 && currentTime !== 0 && duration - currentTime <= 5) {
  110. this.setData({
  111. isMonitoring: true
  112. });
  113. }
  114. }
  115. })
 
 
 
  1. {{playVideoList[playIndex].title}}
  2. s-if="{{playVideoList[playIndex].time || playVideoList[playIndex].introduction}}"
  3. class="video-content-introduction-title-switch {{introSwitch ? 'off': '' }}"
  4. mode="scaleToFill"
  5. src="../../common/images/arrow.png" bindtap="introductionSwitch">
  6. {{playVideoList[playIndex].playNum}}次播放
  7. s-if="{{playVideoList[playIndex].authorImage}}" src="{{playVideoList[nextIndex].autorImage}}">
  8. {{playVideoList[playIndex].authorName}}
  9. s-if="{{introSwitch && (playVideoList[playIndex].time || playVideoList[playIndex].introduction)}}">
  10. 发布时间:{{playVideoList[playIndex].time}}
  11. s-if="{{playVideoList[playIndex].introduction}}">{{playVideoList[playIndex].introduction}}
 
 
 
  1. Page({
  2. ...
  3. /**
  4. * 展开、收起简介信息
  5. */
  6. introductionSwitch() {
  7. this.setData({
  8. introSwitch: !this.data.introSwitch
  9. });
  10. }
  11. })
  • 长视频信息区。当资源配置了落地页时,展示加入书架按钮和观看正片按钮,点击长视频封面和观看正片按钮可跳转至长视频落地页。当资源未配置落地页时(资源未上映),默认仅展示预约观看按钮。加入书架功能具体接入流程参考书架同步功能介绍,支持将资源同步至百度 App -书架;预约功能具体接入流程参考预约订阅组件(平台配置版)和预约订阅组件(API版)。

  • SWAN

 
 
 
  1. {{longVideoInfo.name}}
  2. {{longVideoInfo.info}}
  3. data-path="{{longVideoInfo.path}}">观看正片
  4. s-if="{{longVideoInfo.path || longVideoInfo.bookInfo}}">加入书架
  5. report-type="subscribe" template-id="BD2305" subscribe-id="1235" bindsubmit="formSubmit">
  • 活动运营位。开发者提供活动运营图片和跳转地址,支持跳转到当前小程序内的其他页面。例如:可配置新用户购买会员优惠活动。

  • SWAN

 
 
 
  • 百青藤广告区。具体接入流程参考 ad 广告组件。获取 ad 组件代码后可替换模板中的 ad 组件。

  • SWAN

 
 
 
  • 推荐短视频区。展示播放列表的短视频。默认最多展示 5 条短视频,超过数量的短视频将被折叠,点击查看更多每次可再展开 10 条短视频,包含视频的标题、播放次数、封面、时长等,点击后跳转到短视频落地页。

  • SWAN

  • JS
 
 
 
  1. {{item.title}}
  2. {{item.playNum}}次播放
  3. {{item.duration}}
  4. {{feedMore ? '查看更多': '没有更多了'}}
 
 
 
  1. Page({
  2. ...
  3. /**
  4. * 查看更多短视频
  5. */
  6. feedMoerHandler() {
  7. let {
  8. feedMore,
  9. feedShowList
  10. } = this.data;
  11. const start = feedShowList.length;
  12. let end = start + 10;
  13. // 结束位超出,展示剩余的视频
  14. if (end > this.attr.feedList.length) {
  15. end = start + this.attr.feedList.length - feedShowList.length;
  16. feedMore = false;
  17. }
  18. feedShowList.push(...this.attr.feedList.slice(start, end));
  19. this.setData({
  20. feedShowList: feedShowList,
  21. feedMore: feedMore
  22. });
  23. }
  24. })
  • 互动区。使用一站式互动组件。
  1. 使用点赞、评论功能时需要进行登入。
  2. 从其他页面跳转到本模板时,snid 文章 id 需要在加在跳转到本页面的路径上,跳转本页面的路径如:@smt-ui-template-page-video/pages/index/index?snid=10070000311753961
  • SWAN
  • JS
 
 
 
  1. class="video-comment"
  2. is-page-scroll="false"
  3. comment-param="{{commentParam}}"
  4. detail-path="{{detailPath}}"
  5. toolbar-config="{{toolbarConfig}}">
 
 
 
  1. Page({
  2. data: {
  3. ...
  4. // 评论参数
  5. commentParam: {},
  6. // 评论详情页面路径
  7. detailPath: '/@smt-ui-template-page-video/pages/comment-detail/index',
  8. },
  9. onLoad(options) {
  10. this.getPageData();
  11. // 获取文章 id,示例中 mock 数据,使用时请使用真实数据
  12. if (!options.snid) {
  13. options.snid = '10070000311753961';
  14. }
  15. this.attr.options = options;
  16. },
  17. onReady() {
  18. requireDynamicLib('myDynamicLib').listenEvent();
  19. },
  20. getPageData() {
  21. ...
  22. this.setData({
  23. ...
  24. commentParam: {
  25. // 文章的唯一标识
  26. snid: this.attr.options.snid,
  27. path: `/@smt-ui-template-page-video/pages/index/index?snid=${this.attr.options.snid}`,
  28. title: res.longVideoInfo.name
  29. }
  30. });
  31. }
  32. })

评论详情页

展示评论详情。

页面路径:pages/comment-detail

  • SWAN
  • JSON
  • JS
 
 
 
  1. comment-param="{{commentParam}}"
  2. srid="{{srid}}">
 
 
 
  1. {
  2. "navigationBarTitleText": "评论详情",
  3. "usingSwanComponents": {
  4. "comment-detail": "dynamicLib://myDynamicLib/comment-detail"
  5. }
  6. }
 
 
 
  1. import {
  2. login
  3. } from '../../utils';
  4. Page({
  5. data: {
  6. srid: '',
  7. commentParam: {}
  8. },
  9. onLoad(options) {
  10. if (options.srid) {
  11. this.setData({
  12. srid: options.srid
  13. });
  14. }
  15. const param = getApp().globalData.commentParam;
  16. if (param && Object.keys(param).length) {
  17. this.setData({
  18. 'commentParam': param
  19. });
  20. } else {
  21. this.setData({
  22. commentParam: {
  23. snid: '10070000311753961',
  24. path: '/pages/comment/index?snid=10070000311753961',
  25. title: '测试文章标题'
  26. }
  27. });
  28. }
  29. },
  30. });

字段说明

对模板使用到的字段进行说明,此部分的数据在使用模板时需从 server 获取。模板作为示例进行了 mock ,开发者可参考数据格式进行开发。

返回示例说明

字段名 类型 说明
code Number 接口信息。code 0:正常获取数据;99999:无网络;其他:服务异常
longVideoInfo Object 长视频信息,对应模板长视频信息区部分
playVideoList Array 连播列表,对应视频播放区、短视频标题及辅助信息区和短视频列表区部分
operateInfo Object 运营位信息,对应模板运营位部分
  • JSON
 
 
 
  1. {
  2. // 接口信息
  3. code: 0,
  4. // 长视频信息
  5. longVideoInfo: {
  6. // 长视频封面图
  7. poster: '../../common/images/poster1.png',
  8. // 长视频名称
  9. name: '延禧攻略',
  10. // 长视频详情页路径,已完结、更新中的资源必须填写
  11. path: '/longVideo',
  12. // 资源类型,如:电视剧
    网站名称:创新互联百度小程序教程:page-video短视频详情页模板
    链接分享:http://cdbrznjsb.com/article/dhphepd.html
  • 网站建设专属方案

  • 网站定制化设计

  • 7X24小时服务

  • N对管家服务

让你的专属顾问为你服务