Commit 76eac997 by zhangquan

设置权限判断

1 parent 471ba7b1
...@@ -201,16 +201,43 @@ Page({ ...@@ -201,16 +201,43 @@ Page({
download() { download() {
wx.showModal({ wx.showModal({
content: '确认下载海报?', content: '确认下载海报?',
success: (res) => { success: async (res) => {
console.log(res)
if(res.confirm){ if(res.confirm){
this.createImg() let hasAuth = await this.toSetting()
if(hasAuth){
this.createImg()
}
} }
}, },
fail: (res) => {}, fail: (res) => {},
complete: (res) => {}, complete: (res) => {},
}) })
}, },
toSetting(){
return new Promise((resolve,reject)=>{
wx.getSetting({
success: (res)=> {
if(res.authSetting['scope.writePhotosAlbum']){
resolve(true)
}else{
wx.openSetting({
success :(resp)=> {
if(resp.authSetting['scope.writePhotosAlbum']){
resolve(true)
}else{
wx.showToast({
title: "下载海报前需要您授权'添加到相册'权限",
icon: "none",
duration: 2500,
});
}
}
})
}
}
})
})
},
//模态框关闭 //模态框关闭
modelClose() { modelClose() {
// this.setData({ // this.setData({
......
...@@ -124,22 +124,50 @@ Component({ ...@@ -124,22 +124,50 @@ Component({
curTabIdx: idx curTabIdx: idx
}) })
}, },
downVideo(e) { async downVideo(e) {
let {url} = e.target.dataset let hasAuth = await this.toSetting()
wx.$api.showToast('正在下载视频...') if(hasAuth){
wx.downloadFile({ let {url} = e.target.dataset
url:url, wx.$api.showToast('正在下载视频...')
success (res) { wx.downloadFile({
if (res.statusCode === 200) { url:url,
success (res) {
wx.saveVideoToPhotosAlbum({ if (res.statusCode === 200) {
filePath: res.tempFilePath,
success (res) { wx.saveVideoToPhotosAlbum({
wx.$api.showToast('下载成功!') filePath: res.tempFilePath,
} success (res) {
}) wx.$api.showToast('下载成功!')
}
})
}
} }
} })
}
},
toSetting(){
return new Promise((resolve,reject)=>{
wx.getSetting({
success: (res)=> {
if(res.authSetting['scope.writePhotosAlbum']){
resolve(true)
}else{
wx.openSetting({
success :(resp)=> {
if(resp.authSetting['scope.writePhotosAlbum']){
resolve(true)
}else{
wx.showToast({
title: "下载视频前需要您授权'添加到相册'权限",
icon: "none",
duration: 2500,
});
}
}
})
}
}
})
}) })
}, },
getImgHeight(){ getImgHeight(){
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!