Files
AGuestSaas/pages/user/code/code.js
2020-12-31 13:15:31 +08:00

172 lines
4.7 KiB
JavaScript

const style = {
codeContent: {
backgroundColor: 'white',
width: '375',
height: '525'
},
codeNickname: {
width: '355',
height: '46',
textAlign: 'center',
fontSize: '25',
verticalAlign: 'middle',
marginTop: '40',
marginLeft: '10'
},
codeJob: {
width: '355',
height: '30',
textAlign: 'center',
verticalAlign: 'middle',
fontSize: '15',
marginLeft: '10'
},
codeImg: {
width: '151',
height: '151',
marginTop: '30',
marginBottom: '40',
marginLeft: '112'
},
codeLogo: {
width: '51',
height: '51',
marginLeft: '162',
marginBottom: '5',
},
codeCompany: {
width: '355',
height: '30',
textAlign: 'center',
verticalAlign: 'middle',
fontSize: '15',
marginLeft: '10',
marginBottom: '20',
},
codeText: {
width: '355',
height: '30',
textAlign: 'center',
verticalAlign: 'middle',
fontSize: '13',
marginLeft: '10',
color: 'gray'
}
}
Page({
/**
* 页面的初始数据
*/
data: {
code: "", //二维码
company: {}, //公司信息
user: {}, //用户信息,
name:'',//用户名
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.getStorage({
key: 'compayId',
success: res => {
console.log(res);
wx.$api.user.getShareCode(res.data).then(res => {
this.setData({
user: {
job: res.job,
cover: res.cover,
name:options.name
},
company: {
name: res.company,
logo: res.logo,
id: res.company_id
},
code: res.code
})
})
}
})
},
/**
* 绘制分享海报
*/
canvasDowImg() {
wx.showLoading({
title: "绘制海报中"
})
const wxml = `
<view class="code-content">
<text class="code-nickname">` + this.data.user.name + `</text>
<image class="code-img" src="` + this.data.code + `" mode="widthFix"></image>
<image class="code-logo" src="` + this.data.company.logo + `" mode="aspectFit"></image>
<text class="code-company">` + this.data.company.name + `</text>
<text class="code-text">扫一扫,快速了解我们的企业</text>
</view>
`
this.codeimg = this.selectComponent('.codeImg')
this.codeimg.renderToCanvas({
wxml,
style
}).then(() => {
this.codeimg.canvasToTempFilePath().then(res => {
console.log(res);
if (res.tempFilePath) {
wx.hideLoading()
this.dowQrCodeImg(res.tempFilePath)
} else {
wx.showToast({
title: "绘制失败,请稍后重试",
icon: "none"
})
}
})
})
},
/**
* 保存canvas图片到本地
*/
dowQrCodeImg(path) {
wx.saveImageToPhotosAlbum({
filePath: path,
success: () => {
wx.showToast({
title: "保存成功,分享图已存储至您的手机相册",
icon: "none"
})
},
fail: () => {
wx.showModal({
title: "提示",
content: "由于您的设置,系统暂无权限访问您的相册,保存海报失败",
cancelText: "以后再说",
cancelColor: "#4f4f4f",
confirmText: "去设置",
confirmColor: "#0b0041",
success: res => {
if (res.confirm) {
wx.openSetting()
}
}
})
}
})
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
return {
title: this.data.user.name + "邀请您快速了解" + this.data.company.name,
imageUrl: this.data.user.cover,
path: "/pages/employees/join/join?companyId=" + this.data.company.id
}
}
})