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/
assets/css/style.css
assets/css/style.css.map
yarn.lock

20
components/StorePoster.vue

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

15
utils/index.js

@ -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,6 +245,11 @@ 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) {
@ -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('登录接口调用失败')
})

Loading…
Cancel
Save