index.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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. console.log('评测结果', detail);
  371. this.setReadDetail(detail)
  372. if (this.data.readingType == 'public' || this.data.readingType == 'readMatch') {
  373. wx.navigateTo({
  374. url: `/pages/score/index?readingType=${this.data.readingType}&activityId=${this.data.activityId}`,
  375. events: {
  376. // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
  377. goback: (data) => {
  378. this.setData({
  379. readingReset: data.reset || false,
  380. readingType: data.readingType || 'public',
  381. uploadHide: data.uploadHide
  382. })
  383. }
  384. },
  385. })
  386. } else {
  387. this.uploadAudio()
  388. }
  389. },
  390. // 挑战录音上传
  391. uploadAudio() {
  392. this.setData({
  393. uploadState: true
  394. })
  395. const uploadTask = wx.uploadFile({
  396. url: 'https://reader-api.ai160.com//file/upload',
  397. filePath: this.data.tempFilePath,
  398. name: '朗读录音',
  399. header: {
  400. uid: wx.getStorageSync('uid')
  401. },
  402. success: async (res) => {
  403. const formateRes = JSON.parse(res.data);
  404. let audioPath = formateRes.data;
  405. let uploadRes = await publishWorks({
  406. exampleId: this.data.pkData.exampleId,
  407. audioPath,
  408. })
  409. let _data = this.data.readDetail
  410. let scoreRes = await postWorksScore({
  411. "userReadId": uploadRes.id,
  412. "complete": _data.integrity,
  413. "accuracy": _data.accuracy,
  414. "speed": _data.fluency,
  415. "intonation": _data.tone,
  416. "score": _data.myOverall
  417. })
  418. console.log({
  419. "userReadId": uploadRes.id,
  420. "complete": _data.integrity,
  421. "accuracy": _data.accuracy,
  422. "speed": _data.fluency,
  423. "intonation": _data.tone,
  424. "score": _data.myOverall
  425. }, 'score', scoreRes, 'scoreRes');
  426. let data = {
  427. challengerUserReadId: uploadRes.id,
  428. userReadId: this.data.pkData.id,
  429. winnerUId: this.data.pkData.score > _data.myOverall ? this.data.pkData.uid : this.data.pkData.score == _data.myOverall ? '' : wx.getStorageSync('uid')
  430. }
  431. let result = await uploadPk(data)
  432. await userEvent({
  433. action: 'WXPKUPLOAD',
  434. })
  435. wx.redirectTo({
  436. url: `/pages/pkResult/index?id=${result.id}`
  437. })
  438. },
  439. complete: () => {
  440. this.setData({
  441. uploadState: false
  442. })
  443. }
  444. });
  445. uploadTask.onProgressUpdate((res) => {
  446. this.setData({
  447. percent: res.progress
  448. })
  449. })
  450. },
  451. // 字体换行
  452. startRecording() {
  453. setTimeout(() => {
  454. if (this.data.currentRow == null) {
  455. this.setData({
  456. currentRow: 0
  457. })
  458. }
  459. let row = this.data.article[this.data.currentRow]
  460. if (!row.readTime) {
  461. return
  462. }
  463. this.setTimeoutObj = setTimeout(() => {
  464. this.setData({
  465. currentRow: ++this.data.currentRow
  466. })
  467. this.setData({
  468. scrollTop: this.rowH * this.data.currentRow
  469. })
  470. this.startRecording()
  471. },
  472. row.readTime);
  473. }, 100)
  474. },
  475. // 视频播放结束
  476. videoEnd() {
  477. this.resetReading()
  478. },
  479. videoPlay() {
  480. if (this.data.state) {
  481. return
  482. }
  483. if (this.data.videoInfo.userReadExtend.resourcesType == 1) {
  484. if (this.data.exampleState) {
  485. this.setData({
  486. exampleState: false
  487. })
  488. return this.resultAudioContext.stop()
  489. }
  490. this.resultAudioContext.src = this.data.readingReset ? this.data.readDetail.tempFilePath : this.data.videoInfo.userRead.audioPath;
  491. setTimeout(() => {
  492. this.resultAudioContext.play();
  493. }, 200)
  494. this.setData({
  495. exampleState: true
  496. })
  497. } else {
  498. if (this.data.readingReset) {
  499. this.resultAudioContext.src = this.data.readDetail.tempFilePath;
  500. this.resultAudioContext.play();
  501. this.setData({
  502. muted: true,
  503. exampleState: true
  504. })
  505. } else {
  506. this.setData({
  507. muted: false,
  508. exampleState: true
  509. })
  510. }
  511. this.setData({
  512. videoPath: this.data.videoInfo.userRead.videoPath
  513. })
  514. wx.nextTick(() => {
  515. this.videoContext.play()
  516. })
  517. }
  518. submitPlayLog({
  519. userReadId: this.data.videoInfo.userRead.exampleId,
  520. playStopTime: 1000
  521. })
  522. },
  523. // 控制视频或音频的播放状态
  524. async playMediaState() {
  525. this.setData({
  526. muted: false
  527. })
  528. if (this.data.videoInfo.userReadExtend.resourcesType == 0) {
  529. this.setData({
  530. videoPath: this.data.videoInfo.userRead.originVideo
  531. })
  532. wx.nextTick(() => {
  533. this.videoContext.play()
  534. })
  535. } else {
  536. this.innerAudioContext.play();
  537. }
  538. await userEvent({
  539. action: 'WXREADING',
  540. readId: this.data.videoInfo.userRead.id
  541. })
  542. },
  543. // 重置一切状态
  544. resetReading() {
  545. clearTimeout(this.setTimeoutObj)
  546. clearInterval(this.stl)
  547. // 重置视频
  548. if (this.data.videoInfo.userReadExtend.resourcesType == 0) {
  549. this.videoContext.stop()
  550. this.videoContext.seek(0)
  551. }
  552. // 重置试听音频
  553. if (this.data.exampleState) {
  554. this.resultAudioContext.stop()
  555. // 重置录音时的背景音乐
  556. this.innerAudioContext.stop();
  557. console.log('是我暂停了');
  558. }
  559. if (this.data.state) {
  560. // 重置录音时的背景音乐
  561. this.innerAudioContext.stop();
  562. /*微信录音结束*/
  563. recorderManager.stop();
  564. }
  565. this.setData({
  566. exampleState: false,
  567. state: false,
  568. currentRow: null,
  569. scrollTop: 0,
  570. ["silderData.sliderValue"]: 0,
  571. ["silderData.currentTime"]: '00:00'
  572. })
  573. },
  574. // 获取设备高度与行高度
  575. getHeight() {
  576. var query = wx.createSelectorQuery();
  577. query.select('.content').boundingClientRect((rect) => {
  578. this.setData({
  579. contentH: rect.height
  580. })
  581. }).exec()
  582. query.select('.row').boundingClientRect((rect) => {
  583. this.rowH = rect.height
  584. }).exec()
  585. },
  586. // 进度条
  587. slider({
  588. detail
  589. }) {
  590. this.resultAudioContext.pause();
  591. this.resultAudioContext.seek(detail.value / 100 * this.data.videoInfo.userRead.duration)
  592. setTimeout(() => {
  593. this.resultAudioContext.play()
  594. }, 300)
  595. },
  596. onHide() {
  597. console.log('结束了吗');
  598. this.resetReading()
  599. },
  600. onUnload() {
  601. this.resetReading()
  602. this.storeBindings.destroyStoreBindings()
  603. },
  604. backReading() {
  605. wx.navigateBack({
  606. delta: 1
  607. })
  608. },
  609. creatShare() {
  610. return new Promise((resolve, reject) => {
  611. let video = this.data.videoInfo
  612. let context = wx.createSelectorQuery();
  613. context
  614. .select('#share')
  615. .fields({
  616. node: true,
  617. size: true
  618. }).exec((res) => {
  619. const canvas = res[0].node;
  620. const ctx = canvas.getContext('2d');
  621. const dpr = wx.getSystemInfoSync().pixelRatio;
  622. canvas.width = res[0].width * dpr;
  623. canvas.height = res[0].height * dpr;
  624. ctx.scale(dpr, dpr);
  625. ctx.font = '14px PingFang';
  626. let pic = canvas.createImage();
  627. pic.src = video.userReadExtend && video.userReadExtend.resourcesType == 1 ? video.userReadExtend.backgroundVirtualImg : video.userRead.coverImg;
  628. pic.onload = () => {
  629. ctx.drawImage(pic, 0, 0, 375, 211);
  630. let peiyin = canvas.createImage();
  631. peiyin.src = '/static/peiyin.jpg';
  632. peiyin.onload = () => {
  633. ctx.drawImage(peiyin, 0, 211, 375, 89);
  634. //分享
  635. let fx = canvas.createImage();
  636. fx.src = '/static/share.png'
  637. fx.onload = () => {
  638. ctx.drawImage(fx, 12, 220, 20, 20)
  639. ctx.fillText('分享', 36, 238)
  640. // 收藏,一个一个渲染
  641. let sc = canvas.createImage();
  642. sc.src = '/static/no_collect.png'
  643. sc.onload = () => {
  644. ctx.drawImage(sc, 110, 220, 19, 19)
  645. ctx.fillText('收藏', 134, 238)
  646. //点赞
  647. let dz = canvas.createImage();
  648. dz.src = '/static/heart.png'
  649. dz.onload = () => {
  650. ctx.drawImage(dz, 318, 222, 22, 22)
  651. ctx.fillText(0, 254, 238)
  652. // 评论
  653. let pl = canvas.createImage();
  654. pl.src = '/static/comment.png'
  655. pl.onload = () => {
  656. ctx.drawImage(pl, 228, 222, 22, 22)
  657. ctx.fillText(0, 340, 238)
  658. if (video.userReadExtend.resourcesType == 1) {
  659. let aBg = canvas.createImage();
  660. aBg.src = '/static/shareAudioBg.png';
  661. aBg.onload = () => {
  662. ctx.drawImage(aBg, 127.5, 38, 120, 120);
  663. let rate = 0.5
  664. ctx.arc(
  665. Math.floor(375 * rate),
  666. 98,
  667. Math.floor(100 * rate),
  668. 0,
  669. 2 * Math.PI
  670. );
  671. ctx.clip() //裁剪
  672. let coverImg = canvas.createImage();
  673. coverImg.src = video.userRead.coverImg;
  674. coverImg.onload = () => {
  675. ctx.drawImage( //定位在圆圈范围内便会出现
  676. coverImg, //图片暂存路径
  677. 129, 42,
  678. 110, 110,
  679. );
  680. ctx.restore()
  681. }
  682. }
  683. }
  684. setTimeout(() => {
  685. console.log(wx.getStorageSync('shareVideoId'), 'reading-wx.getStorageSync');
  686. wx.canvasToTempFilePath({
  687. canvas: canvas,
  688. success(res) {
  689. resolve({
  690. title: '我的新作品发布啦,快来捧场点赞!',
  691. path: `/pages/pkPage/index?videoId=${wx.getStorageSync('shareVideoId')}&uid=${wx.getStorageSync('uid')}&isShare=true`,
  692. imageUrl: res.tempFilePath
  693. })
  694. },
  695. fail(res) {
  696. reject()
  697. }
  698. }, this)
  699. }, 500)
  700. }
  701. }
  702. }
  703. }
  704. }
  705. }
  706. })
  707. })
  708. },
  709. onShareAppMessage({
  710. from,
  711. target
  712. }) {
  713. if (from == 'button') {
  714. const promise = new Promise(resolve => {
  715. this.creatShare().then(res => {
  716. resolve(res)
  717. })
  718. })
  719. return {
  720. title: '我的新作品发布啦,快来捧场点赞!',
  721. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  722. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg',
  723. promise
  724. }
  725. } else {
  726. return {
  727. title: '自从用了它,家里朗朗书声,美妙极了!你家孩子也快来试试!',
  728. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  729. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg'
  730. }
  731. }
  732. },
  733. })