Skip to content

title: 小程序相关 date: 2022-04-30 06:49:12

  • 在macOS使用数码测色计取色时,选择以sRGB显示,转16进制即可。

多文件上传方法

git clone https://github.com/zlyboy/wx-formdata.git

const FormData = require('../wx-formdata/formData')

const httpsPost = (url, data = {}, contentType = "application/json") => {
  return new Promise((resolve, reject) => {
    wx.request({
      header: {
        "Content-Type": contentType
      },
      method: "POST",
      url: apiUrl + url,
      data: data,
      success: function (res) {
        resolve(res)
      },
      fail: function (err) {
        reject(err)
      }
    })
  })
}

const uploadFiles = (url, data = [], filesPath = []) => {
  return new Promise((resolve, reject) => {
    let formData = new FormData()
    for (var i in data) {
      formData.append(data[i][0], data[i][1])
    }
    for (var i in filesPath) {
      formData.appendFile("files", filesPath[i], getFileNameFromPath(filesPath[i]))
    }
    let fdata = formData.getData();
    httpsPost(url, fdata.buffer, fdata.contentType).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
}

const submit = function () {
    var _this = this

    var info = new Report(1, "1", "1", "1")
    
    return new Promise((resolve, reject) => {
      let tempFilePath = []
      for (var i = 0; i < _this.data.photos.length; i++) {
        tempFilePath.push(_this.data.photos[i].tempFilePath)
      }
      _this.uploadFiles("yoururl", info.toList(), tempFilePath).then((res) => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
    });
  }
  
class Report {
  id
  type
  description
  openid
  photo_count

  constructor(id, type, description, openid) {
    this.id = id
    this.type = type
    this.description = description
    this.openid = openid
  }

  toList() {
    return [["type", this.type], ["description", this.description], ["openid", this.openid]]
  }
}