index.js 23 KB

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