index.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. import {
  2. getreadInfo,
  3. submitPlayLog
  4. } from '~/api/video'
  5. import {
  6. publishWorks,
  7. uploadPk,
  8. postWorksScore
  9. } from '~/api/works'
  10. import {
  11. userEvent
  12. } from '~/api/global'
  13. import {
  14. createStoreBindings
  15. } from 'mobx-miniprogram-bindings'
  16. import {
  17. store
  18. } from '~/store/index'
  19. import {
  20. setDuration
  21. } from '~/utils/util'
  22. const aiengine = require('~/utils/ChivoxAiEngine')
  23. const sha1 = require('~/utils/sha1');
  24. // 文章行高
  25. let rowH = 0
  26. let videoContext = null
  27. // 滚动变色定时器
  28. let stl = null
  29. // 倒计时
  30. let setTimeoutObj = null
  31. // 录音
  32. let innerAudioContext = null
  33. // 试听
  34. let resultAudioContext = null
  35. /*创建基础引擎*/
  36. let wsEngine = aiengine.createWsEngine({});
  37. /*微信录音*/
  38. let recorderManager = wx.getRecorderManager();
  39. Page({
  40. data: {
  41. videoInfo: {},
  42. videoPath: '',
  43. currentRow: null,
  44. state: false,
  45. // 示例播放状态
  46. exampleState: false,
  47. // 是否静音播放视频
  48. muted: false,
  49. countDown: {
  50. state: false,
  51. num: 3,
  52. },
  53. contentH: 0,
  54. scrollTop: 0,
  55. //如果readingReset为true就是重读
  56. readingReset: false,
  57. //readingType为public是普通阅读,为pk是pk逻辑,readMatch为朗读赛
  58. readingType: 'public',
  59. percent: 0,
  60. uploadState: false,
  61. article: [],
  62. silderData: {
  63. currentTime: '00:00',
  64. endTime: '00:00',
  65. silderValue: 0
  66. }
  67. },
  68. onLoad(options) {
  69. console.log(options);
  70. let videoId = options.videoId
  71. this.getreadInfo(videoId, options.reset)
  72. this.setData({
  73. readingReset: options.reset || false,
  74. readingType: options.readingType || 'public',
  75. uploadHide: options.uploadHide
  76. })
  77. // 手工绑定
  78. this.storeBindings = createStoreBindings(this, {
  79. store,
  80. fields: {
  81. userInfo: 'userInfo',
  82. readDetail: 'readDetail',
  83. pkData: 'pkData'
  84. },
  85. actions: {
  86. setReadDetail: 'setReadDetail'
  87. }
  88. })
  89. // 录音授权
  90. wx.getSetting({
  91. success(res) {
  92. if (!res.authSetting['scope.record']) {
  93. wx.authorize({
  94. scope: 'scope.record',
  95. success() {
  96. // 用户已经同意小程序使用录音功能,后续调用接口不会弹窗询问
  97. wx.getRecorderManager()
  98. }
  99. })
  100. }
  101. }
  102. })
  103. /*监听评测结果:必须在基础引擎创建后,调用任何评测接口前设置监听,否则有可能收不到相关事件。*/
  104. wsEngine.onResult((res) => {
  105. this.getRecordScore(res)
  106. });
  107. wsEngine.onErrorResult((res) => {
  108. console.log("===收到错误结果=============", res)
  109. });
  110. this.innerAudioContext = wx.createInnerAudioContext();
  111. this.innerAudioContext.onTimeUpdate(res => {
  112. this.setData({
  113. ["silderData.sliderValue"]: Math.round(this.innerAudioContext.currentTime / this.innerAudioContext.duration * 100),
  114. ["silderData.currentTime"]: setDuration(this.innerAudioContext.currentTime)
  115. })
  116. })
  117. this.resultAudioContext = wx.createInnerAudioContext();
  118. this.resultAudioContext.onTimeUpdate(res => {
  119. this.setData({
  120. ["silderData.sliderValue"]: Math.round(this.resultAudioContext.currentTime / this.resultAudioContext.duration * 100),
  121. ["silderData.currentTime"]: setDuration(this.resultAudioContext.currentTime)
  122. })
  123. })
  124. this.resultAudioContext.onError(res => {
  125. console.log(res, 'resultAudioContext');
  126. })
  127. this.innerAudioContext.onError(res => {
  128. console.log(res, 'bbbb');
  129. })
  130. this.resultAudioContext.onEnded(res => {
  131. console.log('102-resultAudioContext.ended');
  132. this.setData({
  133. exampleState: false
  134. })
  135. if (this.data.videoInfo.userReadExtend.resourcesType == 0) {
  136. this.videoContext.stop()
  137. this.videoContext.seek(0)
  138. }
  139. })
  140. this.resultAudioContext.onStop((res) => {
  141. console.log('109-resultAudioContext.onStop');
  142. this.setData({
  143. exampleState: false
  144. })
  145. if (this.data.videoInfo.userReadExtend.resourcesType == 0) {
  146. this.videoContext.stop()
  147. this.videoContext.seek(0)
  148. }
  149. });
  150. this.resultAudioContext.onEnded(res => {
  151. this.setData({
  152. ["silderData.sliderValue"]: 100
  153. })
  154. })
  155. },
  156. // 获取阅读内容
  157. async getreadInfo(videoId, reset = false) {
  158. let videoInfo = await getreadInfo(videoId)
  159. wx.setNavigationBarTitle({
  160. title: videoInfo.userRead.title
  161. })
  162. let data = JSON.parse(videoInfo.userReadExtend.lessonText)
  163. data = data.map((item, index) => {
  164. item.time = Number(item.time)
  165. item.readTime = data[index + 1] ? data[index + 1].time - item.time : ''
  166. return item
  167. })
  168. this.setData({
  169. videoPath: videoInfo.userRead.originVideo,
  170. article: data,
  171. videoInfo,
  172. ["silderData.endTime"]: setDuration(videoInfo.userRead.duration)
  173. })
  174. if (!reset) {
  175. this.getHeight()
  176. }
  177. if (this.data.videoInfo.userReadExtend.resourcesType == 0) {
  178. this.videoContext = wx.createVideoContext('myVideo')
  179. } else {
  180. this.innerAudioContext.src = videoInfo.userRead.originVideo
  181. this.innerAudioContext.onEnded(res => {
  182. console.log("138innerAudioContext触发的");
  183. this.resetReading()
  184. })
  185. this.innerAudioContext.onStop((res) => {
  186. console.log("143innerAudioContext触发的");
  187. });
  188. }
  189. },
  190. // 开始录制
  191. setCountDown() {
  192. let child = this.selectComponent('#readingTips').data
  193. // 判断是否有权限朗读 不是vip并且没有朗读机会
  194. const isVip = child.vipTime ? true : false
  195. if (!isVip && child.userInfo.experienceAmount <= 0 && this.data.readingType != 'readMatch') {
  196. return this.selectComponent('#readingTips').showModal();
  197. }
  198. if (this.data.state) {
  199. this.resetReading()
  200. return
  201. }
  202. if (!this.data.readingReset) {
  203. this.getHeight()
  204. }
  205. this.resetReading()
  206. this.setData({
  207. readingReset: false,
  208. 'countDown.state': true
  209. })
  210. this.stl = setInterval(() => {
  211. if (this.data.countDown.num == 0) {
  212. clearInterval(this.stl)
  213. this.setData({
  214. state: true,
  215. countDown: {
  216. state: false,
  217. num: 3
  218. }
  219. })
  220. this.playMediaState()
  221. this.soundRecording()
  222. this.startRecording()
  223. } else {
  224. this.setData({
  225. 'countDown.num': --this.data.countDown.num
  226. })
  227. }
  228. }, 1000)
  229. },
  230. // 录音
  231. soundRecording() {
  232. console.log('zzz');
  233. /*调用微信开始录音接口,并启动语音评测*/
  234. let timeStamp = new Date().getTime()
  235. let sig = sha1(`16075689600000da${timeStamp}caa8e60da6042731c230fe431ac9c7fd`)
  236. let app = {
  237. applicationId: '16075689600000da',
  238. sig, //签名字符串
  239. alg: 'sha1',
  240. timestamp: timeStamp + '',
  241. userId: wx.getStorageSync('uid')
  242. }
  243. let lessonText = JSON.parse(this.data.videoInfo.userReadExtend.lessonText).map((item) => {
  244. return item.text
  245. }).join('\n')
  246. // https://www.chivox.com/opendoc/#/ChineseDoc/coreCn/Chinese/cn.sent.raw?id=%e5%8f%82%e6%95%b0%e8%af%b4%e6%98%8e <----参数说明
  247. wsEngine.start({
  248. request: {
  249. coreType: "cn.pred.raw",
  250. refText: lessonText,
  251. rank: 100,
  252. attachAudioUrl: 1,
  253. result: {
  254. details: {
  255. gop_adjust: -0.1
  256. }
  257. }
  258. },
  259. app,
  260. audio: {
  261. audioType: "mp3",
  262. channel: 1,
  263. sampleBytes: 2,
  264. sampleRate: 16000
  265. },
  266. success: (res) => {
  267. /*引擎启动成功,可以启动录音机开始录音,并将音频片传给引擎*/
  268. const options = {
  269. duration: 600000,
  270. sampleRate: 44100, //采样率
  271. numberOfChannels: 1, //录音通道数
  272. encodeBitRate: 192000, //编码码率
  273. format: 'mp3', //音频格式,有效值aac/mp3
  274. frameSize: 50 //指定帧大小,单位 KB
  275. };
  276. //开始录音,在开始录音回调中feed音频片
  277. recorderManager.start(options);
  278. },
  279. fail: (res) => {
  280. console.log("fail============= " + res);
  281. },
  282. });
  283. recorderManager.onError(res => {
  284. console.log(res, 'rrrrrsse');
  285. })
  286. //监听录音开始事件
  287. recorderManager.onStart(() => {});
  288. //监听录音结束事件
  289. recorderManager.onStop((res) => {
  290. console.log('录音结束', res);
  291. this.setData({
  292. tempFilePath: res.tempFilePath,
  293. });
  294. //录音机结束后,驰声引擎执行结束操作,等待评测返回结果
  295. wsEngine.stop({
  296. success: () => {
  297. console.log('====== wsEngine stop success ======');
  298. },
  299. fail: (res) => {
  300. console.log('录音结束报错', res);
  301. },
  302. });
  303. });
  304. //监听已录制完指定帧大小的文件事件。如果设置了 frameSize,则会回调此事件。
  305. recorderManager.onFrameRecorded((res) => {
  306. const {
  307. frameBuffer
  308. } = res
  309. //TODO 调用feed接口传递音频片给驰声评测引擎
  310. wsEngine.feed({
  311. data: frameBuffer, // frameBuffer为微信录音机回调的音频数据
  312. success: () => {},
  313. fail: (res) => {
  314. console.log('监听已录制完指定帧大小报错', res)
  315. },
  316. });
  317. });
  318. },
  319. // eeeeee() {
  320. // wx.navigateTo({
  321. // url: `/pages/score/index?readingType=${this.data.readingType}`,
  322. // events: {
  323. // // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
  324. // someEvent: (data) => {
  325. // console.log(data)
  326. // this.setData({
  327. // readingReset: data.reset || false,
  328. // readingType: data.readingType || 'public',
  329. // uploadHide: data.uploadHide
  330. // })
  331. // console.log(this.data, 'ggggggggg');
  332. // }
  333. // },
  334. // })
  335. // },
  336. // 获取测评结果
  337. getRecordScore(res) {
  338. const result = res.result;
  339. const integrity = Math.floor(result.integrity); //完成度
  340. const tone = Math.floor(result.tone); // 语调声调
  341. const accuracy = Math.floor(result.accuracy); // 准确度 发音分
  342. const fluency = Math.floor(result.fluency.overall); //流利度
  343. let myOverall = Math.floor(integrity * 0.45 + accuracy * 0.35 + fluency * 0.1 + tone * 0.1);
  344. let detail = {
  345. integrity,
  346. tone,
  347. accuracy,
  348. fluency,
  349. myOverall,
  350. tempFilePath: this.data.tempFilePath,
  351. title: this.data.videoInfo.userRead.title,
  352. id: this.data.videoInfo.userRead.exampleId,
  353. coverImg: this.data.videoInfo.userRead.coverImg,
  354. resourcesType: this.data.videoInfo.userReadExtend.resourcesType,
  355. aBg: this.data.videoInfo.userReadExtend.resourcesType == 1 ? this.data.videoInfo.userReadExtend.backgroundVirtualImg : '',
  356. originVideo: this.data.videoInfo.userRead.originVideo
  357. }
  358. this.setReadDetail(detail)
  359. if (this.data.readingType == 'public' || this.data.readingType == 'readMatch') {
  360. wx.navigateTo({
  361. url: `/pages/score/index?readingType=${this.data.readingType}`,
  362. events: {
  363. // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
  364. goback: (data) => {
  365. console.log(data)
  366. this.setData({
  367. readingReset: data.reset || false,
  368. readingType: data.readingType || 'public',
  369. uploadHide: data.uploadHide
  370. })
  371. console.log(this.data);
  372. }
  373. },
  374. })
  375. } else {
  376. this.uploadAudio(detail)
  377. }
  378. },
  379. // 挑战录音上传
  380. uploadAudio(detail) {
  381. this.setData({
  382. uploadState: true
  383. })
  384. const uploadTask = wx.uploadFile({
  385. url: 'https://reader-api.ai160.com//file/upload',
  386. filePath: this.data.tempFilePath,
  387. name: '朗读录音',
  388. header: {
  389. uid: wx.getStorageSync('uid')
  390. },
  391. success: async (res) => {
  392. const formateRes = JSON.parse(res.data);
  393. let audioPath = formateRes.data;
  394. let uploadRes = await publishWorks({
  395. exampleId: this.data.pkData.exampleId,
  396. audioPath
  397. })
  398. let _data = this.data.readDetail
  399. console.log('挑战分数-----', {
  400. "userReadId": uploadRes.id,
  401. "complete": _data.integrity,
  402. "accuracy": _data.accuracy,
  403. "speed": _data.fluency,
  404. "intonation": _data.tone,
  405. "score": _data.myOverall
  406. });
  407. postWorksScore({
  408. "userReadId": uploadRes.id,
  409. "complete": _data.integrity,
  410. "accuracy": _data.accuracy,
  411. "speed": _data.fluency,
  412. "intonation": _data.tone,
  413. "score": _data.myOverall
  414. })
  415. let data = {
  416. challengerUserReadId: uploadRes.id,
  417. userReadId: this.data.pkData.id,
  418. winnerUId: this.data.pkData.score > _data.myOverall ? this.data.pkData.uid : this.data.pkData.score == _data.myOverall ? '' : wx.getStorageSync('uid')
  419. }
  420. console.log('uploadPk-----', data);
  421. let result = await uploadPk(data)
  422. wx.redirectTo({
  423. url: `/pages/pkResult/index?id=${result.id}`
  424. })
  425. },
  426. complete: () => {
  427. this.setData({
  428. uploadState: false
  429. })
  430. }
  431. });
  432. uploadTask.onProgressUpdate((res) => {
  433. this.setData({
  434. percent: res.progress
  435. })
  436. })
  437. },
  438. // 字体换行
  439. startRecording() {
  440. if (this.data.currentRow == null) {
  441. this.setData({
  442. currentRow: 0
  443. })
  444. }
  445. let row = this.data.article[this.data.currentRow]
  446. if (!row.readTime) {
  447. return
  448. }
  449. this.setTimeoutObj = setTimeout(() => {
  450. this.setData({
  451. currentRow: ++this.data.currentRow
  452. })
  453. this.setData({
  454. scrollTop: this.rowH * this.data.currentRow
  455. })
  456. this.startRecording()
  457. },
  458. row.readTime);
  459. },
  460. // 视频播放结束
  461. videoEnd() {
  462. this.resetReading()
  463. },
  464. videoPlay() {
  465. if (this.data.state) {
  466. return
  467. }
  468. if (this.data.videoInfo.userReadExtend.resourcesType == 1) {
  469. if (this.data.exampleState) {
  470. this.setData({
  471. exampleState: false
  472. })
  473. return this.resultAudioContext.stop()
  474. }
  475. this.resultAudioContext.src = this.data.readingReset ? this.data.readDetail.tempFilePath : this.data.videoInfo.userRead.audioPath;
  476. setTimeout(() => {
  477. this.resultAudioContext.play();
  478. }, 200)
  479. this.setData({
  480. exampleState: true
  481. })
  482. } else {
  483. if (this.data.readingReset) {
  484. this.resultAudioContext.src = this.data.readDetail.tempFilePath;
  485. this.resultAudioContext.play();
  486. this.setData({
  487. muted: true,
  488. exampleState: true
  489. })
  490. } else {
  491. this.setData({
  492. muted: false,
  493. exampleState: true
  494. })
  495. }
  496. this.setData({
  497. videoPath: this.data.videoInfo.userRead.videoPath
  498. })
  499. wx.nextTick(() => {
  500. this.videoContext.play()
  501. })
  502. }
  503. submitPlayLog({
  504. userReadId: this.data.videoInfo.userRead.exampleId,
  505. playStopTime: 1000
  506. })
  507. },
  508. // 控制视频或音频的播放状态
  509. async playMediaState() {
  510. this.setData({
  511. muted: false
  512. })
  513. if (this.data.videoInfo.userReadExtend.resourcesType == 0) {
  514. this.setData({
  515. videoPath: this.data.videoInfo.userRead.originVideo
  516. })
  517. wx.nextTick(() => {
  518. this.videoContext.play()
  519. })
  520. } else {
  521. this.innerAudioContext.play();
  522. }
  523. await userEvent({
  524. action: 'READING',
  525. readId: this.data.videoInfo.userRead.id
  526. })
  527. },
  528. // 重置一切状态
  529. resetReading() {
  530. clearTimeout(this.setTimeoutObj)
  531. clearInterval(this.stl)
  532. // 重置视频
  533. if (this.data.videoInfo.userReadExtend.resourcesType == 0) {
  534. this.videoContext.stop()
  535. this.videoContext.seek(0)
  536. }
  537. // 重置试听音频
  538. if (this.data.exampleState) {
  539. this.resultAudioContext.stop()
  540. // 重置录音时的背景音乐
  541. this.innerAudioContext.stop();
  542. console.log('是我暂停了');
  543. }
  544. if (this.data.state) {
  545. // 重置录音时的背景音乐
  546. this.innerAudioContext.stop();
  547. /*微信录音结束*/
  548. recorderManager.stop();
  549. }
  550. this.setData({
  551. exampleState: false,
  552. state: false,
  553. currentRow: null,
  554. scrollTop: 0,
  555. ["silderData.sliderValue"]: 0,
  556. ["silderData.currentTime"]: '00:00'
  557. })
  558. },
  559. // 获取设备高度与行高度
  560. getHeight() {
  561. var query = wx.createSelectorQuery();
  562. query.select('.content').boundingClientRect((rect) => {
  563. this.setData({
  564. contentH: rect.height
  565. })
  566. }).exec()
  567. query.select('.row').boundingClientRect((rect) => {
  568. this.rowH = rect.height
  569. }).exec()
  570. },
  571. // 进度条
  572. slider({
  573. detail
  574. }) {
  575. this.resultAudioContext.pause();
  576. console.log(detail.value / 100 * this.data.videoInfo.userRead.duration)
  577. this.resultAudioContext.seek(detail.value / 100 * this.data.videoInfo.userRead.duration)
  578. setTimeout(() => {
  579. this.resultAudioContext.play()
  580. }, 300)
  581. },
  582. onHide() {
  583. console.log('结束了吗');
  584. this.resetReading()
  585. },
  586. onUnload() {
  587. console.log('结束了吗22222');
  588. this.resetReading()
  589. this.storeBindings.destroyStoreBindings()
  590. },
  591. creatShare() {
  592. return new Promise((resolve, reject) => {
  593. let video = this.data.videoInfo
  594. let context = wx.createSelectorQuery();
  595. context
  596. .select('#share')
  597. .fields({
  598. node: true,
  599. size: true
  600. }).exec((res) => {
  601. const canvas = res[0].node;
  602. const ctx = canvas.getContext('2d');
  603. const dpr = wx.getSystemInfoSync().pixelRatio;
  604. canvas.width = res[0].width * dpr;
  605. canvas.height = res[0].height * dpr;
  606. ctx.scale(dpr, dpr);
  607. ctx.font = '14px PingFang';
  608. let pic = canvas.createImage();
  609. pic.src = video.userReadExtend && video.userReadExtend.resourcesType == 1 ? video.userReadExtend.backgroundVirtualImg : video.userRead.coverImg;
  610. pic.onload = () => {
  611. ctx.drawImage(pic, 0, 0, 375, 211);
  612. let peiyin = canvas.createImage();
  613. peiyin.src = '/static/peiyin.jpg';
  614. peiyin.onload = () => {
  615. ctx.drawImage(peiyin, 0, 211, 375, 89);
  616. //分享
  617. let fx = canvas.createImage();
  618. fx.src = '/static/share.png'
  619. fx.onload = () => {
  620. ctx.drawImage(fx, 12, 220, 20, 20)
  621. ctx.fillText('分享', 36, 238)
  622. // 收藏,一个一个渲染
  623. let sc = canvas.createImage();
  624. sc.src = '/static/no_collect.png'
  625. sc.onload = () => {
  626. ctx.drawImage(sc, 110, 220, 19, 19)
  627. ctx.fillText('收藏', 134, 238)
  628. //点赞
  629. let dz = canvas.createImage();
  630. dz.src = '/static/heart.png'
  631. dz.onload = () => {
  632. ctx.drawImage(dz, 318, 222, 22, 22)
  633. ctx.fillText(0, 254, 238)
  634. // 评论
  635. let pl = canvas.createImage();
  636. pl.src = '/static/comment.png'
  637. pl.onload = () => {
  638. ctx.drawImage(pl, 228, 222, 22, 22)
  639. ctx.fillText(0, 340, 238)
  640. if (video.userReadExtend.resourcesType == 1) {
  641. let aBg = canvas.createImage();
  642. aBg.src = '/static/shareAudioBg.png';
  643. aBg.onload = () => {
  644. ctx.drawImage(aBg, 127.5, 38, 120, 120);
  645. let rate = 0.5
  646. ctx.arc(
  647. Math.floor(375 * rate),
  648. 98,
  649. Math.floor(100 * rate),
  650. 0,
  651. 2 * Math.PI
  652. );
  653. ctx.clip() //裁剪
  654. let coverImg = canvas.createImage();
  655. coverImg.src = video.userRead.coverImg;
  656. coverImg.onload = () => {
  657. ctx.drawImage( //定位在圆圈范围内便会出现
  658. coverImg, //图片暂存路径
  659. 129, 42,
  660. 110, 110,
  661. );
  662. ctx.restore()
  663. }
  664. }
  665. }
  666. setTimeout(() => {
  667. wx.canvasToTempFilePath({
  668. canvas: canvas,
  669. success(res) {
  670. resolve({
  671. title: '我的新作品发布啦,快来捧场点赞!',
  672. path: `/pages/pkPage/index?videoId=${wx.getStorageSync('shareVideoId')}&uid=${wx.getStorageSync('uid')}&isShare=true`,
  673. imageUrl: res.tempFilePath
  674. })
  675. },
  676. fail(res) {
  677. reject()
  678. }
  679. }, this)
  680. }, 500)
  681. }
  682. }
  683. }
  684. }
  685. }
  686. }
  687. })
  688. })
  689. },
  690. onShareAppMessage({
  691. from,
  692. target
  693. }) {
  694. if (from == 'button') {
  695. const promise = new Promise(resolve => {
  696. this.creatShare().then(res => {
  697. resolve(res)
  698. })
  699. })
  700. return {
  701. title: '我的新作品发布啦,快来捧场点赞!',
  702. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  703. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg',
  704. promise
  705. }
  706. } else {
  707. return {
  708. title: '自从用了它,家里朗朗书声,美妙极了!你家孩子也快来试试!',
  709. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  710. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg'
  711. }
  712. }
  713. },
  714. })