index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {
  2. storeBindingsBehavior
  3. } from 'mobx-miniprogram-bindings'
  4. import {
  5. store
  6. } from '~/store/index'
  7. import {
  8. publishWorks,
  9. postWorksScore,
  10. publishRankWorks
  11. } from '~/api/works'
  12. Component({
  13. behaviors: [storeBindingsBehavior],
  14. storeBindings: {
  15. store,
  16. fields: {
  17. readDetail: 'readDetail'
  18. },
  19. actions: {
  20. setReadDetail: 'setReadDetail'
  21. }
  22. },
  23. /**
  24. * 组件的属性列表
  25. */
  26. properties: {
  27. readingType: ''
  28. },
  29. /**
  30. * 组件的初始数据
  31. */
  32. data: {
  33. tempFilePath: '',
  34. uploadSuccess: false,
  35. uploadFlag: false,
  36. // 是否上传过
  37. uploadState: false,
  38. percent: 0,
  39. },
  40. /**
  41. * 组件的方法列表
  42. */
  43. methods: {
  44. upload() {
  45. if (this.data.uploadState) {
  46. return
  47. }
  48. this.setData({
  49. uploadFlag: true
  50. })
  51. const uploadTask = wx.uploadFile({
  52. url: 'https://reader-api.ai160.com//file/upload',
  53. filePath: this.data.readDetail.tempFilePath,
  54. name: '朗读录音',
  55. header: {
  56. uid: wx.getStorageSync('uid')
  57. },
  58. success: (res) => {
  59. const formateRes = JSON.parse(res.data);
  60. let audioPath = formateRes.data;
  61. this.uploadWorks(audioPath);
  62. this.setData({
  63. uploadState: true,
  64. uploadSuccess: true,
  65. })
  66. },
  67. complete: () => {
  68. this.setData({
  69. uploadFlag: false
  70. })
  71. }
  72. })
  73. uploadTask.onProgressUpdate((res) => {
  74. this.setData({
  75. percent: res.progress
  76. })
  77. })
  78. },
  79. cancelMask() {
  80. this.setData({
  81. uploadSuccess: false
  82. })
  83. },
  84. async uploadWorks(audio) {
  85. const data = {
  86. "exampleId": this.data.readDetail.id,
  87. "audioPath": audio,
  88. "originVideo": this.data.readDetail.originVideo,
  89. };
  90. let res
  91. if (this.properties.readingType == 'readMatch') {
  92. res = await publishRankWorks(data)
  93. } else {
  94. res = await publishWorks(data)
  95. }
  96. wx.setStorageSync('shareVideoId', res.id)
  97. let _data = this.data.readDetail
  98. await postWorksScore({
  99. "userReadId": res.id,
  100. "complete": _data.integrity,
  101. "accuracy": _data.accuracy,
  102. "speed": _data.fluency,
  103. "intonation": _data.tone,
  104. "score": _data.myOverall
  105. })
  106. },
  107. },
  108. })