diff --git a/api/interfaces/user.js b/api/interfaces/user.js index 07e26ec..8ce6297 100644 --- a/api/interfaces/user.js +++ b/api/interfaces/user.js @@ -1,49 +1,55 @@ - /* - * 手太欠 - * 愿这世界都如故事里一样 美好而动人~ -*/ - -import { req } from "../request" - -// 用户中心 -const userIndex = () => req({ - url: "user" -}) - -// 用户设置 -const userSetup = () => req({ - url: "user/setting" -}) - -//修改用户信息 -const setting = (key, data) => req({ - url: "user/setting/" + key, - method: "PUT", - data: data -}) - -// 我的推广码 -const invitesCode = data => req({ - url: "user/invite", - data: data -}) - -// 小程序码 -const miniShare = data => req({ - url: "user/mini_share", - data: data -}) - -// 帮助分类 -const helpsNav = () => req({ - url: "cms/categories/helps" -}) - -export default ({ - userIndex, - userSetup, - setting, - invitesCode, - miniShare, - helpsNav + /* + * 手太欠 + * 愿这世界都如故事里一样 美好而动人~ +*/ + +import { req } from "../request" + +// 用户中心 +const userIndex = () => req({ + url: "user" +}) + +// 用户设置 +const userSetup = () => req({ + url: "user/setting" +}) + +//修改用户信息 +const setting = (key, data) => req({ + url: "user/setting/" + key, + method: "PUT", + data: data +}) + +// 我的推广码 +const invitesCode = data => req({ + url: "user/invite", + data: data +}) + +// 小程序码 +const miniShare = data => req({ + url: "user/mini_share", + data: data +}) + +// 帮助分类 +const helpsNav = () => req({ + url: "cms/categories/helps" +}) + +// 邀请码背景 +const poster = (data) => req({ + url: "agent/poster", + data: data +}) +export default ({ + userIndex, + userSetup, + setting, + invitesCode, + miniShare, + helpsNav, + poster }) \ No newline at end of file diff --git a/pages/user/code/code.js b/pages/user/code/code.js index e6bdfce..539ef61 100644 --- a/pages/user/code/code.js +++ b/pages/user/code/code.js @@ -1,71 +1,90 @@ + /* * 手太欠 * 愿这世界都如故事里一样 美好而动人~ */ Page({ - /** * 页面的初始数据 */ data: { - barHeight : getApp().globalData.barHeight, // 状态栏高度 - shareSee : false, //分享弹出 - inviteText : '', //邀请码 - inviteCode : '', //二维码 - - //海报 - canvas : '' + nameInfo: '', // 用户名 + invite : '', // 邀请码 + qrcode : '', // 二维码 + posters : [], // 海报数组 + current : 0, // 选项卡下标 }, - - /** - * 生命周期函数--监听页面加载 - */ - onLoad(options) { - // 初始化画布 - wx.createSelectorQuery().select('#coverCanvas').fields({node: true, size: true}).exec(canvasNode => { - const canvas = canvasNode[0].node - canvas.width = 375 - canvas.height = 800 - this.setData({ - canvas - }) - }) - }, - /** * 生命周期函数--监听页面显示 */ - onShow() { - // 获取信息 - this.inviteInfo(); + onLoad() { + let miniShareFun = wx.$api.user.poster({ type: '2' }) + // wx.$api.user.poster({ url: 'pages/mall/index' }).then(res => { + // console.log(res.data) + // this.setData({ + // nameInfo : res.data.name, + // posters : res.data.posters, + // qrcode : res.data.qrcode + // }) + // }) - // 小程序码 - this.ShareInfo(); - }, + wx.showLoading({ + title: '加载中...', + mask : true + }) - /** - * 获取信息 - */ - inviteInfo() { - wx.$api.user.invitesCode().then(res => { + Promise.all([miniShareFun]).then(res => { + let miniShareData = res[0].data this.setData({ - inviteText : res.data.invite + posters : miniShareData.posters, + qrcode : miniShareData.qrcode, + invite : miniShareData.invite, + current : 0 }) - }).catch(err => {}) + // wx.getImageInfo({ + // src : miniShareData.qrcode, + // success : qrcodePath => { + // this.setData({ + // qrcode : qrcodePath.path, + // posters : miniShareData.posters, + // nameName : miniShareData.name, + // current: 0 + // }) + // } + // }) + wx.hideLoading() + }) + }, + swiperChange(e) { + let index = e.detail.current + this.setData({ + current: index + }) }, - /** - * 小程序码 + * 检查授权信息 */ - ShareInfo() { - wx.$api.user.miniShare({ - url: '/pages/index/index' - }).then(res => { - this.setData({ - inviteCode: res.data.qrcode - }) - }).catch(err => {}) + onCheckSetting(){ + wx.getSetting({ + success: res => { + if(res.authSetting['scope.writePhotosAlbum'] || res.authSetting['scope.writePhotosAlbum'] === undefined){ + this.onCanvas() + return + } + wx.showModal({ + title : '提示', + content : '暂未授权小程序写入您的相册,无法存储海报', + confirmColor: '#144592', + confirmText : '去设置', + success: res => { + if (res.confirm) { + wx.openSetting() + } + } + }) + } + }) }, /** @@ -73,113 +92,99 @@ Page({ */ onCanvas(){ wx.showLoading({ - title: '生成图片中...', + title: '加载中...', mask : true }) - const canvas = this.data.canvas - const ctx = canvas.getContext('2d') - const codeImgEl = canvas.createImage() - const backBackEl = canvas.createImage() + wx.getImageInfo({ + src: this.data.posters[this.data.current].cover, + success: imgInfo => { + wx.hideLoading() + wx.showLoading({ + title : '生成海报中...', + mask : true + }) + let posterSrc = imgInfo.path + let posterW = this.data.posters[this.data.current].width + let posterH = this.data.posters[this.data.current].height + let posterY = this.data.posters[this.data.current].position.y + let posterX = this.data.posters[this.data.current].position.x + let qrcodeSize = this.data.posters[this.data.current].position.size + let qrcodeSrc = this.data.qrcode - codeImgEl.src = this.data.inviteCode //二维码 - backBackEl.src = 'https://cdn.shuiganying.com/images/2023/03/31/30a1fde15c33efce2c182ef5fb7073fd.jpg' //背景素材 - const codeImgLoding = new Promise((resolve, reason) => { - codeImgEl.onload = () => { - resolve() - } - }) - const backBackLoding = new Promise((resolve, reason) => { - backBackEl.onload = () => { - resolve() - } - }) - Promise.all([codeImgLoding, backBackLoding]).then(() => { - ctx.drawImage(backBackEl, 0, 0, 375, 800) - // 绘制[二维码-白色背景] - ctx.fillStyle = "#ffffff"; - ctx.fillRect(30, 400, 130, 130); + wx.createSelectorQuery().select('#canvas').fields({ node: true, size: true }).exec(res => { + const canvas = res[0].node; + const ctx = canvas.getContext("2d"); + const img = canvas.createImage() + const code = canvas.createImage() + const dpr = wx.getSystemInfoSync().pixelRatio - // 绘制[二维码-白色背景黑框] - ctx.strokeStyle = "#0e2c58"; - ctx.lineWidth = 2 - ctx.strokeRect(29, 399, 132, 132); + // 设置画布 + canvas.width = posterW * dpr + canvas.height = posterH * dpr + ctx.scale(dpr, dpr) + // 清理画布 + ctx.clearRect(0, 0, canvas.width, canvas.height) + // 绘制背景 + img.src = posterSrc + img.onload = () => { + ctx.drawImage(img, 0, 0, posterW, posterH) + + // 绘制图片二维码 + code.src = qrcodeSrc + code.onload = () => { + ctx.arc( posterX + qrcodeSize/2, posterY + qrcodeSize/2, qrcodeSize/2 + 5, 0, 2 * Math.PI ); + ctx.fillStyle = "#ffffff"; + ctx.fill(); + ctx.drawImage(code, posterX, posterY, qrcodeSize, qrcodeSize) - // 绘制[二维码] - ctx.drawImage(codeImgEl, 40, 410, 110, 110) - - // 文字 - ctx.font = "bold 14px Arial"; //字体大小 - ctx.fillStyle = "#0e2c58"; //字体颜色 - ctx.textAlign = "center" - ctx.fillText('扫描二维码了解更多', 96, 560); - - wx.hideLoading() - wx.canvasToTempFilePath({ - canvas: this.data.canvas, - success : res => { - wx.saveImageToPhotosAlbum({ - filePath: res.tempFilePath, - success: saveRes => { - wx.showToast({ - title: '海报已保存至您的相册', - icon : 'none' - }) - this.setData({ - shareSee: false - }) - }, - fail: () => { - wx.hideLoading() - wx.showModal({ - title: '提示', - content: '暂未授权小程序写入您的相册,无法存储海报', - confirmColor: '#e50d01', - confirmText: '去设置', - success: res => { - if (res.confirm) { - wx.openSetting() - } + // 保存海报 + wx.canvasToTempFilePath({ + canvas : canvas, + width : canvas.width, + height : canvas.height, + destWidth : canvas.width, + destHeight : canvas.height, + quality : 1, + success : paths => { + wx.saveImageToPhotosAlbum({ + filePath: paths.tempFilePath, + success: res => { + wx.showToast({ + title : '海报已保存', + }) + } + }) + }, + fail: () => { + wx.hideLoading() + wx.showModal({ + title: '提示', + content: '暂未授权小程序写入您的相册,无法存储海报', + confirmColor: '#e50d01', + confirmText: '去设置', + success: res => { + if (res.confirm) { + wx.openSetting() + } + } + }) } }) } - }) - }, - }) - }).catch(err => { - wx.showToast({ - title: '图片加载失败', - icon : 'none' - }) + } + }) + } }) }, - /** - * 分享弹出 - */ - shareTap() { - this.setData({ - shareSee: !this.data.shareSee - }) - }, - - // 返回上一页 - returnGo() { - wx.navigateBack({ - delta: 1 - }) - }, - - /** + /** * 微信分享 */ onShareAppMessage(){ - this.setData({ - shareSee: false - }) return { - title : '水感应修复、紧致、舒缓喷雾', - path : "/pages/index/index?invite=" + wx.getStorageSync("invite"), - imageUrl: "https://cdn.shuiganying.com/images/2023/04/04/9cd9968136e7efd85028fba69e4c587a.jpg" + title : '锶源昆仑', + path : "/pages/index/index?invite=" + this.data.invite, + imageUrl: "http://cdn.siyuankunlun.com/materials/2022/09/14/code.jpg" } } }) \ No newline at end of file diff --git a/pages/user/code/code.json b/pages/user/code/code.json index f7efdab..2392939 100644 --- a/pages/user/code/code.json +++ b/pages/user/code/code.json @@ -1,4 +1,4 @@ { "usingComponents": {}, - "navigationStyle": "custom" - } \ No newline at end of file + "navigationBarTitleText": "邀请码" +} \ No newline at end of file diff --git a/pages/user/code/code.wxml b/pages/user/code/code.wxml index 4206743..a7c1a56 100644 --- a/pages/user/code/code.wxml +++ b/pages/user/code/code.wxml @@ -1,35 +1,32 @@ - - - - - - - - - - 扫描二维码了解更多 - - - - 分享 - - + + - - - - - - - - - - 保存二维码 + + + 保存海报 - 取消 + + \ No newline at end of file diff --git a/pages/user/code/code.wxss b/pages/user/code/code.wxss index 6e9d51a..8d3ed26 100644 --- a/pages/user/code/code.wxss +++ b/pages/user/code/code.wxss @@ -1,148 +1,18 @@ -/* 返回上一页 */ -.navigation{ - position: fixed; - top: 0; - left: 0; - z-index: 99; - width: 100%; - height: 90rpx; - background-color: transparent; - transition: .2s; -} - -.navigation.active { - background-color: transparent; -} - -.navigation-arrow { - width: 44rpx; - height: 44rpx; - margin: 20rpx 15rpx 0 20rpx; -} - - -/* 二维码 */ -.code { - width: 100vw; - height: 100vh; - position: relative; -} - -.code-back { - position: absolute; - left: 0; - top: 0; - width: 100%; - height: 100%; -} - -.code-cont { - width: 400rpx; - position: absolute; - z-index: 9; - text-align: center; - left: 0; - bottom: 30%; -} - -.code-img{ - margin: 0 auto 20rpx; - overflow: hidden; - width: 260rpx; - height: 260rpx; - border: 4rpx solid #144592; - background-color: #ffffff; - padding: 10rpx; - box-sizing: border-box; -} - -.code-img image { - width: 100%; -} - -.code-text { - color: #144592; - font-size: 28rpx; - font-weight: 600; -} - -.code-share { - position: absolute; - z-index: 10; - left: 0; - bottom: 13%; - background: linear-gradient(to right, #3f7fff, #568fff); - width: 50rpx; - text-align: center; - border-radius: 0 26rpx 26rpx 0; - padding: 30rpx 15rpx 30rpx 12rpx; - box-shadow: 0 0 6rpx 6rpx rgba(0, 0, 0, .2); -} - -.code-share-name { - writing-mode:vertical-rl; - font-size: 30rpx; - padding-left: 4rpx; - color: #fff; -} - -.code-share image { - width: 36rpx; - height: 36rpx; - margin-bottom: 5rpx; -} - -.sharePop { - position: fixed; - width: 100%; - z-index: 99; - left: 0; - bottom: 0; - background-color: #0a1930; - display: none; -} - -.sharePop.active { - display: block; -} - -.shareCont-label image { - width: 60rpx; - height: 60rpx; - display: block; - margin: 0 auto 10rpx; -} - -.shareCancel { - border-top: 2rpx solid #0e2c58; - color: #ffffff; - width: 100%; - text-align: center; - line-height: 100rpx; -} - -.shareCont{ - display: flex; - padding: 30rpx 0; -} - -.shareCont-label { - color: #ffffff; - flex: 2; - text-align: center; - font-size: 28rpx; -} - -.codeShare-button { - background-color: transparent; - padding: 0; - font-weight: normal; -} - -/* canvas */ -.canvas-img { - position: fixed; - left: -10000%; - top: 0; - z-index: 99; -} \ No newline at end of file + +.content{ display: flex; align-items: center; flex-direction: column; justify-content: center; background: white; box-shadow: brown; min-height: 100vh;} + +/* 海报预览 */ +.poster{ width: 550rpx; height: 900rpx; background: white; box-shadow: 0 0 10rpx 10rpx rgba(0, 0, 0, .05); border-radius: 20rpx; overflow: hidden; } +.poster-item{ width: 550rpx; height: 900rpx; background-position: center; background-size: cover; position: relative; } +.poster-qrocde{ position: absolute; background-color: white; padding: 10rpx; border-radius: 50%;} + +/* 分享功能 */ +.tool{ display: flex; align-items: center; justify-content: space-around; width: 70vw; margin-top: 80rpx; } +.tool-item{ text-align: center; } +.tool-item[size="mini"]{ padding: 0; margin: 0; background-color: transparent; } +.tool-icon{ background: #f7f8f9; width: 88rpx; height: 88rpx; border-radius: 50%; vertical-align: top; } +.tool-text{ color: gray; font-size: 30rpx; line-height: 40rpx; margin-top: 10rpx; font-weight: normal;} + +/* canvas */ +.canvas{ background: #ddd; position: absolute; top: 0; left:-200%; } + diff --git a/static/share_00.png b/static/share_00.png new file mode 100644 index 0000000..3216977 Binary files /dev/null and b/static/share_00.png differ diff --git a/static/share_01.png b/static/share_01.png new file mode 100644 index 0000000..7ab1a36 Binary files /dev/null and b/static/share_01.png differ