Commit 76eac997 by zhangquan

设置权限判断

1 parent 471ba7b1
......@@ -201,16 +201,43 @@ Page({
download() {
wx.showModal({
content: '确认下载海报?',
success: (res) => {
console.log(res)
success: async (res) => {
if(res.confirm){
this.createImg()
let hasAuth = await this.toSetting()
if(hasAuth){
this.createImg()
}
}
},
fail: (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() {
// this.setData({
......
......@@ -124,22 +124,50 @@ Component({
curTabIdx: idx
})
},
downVideo(e) {
let {url} = e.target.dataset
wx.$api.showToast('正在下载视频...')
wx.downloadFile({
url:url,
success (res) {
if (res.statusCode === 200) {
wx.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success (res) {
wx.$api.showToast('下载成功!')
}
})
async downVideo(e) {
let hasAuth = await this.toSetting()
if(hasAuth){
let {url} = e.target.dataset
wx.$api.showToast('正在下载视频...')
wx.downloadFile({
url:url,
success (res) {
if (res.statusCode === 200) {
wx.saveVideoToPhotosAlbum({
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(){
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!