index.js 22 KB

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