1. 程式人生 > >微信小程式-仿今日頭條客戶端

微信小程式-仿今日頭條客戶端

歡迎訪問我的微信小程式:

(本小程式是模仿新聞類的app做的一個小程式)

在此特別感謝: 有夢想的程式丶猿 提供的免費開放介面API

這裡寫圖片描述

本次發版主要實現功能如下:(2018年7月5日釋出)

效果圖如下

1.實現底部的2個tab顯示:(首頁,我的頁面)

在app.json內配置如下程式碼,即可實現底部的tab"tabBar": {
    "color": "#ccc",
    "selectedColor": "#00FF00",
    "borderStyle": "white",
    "backgroundColor"
: "#f9f9f9", "list": [ { "text": "首頁", "pagePath": "pages/main/main", "iconPath": "pic/icon_component.png", "selectedIconPath": "pic/icon_component_HL.png" }, { "text": "我的", "pagePath": "pages/my/my", "iconPath": "pic/wechat.png"
, "selectedIconPath": "pic/wechatHL.png" } ] },

2.實現頂部的4個頁籤的顯示以及滑動;

<view class="swiper-tab">
<view class="tab-item {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">推薦</view>
  <view class="tab-item {{currentTab==1 ? 'on' : ''}}" data-current
="1" bindtap="swichNav">
純文字</view> <view class="tab-item
{{currentTab==2 ? 'on' : ''}}" data-current="2" bindtap="swichNav">圖片</view> <view class="tab-item {{currentTab==3 ? 'on' : ''}}" data-current="3" bindtap="swichNav">視訊</view> </view> <swiper current="{{currentTab}}" class="swiper" duration="300" style="height:{{winHeight}}px" bindchange="bindChange"> <swiper-item> <scroll-view scroll-y="{{true}}" style="height:{{winHeight}}px" class="list" bindscrolltolower="bindDownLoad" bindscroll="scroll" bindscrolltoupper="refresh"> <view class='listview' wx:for="{{resultdata}}" wx:for-item="item" wx:key="*this"> <view bindtap="bindViewTap" data-item='{{item}}'> <template is="{{item.type == '29' ? 'joy-text' : (item.type == '10' ? 'joy-pic' : (item.type == '41' ? 'joy-video' : 'joy-pic'))}}" data="{{...item}}"></template> </view> </view> </scroll-view> </swiper-item> ···省略swiper-item 3個內容··· </swiper>

3.實現內容頁列表的上拉重新整理和下拉載入更多功能;

上面2中的下面程式碼,實現了上拉載入和下拉重新整理功能
bindscrolltolower="bindDownLoad"  bindscrolltoupper="refresh"

4.實現模板化展示資料;

上面2中的下面程式碼,實現模板功能
<import src="../../utils/template.wxml" />
<template  is="{{item.type == '29' ? 'joy-text' :
 (item.type == '10' ? 'joy-pic' :
  (item.type == '41' ? 'joy-video' : 'joy-pic'))}}" data="{{...item}}"></template>

5.實現資料的本地收藏和取消收藏功能;

···
wx.setStorage({
key: “collects”, //以使用者id和使用者建立該資料的時間作為唯一的key
data: JSON.stringify(itemArr),
success: function() {}
})
//收藏和取消收藏使用了一個key,收藏時將陣列新增一個元素;取消收藏時將陣列減去該元素;
···

6.實現頁面的跳轉功能,轉發功能;

//實現跳轉頁面功能
 bindViewTap: function(event) {
    var item = event.currentTarget.dataset.item;
    wx.navigateTo({
      url: '../detail/detail?jsonStr=' + JSON.stringify(event.currentTarget.dataset.item),
      success: function(res) {
        // success
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
 /**
   * js檔案中新增下面程式碼,使用者即可以點選右上角分享
   */
  onShareAppMessage: function() {
    wx.showToast({
      title: '你好',
      icon: '',
      image: '',
      duration: 0,
      mask: true,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  }

7.實現本地收藏資料的列表顯示功能; 等

//js中獲取所有收藏的資料,並通過頁面展示出來,此處是獲取本地收藏資料
  requesLocalData:function(){
    var list = [];
    try {
      var value = wx.getStorageSync('collects');
      if (value) {
        // Do something with return value
        var itemArr = JSON.parse(value);
        if (itemArr) {
          list = itemArr;
        }
      }
    } catch (e) {
      // Do something when catch error
      wx.showToast({
        title: '獲取快取資料出錯',
        icon: 'fail'
      })
    }
    this.setData({
      collects: list,
    })
  }

這裡寫圖片描述

規劃:第二版v0.0.388主要實現功能如下(預計2018年7月13日釋出)

1.新增我的頁面:將之前我的頁面名稱改為收藏頁面;新我的頁面包含功能如下:

a.顯示我的微信頭像;
b.顯示本地快取記憶體大小;
c.顯示我的收藏節點;
d.清除本地記憶體功能;

2.小程式的列表,詳情中人物頭像改為圓形;

3.在列表中加入收藏按鈕,方便列表中進行操作; 等