小程序“账本小记”的意见反馈实现批量上传附件

效果图如下,上传之后提交实现批量上传

对应的源码分享

fedback.wxml文件:

<!--pages/my/feedback/feedback.wxml-->

<view class='view-page'>

  <navbar page-name="意见反馈"  showMy="{{true}}" showHome="{{false}}" showNav="{{false}}" showReport="{{false}}"></navbar>

  <view class='page-content' style='height:calc(100vh - {{navH}}px)'>

    <view class="container">

       <!--判断微信版本是否可用-->

      <view wx:if="canIUse">

        <view wx:if="{{isAuth}}">

          <view class="greyarea"></view>

          <view class="inputarea">

          <textarea class="fbinput" name="fbinfo" placeholder="请输入遇到的问题或建议..." auto-focus="true" value="{{fbcontent}}" bindinput="fbinput" maxlength="200" auto-height="true" bindlinechange="fblineaction"></textarea>

          <ivew class="wordcss"><view style="float: left;font-size:30rpx;padding-left:30rpx;">上传图片(选填)</view><view style="float:right;font-size:25rpx;padding-right:30rpx;">{{curword}}/200</view></ivew>

          </view>

          <view class="picture">

            <view class="upLoad">

              <view class="uplaodImgItem" wx:for="{{pic}}" wx:key="index">

                <image src="{{item}}"></image>

                <view class="deleteImg" bindtap="bindDeleteImg" data-index="{{index}}"><text class="iconfont icon-shanchu"></text></view>

              </view>

              <view class="uploadImg" bindtap="bindUpload"><text class="iconfont icon-shurukuang-shangchuantupian"></text></view>

            </view>

          </view>




 

          <button type="primary" lang="zh_CN" bind:tap="submitfb" style="margin:1rpx 30rpx;width:auto;background-color:#31D4FF;"><view style="height:35rpx;line-height:35rpx;font-size:30rpx;justify-content: center;" ><text>提交</text></view></button>

        

        </view>

        <view wx:else>未授权登录</view>

      </view>

      <view wx:else>请先升级微信</view>

    

    </view>

  

  </view>

</view>


 

wxss文件:

/* pages/my/feedback/feedback.wxss */

@import "../../../utils/iconfont.wxss";

.page-content{

  top:auto;

  position: relative;

}

.inputarea{

}

.fbinput{

  margin:30rpx;

  width: auto;

  min-height: 200rpx;

  justify-content: center;

  font-size: 30rpx;

  border: 1rpx solid rgb(235, 235, 235);

  background-color: rgb(245, 245, 245);

}

.wordcss{

  margin-right:30rpx;

}

.picture{

  background: #ffffff;

  margin-top:16rpx;

  margin-bottom:16rpx;

  padding:30rpx;

}

.upLoad{

  display: flex;

  align-items: center;

  flex-wrap: wrap;

}

.uplaodImgItem{

  width:160rpx;

  height:160rpx;

  margin-right:16rpx;

  position: relative;

}

.uplaodImgItem image{

  width:100%;

  height: 100%;

}

.deleteImg {

  position: absolute;

  width: 32rpx;

  height: 32rpx;

  background: rgba(0, 0, 0, 0.65);

  border-radius: 0px 4rpx 0px 200rpx;

  top: 0;

  right: 0;

  text-align: right;

  line-height: 24rpx;

}

.icon-shanchu {

  color: #ffffff;

  font-size: 26rpx;

}

.uploadImg{

  width:160rpx;

  height:160rpx;

  line-height: 160rpx;

  text-align: center;

  background: #dddde2;

  border-radius: 4rpx;

}

.icon-shurukuang-shangchuantupian{

  color:#859db6;

  font-size:50rpx;

}




 

.greyarea{

  height: 20rpx;

  width:100%;

  background-color: rgb(248,248,248);

}

.btarea{

  position:fixed;

  padding-left: 3%;

  padding-right: 3%;

  bottom: 1rpx;

  width:94%;

}

重点是处理逻辑js文件:

// pages/my/myledger/myledger.js

const app = getApp();

var util=require("../../../utils/util.js");

Page({

  /**

   * 组件的初始数据

   */

  data: {

    isAuth:null,//显示未授权

    navH:"",

    fbword:"",

    curword:0,

    pic:[],

    index:0,

    imgUrl:[],

    item:"",

  },

  //事件函数

  fbinput:function(e){

    var that=this;

    var value=e.detail.value;

    var wordlength=parseInt(value.length);

    if(wordlength>200){

      return;

    }

    that.setData({

      fbword:value,

      curword:wordlength

    });

  },

  fblineaction:function(options){

    let lineCount=options.detail.lineCount;

    let height=options.detail.height;

    let heightRpx=options.detail.heightRpx;

  },

  

  //删除图片

  bindDeleteImg:function(e){

    var imgIndex=e.currentTarget.dataset.index;

    var that=this;

    that.data.pic.map(function(item,index){

      if(imgIndex==index){

        that.data.pic.splice(index,1);

        that.setData({

          pic:that.data.pic

        })

      }

    })

    that.data.imgUrl.map(function(item,index){

      if(imgIndex==index){

        that.data.imgUrl.splice(index,1);

        that.setData({

          imgUrl:that.data.imgUrl

        })

      }

    })

  },

  //上传图片

  bindUpload:function(e){

    var that=this;

    var picLength=this.data.pic.length;

    var count=5-picLength;

    if(count !=0){

      wx.chooseImage({

        count:count,

        success:function(res){

          wx.showLoading({

            title: '上传中...',

          })

          const tempFilePaths=res.tempFilePaths;

          console.log("tempFilePaths的值",tempFilePaths)

          var i =0; //第几张图片的index

          var successImgCount=0; //成功图片数量

          var failImgCount=0; //失败图片数量

          var imgLength=res.tempFilePaths.length; //上传图片长度

          tempFilePaths.map(function(item,index){

            that.data.pic.push(tempFilePaths[index]);

          })

          console.log("that.data.pic====",that.data.pic)

          that.setData({

            pic:that.data.pic

          });

          wx.hideLoading();

          //util.uploadImg(that,tempFilePaths,successImgCount,failImgCount,imgLength,i);

          console.log("i的值",i)

        },

        fail:function(res){

          console.log(res);

        }

      })

    }else{

      wx.showToast({

        title: '最多上传5张',

        icon:"none"

      })

    }

  },

  //提交

  submitfb:function(){

    var fbword=this.data.fbword;

    var piclist=this.data.pic;

    console.log("fbword====",getApp().globalData.urlpath+"/feedback")

    console.log("piclist====",piclist)

    let file=[]

    for(let i=0;i<piclist.length;i++){

      const fileSystemManager=wx.getFileSystemManager()

      const data=fileSystemManager.readFileSync(piclist[i],'base64')

      file.push('【data:image/jpeg;base64,'+data+"】")

    }

    console.log("file==",file)

    wx.login({

      success:function(res){

        console.log("res.code===",res.code)

        //请求接口

        wx.request({

          url:getApp().globalData.urlpath+"/feedback",

          data:{"code":res.code,"picfile":file,"word":fbword},

          method:"POST",

          header:{'content-type':'application/x-www-form-urlencoded' },

          success:function(res){

            console.log("11111")

          },

          fail:function(res){

            console.log("22222")

          },

          complete:function(res){

            console.log("3333")

          }

        })

      }

    })

  },

  onLoad: function (options) {

    var that=this;

    that.setData({

      navH:app.globalData.navHeight

    })

    var authcache=wx.getStorageSync('authcache')

    var name=wx.getStorageSync('namecache')

    if(name){

      that.setData({

        isAuth:authcache

      })

    }



 

  },







 

  

})

更多源码关注公众号 py编码

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
基于微信小程序的记账账本app设计与实现,主要包括以下几个方面。 首先,设计用户界面。该小程序应具备用户登录、注册、修改密码等基本功能,用户可以通过微信账号登录。另外,还应设计主页面,用于显示用户的账单列表和账单的分类统计信息。账单列表应以时间倒序排列,同时显示每条账单的金额、分类等信息。分类统计信息应以柱状图或饼图等形式展示,方便用户直观地了解自己的收入和支出情况。 其次,实现账单的添加和编辑功能。用户可以通过点击页面上的“添加账单”按钮进入账单录入页面,填写相关信息(日期、金额、分类等),并保存到数据库中。账单的编辑功能也应提供,允许用户修改已有的账单信息。 再次,实现账单的删除和查询功能。用户可以通过长按账单记录或选择账单后,展示删除按钮,点击后可删除对应的账单。此外,用户还可以通过日期、分类等条件进行账单查询,系统会根据用户选择的条件,展示相关的账单记录。 最后,实现数据的同步与备份功能。为保证用户的数据安全,可以将用户的账单数据自动备份到云端存储中,并保证数据的同步。这样,用户可以在不同的设备上使用该小程序,并随时查看和编辑自己的账单记录。 总之,基于微信小程序的记账账本app设计与实现,需要考虑用户界面设计、账单的添加、编辑、删除、查询功能以及数据的同步与备份等方面,不仅要实现基本的功能需求,还需要注重用户体验,提供简洁、友好的操作界面,让用户能够方便地进行记账。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

py编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值