codecamp

百度智能小程序 图文详情页模板

page-content-detail 图文详情页模板

解释:图文详情页模板。你可以加载含有图片、文本、引用、标题等形式的内容。同时,图文详情页模板内置了回到顶端按钮与关注/取消关注按钮,支持点击作者跳转与图片查看器。图文详情页通常用来展示文章、帖子等内容的详情。

示例


使用方式

方式一 【 NPM 】

  1. 在小程序根目录执行下方命令,下载页面模板的 npm 包:
    npm i @smt-ui-template/page-content-detail
    
  2. 将 /node_modules/@smt-ui-template/@smt-ui-template-content-detail 下的 @smt-ui-template-content-detail 文件夹拷贝到当前小程序合适的目录下 (如 pages ):
    .
    ├── project.swan.json                   
    ├── app.json                            
    ├── app.js                              
    ├── pages
        └── @smt-ui-template-content-detail    // 模板文件
    
  3. 在小程序根目录的 app.json 中配置模板页面的 path 路径,查看效果,如:
    {
        "pages": [
            ...
            "pages/@smt-ui-template-content-detail/index/index",
            ...
        ]
    }
    
  4. 为了方便在开发者工具中查看模板页的效果,可以设置模板页为小程序预览的首页。该功能的说明请参考自定义编译文档

方式二 【 开发者工具-页面模板 】

  1. 打开开发者工具,点击 ”页面模板“,在下方找到 ”图文详情页模板“,选中该模板后点击右下角 ”立即使用”,填写相关信息点击右下角 ”完成“ 按钮。
  2. 使用开发者工具的编辑器或者选择自己熟悉的编辑器对模板进行二次开发。

    代码示例

    <view class="wrap">
        <view s-if="!showPageStatus" class="content-header" ></view>
        <scroll-view scroll-y scroll-top="{=scrollTop=}" s-if="!showPageStatus" class="content-container {{isPhoneX ? 'content-container-ipx' : ''}}" bindscroll="onPageScroll" bindtouchmove="scrollPage" bindtouchstart="touchstart">
            <view class="content-title">
                <text selectable>{{title}}</text>
            </view>
            <view class="content-desp">
                <view class="author-detail" bindtap="tapuser" data-user-id="{{authorId}}">
                    <image class="author-avator" mode="widthFix" src="{{avator}}"></image>
                    <view class="author-other">
                        <view class="author-name">{{author}}</view>
                        <view class="publish-date">{{date}}</view>
                    </view>
                </view>
                <button s-if="showFollowBtn" class="follow-btn" size="mini" type="{{isFollow ? 'default' : 'primary'}}" bindtap="tapfollow" loading="{{btnLoading}}">{{btnLoading ? '' : (isFollow ? '已关注' : '关注')}}</button>
            </view>
            <view class="content-detail">
                <view s-for="item in content" class="detail-{{item.type}}">
                    <quote s-if="item.type == 'quote'" content="{{item.content}}"></quote>
                    <text selectable s-if="item.type == 'p' || item.type == 'title'">{{item.content}}</text>
                    <image lazy-load s-if="item.type == 'img'" mode="widthFix" src="{{item.content}}"  data-src="{{item.content}}" bindtap="tapimg" bindlongpress="longtapimg"></image>
                </view>
            </view>
            <top class="top-view {{showTopBtn ? 'top-view-show' : 'top-view-hide'}}" bind:top="backToTop"></top>
        </scroll-view>
    </view>
    

    设计指南

    为保证信息流分发时落地页浏览体验的一致性,建议正文字号使用默认字号 57px,如需自定义正文字号,可在正负 3px 空间内浮动。

  3. 获取数据:获取文章详情、页面跳转、关注/取消关注。
    • 获取内容详情所需要的数据,请修改为相关的请求地址参数
              getArticleDetail(articleId, cb) {
              let params = {
                  url: '',
                  method: 'GET',
                  data: {
                      articleId
                  },
             ...     
      
    • 点击用户事件处理,通常是跳转到用户详情页
              swan.navigateTo({
                  url: `/user-detail/user-detail?userId=${userId}`
              });
      
    • 发送 关注/取消关注 请求,请修改为相关的请求地址参数
              tapfollow(e) {
                  ...
                  let params = {
                      url: '',
                      method: 'POST',
                      data: {
                          authorId: this.data.authorId
                      },
                  ...
              }
      

Bug & Tip

  • Tip:模板中使用的是测试数据,你需要从接口中获取真实的数据。
  • Tip:模板中内置了部分数据记录,你可以定义自己需要记录的数据。
  • Tip: 页面模板功能从开发者工具 v2.25.1-rc 版本开始支持


百度智能小程序 信息流模板
百度智能小程序 登录中间页模板
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

百度智能小程序开发文档

百度智能小程序 组件

百度智能小程序 地图

百度智能小程序 画布

百度智能小程序 API

百度智能小程序 界面

百度智能小程序 关注小程序引导组件

百度智能小程序 自定义组件

百度智能小程序 媒体

百度智能小程序 设备

百度智能小程序 拨打电话

百度智能小程序 内存警报

百度智能小程序 手机联系人

百度智能小程序 用户截屏事件

百度智能小程序 第三方平台

百度智能小程序 开放接口

百度智能小程序 百度收银支付

百度智能小程序 分包预下载

百度智能小程序 数据分析

百度智能小程序 服务端

百度智能小程序 云开发

百度智能小程序 初始化

百度智能小程序 云函数

百度智能小程序 服务端初始化

百度智能小程序 服务器获取上下文

百度智能小程序 服务端云函数

百度智能小程序 开发教程

百度智能小程序 功能开发

百度智能小程序 基本原理

百度智能小程序 小程序自动化

百度智能小程序 视频教程

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }