123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- const app=getApp();
- const utils = require("../../utils/http");
- let winwidth = 0;
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- showTask: {
- type: Boolean,
- value: true
- },
- wshareshow: {
- type: Boolean,
- value:false
- },
- posterimg:{
- type:String,
- value:''
- },
- qrcode:{
- type:String,
- value:''
- },
- title:{
- type:String,
- value:''
- },
- islist: {
- type: Boolean,
- value:false
- },
- imgurlflag: {
- type: Boolean,
- value:false,//默认是false,
- },
- type: {
- type: String,
- value: ""
- },
- contentid: {
- type: Number|String,
- value: ""
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- imgUrl:app.globalData.imgUrl,
- imgflag:false,
- cangth: 100,
- shareImg:''
- },
- /**
- * 组件的方法列表
- */
- methods: {
- dothis:function(){},
- cancletap:function(){
- this.setData({
- wshareshow:false
- })
- },
- // sharefriendtap:function(){
- // var that=this;
- // that.triggerEvent("sfriend", '')
- // this.setData({
- // wshareshow:false
- // })
- // },
- shareurltap:function(){
- var that=this;
- that.triggerEvent("shareurl", '')
- this.setData({
- wshareshow:false
- })
- },
- setposter:function(){
- var that=this;
- wx.getSystemInfo({
- success: (res) => {
- winwidth = res.windowWidth;
- }
- })
-
- // that.setData({
- // imgflag:true
- // })
- // setTimeout(function(){
- // that.createdCode();
- // },500)
- that.triggerEvent("poster", '')
- this.setData({
- wshareshow:false
- })
-
- },
- sendfriend:function(){
- var that=this;
- that.triggerEvent("sendfriendcircle", '')
- this.setData({
- wshareshow:false
- })
- },
- setTasktap: function() {
- const that = this;
- utils.$get({
- url: app.globalData.webUrl + 'api/agentEmp/set_share_content',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- content_id: that.data.contentid,
- type: that.data.type
- },
- success: function (res) {
- if (res.data.code == '0') {
- wx.showToast({
- title: res.data.msg,
- icon: "none",
- duration: 1500
- })
- }
- }
- })
- },
- //开始绘图
- createdCode: function () {
- let that = this;
- if(that.data.title.length>26){
- that.setData({
- title:that.data.title.substring(0,23)+'...'
- })
- }
-
- var posterimg=that.data.posterimg;
- posterimg = posterimg.replace('http://o.nczyzs.com',"https://o.nczyzs.com");
- var qrcode=that.data.qrcode;
- qrcode = qrcode.replace('http://o.nczyzs.com',"https://o.nczyzs.com");
- let topwidth = winwidth * 590 / 750,topheight = '';
- // const ctx = wx.createCanvasContext('myCanvas'); //绘图上下文
- wx.createSelectorQuery().select('#myCanvas')
- .fields({ node: true, size: true })
- .exec((rest) => {
- console.log(rest)
- const canvas = rest[0].node;
- const ctx = canvas.getContext('2d')
- wx.getImageInfo({
- src: posterimg,
- success(res) {
- wx.getImageInfo({
- src: qrcode,
- success(rs) {
- topheight = topwidth * res.height / res.width;
- that.setData({
- cangth: topheight + 64
- })
- ctx.save();
- ctx.drawImage(res.path, 0, 0, topwidth, topheight);
-
- ctx.rect(0, topheight, topwidth, 64);
- ctx.setFillStyle('#FFFFFF');
- ctx.fill();
-
- ctx.restore()
- ctx.setFontSize(14);
- ctx.fillText("@" + app.globalData.personMsg.nickname, 12, topheight + 24, topwidth - 70);
- //
- ctx.fillText(that.data.title, 12, topheight + 48, topwidth - 70);
-
- ctx.drawImage(rs.path, topwidth - 52, topheight + 12, 40, 40);
- ctx.draw();
- wx.hideLoading();
- setTimeout(() => {
- wx.canvasToTempFilePath({
- x: 0,
- y: 0,
- canvasId: 'myCanvas',
- success: function (res) {
- let shareImg = res.tempFilePath;
- that.setData({
- shareImg: shareImg,
- })
- },
- fail: function (res) {}
- })
- },500)
- },fail(res){
- console.log(res)
- },
- })
- },fail(res){
- console.log(res)
- }
- })
- })
-
- },
- saveimgtap: function () {
- let that = this;
- // 获取用户是否开启用户授权相册
- wx.getSetting({
- success(res) {
- // 如果没有则获取授权
- if (!res.authSetting['scope.writePhotosAlbum']) {
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- wx.saveImageToPhotosAlbum({
- filePath: that.data.shareImg,
- success() {
- wx.showToast({
- title: '保存成功'
- })
- },
- fail() {
- wx.showToast({
- title: '保存失败',
- icon: 'none'
- })
- }
- })
- },
- fail() {
- // 如果用户拒绝过或没有授权,则再次打开授权窗口
- //(ps:微信api又改了现在只能通过button才能打开授权设置,以前通过openSet就可打开,下面有打开授权的button弹窗代码)
- that.setData({
- openSet: true
- })
- }
- })
- } else {
- // 有则直接保存
- wx.saveImageToPhotosAlbum({
- filePath: that.data.shareImg,
- success() {
- wx.showToast({
- title: '保存成功'
- })
- },
- fail() {
- wx.showToast({
- title: '保存失败',
- icon: 'none'
- })
- }
- })
- }
- }
- })
- },
- }
- })
|