Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

form-upload.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const reqInterface = require("../../../api/models");
  2. const Base64 = require("../../../utils/base64");
  3. const {
  4. imagePrefix, getApi
  5. } = require("../../../utils/dataHelper");
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. image: {
  12. type: String,
  13. value: ''
  14. },
  15. uploadTxt: String,
  16. },
  17. observers: {
  18. 'image': function (val) {
  19. let self = this;
  20. if (val) {
  21. self.setData({
  22. imageUrl: val
  23. })
  24. }
  25. }
  26. },
  27. lifetimes: {
  28. attached() {
  29. this.setData({
  30. 'header.Blade-Auth': `bearer ${wx.getStorageSync('token')}`
  31. })
  32. this.setData({
  33. api: getApi()
  34. })
  35. }
  36. },
  37. data: {
  38. styleCss: 'padding: 20rpx 0; line-height: 36rpx font-size: 28rpx; border-bottom: 1rpx dashed #f0f0f0;',
  39. api: '',
  40. imageUrl: '',
  41. header: {
  42. 'Authorization': `Basic ${Base64.Base64.encode('miniapp:miniapp_secret')}`,
  43. 'Blade-Auth': `bearer ${wx.getStorageSync('token')}`
  44. }
  45. },
  46. /**
  47. * 组件的方法列表
  48. */
  49. methods: {
  50. uploadSuccess(e) {
  51. let self = this;
  52. let res = JSON.parse(e.detail.file.res.data);
  53. if (res.data) {
  54. self.setData({
  55. image: res.data.url
  56. })
  57. } else {
  58. if (res.code == 401) {
  59. wx.showModal({
  60. title: '错误信息',
  61. content: '登录已过期',
  62. confirmText: '重新登录',
  63. showCancel: false,
  64. success(res1) {
  65. wx.removeStorageSync('token')
  66. wx.reLaunch({
  67. url: '/pages/my/index/index',
  68. })
  69. }
  70. })
  71. } else {
  72. wx.showModal({
  73. title: '错误信息',
  74. content: '上传报错,请联系相关人员',
  75. confirmText: '知道了',
  76. showCancel: false,
  77. success(res1) {
  78. }
  79. })
  80. }
  81. }
  82. self.triggerEvent('sumbitImageInfo', res.data)
  83. },
  84. uploadFail(e) {
  85. console.log(e)
  86. },
  87. preview(e) {
  88. wx.previewImage({
  89. current: e.currentTarget.dataset.src, // 当前显示图片的http链接
  90. urls: [e.currentTarget.dataset.src] // 需要预览的图片http链接列表
  91. })
  92. },
  93. }
  94. })