index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. this.jumpWork()
  95. },
  96. async uploadWorks(audio) {
  97. const data = {
  98. exampleId: this.data.readDetail.id,
  99. audioPath: audio,
  100. originVideo: this.data.readDetail.originVideo,
  101. activityId: this.properties.activityId
  102. };
  103. let res
  104. if (this.properties.readingType == 'readMatch') {
  105. res = await publishRankWorks(data)
  106. } else {
  107. res = await publishWorks(data)
  108. }
  109. wx.setStorageSync('shareVideoId', res.id)
  110. let _data = this.data.readDetail
  111. let scoreRes = {}
  112. // if (_data.businessType != 2) {
  113. scoreRes = await postWorksScore({
  114. userReadId: res.id,
  115. complete: _data.integrity,
  116. accuracy: _data.accuracy,
  117. speed: _data.fluency,
  118. intonation: _data.tone,
  119. score: _data.myOverall,
  120. })
  121. // }
  122. console.log(scoreRes, 'scoreRes');
  123. this.setData({
  124. uploadFlag: false,
  125. uploadState: true,
  126. uploadSuccess: true,
  127. userReadId: res.id,
  128. })
  129. },
  130. beforeleave() {
  131. this.setData({
  132. uploadState: true
  133. })
  134. },
  135. jumpWork() {
  136. wx.redirectTo({
  137. url: '/pages/userWorks/index'
  138. })
  139. }
  140. },
  141. })