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