敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.0 KiB

4 months ago
4 months ago
4 months ago
4 months ago
  1. function authorize(scope){
  2. return new Promise((success, error) => {
  3. uni.authorize({
  4. /* scope.writePhotosAlbum 类型是保存到相册 */
  5. scope,
  6. success,
  7. complete(res) {
  8. /* 判断如果没有授权就打开设置选项让用户重新授权 */
  9. // 获取授权信息
  10. uni.getSetting({
  11. success(res) {
  12. if (!res.authSetting[scope]) {
  13. setting()
  14. }
  15. }
  16. });
  17. }
  18. });
  19. function setting(){
  20. uni.showModal({
  21. title: '当前操作未授权,请授权!',
  22. content: '拒绝授权将影响本小程序部分功能的使用',
  23. confirmText: '授权',
  24. confirmColor: '#019245',
  25. success(e) {
  26. if(!e.confirm){
  27. return error()
  28. }
  29. // 打开小程序设置页 手动设置
  30. uni.openSetting({
  31. success(res) {
  32. if (!res.authSetting[scope]) {
  33. uni.showToast({
  34. title: '授权失败',
  35. icon: 'none',
  36. })
  37. return error()
  38. }
  39. success()
  40. }
  41. });
  42. }
  43. })
  44. }
  45. })
  46. }
  47. export default authorize