123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import {
- storeBindingsBehavior
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from '~/store/index'
- import {
- userEvent
- } from '~/api/global'
- import {
- publishWorks,
- postWorksScore,
- publishRankWorks
- } from '~/api/works'
- Component({
- behaviors: [storeBindingsBehavior],
- storeBindings: {
- store,
- fields: {
- readDetail: 'readDetail'
- },
- },
- /**
- * 组件的属性列表
- */
- properties: {
- readingType: {
- type: String,
- value: ""
- },
- activityId: ''
- },
- /**
- * 组件的初始数据
- */
- data: {
- tempFilePath: '',
- uploadSuccess: false,
- uploadFlag: false,
- // 是否上传过
- uploadState: false,
- percent: 0,
- userReadId: '',
- tips: false
- },
- /**
- * 组件的方法列表
- */
- methods: {
- async upload() {
- if (this.data.uploadState) {
- return
- }
- this.setData({
- uploadFlag: true
- })
- const uploadTask = wx.uploadFile({
- url: 'https://reader-api.ai160.com//file/upload',
- filePath: this.data.readDetail.tempFilePath,
- name: '朗读录音',
- header: {
- uid: wx.getStorageSync('uid')
- },
- success: (res) => {
- const formateRes = JSON.parse(res.data);
- let audioPath = formateRes.data;
- this.uploadWorks(audioPath);
- },
- fail: () => {
- wx.showToast({
- title: '上传失败请重试',
- icon: 'error',
- duration: 2000
- })
- this.setData({
- uploadFlag: false
- })
- }
- })
- uploadTask.onProgressUpdate((res) => {
- console.log(res.progress, 'ppppp');
- this.setData({
- percent: res.progress - 1
- })
- })
- userEvent({
- action: 'WXUPLOAD',
- })
- },
- cancelMask() {
- this.setData({
- uploadSuccess: false
- })
- this.jumpWork()
- },
- async uploadWorks(audio) {
- const data = {
- exampleId: this.data.readDetail.id,
- audioPath: audio,
- originVideo: this.data.readDetail.originVideo,
- activityId: this.properties.activityId
- };
- let res
- if (this.properties.readingType == 'readMatch') {
- res = await publishRankWorks(data)
- } else {
- res = await publishWorks(data)
- }
- wx.setStorageSync('shareVideoId', res.id)
- let _data = this.data.readDetail
- let scoreRes = {}
- // if (_data.businessType != 2) {
- scoreRes = await postWorksScore({
- userReadId: res.id,
- complete: _data.integrity,
- accuracy: _data.accuracy,
- speed: _data.fluency,
- intonation: _data.tone,
- score: _data.myOverall,
- })
- // }
- console.log(scoreRes, 'scoreRes');
- this.setData({
- uploadFlag: false,
- uploadState: true,
- uploadSuccess: true,
- userReadId: res.id,
- })
- },
- beforeleave() {
- this.setData({
- uploadState: true
- })
- },
- jumpWork() {
- wx.redirectTo({
- url: '/pages/userWorks/index'
- })
- }
- },
- })
|