index.js 22 KB

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