从 0 到精致|用微信小程序打造路虎品牌展示与试驾预约页

82 阅读3分钟

从 0 到精致|用微信小程序打造路虎品牌展示与试驾预约页

一、项目概述

本笔记记录了一个以“路虎汽车”为主题的微信小程序页面开发过程,核心功能包括:

  • 4S 店扫码进入展示页
  • 支持微信好友转发
  • 展示汽车品牌与车型信息
  • 在线预约试驾功能

该页面的主要实现思路是数据驱动页面结构,结合微信小程序的组件体系(swipernavigatorblock)与灵活的样式复用机制,实现高复用性和视觉一致性。


二、数据驱动的页面结构

在页面的 JS 文件中,通过定义 data 对象来驱动视图渲染。主要数据包括:

1. 幻灯片数据 slides

用于首页顶部的品牌轮播展示。

Page({
  data: {
    slides: [
      {
        id: 5,
        header: "全新一代发现",
        sub_header: "Discovery",
        description: "全尺寸七座 SUV,现已接受预定",
        image: "https://resources.ninghao.net/landrover/discover-1.jpg"
      },
      {
        id: 3,
        header: "全新揽胜星脉",
        sub_header: "Range Rover",
        description: "标新立异的前卫揽胜。",
        image: "https://resources.ninghao.net/landrover/velar-1.jpg"
      },
      {
        id: 6,
        header: "发现神行",
        sub_header: "Discovery",
        description: "发现的绝佳时刻。",
        image: "https://resources.ninghao.net/landrover/discovery-sport-1.jpg"
      }
    ]
  }
})

2. 车辆数据 vehicles

用于卡片式车辆展示,包含丰富的车辆详情与多层级嵌套字段:

vehicles: [
  {
    id: 1,
    header: "揽胜",
    sub_header: "Range Rover",
    description: "世界顶级奢华 SUV 的极致巅峰。",
    image: "https://resources.ninghao.net/landrover/range-rover-small.jpg",
    meta: {
      price: "RMB 1,588,000 起",
      carbon_dioxide: 262,
      fuel: 10.7,
      exterior_design: [ ... ],
      interior_design: [ ... ]
    }
  },
  ...
]

通过这种数据结构,页面内容完全由 JS 数据控制,后期扩展或动态渲染时只需更新数据即可。


三、WXML 页面结构

页面分为两个主要部分:

  1. 轮播图展示(swiper)
  2. 车辆列表卡片(cards)
<swiper class="section hero white" indicator-dots="{{true}}">
  <block wx:for="{{slides}}" wx:key="id">
    <swiper-item>
      <image src="{{item.image}}" mode="aspectFill"/>
      <view class="content center">
        <view class="sub-header">{{item.sub_header}}</view>
        <view class="header">{{item.header}}</view>
        <view class="description">{{item.description}}</view>
        <view class="action">
          <button class="button">预约试驾</button>
          <button class="button primary">了解更多</button>
        </view>
      </view>
    </swiper-item>
  </block>
</swiper>

<view class="cards">
  <view class="card" wx:for="{{vehicles}}" wx:key="id">
    <navigator hover-class="none" to="/pages/vehicles/show?id={{item.id}}">
      <image src="{{item.image}}" mode="aspectFill"/>
      <view class="content">
        <view class="header">
          {{item.header}}
          <view class="sub-header">{{item.sub_header}}</view>
        </view>
        <view class="descrpition">{{item.description}}</view>
        <view class="meta">{{item.meta.price}}</view>
      </view>
    </navigator>
  </view>
</view>

swiper 用于顶部主视觉图切换,navigator 用于跳转到车型详情页,实现了结构化、分区清晰的界面布局。


四、样式设计与复用

微信小程序支持全局样式与页面样式两种范围。

当多个页面中出现重复的样式规则时,应将样式抽取到 app.wxss 中进行全局复用。

1. 全局基础样式

page {
  background: #f8f8f8;
  line-height: 1.5;
  font-size: 32rpx;
}
image {
  display: block;
  width: 100%;
}

2. 组件化样式

通过将样式划分为细粒度的组合类,可以大幅提升可复用性:

.section {
  height: 100vh;
}
.hero.white {
  background: white;
}
.hero .content.center {
  text-align: center;
}
.hero .header {
  font-size: 72rpx;
  font-weight: bold;
  margin: 0 12% 16rpx;
}

3. 卡片样式

.cards {
  padding: 32rpx;
}
.card {
  background: #fff;
  margin-bottom: 32rpx;
}
.card image {
  height: 36vh;
}
.card .content {
  padding: 48rpx 48rpx 64rpx;
}
.card .header {
  font-size: 48rpx;
  font-weight: bold;
  position: relative;
}
.card .header::after {
  content: "";
  position: absolute;
  bottom: -20rpx;
  width: 80rpx;
  border-bottom: 4rpx solid #000;
}

这种模块化写法,保证了样式在不同页面间的高复用性,也方便主题替换与版本升级。


五、开发要点总结

  1. 数据驱动视图:通过 data 定义所有展示内容,使得页面逻辑清晰、易扩展。
  2. 组件化布局swiper + card 模式结构明确,方便维护。
  3. 样式复用策略:将通用样式提取为全局,减少重复代码。
  4. 响应式适配:使用 rpx 进行多设备尺寸自适应。
  5. 交互提升:通过 navigator 实现自然的页面跳转体验。

六、结语

本次小程序开发展示了如何通过数据驱动 + 模块化样式快速构建一个可复用、可扩展的品牌展示型页面。
这种思路不仅适用于汽车品牌展示,也能迁移到房地产、时尚、家电等其他行业的小程序开发中。