找回密码
 立即注册

扫一扫,访问微社区

查看: 5268|回复: 1

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

[复制链接]

910

主题

1190

回帖

3万

金钱

管理员

论坛管理员

积分
0

突出贡献优秀版主荣誉管理论坛元老

QQ
发表于 2017-1-7 16:15:58 | 显示全部楼层 |阅读模式
1:实现了基本布局及瀑布流,上传下载功能未真机测试:2:登录后刷新跳转到新页面



代码示例:[mw_shl_code=html,true]/*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){
            var data = 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,
              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"
// }[/mw_shl_code]


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

0

主题

222

回帖

509

金钱

新人求带

积分
0
发表于 2020-4-25 14:25:46 | 显示全部楼层
我有流量,寻求个人游戏开发者合作,有意者联系微信号jim20180688
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|微信小程序开发|教程|文档|资源汇总_即速论坛 ( 粤ICP备14097199号-1  

GMT+8, 2024-5-4 07:12 , Processed in 0.120630 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表