businessGoodsEdit.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. fileList: [
  7. {
  8. url: 'https://img.yzcdn.cn/vant/leaf.jpg',
  9. status: 'uploading',
  10. message: '上传中'
  11. }
  12. ]
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad(options) {
  18. },
  19. /**
  20. * 生命周期函数--监听页面初次渲染完成
  21. */
  22. onReady() {
  23. },
  24. /**
  25. * 生命周期函数--监听页面显示
  26. */
  27. onShow() {
  28. },
  29. /**
  30. * 生命周期函数--监听页面隐藏
  31. */
  32. onHide() {
  33. },
  34. /**
  35. * 生命周期函数--监听页面卸载
  36. */
  37. onUnload() {
  38. },
  39. /**
  40. * 页面相关事件处理函数--监听用户下拉动作
  41. */
  42. onPullDownRefresh() {
  43. },
  44. /**
  45. * 页面上拉触底事件的处理函数
  46. */
  47. onReachBottom() {
  48. },
  49. /**
  50. * 用户点击右上角分享
  51. */
  52. onShareAppMessage() {
  53. },
  54. beforeRead(event) {
  55. const { file, callback } = event.detail
  56. callback(file.type === 'image')
  57. },
  58. afterRead(event) {
  59. const { file } = event.detail
  60. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  61. wx.uploadFile({
  62. url: 'https://example.weixin.qq.com/upload', // 仅为示例,非真实的接口地址
  63. filePath: file.url,
  64. name: 'file',
  65. formData: { user: 'test' },
  66. success(res) {
  67. // 上传完成需要更新 fileList
  68. const { fileList = [] } = this.data
  69. fileList.push({ ...file, url: res.data })
  70. this.setData({ fileList })
  71. }
  72. })
  73. },
  74. delete(event) {
  75. const { index } = event.detail
  76. this.data.fileList.splice(index, 1)
  77. this.setData({
  78. fileList: this.data.fileList
  79. })
  80. },
  81. onSubmit(e) {
  82. console.log(e.detail)
  83. }
  84. })