import { createStoreBindings } from 'mobx-miniprogram-bindings' import { store } from '~/store/index' Page({ /** * 页面的初始数据 */ data: { score: {}, tempFilePath: '', uploadFlag: false, uploadSuccess: false, // 是否上传过 uploadState: false, percent: 0, audioPath: '' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.storeBindings = createStoreBindings(this, { store, fields: { userInfo: 'userInfo', readDetail: 'readDetail' }, }) this.storeBindings.updateStoreBindings() let score = this.data.readDetail wx.setNavigationBarTitle({ title: score.title }) this.setData({ score, }) }, upload() { if (this.data.uploadState) { return } this.setData({ uploadFlag: true, uploadState: true }) const uploadTask = wx.uploadFile({ url: 'https://reader-api.ai160.com//file/upload', filePath: this.data.score.tempFilePath, name: '朗读录音', header: { uid: wx.getStorageSync('uid') }, success: (res) => { const formateRes = JSON.parse(res.data); let audioPath = formateRes.data; this.setData({ uploadSuccess: true, audioPath }) }, complete: () => { this.setData({ uploadFlag: false }) } }) uploadTask.onProgressUpdate((res) => { this.setData({ percent: res.progress }) }) }, backReading() { wx.redirectTo({ url: `/pages/reading/index?videoId=${this.data.score.id}&reset=true`, }) }, cancelMask() { this.setData({ uploadSuccess: false }) }, onShareAppMessage() { this.setData({ uploadSuccess: false }) } })