index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. },
  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. await userEvent({
  79. action: 'WXUPLOAD',
  80. })
  81. },
  82. cancelMask() {
  83. this.setData({
  84. uploadSuccess: false
  85. })
  86. },
  87. async uploadWorks(audio) {
  88. const data = {
  89. exampleId: this.data.readDetail.id,
  90. audioPath: audio,
  91. originVideo: this.data.readDetail.originVideo,
  92. activityId: this.properties.activityId
  93. };
  94. let res
  95. if (this.properties.readingType == 'readMatch') {
  96. res = await publishRankWorks(data)
  97. } else {
  98. res = await publishWorks(data)
  99. }
  100. console.log('shareVideo', res);
  101. wx.setStorageSync('shareVideoId', res.id)
  102. let _data = this.data.readDetail
  103. let scoreRes = await postWorksScore({
  104. "userReadId": res.id,
  105. "complete": _data.integrity,
  106. "accuracy": _data.accuracy,
  107. "speed": _data.fluency,
  108. "intonation": _data.tone,
  109. "score": _data.myOverall
  110. })
  111. this.setData({
  112. uploadState: true,
  113. uploadSuccess: true,
  114. })
  115. },
  116. },
  117. })