index.js 21 KB

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