小程序上傳wx.uploadFile - 小程序請假

小程序上傳wx.uploadFile

UploadTask wx.uploadFile(Object object) 將本地資源上傳到服務器。客戶端發起一個 HTTPS POST 請求,其中 content-type 爲 multipart/form-data。使用前請注意閱讀相關說明。小程序

url string 開發者服務器地址bash

filePath string 要上傳文件資源的路徑服務器

name string 文件對應的 key,開發者在服務端能夠經過這個 key 獲取文件的二進制內容函數

header HTTP 請求 Header,Header 中不能設置 Refererflex

formData HTTP 請求中其餘額外的 form dataurl

success 接口調用成功的回調函數spa

fail接口調用失敗的回調函數code

complete 接口調用結束的回調函數(調用成功、失敗都會執行)orm

示例代碼
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%;
}
複製代碼
相關文章
相關標籤/搜索