common.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {
  2. encode
  3. } from '@/access/base64.js';
  4. /**
  5. * 判断是否登陆
  6. * returns {boolean}
  7. */
  8. export function isLogin() {
  9. return !!uni.getStorageSync('token')
  10. }
  11. /**
  12. * 判断当前系统
  13. */
  14. export function source() {
  15. // #ifdef H5
  16. const app = navigator.appVersion;
  17. const ua = navigator.userAgent.toLowerCase(); //获取判断用的对象
  18. //在微信浏览器中打开
  19. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  20. return 9
  21. } else {
  22. return 5
  23. }
  24. return 5;
  25. // #endif
  26. // #ifdef MP-WEIXIN
  27. return 3;
  28. // #endif
  29. // #ifdef MP-TOUTIAO
  30. return 8;
  31. // #endif
  32. // #ifdef APP-PLUS
  33. const res = uni.getSystemInfoSync();
  34. return res.platform === 'ios' ? 1 : 2;
  35. // #endif
  36. }
  37. /**
  38. * 获取用户信息
  39. */
  40. export function getUserInfo() {
  41. const session = JSON.parse(uni.getStorageSync('userInfo')) || {}
  42. return session
  43. }
  44. /**
  45. * 获取登录过期时间
  46. */
  47. export function getExpireTime() {
  48. const session = uni.getStorageSync('expireTime') || ''
  49. return session
  50. }
  51. /**
  52. * 获取用户登录token
  53. */
  54. export function getToken() {
  55. const token = uni.getStorageSync('token') || ''
  56. return token
  57. }
  58. // 获取微信小程序用户的图像
  59. export function getAvator() {
  60. const avator = uni.getStorageSync('avator') || ''
  61. return avator
  62. }
  63. // 获取微信小程序用户昵称
  64. export function getName() {
  65. const NickName = uni.getStorageSync('NickName') || ''
  66. return NickName
  67. }
  68. // 获取微信小程序session_key
  69. export function getkey() {
  70. const session_key = uni.getStorageSync('session_key') || ''
  71. return session_key
  72. }
  73. // 获取微信小程序getUnionId
  74. export function getUnionId() {
  75. const unionId = uni.getStorageSync('unionid') || ''
  76. return unionId
  77. }
  78. // 一键登录的手机号
  79. export function getphoneNumber() {
  80. const phoneNumber = uni.getStorageSync('phoneNumber') || ''
  81. return phoneNumber
  82. }
  83. /**
  84. * 获取企业token
  85. */
  86. export function getEnToken() {
  87. // return '35e97bca34dab476692d2ad8cc47954b' //dev
  88. // return 'b8ca10e4ce35fded735c980403dfedf7' //master
  89. // #ifdef MP
  90. // const entoken = uni.getExtConfigSync().token || ''
  91. return "931544405107da76ca2ec31cd63fae49"
  92. // return "fa4c7dee4c8c37d41204a9c1e11f3e43"
  93. // return entoken
  94. // #endif
  95. // #ifdef H5||APP-PLUS
  96. // return "fa4c7dee4c8c37d41204a9c1e11f3e43"
  97. return "931544405107da76ca2ec31cd63fae49"
  98. // #endif
  99. }
  100. // 获取openid
  101. export function getOpenid() {
  102. const openid = uni.getStorageSync('openid') || '';
  103. return openid;
  104. }
  105. // 获取 请求头 定位信息
  106. export function getLocation() {
  107. const location = uni.getStorageSync('locationObj') || '';
  108. return encode(location);
  109. }