微信小程序学习用demo:瀑布流及登录后页面刷新

来源:互联网 发布:网络唤醒电脑开机 编辑:程序博客网 时间:2024/05/16 14:26
1:实现了基本布局及瀑布流,上传下载功能未真机测试:2:登录后刷新跳转到新页面

 

代码示例:
[AppleScript] 纯文本查看 复制代码
?
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*my.js*/
"user strict";
 
var app =getApp();
 
Page({
  data:{
    //text:"这是一个页面"
    uinfo:{},
    source:'',
    images:[]
  },
  //上传图片
  bindUploadHeader:function(){
    var self =this;
    wx.chooseImage({
      count:1,//默认9
      sizeType:['original','compressed'],//可以指定是原图还是压缩图,默认二者都有
      sourceType:['album','camera'],//可以指定来源是相册还是相机,默认二者都有
      success:function(res){
        var tempFilePaths =res.tempFilePaths
 
        //及时预览
        self.setData({
          source:tempFilePaths[0]
        })
        wx.uploadFile({
          url:'http://www.kunyujie.com/myself/test/imageUpload?name=admin&passwd=admin',
          filePath:tempFilePaths[0],
          name:'file',
          header:{
              "Content-Type":"multipart/form-data"
          },
          success:function(suc){
            vardata= JSON.parse(suc.data);
            self.setData({
              source:'http://www.kunyujie.com/myself/'+data.path
            })
          },
          fail:function(err){
            console.log(err)
          },
          complete:function(all){
            //console.log(all)
          }
        })
      }
    })
  },
  //上传图片
  bindUploadHeader:function(){
    var self =this;
    wx.chooseImage({
      count:1,//默认9
      sizeType:['original','compressed'],//可以指定是原图还是压缩图,默认二者都有
      sourceType:['album','camera'],//可以指定来源是相册还是相机,默认二者都有
      success:function(res){
        var tempFilePaths =res.tempFilePaths;
        var param ={
              filePath:tempFilePaths[0],
              name:'file',
              formData:{}
            };
        app.api.imageUpload('test/imageUpload?name=admin&passwd=admin',param)
        .then(function(res){
          var res =JSON.parse(res);
          self.setData({
            source:app.uri+res.path
          })
        }).catch(function(err){
          console.error(err)
        })
 
        //end
      }
    })
  },
  //上传图片
  bindUploadHeader:function(){
    var self =this;
    wx.chooseImage({
      count:2,//默认9
      sizeType:['original','compressed'],//可以指定是原图还是压缩图,默认二者都有
      sourceType:['album','camera'],//可以指定来源是相册还是相机,默认二者都有
      success:function(res){
        //批量图片上传
        var imageArr =[],tempFilePaths =res.tempFilePaths;
        for(var i=0,len=tempFilePaths.length; i<len; i++){
          var param ={
              filePath:tempFilePaths[i],
              name:'file',
              formData:{
                name:'admin',
                passwd:'21232f297a57a5a743894a0e4a801fc3'
              }
            };
            //上传操作
            app.api.imageUpload('test/imageUpload',param)
            .then(function(res){
              var res =JSON.parse(res)
              imageArr.push(app.uri+res.path)
              self.setData({
                images:imageArr
              })
            }).catch(function(err){
              console.error(err)
            })
        }
 
        //end
      }
    })
  },
 
 
})
 
 
//getUserInfo();返回结果
//userInfo:{
//  avatarUrl:"http://wx.qlogo.cn/mmhead/Q3auHgzwzM7ejmgVyn1GmSv6EWv2TN0dwtwr5xNF3ZF6SmK7A6ZVeA/132"
//  city:"Haidian"
//  gender:1
//  nickName:"The Arrival"
//  province:"Beijing"
//}


项目地址及下载:

本帖隐藏的内容

https://github.com/hell007/waterfall
 waterfall-master.zip
0 0
原创粉丝点击