Commit 463e69a3357a8a096dbafa2f44189edaedbbf3f3
1 parent
5202680b
直播海报优化
Showing
2 changed files
with
340 additions
and
301 deletions
packageA/pages/liveStream/liveStream.js
| ... | ... | @@ -10,7 +10,6 @@ var t = require("../../../utils/util"), |
| 10 | 10 | o = s.globalData.setting, |
| 11 | 11 | os = o; |
| 12 | 12 | var regeneratorRuntime = require('../../../utils/runtime.js'); |
| 13 | - | |
| 14 | 13 | const app = getApp(); |
| 15 | 14 | let self = null; |
| 16 | 15 | |
| ... | ... | @@ -22,14 +21,14 @@ Page({ |
| 22 | 21 | data: { |
| 23 | 22 | curPage: 1, |
| 24 | 23 | ad_data: null, |
| 25 | - sharimg:"", | |
| 24 | + sharimg: "", | |
| 26 | 25 | living: {}, |
| 27 | 26 | livetoBegin: {}, |
| 28 | 27 | liveOver: {}, |
| 29 | - list: null, | |
| 30 | - isLoading: false, // 检测是否已经发送请求,防止重复发送请求 | |
| 31 | - noMore: false, // 检测是否有更多数据,true为没有更多数据,false为还有数据 | |
| 32 | - pageNum: 1, // 当前页数 | |
| 28 | + list: null, | |
| 29 | + isLoading: false, // 检测是否已经发送请求,防止重复发送请求 | |
| 30 | + noMore: false, // 检测是否有更多数据,true为没有更多数据,false为还有数据 | |
| 31 | + pageNum: 1, // 当前页数 | |
| 33 | 32 | details: {}, |
| 34 | 33 | status: '', |
| 35 | 34 | btnText: '', |
| ... | ... | @@ -47,7 +46,7 @@ Page({ |
| 47 | 46 | canvasHidden: 1, |
| 48 | 47 | gid: '', |
| 49 | 48 | shareImgPath: '', |
| 50 | - shartitle:"" | |
| 49 | + shartitle: "" | |
| 51 | 50 | }, |
| 52 | 51 | // list: [], |
| 53 | 52 | // live: { |
| ... | ... | @@ -61,15 +60,15 @@ Page({ |
| 61 | 60 | // id:列表项id |
| 62 | 61 | // live:直播类别 即将开始/直播中/精彩回放 |
| 63 | 62 | |
| 64 | - if(e.currentTarget.dataset.live==101){ | |
| 65 | - var live_status = 'ing' | |
| 63 | + if (e.currentTarget.dataset.live == 101) { | |
| 64 | + var live_status = 'ing' | |
| 66 | 65 | } |
| 67 | - if(e.currentTarget.dataset.live==102){ | |
| 66 | + if (e.currentTarget.dataset.live == 102) { | |
| 68 | 67 | var live_status = 'toBegin' |
| 69 | - } | |
| 70 | - if(e.currentTarget.dataset.live==103){ | |
| 68 | + } | |
| 69 | + if (e.currentTarget.dataset.live == 103) { | |
| 71 | 70 | var live_status = 'over' |
| 72 | - } | |
| 71 | + } | |
| 73 | 72 | wx.navigateTo({ |
| 74 | 73 | url: '/packageA/pages/liveStreamDetails/liveStreamDetails?id=' + e.currentTarget.dataset.id + '&live=' + live_status |
| 75 | 74 | }) |
| ... | ... | @@ -98,9 +97,9 @@ Page({ |
| 98 | 97 | }, |
| 99 | 98 | success: function (res) { |
| 100 | 99 | // console.log('我发起了PUT请求,请求结果:', res.data); |
| 101 | - if(res.data.code == 0) { | |
| 102 | - resolve(); | |
| 103 | - }; | |
| 100 | + if (res.data.code == 0) { | |
| 101 | + resolve(); | |
| 102 | + }; | |
| 104 | 103 | } |
| 105 | 104 | }); |
| 106 | 105 | }); |
| ... | ... | @@ -237,10 +236,10 @@ Page({ |
| 237 | 236 | * 生命周期函数--监听页面加载 |
| 238 | 237 | */ |
| 239 | 238 | onLoad: function (options) { |
| 240 | - self=this; | |
| 241 | - getApp().is_Single_page(this,function(){ | |
| 242 | - app.isLogin().then(function(data) {//进入页面前已经授权登录成功 | |
| 243 | - self.setData({ | |
| 239 | + self = this; | |
| 240 | + getApp().is_Single_page(this, function () { | |
| 241 | + app.isLogin().then(function (data) {//进入页面前已经授权登录成功 | |
| 242 | + self.setData({ | |
| 244 | 243 | userInfo: data, |
| 245 | 244 | }); |
| 246 | 245 | }); |
| ... | ... | @@ -274,52 +273,53 @@ Page({ |
| 274 | 273 | * 生命周期函数--监听页面初次渲染完成 |
| 275 | 274 | */ |
| 276 | 275 | onReady: function () { |
| 277 | - | |
| 276 | + | |
| 278 | 277 | }, |
| 279 | 278 | |
| 279 | + | |
| 280 | 280 | /** |
| 281 | 281 | * 生命周期函数--监听页面显示 |
| 282 | 282 | */ |
| 283 | 283 | onShow: function () { |
| 284 | 284 | |
| 285 | - getApp().check_can_share(); | |
| 286 | - if(app.globalData.userInfo) { | |
| 287 | - if(!this.data.isLogin) { | |
| 288 | - this.setData({ | |
| 289 | - userInfo: app.globalData.userInfo, | |
| 290 | - imghost: app.globalData.setting.imghost, | |
| 291 | - isLogin: true, | |
| 292 | - }); | |
| 293 | - | |
| 294 | - this.updateLiveList().then(() => { | |
| 295 | - | |
| 296 | - self.getData(true, '/api/weshop/wx/livelist/page', { //请求直播中列表 | |
| 297 | - storedId: o.stoid, | |
| 285 | + getApp().check_can_share(); | |
| 286 | + if (app.globalData.userInfo) { | |
| 287 | + if (!this.data.isLogin) { | |
| 288 | + this.setData({ | |
| 289 | + userInfo: app.globalData.userInfo, | |
| 290 | + imghost: app.globalData.setting.imghost, | |
| 291 | + isLogin: true, | |
| 292 | + }); | |
| 293 | + | |
| 294 | + this.updateLiveList().then(() => { | |
| 295 | + | |
| 296 | + self.getData(true, '/api/weshop/wx/livelist/page', { //请求直播中列表 | |
| 297 | + storedId: o.stoid, | |
| 298 | 298 | pageSize: 100, |
| 299 | - ordertype:1, | |
| 300 | - liveshow:1 | |
| 301 | - }).then((res) => { | |
| 299 | + ordertype: 1, | |
| 300 | + liveshow: 1 | |
| 301 | + }).then((res) => { | |
| 302 | 302 | var list = self.data.list |
| 303 | - for(var i in list.pageData){ | |
| 303 | + for (var i in list.pageData) { | |
| 304 | 304 | var share_img = list.pageData[i].share_img |
| 305 | - list.pageData[i].share_img = share_img.replace("http://",'https://') | |
| 305 | + list.pageData[i].share_img = share_img.replace("http://", 'https://') | |
| 306 | 306 | } |
| 307 | - self.setData({ | |
| 308 | - living: list, | |
| 309 | - }); | |
| 310 | - | |
| 311 | - }); | |
| 312 | - | |
| 313 | - | |
| 314 | - | |
| 315 | - | |
| 316 | - | |
| 317 | - }); | |
| 318 | - | |
| 319 | - | |
| 320 | - | |
| 321 | - }; | |
| 322 | - }; | |
| 307 | + self.setData({ | |
| 308 | + living: list, | |
| 309 | + }); | |
| 310 | + | |
| 311 | + }); | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + }); | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + }; | |
| 322 | + }; | |
| 323 | 323 | }, |
| 324 | 324 | |
| 325 | 325 | /** |
| ... | ... | @@ -337,19 +337,19 @@ Page({ |
| 337 | 337 | }, |
| 338 | 338 | |
| 339 | 339 | |
| 340 | - | |
| 340 | + | |
| 341 | 341 | // 分享操作表 |
| 342 | 342 | clickShare: function (e) { |
| 343 | - var sharimg = e.currentTarget.dataset.sharimg | |
| 344 | - var shartitle = e.currentTarget.dataset.shartitle | |
| 345 | - if(!getApp().globalData.user_id){ | |
| 346 | - getApp().goto("/packageE/pages/togoin/togoin"); | |
| 347 | - return false; | |
| 343 | + var sharimg = e.currentTarget.dataset.sharimg | |
| 344 | + var shartitle = e.currentTarget.dataset.shartitle | |
| 345 | + if (!getApp().globalData.user_id) { | |
| 346 | + getApp().goto("/packageE/pages/togoin/togoin"); | |
| 347 | + return false; | |
| 348 | 348 | } |
| 349 | 349 | this.setData({ |
| 350 | 350 | showActionSheet: !this.data.showActionSheet, |
| 351 | - sharimg : sharimg, | |
| 352 | - shartitle:shartitle | |
| 351 | + sharimg: sharimg, | |
| 352 | + shartitle: shartitle | |
| 353 | 353 | }) |
| 354 | 354 | }, |
| 355 | 355 | |
| ... | ... | @@ -358,13 +358,13 @@ Page({ |
| 358 | 358 | this.setData({ |
| 359 | 359 | showActionSheet: 'false' |
| 360 | 360 | }) |
| 361 | - if(!this.data.showPlaybill) { | |
| 361 | + if (!this.data.showPlaybill) { | |
| 362 | 362 | this.setData({ |
| 363 | 363 | showPlaybill: 'true' |
| 364 | 364 | }); |
| 365 | 365 | } |
| 366 | 366 | }, |
| 367 | - | |
| 367 | + | |
| 368 | 368 | // 获取图片信息 |
| 369 | 369 | getImageInfo(src) { |
| 370 | 370 | return new Promise((resolve, reject) => { |
| ... | ... | @@ -389,29 +389,29 @@ Page({ |
| 389 | 389 | wx.showLoading({ |
| 390 | 390 | title: '正在生成海报...' |
| 391 | 391 | }); |
| 392 | - | |
| 392 | + | |
| 393 | 393 | // 3.展示生成的海报 |
| 394 | 394 | this.setData({ |
| 395 | 395 | showActionSheet: 'false', |
| 396 | 396 | // showPlaybill: !this.data.showPlaybill |
| 397 | 397 | }); |
| 398 | - | |
| 399 | - // 2.生成海报,如果生成完毕,关闭提示 | |
| 400 | - this.drawPlaybill(); | |
| 401 | - | |
| 398 | + | |
| 399 | + // 2.生成海报,如果生成完毕,关闭提示 | |
| 400 | + this.drawPlaybill(); | |
| 401 | + | |
| 402 | 402 | }, |
| 403 | 403 | |
| 404 | - | |
| 405 | - // 生成海报 | |
| 406 | - drawPlaybill: async function () { | |
| 407 | 404 | |
| 408 | - var that=this; | |
| 405 | + // 生成海报 | |
| 406 | + drawPlaybill: async function () { | |
| 407 | + | |
| 408 | + var that = this; | |
| 409 | 409 | // wx.showLoading({ |
| 410 | 410 | // title: '正在生成海报...' |
| 411 | 411 | // }); |
| 412 | 412 | |
| 413 | 413 | |
| 414 | - if(!this.data.coverImg) { | |
| 414 | + | |
| 415 | 415 | |
| 416 | 416 | // 请求主图 |
| 417 | 417 | await that.getImageInfo(that.data.sharimg).then(res => { |
| ... | ... | @@ -424,41 +424,49 @@ Page({ |
| 424 | 424 | }); |
| 425 | 425 | // console.log('主图加载成功~', that.data.coverImgSize); |
| 426 | 426 | }); |
| 427 | - } | |
| 428 | - | |
| 429 | - if(!this.data.avatarUrl) { | |
| 430 | - var path2 = getApp().globalData.userInfo.head_pic; | |
| 431 | - if (path2 == "") { | |
| 432 | - path2 = "../../../images/share/hui_hear_pic.png"; | |
| 433 | - } else { | |
| 434 | - getApp().request.promiseGet("/api/weshop/marketing/help/help/imgbase64/get", { | |
| 435 | - data: { | |
| 436 | - imgurl:path2 | |
| 437 | - } | |
| 438 | - }).then(res => { | |
| 439 | - if (res.data.code == 0) { | |
| 440 | - console.log(9999) | |
| 441 | - path2 = 'data:image/jpg;base64,' + res.data.data | |
| 442 | - that.setData({ | |
| 443 | - avatarUrl: path2 | |
| 444 | - }); | |
| 445 | - | |
| 446 | - } | |
| 447 | - }) | |
| 427 | + | |
| 448 | 428 | |
| 449 | 429 | |
| 450 | - | |
| 451 | - } | |
| 452 | 430 | |
| 453 | - // 请求头像 | |
| 454 | 431 | |
| 432 | + var path2 = getApp().globalData.userInfo.head_pic; | |
| 433 | + if (path2 == "") { | |
| 434 | + path2 = "../../../images/share/hui_hear_pic.png"; | |
| 435 | + } else { | |
| 436 | + getApp().request.promiseGet("/api/weshop/marketing/help/help/imgbase64/get", { | |
| 437 | + data: { | |
| 438 | + imgurl: path2 | |
| 439 | + } | |
| 440 | + }).then(res => { | |
| 441 | + if (res.data.code == 0) { | |
| 442 | + console.log(9999) | |
| 443 | + | |
| 444 | + var imgSrc = res.data.data;//base64编码 | |
| 445 | + var save = wx.getFileSystemManager(); | |
| 446 | + var number = Math.random(); | |
| 447 | + save.writeFile({ | |
| 448 | + filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png', | |
| 449 | + data: imgSrc, | |
| 450 | + encoding: 'base64', | |
| 451 | + success: res => { | |
| 452 | + that.setData({ | |
| 453 | + avatarUrl: wx.env.USER_DATA_PATH + '/pic' + number + '.png' | |
| 454 | + }); | |
| 455 | + console.log(wx.env.USER_DATA_PATH + '/pic' + number + '.png') | |
| 456 | + }, fail: err => { | |
| 457 | + console.log(err) | |
| 458 | + } | |
| 459 | + }) | |
| 460 | + } | |
| 461 | + }) | |
| 455 | 462 | } |
| 463 | + | |
| 456 | 464 | |
| 457 | 465 | // 请求二维码 |
| 458 | 466 | var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + |
| 459 | - os.stoid + "?sceneValue=1012" + "&pageValue=pages/goods/goodsInfo/goodsInfo"; | |
| 467 | + os.stoid + "?sceneValue=1012" + "&pageValue=pages/goods/goodsInfo/goodsInfo"; | |
| 460 | 468 | |
| 461 | - if(!this.data.ewm) { | |
| 469 | + if (!this.data.ewm) { | |
| 462 | 470 | |
| 463 | 471 | await that.getImageInfo(path3).then(res => { |
| 464 | 472 | that.setData({ |
| ... | ... | @@ -469,7 +477,7 @@ Page({ |
| 469 | 477 | } |
| 470 | 478 | |
| 471 | 479 | |
| 472 | - | |
| 480 | + | |
| 473 | 481 | // 数据准备 |
| 474 | 482 | const title = this.data.shartitle; |
| 475 | 483 | // const headImg = app.globalData.userInfo['head_pic']; |
| ... | ... | @@ -478,7 +486,7 @@ Page({ |
| 478 | 486 | |
| 479 | 487 | var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + |
| 480 | 488 | os.stoid + "?sceneValue=1012" + "&pageValue=packageA/pages/liveStreamDetails/liveStreamDetails"; |
| 481 | - | |
| 489 | + | |
| 482 | 490 | // 以iPhone6为例,375/750 = 0.5 |
| 483 | 491 | // let scale = this.data.windowWidth / 375; |
| 484 | 492 | let scale = this.data.screenWidth / 750 * 1.35 |
| ... | ... | @@ -493,13 +501,13 @@ Page({ |
| 493 | 501 | |
| 494 | 502 | // 放大 因为不放大的话,生成的分享图会模糊。暂时先注释 |
| 495 | 503 | // ctx.scale(this.data.canvasScale, this.data.canvasScale) |
| 496 | - | |
| 497 | - | |
| 498 | 504 | |
| 499 | - // var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + | |
| 500 | - // os.stoid + "?sceneValue=1012" + "&pageValue=pages/goods/goodsInfo/goodsInfo"; | |
| 501 | - // + "?sceneValue=1012" + "&pageValue=packageA/pages/liveStreamDetails/liveStreamDetails" | |
| 502 | - // console.log('path3---->', path3); | |
| 505 | + | |
| 506 | + | |
| 507 | + // var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + | |
| 508 | + // os.stoid + "?sceneValue=1012" + "&pageValue=pages/goods/goodsInfo/goodsInfo"; | |
| 509 | + // + "?sceneValue=1012" + "&pageValue=packageA/pages/liveStreamDetails/liveStreamDetails" | |
| 510 | + // console.log('path3---->', path3); | |
| 503 | 511 | |
| 504 | 512 | |
| 505 | 513 | // 绘制主背景白色 |
| ... | ... | @@ -509,7 +517,7 @@ Page({ |
| 509 | 517 | // 绘制头像 |
| 510 | 518 | ctx.save(); |
| 511 | 519 | ctx.beginPath(); |
| 512 | - ctx.arc(58, 52, 28, 0, 2*Math.PI); | |
| 520 | + ctx.arc(58, 52, 28, 0, 2 * Math.PI); | |
| 513 | 521 | ctx.clip(); |
| 514 | 522 | // console.log('1__________________>',app.globalData.userInfo['head_pic']); |
| 515 | 523 | ctx.drawImage(this.data.avatarUrl, 30, 24, 56, 56); |
| ... | ... | @@ -521,51 +529,51 @@ Page({ |
| 521 | 529 | ctx.fillText(this.data.nickName, 106, 60); |
| 522 | 530 | |
| 523 | 531 | // 绘制主图 |
| 524 | - ctx.setFillStyle('#f8f8f8'); | |
| 525 | - ctx.fillRect(0, 104, 480, 380); | |
| 526 | - | |
| 527 | - // var w = this.data.coverImgWidth; | |
| 528 | - // var h = this.data.coverImgHeight; | |
| 529 | - var w = this.data.coverImgSize.imageWidth; | |
| 530 | - var h = this.data.coverImgSize.imageHeight; | |
| 531 | - // var dw = 480/w //canvas与图片的宽高比 | |
| 532 | - // var dh = 380/h | |
| 533 | - // var ratio | |
| 534 | - // // 裁剪图片中间部分 | |
| 535 | - // if(w > 480 && h > 380 || w < 480 && h < 380){ | |
| 536 | - // if (dw > dh) { | |
| 537 | - // ctx.drawImage(this.data.coverImg, 0, (h - 380/dw)/2, w, 380/dw, 0, 104, 480, 380); | |
| 538 | - // } else { | |
| 539 | - // ctx.drawImage(this.data.coverImg, (w - 480/dh)/2, 0, 480/dh, h, 0, 104, 480, 380); | |
| 540 | - // }; | |
| 541 | - // } | |
| 542 | - // // 拉伸图片 | |
| 543 | - // else{ | |
| 544 | - // if(w < 300){ | |
| 545 | - // ctx.drawImage(this.data.coverImg, 0, (h - 380/dw)/2, w, 380/dw, 0, 104, 480, 380); | |
| 546 | - // }else { | |
| 547 | - // ctx.drawImage(this.data.coverImg, (w - 480/dh)/2, 0, 480/dh, h, 0, 104, 480, 380); | |
| 548 | - // } | |
| 549 | - // }; | |
| 550 | - ctx.drawImage(this.data.coverImg, (480-w)/2, (380-h)/2+104, w, h); | |
| 551 | - | |
| 532 | + ctx.setFillStyle('#f8f8f8'); | |
| 533 | + ctx.fillRect(0, 104, 480, 380); | |
| 534 | + | |
| 535 | + // var w = this.data.coverImgWidth; | |
| 536 | + // var h = this.data.coverImgHeight; | |
| 537 | + var w = this.data.coverImgSize.imageWidth; | |
| 538 | + var h = this.data.coverImgSize.imageHeight; | |
| 539 | + // var dw = 480/w //canvas与图片的宽高比 | |
| 540 | + // var dh = 380/h | |
| 541 | + // var ratio | |
| 542 | + // // 裁剪图片中间部分 | |
| 543 | + // if(w > 480 && h > 380 || w < 480 && h < 380){ | |
| 544 | + // if (dw > dh) { | |
| 545 | + // ctx.drawImage(this.data.coverImg, 0, (h - 380/dw)/2, w, 380/dw, 0, 104, 480, 380); | |
| 546 | + // } else { | |
| 547 | + // ctx.drawImage(this.data.coverImg, (w - 480/dh)/2, 0, 480/dh, h, 0, 104, 480, 380); | |
| 548 | + // }; | |
| 549 | + // } | |
| 550 | + // // 拉伸图片 | |
| 551 | + // else{ | |
| 552 | + // if(w < 300){ | |
| 553 | + // ctx.drawImage(this.data.coverImg, 0, (h - 380/dw)/2, w, 380/dw, 0, 104, 480, 380); | |
| 554 | + // }else { | |
| 555 | + // ctx.drawImage(this.data.coverImg, (w - 480/dh)/2, 0, 480/dh, h, 0, 104, 480, 380); | |
| 556 | + // } | |
| 557 | + // }; | |
| 558 | + ctx.drawImage(this.data.coverImg, (480 - w) / 2, (380 - h) / 2 + 104, w, h); | |
| 559 | + | |
| 552 | 560 | |
| 553 | 561 | // 绘制文字 |
| 554 | 562 | ctx.setFontSize(24); |
| 555 | 563 | ctx.setFillStyle('#1E1E1E'); |
| 556 | - this.drawText(ctx, title, 30, 600, 200, 460, 2); | |
| 564 | + this.drawText(ctx, title, 30, 600, 200, 460, 2); | |
| 557 | 565 | |
| 558 | 566 | // 绘制小程序码 |
| 559 | 567 | ctx.drawImage(this.data.ewm, 310, 540, 132, 132); |
| 560 | - | |
| 568 | + | |
| 561 | 569 | |
| 562 | 570 | //绘制文字:长按识别 |
| 563 | 571 | ctx.setFontSize(20); |
| 564 | 572 | ctx.setFillStyle('#1E1E1E'); |
| 565 | 573 | ctx.fillText('长按识别小程序', 309, 710); |
| 566 | 574 | |
| 567 | - ctx.draw(true, function() { | |
| 568 | - setTimeout(function() { | |
| 575 | + ctx.draw(true, function () { | |
| 576 | + setTimeout(function () { | |
| 569 | 577 | // console.log("我进来了~~~~~"); |
| 570 | 578 | wx.canvasToTempFilePath({ |
| 571 | 579 | x: 0, |
| ... | ... | @@ -576,13 +584,13 @@ Page({ |
| 576 | 584 | destHeight: 1217, |
| 577 | 585 | canvasId: 'myCanvas', |
| 578 | 586 | fileType: 'jpg', |
| 579 | - success: function(res) { | |
| 587 | + success: function (res) { | |
| 580 | 588 | wx.hideLoading(); |
| 581 | 589 | that.setData({ |
| 582 | 590 | canvasToImgPath: res.tempFilePath, |
| 583 | - showPlaybill: !that.data.showPlaybill | |
| 591 | + showPlaybill: !that.data.showPlaybill | |
| 584 | 592 | }); |
| 585 | - // console.log('生成海报陈宫啦', that.data.canvasToImgPath); | |
| 593 | + // console.log('生成海报陈宫啦', that.data.canvasToImgPath); | |
| 586 | 594 | // that.saveImageToPhotosAlbum(res.tempFilePath); |
| 587 | 595 | // console.log('截图陈宫:', that.data.canvasToImgPath); |
| 588 | 596 | // wx.previewImage({ |
| ... | ... | @@ -599,66 +607,66 @@ Page({ |
| 599 | 607 | }, |
| 600 | 608 | |
| 601 | 609 | |
| 602 | - | |
| 603 | - imageResize(imgWidth, imgHeight) { | |
| 604 | - var imageSize = {}; | |
| 610 | + | |
| 611 | + imageResize(imgWidth, imgHeight) { | |
| 612 | + var imageSize = {}; | |
| 605 | 613 | var originalWidth = imgWidth;//图片原始宽 |
| 606 | 614 | var originalHeight = imgHeight;//图片原始高 |
| 607 | - var originalScale = originalHeight/originalWidth;//图片高宽比 | |
| 615 | + var originalScale = originalHeight / originalWidth;//图片高宽比 | |
| 608 | 616 | // console.log('originalWidth: ' + originalWidth) |
| 609 | 617 | // console.log('originalHeight: ' + originalHeight) |
| 610 | - | |
| 618 | + | |
| 611 | 619 | //获取屏幕宽高 |
| 612 | 620 | var winWidth = 480; |
| 613 | - var winHeight = 380; | |
| 614 | - var winScale = winHeight/winWidth;//屏幕高宽比 | |
| 621 | + var winHeight = 380; | |
| 622 | + var winScale = winHeight / winWidth;//屏幕高宽比 | |
| 615 | 623 | // console.log('windowWidth: ' + winWidth) |
| 616 | 624 | // console.log('windowHeight: ' + winHeight) |
| 617 | - if(originalScale < winScale){//图片高宽比小于屏幕高宽比 | |
| 618 | - //图片缩放后的宽为屏幕宽 | |
| 619 | - imageSize.imageWidth = winWidth; | |
| 620 | - imageSize.imageHeight = (winWidth * originalHeight) / originalWidth; | |
| 621 | - }else{//图片高宽比大于屏幕高宽比 | |
| 622 | - //图片缩放后的高为屏幕高 | |
| 623 | - imageSize.imageHeight = winHeight; | |
| 624 | - imageSize.imageWidth = (winHeight * originalWidth) / originalHeight; | |
| 625 | + if (originalScale < winScale) {//图片高宽比小于屏幕高宽比 | |
| 626 | + //图片缩放后的宽为屏幕宽 | |
| 627 | + imageSize.imageWidth = winWidth; | |
| 628 | + imageSize.imageHeight = (winWidth * originalHeight) / originalWidth; | |
| 629 | + } else {//图片高宽比大于屏幕高宽比 | |
| 630 | + //图片缩放后的高为屏幕高 | |
| 631 | + imageSize.imageHeight = winHeight; | |
| 632 | + imageSize.imageWidth = (winHeight * originalWidth) / originalHeight; | |
| 625 | 633 | } |
| 626 | - console.log('缩放后的宽: ' + imageSize.imageWidth) | |
| 627 | - console.log('缩放后的高: ' + imageSize.imageHeight) | |
| 628 | - return imageSize; | |
| 629 | - }, | |
| 630 | - | |
| 631 | - | |
| 632 | -//文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 | |
| 633 | -drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit) { | |
| 634 | - var lineWidth = 0; | |
| 635 | - var lastSubStrIndex = 0; //每次开始截取的字符串的索引 | |
| 636 | - var han = 0; | |
| 637 | - for (let i = 0; i < str.length; i++) { | |
| 638 | - if (han == 2) return; | |
| 639 | - //lineWidth += ctx.measureText(str[i]).width; | |
| 640 | - lineWidth += ut.measureText(str[i], 21.3 * unit); | |
| 641 | - if (lineWidth > canvasWidth) { | |
| 642 | - han++; | |
| 643 | - | |
| 644 | - if (han == 2) { | |
| 645 | - ctx.textAlign = 'justify'; | |
| 646 | - ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分 | |
| 647 | - } else { | |
| 634 | + console.log('缩放后的宽: ' + imageSize.imageWidth) | |
| 635 | + console.log('缩放后的高: ' + imageSize.imageHeight) | |
| 636 | + return imageSize; | |
| 637 | + }, | |
| 638 | + | |
| 639 | + | |
| 640 | + //文本换行 参数:1、canvas对象,2、文本 3、距离左侧的距离 4、距离顶部的距离 5、6、文本的宽度 | |
| 641 | + drawText: function (ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, unit) { | |
| 642 | + var lineWidth = 0; | |
| 643 | + var lastSubStrIndex = 0; //每次开始截取的字符串的索引 | |
| 644 | + var han = 0; | |
| 645 | + for (let i = 0; i < str.length; i++) { | |
| 646 | + if (han == 2) return; | |
| 647 | + //lineWidth += ctx.measureText(str[i]).width; | |
| 648 | + lineWidth += ut.measureText(str[i], 21.3 * unit); | |
| 649 | + if (lineWidth > canvasWidth) { | |
| 650 | + han++; | |
| 651 | + | |
| 652 | + if (han == 2) { | |
| 653 | + ctx.textAlign = 'justify'; | |
| 654 | + ctx.fillText(str.substring(lastSubStrIndex, i) + '...', leftWidth, initHeight); //绘制截取部分 | |
| 655 | + } else { | |
| 656 | + ctx.textAlign = 'justify'; | |
| 657 | + ctx.fillText(str.substring(lastSubStrIndex, i), leftWidth, initHeight); | |
| 658 | + } | |
| 659 | + initHeight += 35; //22为字体的高度 | |
| 660 | + lineWidth = 0; | |
| 661 | + lastSubStrIndex = i; | |
| 662 | + titleHeight += 20; | |
| 663 | + } | |
| 664 | + if (i == str.length - 1) { //绘制剩余部分 | |
| 648 | 665 | ctx.textAlign = 'justify'; |
| 649 | - ctx.fillText(str.substring(lastSubStrIndex, i), leftWidth, initHeight); | |
| 666 | + ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); | |
| 650 | 667 | } |
| 651 | - initHeight += 35; //22为字体的高度 | |
| 652 | - lineWidth = 0; | |
| 653 | - lastSubStrIndex = i; | |
| 654 | - titleHeight += 20; | |
| 655 | - } | |
| 656 | - if (i == str.length - 1) { //绘制剩余部分 | |
| 657 | - ctx.textAlign = 'justify'; | |
| 658 | - ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight); | |
| 659 | 668 | } |
| 660 | - } | |
| 661 | -}, | |
| 669 | + }, | |
| 662 | 670 | |
| 663 | 671 | /** |
| 664 | 672 | * 页面相关事件处理函数--监听用户下拉动作 |
| ... | ... | @@ -697,19 +705,19 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un |
| 697 | 705 | // duration: 1000 |
| 698 | 706 | // }) |
| 699 | 707 | // } |
| 700 | - | |
| 701 | - // console.log('触底啦'); | |
| 702 | - this.scrollToLower('/api/weshop/wx/livelist/page', { | |
| 703 | - storedId: o.stoid, | |
| 704 | - live_status: 103 | |
| 705 | - }); | |
| 708 | + | |
| 709 | + // console.log('触底啦'); | |
| 710 | + this.scrollToLower('/api/weshop/wx/livelist/page', { | |
| 711 | + storedId: o.stoid, | |
| 712 | + live_status: 103 | |
| 713 | + }); | |
| 706 | 714 | }, |
| 707 | 715 | |
| 708 | - /** | |
| 709 | - * 用户点击右上角分享 | |
| 710 | - */ | |
| 716 | + /** | |
| 717 | + * 用户点击右上角分享 | |
| 718 | + */ | |
| 711 | 719 | onShareAppMessage: function (res) { |
| 712 | - getApp().globalData.clear=1; | |
| 720 | + getApp().globalData.clear = 1; | |
| 713 | 721 | this.setData({ |
| 714 | 722 | showActionSheet: 'false' |
| 715 | 723 | }) |
| ... | ... | @@ -720,72 +728,72 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un |
| 720 | 728 | } |
| 721 | 729 | return { |
| 722 | 730 | title: this.data.details.name, |
| 723 | - success: function(res) { | |
| 731 | + success: function (res) { | |
| 724 | 732 | console.log('res---->', res); |
| 725 | 733 | }, |
| 726 | - complete: function(res) { | |
| 734 | + complete: function (res) { | |
| 727 | 735 | console.log('comple', res) |
| 728 | 736 | } |
| 729 | 737 | } |
| 730 | 738 | }, |
| 731 | 739 | |
| 732 | - onShareTimeline: function (res) { | |
| 733 | - getApp().globalData.no_clear=1; | |
| 734 | - var user_id=getApp().globalData.user_id; | |
| 735 | - if(!user_id) user_id=0; | |
| 740 | + onShareTimeline: function (res) { | |
| 741 | + getApp().globalData.no_clear = 1; | |
| 742 | + var user_id = getApp().globalData.user_id; | |
| 743 | + if (!user_id) user_id = 0; | |
| 736 | 744 | |
| 737 | - return { | |
| 738 | - title: '直播列表', | |
| 739 | - query: 'first_leader='+user_id | |
| 740 | - } | |
| 741 | - }, | |
| 742 | - | |
| 743 | - | |
| 744 | - /** | |
| 745 | - * 请求数据 | |
| 746 | - */ | |
| 747 | - getData: function(isInit, url, data) { | |
| 748 | - let p = app.request.promiseGet(url, { | |
| 749 | - data: data, | |
| 750 | - isShowLoading: true, | |
| 751 | - }) | |
| 752 | - .then(function(res) { | |
| 753 | - if(res.data.code == 0) { | |
| 754 | - | |
| 755 | - self.setData({ | |
| 756 | - isLoading: false | |
| 757 | - }); | |
| 758 | - | |
| 759 | - if(isInit) {// 第一次加载 | |
| 760 | - self.setData({ | |
| 761 | - list: res.data.data | |
| 762 | - }); | |
| 763 | - } else { | |
| 764 | - self.setData({ | |
| 765 | - 'list.pageData': self.data.list.pageData.concat(res.data.data.pageData) | |
| 766 | - }); | |
| 767 | - }; | |
| 768 | - | |
| 769 | - if((res.data.data.pageData.length == 0) || (res.data.data.pageSize * res.data.data.page >= res.data.data.total)) { | |
| 770 | - self.setData({ | |
| 771 | - noMore: true | |
| 772 | - }); | |
| 773 | - }; | |
| 774 | - | |
| 775 | - } else { | |
| 776 | - self.setData({ | |
| 777 | - 'list.pageData': [] | |
| 778 | - }); | |
| 779 | - }; | |
| 780 | - | |
| 781 | - }); | |
| 782 | - | |
| 783 | - return p; | |
| 745 | + return { | |
| 746 | + title: '直播列表', | |
| 747 | + query: 'first_leader=' + user_id | |
| 748 | + } | |
| 749 | + }, | |
| 750 | + | |
| 751 | + | |
| 752 | + /** | |
| 753 | + * 请求数据 | |
| 754 | + */ | |
| 755 | + getData: function (isInit, url, data) { | |
| 756 | + let p = app.request.promiseGet(url, { | |
| 757 | + data: data, | |
| 758 | + isShowLoading: true, | |
| 759 | + }) | |
| 760 | + .then(function (res) { | |
| 761 | + if (res.data.code == 0) { | |
| 762 | + | |
| 763 | + self.setData({ | |
| 764 | + isLoading: false | |
| 765 | + }); | |
| 766 | + | |
| 767 | + if (isInit) {// 第一次加载 | |
| 768 | + self.setData({ | |
| 769 | + list: res.data.data | |
| 770 | + }); | |
| 771 | + } else { | |
| 772 | + self.setData({ | |
| 773 | + 'list.pageData': self.data.list.pageData.concat(res.data.data.pageData) | |
| 774 | + }); | |
| 775 | + }; | |
| 776 | + | |
| 777 | + if ((res.data.data.pageData.length == 0) || (res.data.data.pageSize * res.data.data.page >= res.data.data.total)) { | |
| 778 | + self.setData({ | |
| 779 | + noMore: true | |
| 780 | + }); | |
| 781 | + }; | |
| 782 | + | |
| 783 | + } else { | |
| 784 | + self.setData({ | |
| 785 | + 'list.pageData': [] | |
| 786 | + }); | |
| 787 | + }; | |
| 788 | + | |
| 789 | + }); | |
| 790 | + | |
| 791 | + return p; | |
| 784 | 792 | }, |
| 785 | - | |
| 786 | 793 | |
| 787 | - // 保存图片到手机 | |
| 788 | - onSaveToPhone() { | |
| 794 | + | |
| 795 | + // 保存图片到手机 | |
| 796 | + onSaveToPhone() { | |
| 789 | 797 | var self = this; |
| 790 | 798 | // 获取用户的当前设置,返回值中有小程序已经向用户请求过的权限 |
| 791 | 799 | this.getSetting().then((res) => { |
| ... | ... | @@ -805,7 +813,7 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un |
| 805 | 813 | //打开设置,引导用户授权 |
| 806 | 814 | onOpenSetting() { |
| 807 | 815 | wx.openSetting({ |
| 808 | - success:(res) => { | |
| 816 | + success: (res) => { | |
| 809 | 817 | // console.log(res.authSetting) |
| 810 | 818 | } |
| 811 | 819 | }) |
| ... | ... | @@ -835,8 +843,8 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un |
| 835 | 843 | resolve(); |
| 836 | 844 | }, |
| 837 | 845 | // 拒绝授权,这里是用户拒绝授权后的回调 |
| 838 | - fail: res => { | |
| 839 | - if(isFirst === 0) { | |
| 846 | + fail: res => { | |
| 847 | + if (isFirst === 0) { | |
| 840 | 848 | wx.setStorageSync('isFirst', 1); |
| 841 | 849 | wx.showToast({ |
| 842 | 850 | title: '保存失败', |
| ... | ... | @@ -867,7 +875,7 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un |
| 867 | 875 | var self = this; |
| 868 | 876 | return new Promise((resolve, reject) => { |
| 869 | 877 | wx.showLoading({ |
| 870 | - title: '保存中...', | |
| 878 | + title: '保存中...', | |
| 871 | 879 | mask: true, |
| 872 | 880 | }); |
| 873 | 881 | wx.downloadFile({ |
| ... | ... | @@ -920,33 +928,33 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un |
| 920 | 928 | } |
| 921 | 929 | }) |
| 922 | 930 | }, |
| 923 | - | |
| 924 | - | |
| 925 | - /** | |
| 926 | - * 上拉加载 | |
| 927 | - */ | |
| 928 | - scrollToLower(url, requestData) { | |
| 929 | - // 数据总量 | |
| 930 | - let total = this.data.list.total; | |
| 931 | - // 单页最大数据量 | |
| 932 | - let pageSize = this.data.list.pageSize; | |
| 933 | - // 如果数据总量不为0且小于或等于单页最大数据量,说明数据已全部加载,显示‘没有更多了’ | |
| 934 | - if((total != 0)&&(total <= pageSize)) { | |
| 935 | - this.setData({ | |
| 936 | - noMore: true | |
| 937 | - }); | |
| 938 | - }; | |
| 939 | - | |
| 940 | - if(!this.data.isLoading && !this.data.noMore) { | |
| 941 | - this.setData({ | |
| 942 | - isLoading: true, | |
| 943 | - pageNum: this.data.pageNum + 1 | |
| 944 | - }); | |
| 945 | - requestData.page = this.data.pageNum; | |
| 946 | - this.getData(false, url, requestData); | |
| 947 | - }; | |
| 948 | - }, | |
| 949 | - | |
| 950 | - | |
| 931 | + | |
| 932 | + | |
| 933 | + /** | |
| 934 | + * 上拉加载 | |
| 935 | + */ | |
| 936 | + scrollToLower(url, requestData) { | |
| 937 | + // 数据总量 | |
| 938 | + let total = this.data.list.total; | |
| 939 | + // 单页最大数据量 | |
| 940 | + let pageSize = this.data.list.pageSize; | |
| 941 | + // 如果数据总量不为0且小于或等于单页最大数据量,说明数据已全部加载,显示‘没有更多了’ | |
| 942 | + if ((total != 0) && (total <= pageSize)) { | |
| 943 | + this.setData({ | |
| 944 | + noMore: true | |
| 945 | + }); | |
| 946 | + }; | |
| 947 | + | |
| 948 | + if (!this.data.isLoading && !this.data.noMore) { | |
| 949 | + this.setData({ | |
| 950 | + isLoading: true, | |
| 951 | + pageNum: this.data.pageNum + 1 | |
| 952 | + }); | |
| 953 | + requestData.page = this.data.pageNum; | |
| 954 | + this.getData(false, url, requestData); | |
| 955 | + }; | |
| 956 | + }, | |
| 957 | + | |
| 958 | + | |
| 951 | 959 | |
| 952 | 960 | }) |
| 953 | 961 | \ No newline at end of file | ... | ... |
packageA/pages/liveStreamDetails/liveStreamDetails.js
| ... | ... | @@ -157,7 +157,7 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un |
| 157 | 157 | // }); |
| 158 | 158 | |
| 159 | 159 | |
| 160 | - if(!this.data.coverImg) { | |
| 160 | + | |
| 161 | 161 | |
| 162 | 162 | // 请求主图 |
| 163 | 163 | await that.getImageInfo(that.data.details['share_img']).then(res => { |
| ... | ... | @@ -170,18 +170,49 @@ drawText: function(ctx, str, leftWidth, initHeight, titleHeight, canvasWidth, un |
| 170 | 170 | }); |
| 171 | 171 | // console.log('主图加载成功~', that.data.coverImgSize); |
| 172 | 172 | }); |
| 173 | + | |
| 174 | + | |
| 175 | + var path2 = getApp().globalData.userInfo.head_pic; | |
| 176 | + if (path2 == "") { | |
| 177 | + path2 = "../../../images/share/hui_hear_pic.png"; | |
| 178 | + } else { | |
| 179 | + getApp().request.promiseGet("/api/weshop/marketing/help/help/imgbase64/get", { | |
| 180 | + data: { | |
| 181 | + imgurl: path2 | |
| 182 | + } | |
| 183 | + }).then(res => { | |
| 184 | + if (res.data.code == 0) { | |
| 185 | + console.log(9999) | |
| 186 | + | |
| 187 | + var imgSrc = res.data.data;//base64编码 | |
| 188 | + var save = wx.getFileSystemManager(); | |
| 189 | + var number = Math.random(); | |
| 190 | + save.writeFile({ | |
| 191 | + filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png', | |
| 192 | + data: imgSrc, | |
| 193 | + encoding: 'base64', | |
| 194 | + success: res => { | |
| 195 | + that.setData({ | |
| 196 | + avatarUrl: wx.env.USER_DATA_PATH + '/pic' + number + '.png' | |
| 197 | + }); | |
| 198 | + console.log(wx.env.USER_DATA_PATH + '/pic' + number + '.png') | |
| 199 | + }, fail: err => { | |
| 200 | + console.log(err) | |
| 201 | + } | |
| 202 | + }) | |
| 203 | + } | |
| 204 | + }) | |
| 173 | 205 | } |
| 174 | - | |
| 175 | - if(!this.data.avatarUrl) { | |
| 206 | + // if(!this.data.avatarUrl) { | |
| 176 | 207 | |
| 177 | 208 | // 请求头像 |
| 178 | - await that.getImageInfo(app.globalData.userInfo['head_pic']).then(res => { | |
| 179 | - that.setData({ | |
| 180 | - avatarUrl: res.path | |
| 181 | - }); | |
| 182 | - console.log('头像加载成功~') | |
| 183 | - }); | |
| 184 | - } | |
| 209 | + // await that.getImageInfo(app.globalData.userInfo['head_pic']).then(res => { | |
| 210 | + // that.setData({ | |
| 211 | + // avatarUrl: res.path | |
| 212 | + // }); | |
| 213 | + // console.log('头像加载成功~') | |
| 214 | + // }); | |
| 215 | + // } | |
| 185 | 216 | |
| 186 | 217 | // 请求二维码 |
| 187 | 218 | var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" + | ... | ... |