index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import ad from '../index/ad'
  2. ad({
  3. data: {
  4. fileList: [{
  5. uid: 0,
  6. status: 'uploading',
  7. url: 'http://cdn.skyvow.cn/qrcode.jpg',
  8. },
  9. {
  10. uid: 1,
  11. status: 'done',
  12. url: 'http://cdn.skyvow.cn/qrcode.jpg',
  13. },
  14. {
  15. uid: 2,
  16. status: 'error',
  17. url: 'http://cdn.skyvow.cn/qrcode.jpg',
  18. }],
  19. },
  20. onChange(e) {
  21. console.log('onChange', e)
  22. const { file, fileList } = e.detail
  23. if (file.status === 'uploading') {
  24. this.setData({
  25. progress: 0,
  26. })
  27. wx.showLoading()
  28. } else if (file.status === 'done') {
  29. this.setData({
  30. imageUrl: file.url,
  31. })
  32. }
  33. // Controlled state should set fileList
  34. this.setData({ fileList })
  35. },
  36. onSuccess(e) {
  37. console.log('onSuccess', e)
  38. },
  39. onFail(e) {
  40. console.log('onFail', e)
  41. },
  42. onComplete(e) {
  43. console.log('onComplete', e)
  44. wx.hideLoading()
  45. },
  46. onProgress(e) {
  47. console.log('onProgress', e)
  48. this.setData({
  49. progress: e.detail.file.progress,
  50. })
  51. },
  52. onPreview(e) {
  53. console.log('onPreview', e)
  54. const { file, fileList } = e.detail
  55. wx.previewImage({
  56. current: file.url,
  57. urls: fileList.map((n) => n.url),
  58. })
  59. },
  60. onRemove(e) {
  61. const { file, fileList } = e.detail
  62. wx.showModal({
  63. content: '确定删除?',
  64. success: (res) => {
  65. if (res.confirm) {
  66. this.setData({
  67. fileList: fileList.filter((n) => n.uid !== file.uid),
  68. })
  69. }
  70. },
  71. })
  72. },
  73. })