index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {
  2. storeBindingsBehavior
  3. } from 'mobx-miniprogram-bindings'
  4. import {
  5. store
  6. } from '~/store/index'
  7. Component({
  8. behaviors: [storeBindingsBehavior],
  9. storeBindings: {
  10. store,
  11. fields: {
  12. readDetail: 'readDetail'
  13. },
  14. actions: {
  15. setReadDetail: 'setReadDetail'
  16. }
  17. },
  18. /**
  19. * 组件的属性列表
  20. */
  21. properties: {
  22. },
  23. /**
  24. * 组件的初始数据
  25. */
  26. data: {
  27. tempFilePath: '',
  28. uploadFlag: false,
  29. uploadSuccess: false,
  30. // 是否上传过
  31. uploadState: false,
  32. percent: 0,
  33. },
  34. /**
  35. * 组件的方法列表
  36. */
  37. methods: {
  38. upload() {
  39. if (this.data.uploadState) {
  40. return
  41. }
  42. this.setData({
  43. uploadFlag: true,
  44. uploadState: true
  45. })
  46. const uploadTask = wx.uploadFile({
  47. url: 'https://reader-api.ai160.com//file/upload',
  48. filePath: this.data.readDetail.tempFilePath,
  49. name: '朗读录音',
  50. header: {
  51. uid: wx.getStorageSync('uid')
  52. },
  53. success: (res) => {
  54. // const formateRes = JSON.parse(res.data);
  55. // let audioPath = formateRes.data;
  56. // this.setReadDetail({
  57. // audioPath,
  58. // ...this.data.readDetail
  59. // })
  60. this.setData({
  61. uploadSuccess: true,
  62. })
  63. },
  64. complete: () => {
  65. this.setData({
  66. uploadFlag: false
  67. })
  68. }
  69. })
  70. uploadTask.onProgressUpdate((res) => {
  71. this.setData({
  72. percent: res.progress
  73. })
  74. })
  75. },
  76. cancelMask() {
  77. this.setData({
  78. uploadSuccess: false
  79. })
  80. },
  81. }
  82. })