Browse Source

修改保存图片功能失效的问题;修改微信小程序授权前判断是否有权限

master
Gaoxs 3 years ago
parent
commit
40d31fd861
  1. 1
      .gitignore
  2. 20
      components/StorePoster.vue
  3. 15
      utils/index.js

1
.gitignore vendored

@ -15,3 +15,4 @@ package-lock.json
unpackage/ unpackage/
assets/css/style.css assets/css/style.css
assets/css/style.css.map assets/css/style.css.map
yarn.lock

20
components/StorePoster.vue

@ -76,23 +76,37 @@ export default {
this.downloadFile(this.posterImage) this.downloadFile(this.posterImage)
}, },
downloadFile(url) { downloadFile(url) {
uni.authorize({
scope: 'scope.writePhotosAlbum',
success() {
uni.downloadFile({ uni.downloadFile({
url, url,
fail: function (res) { fail: function (res) {
console.log(res)
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '保存失败', content: '保存失败',
}) })
}, },
success: function (res) { success: function (res) {
console.log(res) uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function () {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '保存成功', content: '保存成功',
}) })
}, },
fail: function () {
uni.showModal({
title: '提示',
content: '保存失败',
})
},
})
console.log(res)
},
})
},
}) })
}, },
savePosterPath: function () { savePosterPath: function () {

15
utils/index.js

@ -237,7 +237,7 @@ export const login = loginInfo => {
console.log('————————————————————') console.log('————————————————————')
console.log('获取环境商') console.log('获取环境商')
getProvider() getProvider()
.then(provider => { .then(async provider => {
console.log('当前的环境商') console.log('当前的环境商')
console.log(provider) console.log(provider)
if (!provider) { if (!provider) {
@ -245,6 +245,11 @@ export const login = loginInfo => {
} }
// 调用登录接口 // 调用登录接口
console.log('调用登录接口') console.log('调用登录接口')
let authorizeRes = await authorize('userInfo')
if (!wx.getUserProfile && !authorizeRes) {
reject('用户未授权')
return
}
uni.login({ uni.login({
provider: provider, provider: provider,
success: async function (loginRes) { success: async function (loginRes) {
@ -255,11 +260,6 @@ export const login = loginInfo => {
let code = loginRes.code let code = loginRes.code
cookie.set('wxLoginCode', loginRes.code) cookie.set('wxLoginCode', loginRes.code)
let authorizeRes = await authorize('userInfo')
if (!wx.getUserProfile && !authorizeRes) {
reject('用户未授权')
return
}
if (wx.getUserProfile) { if (wx.getUserProfile) {
if (loginInfo) { if (loginInfo) {
wxappAuth({ wxappAuth({
@ -286,7 +286,8 @@ export const login = loginInfo => {
reject('获取用户信息失败') reject('获取用户信息失败')
}) })
}) })
.catch(error => { // 登录接口调用失败 .catch(error => {
// 登录接口调用失败
console.log(error) console.log(error)
reject('登录接口调用失败') reject('登录接口调用失败')
}) })

Loading…
Cancel
Save