Commit 710fbe2b72c9a0a5209d14e623ced31f9f46fc32

Authored by taiyuan
1 parent 93cb23de

直播

packageA/pages/liveStream/liveStream.js
@@ -44,12 +44,12 @@ Page({ @@ -44,12 +44,12 @@ Page({
44 wx.navigateTo({ 44 wx.navigateTo({
45 url: '/packageA/pages/liveStreamDetails/liveStreamDetails?id=' + e.currentTarget.dataset.id + '&live=' + e.currentTarget.dataset.live 45 url: '/packageA/pages/liveStreamDetails/liveStreamDetails?id=' + e.currentTarget.dataset.id + '&live=' + e.currentTarget.dataset.live
46 }) 46 })
47 - console.log('options-->'); 47 + // console.log('options-->');
48 }, 48 },
49 49
50 // 点击 订阅/观看直播/观看回放 按钮,跳转直播组件 50 // 点击 订阅/观看直播/观看回放 按钮,跳转直播组件
51 clickLive: function (e) { 51 clickLive: function (e) {
52 - console.log('当前房间号roomid:', e.currentTarget.dataset.roomid); 52 + // console.log('当前房间号roomid:', e.currentTarget.dataset.roomid);
53 let roomId = e.currentTarget.dataset.roomid; 53 let roomId = e.currentTarget.dataset.roomid;
54 let customParams = encodeURIComponent(JSON.stringify({ 54 let customParams = encodeURIComponent(JSON.stringify({
55 path: 'pages/index/index', 55 path: 'pages/index/index',
@@ -77,74 +77,74 @@ Page({ @@ -77,74 +77,74 @@ Page({
77 }); 77 });
78 }, 78 },
79 79
80 - loadLiveList: function (curPage) {  
81 - // console.log('---->curPage', curPage);  
82 - // var live = {};  
83 - // live.toBegin = []; // 即将开始  
84 - // live.ing = []; // 直播中  
85 - // var liveOver = []; // 已结束  
86 - var that = this;  
87 - var storeId = o.stoid;  
88 -  
89 - // 请求数据  
90 - getApp().request.promiseGet("/api/weshop/wx/livelist/page", {  
91 - data: {  
92 - storedId: o.stoid,  
93 - page: curPage,  
94 - live_status: 103  
95 - }  
96 - }).then(res => {  
97 - if (res.data.code == 0) {  
98 - console.log('res------------>', res);  
99 - // 计算总页数  
100 - // var total = res.data.data.total;  
101 - // console.log("total", total);  
102 - // var pageSize = res.data.data.pageSize;  
103 - // console.log("pageSize", pageSize);  
104 - // var pageNum = that.pageTotal(total, pageSize);  
105 - // that.setData({  
106 - // pageNum: that.pageTotal(total, pageSize)  
107 - // });  
108 -  
109 - // 如果当前请求的是第一页数据,则执行赋值,否则执行合并再赋值  
110 - if (curPage == 1) {  
111 - that.setData({  
112 - liveOver: that.data.liveOver.concat(res.data.data.pageData)  
113 - })  
114 - } else {  
115 - that.setData({  
116 - liveOver: that.data.liveOver.concat(res.data.data.pageData)  
117 - })  
118 - };  
119 -  
120 - // var list = that.data.list;  
121 - // for(var i in list) {  
122 - // var liveStatus = list[i].live_status;  
123 - // if (liveStatus == '101') {  
124 - // live.ing.push(list[i]);  
125 - // } else if (liveStatus == '102') {  
126 - // live.toBegin.push(list[i]);  
127 - // } else if (liveStatus == '103') {  
128 - // live.over.push(list[i]);  
129 - // }  
130 - // }  
131 -  
132 - // that.setData({  
133 - // liveOver: list  
134 - // });  
135 -  
136 - curPage++;  
137 - that.setData({  
138 - curPage  
139 - });  
140 -  
141 - console.log('上拉已经触发,当前page------------------------->',that.data.curPage);  
142 -  
143 - } else {  
144 - console.error('请求失败!!!!!');  
145 - }  
146 - })  
147 - }, 80 + // loadLiveList: function (curPage) {
  81 + // // console.log('---->curPage', curPage);
  82 + // // var live = {};
  83 + // // live.toBegin = []; // 即将开始
  84 + // // live.ing = []; // 直播中
  85 + // // var liveOver = []; // 已结束
  86 + // var that = this;
  87 + // var storeId = o.stoid;
  88 +
  89 + // // 请求数据
  90 + // getApp().request.promiseGet("/api/weshop/wx/livelist/page", {
  91 + // data: {
  92 + // storedId: o.stoid,
  93 + // page: curPage,
  94 + // live_status: 103
  95 + // }
  96 + // }).then(res => {
  97 + // if (res.data.code == 0) {
  98 + // // console.log('res------------>', res);
  99 + // // 计算总页数
  100 + // // var total = res.data.data.total;
  101 + // // console.log("total", total);
  102 + // // var pageSize = res.data.data.pageSize;
  103 + // // console.log("pageSize", pageSize);
  104 + // // var pageNum = that.pageTotal(total, pageSize);
  105 + // // that.setData({
  106 + // // pageNum: that.pageTotal(total, pageSize)
  107 + // // });
  108 +
  109 + // // 如果当前请求的是第一页数据,则执行赋值,否则执行合并再赋值
  110 + // if (curPage == 1) {
  111 + // that.setData({
  112 + // liveOver: that.data.liveOver.concat(res.data.data.pageData)
  113 + // })
  114 + // } else {
  115 + // that.setData({
  116 + // liveOver: that.data.liveOver.concat(res.data.data.pageData)
  117 + // })
  118 + // };
  119 +
  120 + // // var list = that.data.list;
  121 + // // for(var i in list) {
  122 + // // var liveStatus = list[i].live_status;
  123 + // // if (liveStatus == '101') {
  124 + // // live.ing.push(list[i]);
  125 + // // } else if (liveStatus == '102') {
  126 + // // live.toBegin.push(list[i]);
  127 + // // } else if (liveStatus == '103') {
  128 + // // live.over.push(list[i]);
  129 + // // }
  130 + // // }
  131 +
  132 + // // that.setData({
  133 + // // liveOver: list
  134 + // // });
  135 +
  136 + // curPage++;
  137 + // that.setData({
  138 + // curPage
  139 + // });
  140 +
  141 + // console.log('上拉已经触发,当前page------------------------->',that.data.curPage);
  142 +
  143 + // } else {
  144 + // console.error('请求失败!!!!!');
  145 + // }
  146 + // })
  147 + // },
148 148
149 // pageTotal: function (rowCount, pageSize) { 149 // pageTotal: function (rowCount, pageSize) {
150 // if (rowCount == null || rowCount == "") { 150 // if (rowCount == null || rowCount == "") {
@@ -338,7 +338,7 @@ Page({ @@ -338,7 +338,7 @@ Page({
338 // }) 338 // })
339 // } 339 // }
340 340
341 - console.log('触底啦'); 341 + // console.log('触底啦');
342 this.scrollToLower('/api/weshop/wx/livelist/page', { 342 this.scrollToLower('/api/weshop/wx/livelist/page', {
343 storedId: o.stoid, 343 storedId: o.stoid,
344 live_status: 103 344 live_status: 103
@@ -351,7 +351,7 @@ Page({ @@ -351,7 +351,7 @@ Page({
351 onShareAppMessage: function () { 351 onShareAppMessage: function () {
352 if (res.from === 'button') { 352 if (res.from === 'button') {
353 // 来自页面内转发按钮 353 // 来自页面内转发按钮
354 - console.log(res.target) 354 + // console.log(res.target)
355 } 355 }
356 return { 356 return {
357 title: '直播列表' 357 title: '直播列表'
@@ -362,7 +362,7 @@ Page({ @@ -362,7 +362,7 @@ Page({
362 onShareTimeline: function (res) { 362 onShareTimeline: function (res) {
363 if (res.from === 'button') { 363 if (res.from === 'button') {
364 // 来自页面内转发按钮 364 // 来自页面内转发按钮
365 - console.log(res.target) 365 + // console.log(res.target)
366 } 366 }
367 return { 367 return {
368 title: '直播列表' 368 title: '直播列表'
packageA/pages/liveStreamDetails/liveStreamDetails.js
@@ -79,14 +79,18 @@ Page({ @@ -79,14 +79,18 @@ Page({
79 //生成海报 79 //生成海报
80 createPlaybill: function () { 80 createPlaybill: function () {
81 // 1.提示 “正在生成海报...” 81 // 1.提示 “正在生成海报...”
  82 + wx.showLoading({
  83 + title: '正在生成海报...'
  84 + });
82 85
83 - // 2.生成海报,如果生成完毕,关闭提示  
84 - this.drawPlaybill();  
85 // 3.展示生成的海报 86 // 3.展示生成的海报
86 this.setData({ 87 this.setData({
87 showActionSheet: 'false', 88 showActionSheet: 'false',
88 - showPlaybill: !this.data.showPlaybill 89 + // showPlaybill: !this.data.showPlaybill
89 }); 90 });
  91 +
  92 + // 2.生成海报,如果生成完毕,关闭提示
  93 + this.drawPlaybill();
90 94
91 }, 95 },
92 96
@@ -103,8 +107,8 @@ Page({ @@ -103,8 +107,8 @@ Page({
103 }) 107 })
104 } 108 }
105 }); 109 });
106 - console.log('宽度',this.data.windowWidth);  
107 - console.log('高度',this.data.windowHeight); 110 + // console.log('宽度',this.data.windowWidth);
  111 + // console.log('高度',this.data.windowHeight);
108 }, 112 },
109 113
110 //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 114 //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度
@@ -140,9 +144,9 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un @@ -140,9 +144,9 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un
140 144
141 // 生成海报 145 // 生成海报
142 drawPlaybill: function () { 146 drawPlaybill: function () {
143 - wx.showLoading({  
144 - title: '正在生成海报...'  
145 - }); 147 + // wx.showLoading({
  148 + // title: '正在生成海报...'
  149 + // });
146 150
147 // 数据准备 151 // 数据准备
148 const title = this.data.details.name; 152 const title = this.data.details.name;
@@ -196,26 +200,52 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un @@ -196,26 +200,52 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un
196 ctx.fillText(this.data.nickName, 106, 60); 200 ctx.fillText(this.data.nickName, 106, 60);
197 201
198 // 绘制主图 202 // 绘制主图
199 - ctx.drawImage(this.data.coverImg, 0, 104, 480, 382);  
200 - // ctx.draw(true); 203 + ctx.setFillStyle('#f8f8f8');
  204 + ctx.fillRect(0, 104, 480, 380);
  205 +
  206 + // var w = this.data.coverImgWidth;
  207 + // var h = this.data.coverImgHeight;
  208 + var w = this.data.coverImgSize.imageWidth;
  209 + var h = this.data.coverImgSize.imageHeight;
  210 + // var dw = 480/w //canvas与图片的宽高比
  211 + // var dh = 380/h
  212 + // var ratio
  213 + // // 裁剪图片中间部分
  214 + // if(w > 480 && h > 380 || w < 480 && h < 380){
  215 + // if (dw > dh) {
  216 + // ctx.drawImage(this.data.coverImg, 0, (h - 380/dw)/2, w, 380/dw, 0, 104, 480, 380);
  217 + // } else {
  218 + // ctx.drawImage(this.data.coverImg, (w - 480/dh)/2, 0, 480/dh, h, 0, 104, 480, 380);
  219 + // };
  220 + // }
  221 + // // 拉伸图片
  222 + // else{
  223 + // if(w < 300){
  224 + // ctx.drawImage(this.data.coverImg, 0, (h - 380/dw)/2, w, 380/dw, 0, 104, 480, 380);
  225 + // }else {
  226 + // ctx.drawImage(this.data.coverImg, (w - 480/dh)/2, 0, 480/dh, h, 0, 104, 480, 380);
  227 + // }
  228 + // };
  229 + ctx.drawImage(this.data.coverImg, (480-w)/2, (380-h)/2+104, w, h);
  230 +
201 231
202 // 绘制文字 232 // 绘制文字
203 ctx.setFontSize(24); 233 ctx.setFontSize(24);
204 ctx.setFillStyle('#1E1E1E'); 234 ctx.setFillStyle('#1E1E1E');
205 - this.drawText(ctx, title, 51, 563, 300, 360, 2); 235 + this.drawText(ctx, title, 30, 600, 200, 460, 2);
206 236
207 // 绘制小程序码 237 // 绘制小程序码
208 - ctx.drawImage(this.data.ewm, 310, 525, 132, 132);  
209 - // ctx.draw(true); 238 + ctx.drawImage(this.data.ewm, 310, 540, 132, 132);
  239 +
210 240
211 //绘制文字:长按识别 241 //绘制文字:长按识别
212 ctx.setFontSize(20); 242 ctx.setFontSize(20);
213 ctx.setFillStyle('#1E1E1E'); 243 ctx.setFillStyle('#1E1E1E');
214 - ctx.fillText('长按识别小程序', 309, 675); 244 + ctx.fillText('长按识别小程序', 309, 710);
215 245
216 ctx.draw(true, function() { 246 ctx.draw(true, function() {
217 setTimeout(function() { 247 setTimeout(function() {
218 - console.log("我进来了~~~~~"); 248 + // console.log("我进来了~~~~~");
219 wx.canvasToTempFilePath({ 249 wx.canvasToTempFilePath({
220 x: 0, 250 x: 0,
221 y: 0, 251 y: 0,
@@ -228,10 +258,12 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un @@ -228,10 +258,12 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un
228 success: function(res) { 258 success: function(res) {
229 wx.hideLoading(); 259 wx.hideLoading();
230 that.setData({ 260 that.setData({
231 - canvasToImgPath: res.tempFilePath 261 + canvasToImgPath: res.tempFilePath,
  262 + showPlaybill: !that.data.showPlaybill
232 }); 263 });
  264 + // console.log('生成海报陈宫啦', that.data.canvasToImgPath);
233 // that.saveImageToPhotosAlbum(res.tempFilePath); 265 // that.saveImageToPhotosAlbum(res.tempFilePath);
234 - console.log('截图陈宫:', that.data.canvasToImgPath); 266 + // console.log('截图陈宫:', that.data.canvasToImgPath);
235 // wx.previewImage({ 267 // wx.previewImage({
236 // //将图片预览出来 268 // //将图片预览出来
237 // urls: [that.data.canvasToImgPath] 269 // urls: [that.data.canvasToImgPath]
@@ -446,9 +478,13 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un @@ -446,9 +478,13 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un
446 // 请求主图 478 // 请求主图
447 that.getImageInfo(that.data.details['share_img']).then(res => { 479 that.getImageInfo(that.data.details['share_img']).then(res => {
448 that.setData({ 480 that.setData({
449 - coverImg: res.path 481 + coverImg: res.path,
  482 + coverImgWidth: res.width,
  483 + coverImgHeight: res.height,
  484 + coverImgSize: that.imageResize(res.width, res.height),
  485 + // coverImgHeight: res.height,
450 }); 486 });
451 - console.log('主图加载成功~') 487 + // console.log('主图加载成功~', that.data.coverImgSize);
452 }); 488 });
453 489
454 // 请求头像 490 // 请求头像
@@ -568,7 +604,7 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un @@ -568,7 +604,7 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un
568 /** 604 /**
569 * 用户点击右上角分享 605 * 用户点击右上角分享
570 */ 606 */
571 - onShareAppMessage: function () { 607 + onShareAppMessage: function (res) {
572 this.setData({ 608 this.setData({
573 showActionSheet: 'false' 609 showActionSheet: 'false'
574 }) 610 })
@@ -597,6 +633,36 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un @@ -597,6 +633,36 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un
597 title: this.data.details.name 633 title: this.data.details.name
598 // path: '/page/user?id=123' 634 // path: '/page/user?id=123'
599 } 635 }
600 - } 636 + },
  637 +
  638 +
  639 + imageResize(imgWidth, imgHeight) {
  640 + var imageSize = {};
  641 + var originalWidth = imgWidth;//图片原始宽
  642 + var originalHeight = imgHeight;//图片原始高
  643 + var originalScale = originalHeight/originalWidth;//图片高宽比
  644 + // console.log('originalWidth: ' + originalWidth)
  645 + // console.log('originalHeight: ' + originalHeight)
  646 +
  647 + //获取屏幕宽高
  648 + var winWidth = 480;
  649 + var winHeight = 380;
  650 + var winScale = winHeight/winWidth;//屏幕高宽比
  651 + // console.log('windowWidth: ' + winWidth)
  652 + // console.log('windowHeight: ' + winHeight)
  653 + if(originalScale < winScale){//图片高宽比小于屏幕高宽比
  654 + //图片缩放后的宽为屏幕宽
  655 + imageSize.imageWidth = winWidth;
  656 + imageSize.imageHeight = (winWidth * originalHeight) / originalWidth;
  657 + }else{//图片高宽比大于屏幕高宽比
  658 + //图片缩放后的高为屏幕高
  659 + imageSize.imageHeight = winHeight;
  660 + imageSize.imageWidth = (winHeight * originalWidth) / originalHeight;
  661 + }
  662 + console.log('缩放后的宽: ' + imageSize.imageWidth)
  663 + console.log('缩放后的高: ' + imageSize.imageHeight)
  664 + return imageSize;
  665 + },
  666 +
601 667
602 }) 668 })
packageA/pages/liveStreamDetails/liveStreamDetails.wxml
@@ -75,7 +75,6 @@ @@ -75,7 +75,6 @@
75 <!-- 生成海报 --> 75 <!-- 生成海报 -->
76 <view class="{{showPlaybill ? 'playbill':'playbill active'}}" hidden="{{showPlaybill}}"> 76 <view class="{{showPlaybill ? 'playbill':'playbill active'}}" hidden="{{showPlaybill}}">
77 <image src="{{canvasToImgPath}}" class="playbill-pic" mode="widthFix" bindtap="closeWin"></image> 77 <image src="{{canvasToImgPath}}" class="playbill-pic" mode="widthFix" bindtap="closeWin"></image>
78 - <canvas canvas-id="myCanvas" catchtouchmove="true" style="width:480px;height:738px;position:absolute;left:5000%;"></canvas>  
79 <!-- style="width:{{windowWidth}}px;height:{{windowHeight}}px;" --> 78 <!-- style="width:{{windowWidth}}px;height:{{windowHeight}}px;" -->
80 <view class="playbill-save" bindtap="onSaveToPhone">保存至相册</view> 79 <view class="playbill-save" bindtap="onSaveToPhone">保存至相册</view>
81 </view> 80 </view>
@@ -88,5 +87,7 @@ @@ -88,5 +87,7 @@
88 87
89 </view> 88 </view>
90 89
  90 +<canvas canvas-id="myCanvas" catchtouchmove="true" style="width:480px;height:738px;position:absolute;left:-9999px;"></canvas>
  91 +
91 <!-- <canvas canvas-id="myCanvas" class="" catchtouchmove="true" style="width:480px;height:738px;position:absolute;left:5000%"></canvas> --> 92 <!-- <canvas canvas-id="myCanvas" class="" catchtouchmove="true" style="width:480px;height:738px;position:absolute;left:5000%"></canvas> -->
92 <!-- <canvas canvas-id='share' style='width:750rpx;height:1217rpx;' wx:if='{{!canvasHidden}}'></canvas> --> 93 <!-- <canvas canvas-id='share' style='width:750rpx;height:1217rpx;' wx:if='{{!canvasHidden}}'></canvas> -->