123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import {
- storeBindingsBehavior
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from '~/store/index'
- import {
- publishWorks
- } from '~/api/works'
- Component({
- behaviors: [storeBindingsBehavior],
- storeBindings: {
- store,
- fields: {
- readDetail: 'readDetail'
- },
- actions: {
- setReadDetail: 'setReadDetail'
- }
- },
- /**
- * 组件的属性列表
- */
- properties: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- tempFilePath: '',
- uploadFlag: false,
- uploadSuccess: false,
- // 是否上传过
- uploadState: false,
- percent: 0,
- },
- /**
- * 组件的方法列表
- */
- methods: {
- 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.readDetail.tempFilePath,
- name: '朗读录音',
- header: {
- uid: wx.getStorageSync('uid')
- },
- success: (res) => {
- const formateRes = JSON.parse(res.data);
- let audioPath = formateRes.data;
- this.shareWorks(audioPath);
- this.setData({
- uploadSuccess: true,
- })
- },
- complete: () => {
- this.setData({
- uploadFlag: false
- })
- }
- })
- uploadTask.onProgressUpdate((res) => {
- this.setData({
- percent: res.progress
- })
- })
- },
- cancelMask() {
- this.setData({
- uploadSuccess: false
- })
- },
- async shareWorks(audio) {
- const data = {
- "lessonId": this.data.id,
- "originVideo": this.data.videoUrl,
- "audioPath": audio,
- "title": this.data.title,
- "iconImg": this.data.img,
- "summary": this.data.summary,
- "productId": this.data.productId,
- "grade": this.data.grade,
- "exampleId": this.data.exampleId,
- "coverImg": this.data.coverImg,
- "shareImg": this.data.shareImg
- };
- let res = await publishWorks(data)
- console.log(data, res, '嘎嘎嘎嘎');
- },
- }
- })
|