123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import behavior from '~/mixins/video'
- import {
- getreadInfo
- } from '~/api/video'
- Page({
- behaviors: [behavior],
- data: {
- videoInfo: {}
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- let videoId = options.videoId
- this.getreadInfo(videoId)
- },
- async getreadInfo(videoId) {
- let videoInfo = await getreadInfo(videoId)
- wx.setNavigationBarTitle({
- title: videoInfo.userRead.title
- })
- this.setData({
- videoInfo
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- creatShare(video) {
- return new Promise((resolve, reject) => {
- let context = wx.createSelectorQuery();
- context
- .select('#share')
- .fields({
- node: true,
- size: true
- }).exec((res) => {
- const canvas = res[0].node;
- const ctx = canvas.getContext('2d');
- const dpr = wx.getSystemInfoSync().pixelRatio;
- canvas.width = res[0].width * dpr;
- canvas.height = res[0].height * dpr;
- ctx.scale(dpr, dpr);
- ctx.font = '14px PingFang';
- let pic = canvas.createImage();
- pic.src = video.userRead.coverImg; //可以是本地,也可以是网络图片
- pic.onload = () => {
- ctx.drawImage(pic, 0, 0, 375, 211);
- }
- let peiyin = canvas.createImage();
- peiyin.src = '/static/peiyin.jpg';
- peiyin.onload = () => {
- ctx.drawImage(peiyin, 0, 211, 375, 89);
- // 收藏,一个一个渲染
- let sc = canvas.createImage();
- sc.src = '/static/star.png'
- sc.onload = () => {
- ctx.drawImage(sc, 12, 220, 20, 20)
- ctx.fillText('收藏', 36, 238)
- //分享
- let fx = canvas.createImage();
- fx.src = '/static/share.png'
- fx.onload = () => {
- ctx.drawImage(fx, 78, 220, 22, 22)
- ctx.fillText('分享', 104, 238)
- //点赞
- let dz = canvas.createImage();
- dz.src = video.isLike ? '/static/heart_colored.png' : '/static/heart.png'
- dz.onload = () => {
- ctx.drawImage(dz, 258, 222, 22, 22)
- ctx.fillText(video.userRead.likeAmount, 284, 238)
- //评论
- let pl = canvas.createImage();
- pl.src = '/static/comment.png'
- pl.onload = () => {
- ctx.drawImage(pl, 318, 222, 22, 22)
- ctx.fillText(video.userRead.commentAmount, 340, 238)
- setTimeout(() => {
- wx.canvasToTempFilePath({
- canvas: canvas,
- success(res) {
- resolve({
- title: '请欣赏我的课文朗读作品,点赞+评论。',
- path: `/pages/index/index?readId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}`,
- imageUrl: res.tempFilePath
- })
- },
- fail(res) {
- reject()
- }
- }, this)
- }, 500)
- }
- }
- }
- }
- }
- })
- })
- },
- onShareAppMessage({
- from,
- target
- }) {
- if (from == 'button') {
- let video = this.data.videoInfo
- const promise = new Promise(resolve => {
- this.creatShare(video).then(res => {
- resolve(res)
- })
- })
- return {
- title: '请欣赏我的课文朗读作品,点赞+评论。',
- path: `/pages/index/index?readId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}`,
- imageUrl: video.userRead.coverImg,
- promise
- }
- } else {
- return {
- title: '课文朗读,从未如此有趣。',
- path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
- imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
- }
- }
- },
- onHide() {
- this.setData({
- currentId: ''
- })
- }
- })
|