index.js 1.4 KB

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