From 40d31fd86133e773e5d3103abfa9a8267f7408d0 Mon Sep 17 00:00:00 2001 From: Gaoxs <704041637@qq.com> Date: Mon, 24 Jan 2022 23:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BF=9D=E5=AD=98=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=8A=9F=E8=83=BD=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98;=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=8E=88=E6=9D=83=E5=89=8D=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=9C=89=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + components/StorePoster.vue | 58 +++++++++++++++++++++++--------------- utils/index.js | 39 ++++++++++++------------- 3 files changed, 57 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 2198d27..c346ec6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ package-lock.json unpackage/ assets/css/style.css assets/css/style.css.map +yarn.lock diff --git a/components/StorePoster.vue b/components/StorePoster.vue index da26f44..5d53b0b 100644 --- a/components/StorePoster.vue +++ b/components/StorePoster.vue @@ -49,53 +49,67 @@ export default { posterData: Object, goodId: String, }, - data: function() { + data: function () { return { canvasStatus: false, posterImage: '', } }, watch: { - posterImageStatus: function() { + posterImageStatus: function () { var that = this if (that.posterImageStatus === true) { - that.$nextTick(function() { + that.$nextTick(function () { that.savePosterPath() }) } }, }, - mounted: function() {}, + mounted: function () {}, methods: { - posterImageClose: function() { + posterImageClose: function () { this.posterImageStatus = false this.canvasStatus = false this.$emit('setPosterImageStatus') }, - saveImg: function() { + saveImg: function () { this.downloadFile(this.posterImage) }, downloadFile(url) { - uni.downloadFile({ - url, - fail: function(res) { - console.log(res) - - uni.showModal({ - title: '提示', - content: '保存失败', - }) - }, - success: function(res) { - console.log(res) - uni.showModal({ - title: '提示', - content: '保存成功', + uni.authorize({ + scope: 'scope.writePhotosAlbum', + success() { + uni.downloadFile({ + url, + fail: function (res) { + uni.showModal({ + title: '提示', + content: '保存失败', + }) + }, + success: function (res) { + uni.saveImageToPhotosAlbum({ + filePath: res.tempFilePath, + success: function () { + uni.showModal({ + title: '提示', + content: '保存成功', + }) + }, + fail: function () { + uni.showModal({ + title: '提示', + content: '保存失败', + }) + }, + }) + console.log(res) + }, }) }, }) }, - savePosterPath: function() { + savePosterPath: function () { const that = this uni.showLoading({ diff --git a/utils/index.js b/utils/index.js index 171ee01..d8bf521 100644 --- a/utils/index.js +++ b/utils/index.js @@ -153,7 +153,7 @@ export const getProvider = service => { // 获取当前环境的服务商 uni.getProvider({ service: service || 'oauth', - success: function(res) { + success: function (res) { // 此处可以排除h5 if (res.provider) { resolve(res.provider[0]) @@ -164,7 +164,7 @@ export const getProvider = service => { }, }) }).catch(error => { - console.log('167',error) + console.log('167', error) }) } @@ -196,7 +196,7 @@ export const login = loginInfo => { auth(code) .then(() => { let redirect = cookie.get('redirect').replace(/\ /g, '') - console.log('199',redirect) + console.log('199', redirect) if (redirect) { redirect = redirect.split('/pages')[1] if (!redirect) { @@ -237,7 +237,7 @@ export const login = loginInfo => { console.log('————————————————————') console.log('获取环境商') getProvider() - .then(provider => { + .then(async provider => { console.log('当前的环境商') console.log(provider) if (!provider) { @@ -245,9 +245,14 @@ export const login = loginInfo => { } // 调用登录接口 console.log('调用登录接口') + let authorizeRes = await authorize('userInfo') + if (!wx.getUserProfile && !authorizeRes) { + reject('用户未授权') + return + } uni.login({ provider: provider, - success: async function(loginRes) { + success: async function (loginRes) { console.log(loginRes) // 微信登录 console.log('登录接口调用成功') @@ -255,11 +260,6 @@ export const login = loginInfo => { let code = loginRes.code cookie.set('wxLoginCode', loginRes.code) - let authorizeRes = await authorize('userInfo') - if (!wx.getUserProfile && !authorizeRes) { - reject('用户未授权') - return - } if (wx.getUserProfile) { if (loginInfo) { wxappAuth({ @@ -286,7 +286,8 @@ export const login = loginInfo => { reject('获取用户信息失败') }) }) - .catch(error => { // 登录接口调用失败 + .catch(error => { + // 登录接口调用失败 console.log(error) reject('登录接口调用失败') }) @@ -297,11 +298,11 @@ export const login = loginInfo => { } else { uni.getUserInfo({ provider: provider, - success: function(user) { + success: function (user) { console.log('获取用户信息成功') console.log('开始调用登录接口') wxappAuth({ - // phone: user.phone + // phone: user.phone encryptedData: user.encryptedData, iv: user.iv, code: code, @@ -723,8 +724,8 @@ export function go(delta) { export function back() { uni.navigateBack({ delta: 1, - success: function(e) {}, - fail: function(e) {}, + success: function (e) {}, + fail: function (e) {}, }) } @@ -791,13 +792,13 @@ const getImageInfo = images => { images.map((item, index) => { uni.getImageInfo({ src: item, - fail: function(res) { + fail: function (res) { imageAry[index] = null if (imageAry.length == images.length) { resolve(imageAry) } }, - success: function(res) { + success: function (res) { imageAry[index] = res if (Object.keys(imageAry).length == images.length) { resolve(imageAry) @@ -859,11 +860,11 @@ export const PosterCanvas = (store, successCallBack) => { fileType: 'png', destWidth: WIDTH, destHeight: HEIGHT, - success: function(res) { + success: function (res) { uni.hideLoading() successCallBack && successCallBack(res.tempFilePath) }, - fail: function(error) { + fail: function (error) { console.log(error) }, })