index.js 2.8 KB

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