index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {
  2. createStoreBindings
  3. } from 'mobx-miniprogram-bindings'
  4. import {
  5. store
  6. } from '~/store/index'
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. score: {},
  13. tempFilePath: '',
  14. uploadFlag: false,
  15. uploadSuccess: false,
  16. // 是否上传过
  17. uploadState: false,
  18. percent: 0,
  19. audioPath: ''
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad(options) {
  25. this.storeBindings = createStoreBindings(this, {
  26. store,
  27. fields: {
  28. userInfo: 'userInfo',
  29. readDetail: 'readDetail'
  30. },
  31. })
  32. this.storeBindings.updateStoreBindings()
  33. let score = this.data.readDetail
  34. wx.setNavigationBarTitle({
  35. title: score.title
  36. })
  37. this.setData({
  38. score,
  39. })
  40. },
  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.score.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.setData({
  60. uploadSuccess: true,
  61. audioPath
  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. backReading() {
  77. wx.redirectTo({
  78. url: `/pages/reading/index?videoId=${this.data.score.id}&reset=true`,
  79. })
  80. },
  81. cancelMask() {
  82. this.setData({
  83. uploadSuccess: false
  84. })
  85. },
  86. onShareAppMessage() {
  87. this.setData({
  88. uploadSuccess: false
  89. })
  90. }
  91. })