index.js 23 KB

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