index.js 23 KB

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