裂变星小程序-25.03.04
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.

52 lines
942 B

1 month 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. uni.getSetting({
  10. success(res) {
  11. if (!res.authSetting[scope]) {
  12. setting()
  13. }
  14. }
  15. });
  16. }
  17. });
  18. function setting(){
  19. uni.showModal({
  20. title: '当前操作未授权,请授权!',
  21. content: '拒绝授权将影响本小程序部分功能的使用',
  22. confirmText: '授权',
  23. success(e) {
  24. if(!e.confirm){
  25. return error()
  26. }
  27. uni.openSetting({
  28. success(res) {
  29. if (!res.authSetting[scope]) {
  30. uni.showToast({
  31. title: '授权失败',
  32. icon: 'none',
  33. })
  34. return error()
  35. }
  36. success()
  37. }
  38. });
  39. }
  40. })
  41. }
  42. })
  43. }
  44. export default authorize