Browse Source

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

master
Gaoxs 3 years ago
parent
commit
40d31fd861
  1. 1
      .gitignore
  2. 58
      components/StorePoster.vue
  3. 39
      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

58
components/StorePoster.vue

@ -49,53 +49,67 @@ export default {
posterData: Object, posterData: Object,
goodId: String, goodId: String,
}, },
data: function() { data: function () {
return { return {
canvasStatus: false, canvasStatus: false,
posterImage: '', posterImage: '',
} }
}, },
watch: { watch: {
posterImageStatus: function() { posterImageStatus: function () {
var that = this var that = this
if (that.posterImageStatus === true) { if (that.posterImageStatus === true) {
that.$nextTick(function() { that.$nextTick(function () {
that.savePosterPath() that.savePosterPath()
}) })
} }
}, },
}, },
mounted: function() {}, mounted: function () {},
methods: { methods: {
posterImageClose: function() { posterImageClose: function () {
this.posterImageStatus = false this.posterImageStatus = false
this.canvasStatus = false this.canvasStatus = false
this.$emit('setPosterImageStatus') this.$emit('setPosterImageStatus')
}, },
saveImg: function() { saveImg: function () {
this.downloadFile(this.posterImage) this.downloadFile(this.posterImage)
}, },
downloadFile(url) { downloadFile(url) {
uni.downloadFile({ uni.authorize({
url, scope: 'scope.writePhotosAlbum',
fail: function(res) { success() {
console.log(res) uni.downloadFile({
url,
uni.showModal({ fail: function (res) {
title: '提示', uni.showModal({
content: '保存失败', title: '提示',
}) content: '保存失败',
}, })
success: function(res) { },
console.log(res) success: function (res) {
uni.showModal({ uni.saveImageToPhotosAlbum({
title: '提示', filePath: res.tempFilePath,
content: '保存成功', success: function () {
uni.showModal({
title: '提示',
content: '保存成功',
})
},
fail: function () {
uni.showModal({
title: '提示',
content: '保存失败',
})
},
})
console.log(res)
},
}) })
}, },
}) })
}, },
savePosterPath: function() { savePosterPath: function () {
const that = this const that = this
uni.showLoading({ uni.showLoading({

39
utils/index.js

@ -153,7 +153,7 @@ export const getProvider = service => {
// 获取当前环境的服务商 // 获取当前环境的服务商
uni.getProvider({ uni.getProvider({
service: service || 'oauth', service: service || 'oauth',
success: function(res) { success: function (res) {
// 此处可以排除h5 // 此处可以排除h5
if (res.provider) { if (res.provider) {
resolve(res.provider[0]) resolve(res.provider[0])
@ -164,7 +164,7 @@ export const getProvider = service => {
}, },
}) })
}).catch(error => { }).catch(error => {
console.log('167',error) console.log('167', error)
}) })
} }
@ -196,7 +196,7 @@ export const login = loginInfo => {
auth(code) auth(code)
.then(() => { .then(() => {
let redirect = cookie.get('redirect').replace(/\ /g, '') let redirect = cookie.get('redirect').replace(/\ /g, '')
console.log('199',redirect) console.log('199', redirect)
if (redirect) { if (redirect) {
redirect = redirect.split('/pages')[1] redirect = redirect.split('/pages')[1]
if (!redirect) { if (!redirect) {
@ -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,9 +245,14 @@ 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) {
console.log(loginRes) console.log(loginRes)
// 微信登录 // 微信登录
console.log('登录接口调用成功') console.log('登录接口调用成功')
@ -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('登录接口调用失败')
}) })
@ -297,11 +298,11 @@ export const login = loginInfo => {
} else { } else {
uni.getUserInfo({ uni.getUserInfo({
provider: provider, provider: provider,
success: function(user) { success: function (user) {
console.log('获取用户信息成功') console.log('获取用户信息成功')
console.log('开始调用登录接口') console.log('开始调用登录接口')
wxappAuth({ wxappAuth({
// phone: user.phone // phone: user.phone
encryptedData: user.encryptedData, encryptedData: user.encryptedData,
iv: user.iv, iv: user.iv,
code: code, code: code,
@ -723,8 +724,8 @@ export function go(delta) {
export function back() { export function back() {
uni.navigateBack({ uni.navigateBack({
delta: 1, delta: 1,
success: function(e) {}, success: function (e) {},
fail: function(e) {}, fail: function (e) {},
}) })
} }
@ -791,13 +792,13 @@ const getImageInfo = images => {
images.map((item, index) => { images.map((item, index) => {
uni.getImageInfo({ uni.getImageInfo({
src: item, src: item,
fail: function(res) { fail: function (res) {
imageAry[index] = null imageAry[index] = null
if (imageAry.length == images.length) { if (imageAry.length == images.length) {
resolve(imageAry) resolve(imageAry)
} }
}, },
success: function(res) { success: function (res) {
imageAry[index] = res imageAry[index] = res
if (Object.keys(imageAry).length == images.length) { if (Object.keys(imageAry).length == images.length) {
resolve(imageAry) resolve(imageAry)
@ -859,11 +860,11 @@ export const PosterCanvas = (store, successCallBack) => {
fileType: 'png', fileType: 'png',
destWidth: WIDTH, destWidth: WIDTH,
destHeight: HEIGHT, destHeight: HEIGHT,
success: function(res) { success: function (res) {
uni.hideLoading() uni.hideLoading()
successCallBack && successCallBack(res.tempFilePath) successCallBack && successCallBack(res.tempFilePath)
}, },
fail: function(error) { fail: function (error) {
console.log(error) console.log(error)
}, },
}) })

Loading…
Cancel
Save