123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 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
- })
- }
- })
|