小程序上传wx.uploadFile - 小程序请假

时间:2021-01-27 10:45:02

小程序上传wx.uploadFile

UploadTask wx.uploadFile(Object object)

将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。

url string

开发者服务器地址

filePath string

要上传文件资源的路径

name string

文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容

header

HTTP 请求 Header,Header 中不能设置 Referer

formData

HTTP 请求中其他额外的 form data

success

接口调用成功的回调函数

fail接口调用失败的回调函数

complete

接口调用结束的回调函数(调用成功、失败都会执行)

示例代码
wx.chooseImage({
success (res) {
const tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: 'https://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'file',
formData: {
'user': 'test'
},
success (res){
const data = res.data
//do something
}
})
}
})

小程序请假

<view class="head">
<view class="head_item {{selected?'head_itemActive':''}}" bindtap="selected">新请假</view>
<view class="ring"></view>
<view class="head_item {{selected1?'head_itemActive':''}}" bindtap='selected1'>请假结果</view>
</view>
<view class="main {{selected?'show':'hidden'}}">
<form bindsubmit="formSubmit" bindreset="formReset">
<view class='item'>
\r\n\r\n\r\n\r\n\r\n\r\n年级:
<view class='bk'>
<input name='nickname' class="textarea" placeholder="{{geren.nickname}}" value='{{geren.nickname}}' bindinput="nickname" maxlength='15' auto-height/>
</view>
</view>
<view class='item'>
\r\n\r\n\r\n\r\n\r\n\r\n班级:
<view class='bk'>
<input name='nickname' class="textarea" placeholder="{{geren.nickname}}" value='{{geren.nickname}}' bindinput="nickname" maxlength='15' auto-height/>
</view>
</view>
<view class='item'>
\r\n\r\n\r\n\r\n\r\n\r\n学号:
<view class='bk'>
<input name='realName' class="textarea" placeholder="{{detailgeren.realName}}" value='{{detailgeren.realName}}' bindinput="realName" maxlength='15' auto-height/>
</view>
</view>
<view class='item'>
申请姓名:
<view class='bk'>
<input name='realName' class="textarea" placeholder="{{detailgeren.realName}}" value='{{detailgeren.realName}}' bindinput="realName" maxlength='15' auto-height/>
</view>
</view>
<view class='item'>
请假天数:
<view class='bk'>
<input name='realName' class="textarea" placeholder="{{detailgeren.realName}}" value='{{detailgeren.realName}}' bindinput="realName" maxlength='15' auto-height/>
</view>
</view>
<view class='item'>
开始时间:
<view class='bk'>
<view class='time'>
<picker mode="date" value="{{date}}" start="2018-01-01" end="2222-10-08" bindchange="changeDate" name="starttime" bindchange="changeDate">
<view>
{{date}}
</view>
</picker>
</view>
</view>
</view>
<view class='item'>
结束时间:
<view class='bk'>
<view class='time'>
<picker mode="date" value="{{date1}}" start="2018-11-11" end="2222-01-01" bindchange="changeDate1" name="endtime">
<view>
{{date1}}
</view>
</picker>
</view>
</view>
</view>
<view class='item'>
请假类型:
<view class='bk'>
<input name='realName' class="textarea" placeholder="{{detailgeren.realName}}" value='{{detailgeren.realName}}' bindinput="realName" maxlength='15' auto-height/>
</view>
</view>
<view class='item'>
请假原因:
<view class='bk'>
<input name="detailAddress" class="textarea" placeholder="{{detailgeren.detailAddress}}" value='{{detailgeren.detailAddress}}' bindinput="detailAddress" maxlength='100' auto-height/>
</view>
</view>
<view class='anniu'>
<button class='btn' formType="submit">提交</button>
</view>
</form>
</view>
Page {
background-color: #f1f1f1;
} /* 新请假 */ .item {
display: flex;
flex-direction: row;
font-size: 30rpx;
color: #acacac;
margin: 25rpx;
align-items: center;
} .btn {
background-color: #79caff;
color: #fff;
width: 150rpx;
font-size: 30rpx;
margin-top: 30rpx;
} .bk {
border-radius: 10rpx;
border: 2rpx solid #ccc;
padding: 10rpx;
width: 65%;
} .textarea {
width: 100%;
}