index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import {
  2. storeBindingsBehavior
  3. } from 'mobx-miniprogram-bindings'
  4. import {
  5. store
  6. } from '~/store/index'
  7. import {
  8. userEvent
  9. } from '~/api/global'
  10. import {
  11. publishWorks,
  12. postWorksScore,
  13. publishRankWorks
  14. } from '~/api/works'
  15. Component({
  16. behaviors: [storeBindingsBehavior],
  17. storeBindings: {
  18. store,
  19. fields: {
  20. readDetail: 'readDetail'
  21. },
  22. },
  23. /**
  24. * 组件的属性列表
  25. */
  26. properties: {
  27. readingType: {
  28. type: String,
  29. value: ""
  30. },
  31. activityId: ''
  32. },
  33. /**
  34. * 组件的初始数据
  35. */
  36. data: {
  37. tempFilePath: '',
  38. uploadSuccess: false,
  39. uploadFlag: false,
  40. // 是否上传过
  41. uploadState: false,
  42. percent: 0,
  43. userReadId: '',
  44. tips: false
  45. },
  46. /**
  47. * 组件的方法列表
  48. */
  49. methods: {
  50. async upload() {
  51. if (this.data.uploadState) {
  52. return
  53. }
  54. this.setData({
  55. uploadFlag: true
  56. })
  57. const uploadTask = wx.uploadFile({
  58. url: 'https://reader-api.ai160.com//file/upload',
  59. filePath: this.data.readDetail.tempFilePath,
  60. name: '朗读录音',
  61. header: {
  62. uid: wx.getStorageSync('uid')
  63. },
  64. success: (res) => {
  65. const formateRes = JSON.parse(res.data);
  66. let audioPath = formateRes.data;
  67. this.uploadWorks(audioPath);
  68. },
  69. fail: () => {
  70. wx.showToast({
  71. title: '上传失败请重试',
  72. icon: 'error',
  73. duration: 2000
  74. })
  75. this.setData({
  76. uploadFlag: false
  77. })
  78. }
  79. })
  80. uploadTask.onProgressUpdate((res) => {
  81. console.log(res.progress, 'ppppp');
  82. this.setData({
  83. percent: res.progress - 1
  84. })
  85. })
  86. userEvent({
  87. action: 'WXUPLOAD',
  88. })
  89. },
  90. cancelMask() {
  91. this.setData({
  92. uploadSuccess: false
  93. })
  94. },
  95. async uploadWorks(audio) {
  96. const data = {
  97. exampleId: this.data.readDetail.id,
  98. audioPath: audio,
  99. originVideo: this.data.readDetail.originVideo,
  100. activityId: this.properties.activityId
  101. };
  102. let res
  103. if (this.properties.readingType == 'readMatch') {
  104. res = await publishRankWorks(data)
  105. } else {
  106. res = await publishWorks(data)
  107. }
  108. wx.setStorageSync('shareVideoId', res.id)
  109. let _data = this.data.readDetail
  110. let scoreRes = {}
  111. // if (_data.businessType != 2) {
  112. scoreRes = await postWorksScore({
  113. userReadId: res.id,
  114. complete: _data.integrity,
  115. accuracy: _data.accuracy,
  116. speed: _data.fluency,
  117. intonation: _data.tone,
  118. score: _data.myOverall,
  119. })
  120. // }
  121. console.log(scoreRes, 'scoreRes');
  122. this.setData({
  123. uploadFlag: false,
  124. uploadState: true,
  125. uploadSuccess: true,
  126. userReadId: res.id,
  127. })
  128. },
  129. beforeleave() {
  130. this.setData({
  131. uploadState: true
  132. })
  133. },
  134. jumpWork() {
  135. wx.redirectTo({
  136. url: '/pages/userWorks/index'
  137. })
  138. }
  139. },
  140. })