index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {
  2. storeBindingsBehavior
  3. } from 'mobx-miniprogram-bindings'
  4. import {
  5. store
  6. } from '~/store/index'
  7. import {
  8. publishWorks,
  9. publishRankWorks
  10. } from '~/api/works'
  11. Component({
  12. behaviors: [storeBindingsBehavior],
  13. storeBindings: {
  14. store,
  15. fields: {
  16. readDetail: 'readDetail'
  17. },
  18. actions: {
  19. setReadDetail: 'setReadDetail'
  20. }
  21. },
  22. /**
  23. * 组件的属性列表
  24. */
  25. properties: {
  26. readingType: ''
  27. },
  28. /**
  29. * 组件的初始数据
  30. */
  31. data: {
  32. tempFilePath: '',
  33. uploadFlag: false,
  34. uploadSuccess: false,
  35. // 是否上传过
  36. uploadState: false,
  37. percent: 0,
  38. },
  39. /**
  40. * 组件的方法列表
  41. */
  42. methods: {
  43. upload() {
  44. if (this.data.uploadState) {
  45. return
  46. }
  47. this.setData({
  48. uploadFlag: true,
  49. uploadState: true
  50. })
  51. const uploadTask = wx.uploadFile({
  52. url: 'https://reader-api.ai160.com//file/upload',
  53. filePath: this.data.readDetail.tempFilePath,
  54. name: '朗读录音',
  55. header: {
  56. uid: wx.getStorageSync('uid')
  57. },
  58. success: (res) => {
  59. const formateRes = JSON.parse(res.data);
  60. let audioPath = formateRes.data;
  61. this.uploadWorks(audioPath);
  62. this.setData({
  63. uploadSuccess: true,
  64. })
  65. },
  66. complete: () => {
  67. this.setData({
  68. uploadFlag: false
  69. })
  70. }
  71. })
  72. uploadTask.onProgressUpdate((res) => {
  73. this.setData({
  74. percent: res.progress
  75. })
  76. })
  77. },
  78. cancelMask() {
  79. this.setData({
  80. uploadSuccess: false
  81. })
  82. },
  83. async uploadWorks(audio) {
  84. console.log(this.data);
  85. const data = {
  86. "exampleId": this.data.readDetail.id,
  87. "audioPath": audio,
  88. "originVideo": this.data.readDetail.originVideo,
  89. };
  90. console.log(data, '嘎嘎嘎嘎');
  91. let res
  92. if (!this.properties.readingType) {
  93. res = await publishWorks(data)
  94. } else {
  95. res = await publishRankWorks(data)
  96. }
  97. console.log(res, '嘎2');
  98. },
  99. },
  100. })