auth.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import Taro from "@tarojs/taro";
  2. import { getToken, setToken } from '@/utils/index'
  3. // 用户未授权
  4. export const showAuthModal = (content: string) => {
  5. Taro.showModal({
  6. title: '需要授权',
  7. content: content,
  8. showCancel: false,
  9. confirmText: '去授权',
  10. success: function (res) {
  11. if (res.confirm) {
  12. // 用户点击去授权,跳转到设置页面
  13. Taro.openSetting({
  14. success: function (data) {
  15. console.log(data)
  16. // if (data.authSetting['scope.writePhotosAlbum']) {
  17. // // 用户重新授权后,可以再次调用相关接口
  18. // // 这里可以再次尝试获取用户信息
  19. // }
  20. },
  21. fail: function (err) {
  22. console.error('打开设置失败', err);
  23. }
  24. });
  25. }
  26. }
  27. });
  28. }
  29. // 权限测试
  30. // 'scope.writePhotosAlbum'
  31. // 'scope.record'
  32. export const checkPermission = async (scope: string):Promise<boolean> => {
  33. return new Promise((resolve) => {
  34. Taro.authorize({
  35. scope: scope,
  36. success(res) {
  37. console.log(res)
  38. resolve(true);
  39. },
  40. fail(err) {
  41. console.warn(err)
  42. resolve(false);
  43. }
  44. });
  45. });
  46. }
  47. export const bindPhone = async (phone: string) => {
  48. // const res = await authBind(EBindKind.WechatPhone, phone);
  49. // if (res.data) {
  50. // return res.data
  51. // }
  52. return null
  53. }