
項目為仿今日頭條,使用了百度ApiStore接口查詢數據,使用微信組件/api有 封裝請求方法,底部tab,啟動頁動畫,loading,scroll-view,swiper,列表頁支持上下拉加載更多
效果圖:

啟動歡迎頁,幾行代碼可實現旋轉與縮放:
復制代碼
- //flash.js
- onReady:function(){
- // 頁面渲染完成
- var that = this,duration = 1500;
- var animation = wx.createAnimation({
- duration: duration,
- });
- //step() 方法表示一組動畫的結束
- animation.scale(2).rotate(360).step();
- animation.scale(1).step();
- this.setData({
- animationData : animation.export()
- });
- var timestamp = new Date().getTime();
- setTimeout(function(){
- wx.redirectTo({
- url: '../index/index?time='+timestamp
- })
- },duration*2.5);
- },
復制代碼
- //flash.wxml
- <image class="flash-img" animation="{{animationData}}" src="{{src}}" ></image>
網絡請求方法:
復制代碼
- //app.js
- req: function(url,data,param){
- var requestData = {
- url: url,
- data: typeof data == 'object' ? data : {},
- method: typeof param.method == 'string' && param.method.length > 0 ? param.method.toUpperCase() : 'GET',
- header: typeof param.header == 'object' ? param.header : {},
- success: function(res) {
- typeof param.success == 'function' && param.success(res);
- },
- fail: function(res){
- typeof param.fail == 'function' && param.fail(res);
- },
- complete: function(res){
- typeof param.complete == 'function' && param.complete(res);
- }
- };
- wx.request(requestData);
- },
列表頁:
- //index.js
- var app = getApp(),currentPage = 1;
- const URL = "http://apis.baidu.com/showapi_open_bus/channel_news/search_news";
- Page({
- data:{
- imgUrls: [
- 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
- 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
- 'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
- ],
- toView: "",
- loadingHidden:true,
- renderData:[],
- },
- onLoad:function(options){
- this.loadDataFromServer();
- },
- //api讀取數據
- loadDataFromServer: function(){
- var that = this;
- that.changeLoadingStatus(false);
- app.req(URL,{
- page : currentPage,
- needContent : 1,
- },{
- header: { apikey: app.globalData.apikey },
- success:function(resp){
- console.log(resp);
- console.log("成功加載頁數 "+currentPage);
- var tempData = resp.data.showapi_res_body.pagebean.contentlist;
- var toViewId = currentPage % 2 == 0 ? "top-id" : "top-id2"; //需要改變值頁面才會重新渲染
- that.setData({
- //renderData: that.data.renderData.concat(tempData), 合并數組容易超出長度,無法做到無限加載
- renderData: tempData,
- toView: toViewId,
- });
- that.changeLoadingStatus(true);
- }
- });
- },
- //加載上一頁或者下拉刷新
- refresh:function(e){
- currentPage = currentPage > 1 ? --currentPage : 1;
- this.loadDataFromServer();
- },
- //加載下一頁
- loadMore:function(e){
- ++currentPage;
- this.loadDataFromServer();
- },
- //改變loading狀態
- changeLoadingStatus: function(bool){
- this.setData({
- loadingHidden: bool
- });
- },
- onReady:function(){
- // 頁面渲染完成
- wx.setNavigationBarTitle({
- title: '列表'
- });