首页 > 小程序教程 > 微信小程序商品逛一逛页面样式模板制作设计下载

微信小程序商品逛一逛页面样式模板制作设计下载

上一篇 下一篇
制作好以后效果图如下:
一、wxml页面代码如下:
<view class="container">
    <view class="article-list">
      <block wx:for="{{queue}}" wx:key="cid">
        <!-- 设置一个不存在的 hover-class 否则在点击的一瞬间下面的卡片会显示出来 -->
        <navigator url="../article/article?id={{item.cid}}" hover-class="null">
          <!-- 不用反转数组了,根据索引倒序指定z-index即可保证gotogos数组中的第一个在最上面,最后一个在最下面 -->
          <!-- item.cid == currentCid ? animationData : null 更新之后报错了!故最后的null改为'' -->
          <view
            class="article-box"
            style="z-index:{{queue.length - index}};"
            animation="{{index === 0 ? animationData : ''}}">
            <image src="{{item.cover_image_url}}"></image>
            <view class="article-info">
              <text class="article-title">{{item.title}}</text>
              <text class="price">{{item.price}}</text>
            </view>
          </view>
        </navigator>
      </block>
    </view>
  <view class="operate-area">
    <view bindtap="dislike"><image src="icon/dislike.png"></image></view>
    <view bindtap="like"><image  class="dislike" src="icon/like.png"></image></view>
  </view>
  <text class="view-all" bindtap="viewAll" >查看全部喜欢 ></text>
</view>
 
二、wxss样式文件代码如下:
.container{
  background-color: #f8f8f8;
}

.article-list {
  width: 700rpx;
  height: 586rpx;
  margin: 0 auto;
  margin-top: 140rpx;
  overflow: hidden;
  position: relative;
  /*border: 1px rgb(199,199,205) solid;*/
  line-height: 1;
  box-sizing: border-box;
  border-radius: 4rpx;
  box-shadow:0px 5px 5px 0px rgba(0,0,0,0.05), 0px -2px 5px 0px rgba(0,0,0,0.05);
}

.article-box {
  background-color: #fff;
  position: absolute;
  overflow: hidden;
  padding: 26rpx;
  /*box-shadow:0px 5px 5px 0px rgba(0,0,0,0.05), 0px -2px 5px 0px rgba(0,0,0,0.05);*/
}

.article-box image{
    width: 648rpx;
    height: 422rpx;
}

.article-info {
  /*box-sizing: border-box;
 min-height: 92rpx;*/
 box-sizing: border-box;
 /*background-color: #fff;*/
 /*border-top: 1px rgb(199,199,205) solid;*/
 font-size: 28rpx;
 color: #333;
 padding: 32rpx 0;
 max-width: 648rpx;
}
.article-title {
  box-sizing: border-box;
  /*padding: 0 24rpx;*/
  display: block;
  overflow: hidden; /*自动隐藏文字*/
  text-overflow: ellipsis;/*文字隐藏后添加省略号*/
  white-space: nowrap;/*强制不换行*/
}
.price {
  display: block;
  color:#e60012;
  margin-top: 16rpx;
  /*padding-left: 24rpx;*/
}
.operate-area {
  margin:0 auto;
  margin-top: 124rpx;
  text-align: center;
}
.operate-area view{
  display: inline-block;
}
.operate-area image{
  margin-right: 132rpx;
  width: 140rpx;
  height: 140rpx;
  border-radius: 50%;
  border: 1px rgb(199,199,205) solid;
}
.operate-area .dislike{
  margin-right: 0;
}
/* 卡片3D叠加效果 */

.article-list{
  -webkit-perspective: 800rpx;
          perspective: 800rpx;
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
}
.view-all{
  position: fixed;
  top: 25rpx;
  right: 25rpx;
  color:#999;
  font-size: 26rpx;
}
三、js页面代码如下:
import common from '../../common/app'
import { uniquePush, getLikesFromStorage, setLikesToStorage, removeLikesFromStorate, fetch, getShortCid, extend, throttle, isEmptyObject } from '../../utils/utils'
import API from '../../common/API'
/**
 * [page description]
 * @type {Object}
 *  逛一逛整体逻辑
 *   0. 创建一个队列,放置要进行动画的数据
 *   1. 从服务端拿到的数据放置到全局
 *     1.1 从本地取出历史上的“喜欢”数据
 *     1.2 从服务端拿到的数据若已经存在于上面的“喜欢”数据中,则过滤掉
 *   2. 从已经经过过滤操作的全局数据中拿2条数据
 *   3. 点击“喜欢” or “不喜欢”(若点击“喜欢”则放置到本地中的“喜欢列表中”)
 *     3.1 第一条数据卡片飞走
 *     3.2 飞走之后,偷偷地原路飞回,并把其zindex从1置为0
 *     3.3 飞回的卡片进行数据填充
 */

// 这个数字需要找到一个平衡点
// 如果太大的话,切换时会变卡,但是图片是提前加载出来的
// 如果太小的话,切换时不卡,但是图片可能正在下载...
const queueLength = 5
// 动画运动时间
const duration = 320
// 处理后的数据池指针。每次pointer都指向当前数据。
let pointer = queueLength - 1
let restLength = queueLength
// // 全局变量 --end
const page = {

  onLoad(){
    console.log('gotogo onload...');
    this.load()
  }

  ,viewAll(){
    const likes = wx.getStorageSync('likes')
    if(!likes || likes.length === 0){
      return wx.showModal({
        content: '暂时还没有喜欢的东西哦~',
        showCancel: false
      })
    }
    wx.navigateTo({url:`../all/all?key=likes`})
  }

  ,render(queue){
    console.log('render...');
    this.setData({ queue })
  }

  /**
   * [flag 是否需要处理返回参数]
   * @type {[Boolean]} 是否需要处理返回的参数
   */
  ,getReadInterval(flag = false){
    // debugger
    let read_interval = wx.getStorageSync('read_interval')
    const [start, end]  = read_interval
    const default_read_interval = [0, 0]
    if(!read_interval || isEmptyObject(read_interval) ){
      return default_read_interval
    }
    if(flag && (start === 0 || end === 0)){
      return default_read_interval
    }
    return read_interval.sort()
  }

  ,setReadInterval(read_interval = [0, 0]){
    // const [start, end] = read_interval
    wx.setStorage({ key: 'read_interval', data: read_interval.sort() })
  }

  ,createQueue(gotogos){
    this.setData({ gotogos })
    const queue = gotogos.slice(0, queueLength)
    console.log('createQueue...');
    console.log(queue)
    return queue
  }

  // ,filter(gotogos){
  //   console.log('filter...');
  //   const likes = getLikesFromStorage()
  //   // TODO
  //   return gotogos
  // }

  ,getDataFromServer(){
    console.log('getDataFromServer...');
    wx.showToast( { title: '玩命加载中',icon: 'loading', duration: 10000 } )
    const [start, end] = this.getReadInterval(true)
    const url = `${API.giftBrowser.url}/read_interval[0]=${start}&read_interval[1]=${end}`
    this.setData({loading: true})
    return fetch( url ).then(result => {
      const { errMsg, statusCode, data } = result
      const { meta_infos } = data
      // console.log(data);
      console.log(`${url}接口返回的数据:`, result);
      if(!meta_infos || meta_infos.length === 0){
        return wx.showToast({ title: '暂无数据~'})
      }
      const gotogos = meta_infos.map(meta_info => {
        meta_info.cid = getShortCid(meta_info.cid)
        return meta_info
      })
      this.setData({loading: false})
      wx.hideToast()
      return gotogos
    }).catch(result => {
      console.log(`${url}接口错误:`, result);
      this.setData({loading: false})
      wx.hideToast()
    })
  }

  ,animate(ani={rotate:-30, translateX:-400}){
    // const cids = this.data.cids
    // 如果到最后,提示用户并返回
    // if(pointer === cids.length - 1){
    //   wx.showToast({title: '已经到最后啦亲~', duration: 1000})
    //   return;
    // }
    const {rotate, translateX} = ani
    this.setData({
      loading: true,
      // currentCid,
      // 取消 scale 和 opaticy 增加动画流畅性
      animationData: wx.createAnimation({
                        timingFunction:'ease',
                        duration: duration
                    })
                      // .scale(1.5, 1.5)
                      .rotate(rotate)
                      // .translate3d(translateX,0,0)
                      .translateX(translateX)
                      // .opacity(0)
                      .step().export()
    })
    const {queue, gotogos} = this.data
    const ret = queue.shift()
    const gotogo = gotogos[++pointer]
    queue.push(gotogo)
    setTimeout(() => {
      this.setData({ queue, loading: false })
    }, duration)
    return ret
  }

  ,load(){
    // 为了防止页面缓存,每次刷新页面之后都会重置currentIndex
    pointer = queueLength - 1
    // this.renderByDataFromServer()
    // 拿到原始数据,然后过滤,然后生成队列,然后渲染
    this.getDataFromServer()
        // .then(this.filter)
        .then(this.createQueue)
        .then(this.render).catch(e => console.log(e))
  }

  ,shouldLoad(){
    console.log(this.data.gotogos.length);
    console.log(pointer);
    return this.data.gotogos.length - pointer <= restLength
  }

  /**
   * 喜欢和不喜欢需要做一下函数节流。
   * 防止用户点击过快
   */
  ,dislike(){

    const loading = this.data.loading
    if(loading){
      return console.log('dislike loading是true啦....');
    }

    if( this.shouldLoad() ){
      this.load()
    }

    const gotogo = this.animate()
    const [, end] = this.getReadInterval()
    this.setReadInterval([gotogo.gift_id, end])
  }

  ,like(){
    const loading = this.data.loading
    if(loading){
        return console.log('like loading是true啦....');
    }

    if( this.shouldLoad() ){
      this.load()
    }

    const {cid, title, thumb_image_url, price, gift_id} = this.animate({rotate:30,translateX:400})
    // 精简要存入本地的对象。只存需要的字段。
    const gotogo = {aid: cid, title, thumb_image_url, price, gift_id}
    let likes = wx.getStorageSync('likes')
    if( !likes ) {
      likes = [ gotogo ]
    } else {
      uniquePush( likes, gotogo, 'aid' )
    }
    wx.setStorage({ key: 'likes', data: likes })
    const [, end] = this.getReadInterval()
    this.setReadInterval([gotogo.gift_id, end])
  }
  ,onShareAppMessage: function () {
    return {
      title: '礼物挑选神器',
      desc: '寻找你的心动好礼'
    }
  }
}

// assign会进行递归拷贝
Object.assign(page, common)
Page(page)

模板简介:该模板名称为【微信小程序商品逛一逛页面样式模板制作设计下载】,大小是,文档格式为.,推荐使用打开,作品中的图片,文字等数据均可修改,图片请在作品中选中图片替换即可,文字修改直接点击文字修改即可,您也可以新增或修改作品中的内容,该模板来自用户分享,如有侵权行为请联系网站客服处理。欢迎来懒人模板【小程序教程】栏目查找您需要的精美模板。

相关搜索
  • 下载密码 lanrenmb
  • 下载次数 18,713次
  • 使用软件
  • 文件格式
  • 文件大小
  • 上传时间 06-07
  • 作者 网友投稿
  • 肖像权 人物画像及字体仅供参考
栏目分类 更多 >
热门推荐 更多 >
自适应 响应式 微信公众平台 企业网站 单页式简历模板 微信图片 微信文章 html5 微信素材 微信模板
您可能会喜欢的其他模板