addFeedback.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // pages/addFeedback/addFeedback.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. number: 0,
  8. maxlength: 500,
  9. imgs: []
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. },
  16. chooseImage: function () {
  17. let that = this;
  18. wx.chooseMedia({
  19. count: 1,
  20. mediaType: ['image'], //video
  21. sourceType: ['album', 'camera'],
  22. maxDuration: 30,
  23. camera: 'back',
  24. success(res) {
  25. console.log('res')
  26. console.log(res.tempFiles[0].tempFilePath)
  27. that.upData(res.tempFiles[0].tempFilePath)
  28. }
  29. })
  30. },
  31. upData: function (tempFilePath) {
  32. let that = this
  33. wx.uploadFile({
  34. url: 'https://api.ijolijoli.com/api/upload', //仅为示例,非真实的接口地址
  35. filePath: tempFilePath,
  36. name: 'file',
  37. formData: {
  38. type: 'image'
  39. },
  40. header: {
  41. "token": wx.getStorageSync('token'),
  42. },
  43. success(res) {
  44. var data = JSON.parse(res.data);
  45. that.setData({
  46. imgPath: data.result
  47. })
  48. // const data = res.data
  49. }
  50. })
  51. },
  52. /**
  53. * 生命周期函数--监听页面初次渲染完成
  54. */
  55. onReady: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload: function () {
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {
  76. },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. onReachBottom: function () {
  81. },
  82. /**
  83. * 用户点击右上角分享
  84. */
  85. onShareAppMessage: function () {
  86. }
  87. })