index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. },
  32. /**
  33. * 组件的初始数据
  34. */
  35. data: {
  36. tempFilePath: '',
  37. uploadSuccess: false,
  38. uploadFlag: false,
  39. // 是否上传过
  40. uploadState: false,
  41. percent: 0,
  42. },
  43. /**
  44. * 组件的方法列表
  45. */
  46. methods: {
  47. async upload() {
  48. if (this.data.uploadState) {
  49. return
  50. }
  51. this.setData({
  52. uploadFlag: true
  53. })
  54. const uploadTask = wx.uploadFile({
  55. url: 'https://reader-api.ai160.com//file/upload',
  56. filePath: this.data.readDetail.tempFilePath,
  57. name: '朗读录音',
  58. header: {
  59. uid: wx.getStorageSync('uid')
  60. },
  61. success: (res) => {
  62. const formateRes = JSON.parse(res.data);
  63. let audioPath = formateRes.data;
  64. this.uploadWorks(audioPath);
  65. this.setData({
  66. uploadState: true,
  67. uploadSuccess: true,
  68. })
  69. },
  70. complete: () => {
  71. this.setData({
  72. uploadFlag: false
  73. })
  74. }
  75. })
  76. uploadTask.onProgressUpdate((res) => {
  77. this.setData({
  78. percent: res.progress
  79. })
  80. })
  81. await userEvent({
  82. action: 'WXUPLOAD',
  83. })
  84. },
  85. cancelMask() {
  86. this.setData({
  87. uploadSuccess: false
  88. })
  89. },
  90. async uploadWorks(audio) {
  91. const data = {
  92. exampleId: this.data.readDetail.id,
  93. audioPath: audio,
  94. originVideo: this.data.readDetail.originVideo,
  95. };
  96. let res
  97. if (this.properties.readingType == 'readMatch') {
  98. res = await publishRankWorks(data)
  99. } else {
  100. res = await publishWorks(data)
  101. }
  102. wx.setStorageSync('shareVideoId', res.id)
  103. let _data = this.data.readDetail
  104. await postWorksScore({
  105. "userReadId": res.id,
  106. "complete": _data.integrity,
  107. "accuracy": _data.accuracy,
  108. "speed": _data.fluency,
  109. "intonation": _data.tone,
  110. "score": _data.myOverall
  111. })
  112. },
  113. },
  114. })