user.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import WelfareMall from '../api/welfareMall'
  2. function getUserInfo() {
  3. return wx.getStorageSync('userInfo') || null;
  4. }
  5. function getMobileCache() {
  6. const userInfo = getUserInfo()
  7. if (userInfo != null) {
  8. return userInfo.mobile || ''
  9. }
  10. return ''
  11. }
  12. function getPhoneNumber(e, func) {
  13. var encryptedData = e.detail.encryptedData;
  14. console.log(encryptedData);
  15. var iv = e.detail.iv;
  16. if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
  17. return;
  18. }
  19. //获取手机号
  20. getApp().doDecodePhone(encryptedData, iv, function () {
  21. func(getMobileCache())
  22. });
  23. }
  24. function getPhoneNumberNew(e, func) {
  25. var code = e.detail.code;
  26. console.log(code);
  27. //如果版本过低 没有code 就用之前的放吧
  28. if (!code || code.length == 0 ) {
  29. getPhoneNumber(e,func)
  30. }else{
  31. //获取手机号
  32. getApp().doDecodePhoneNew(code, function () {
  33. func(getMobileCache())
  34. });
  35. }
  36. }
  37. /**
  38. * 获取统一颜色
  39. */
  40. async function getColor(){
  41. let configinfo = wx.getStorageSync('configinfo') || null
  42. if(configinfo != null){
  43. return configinfo;
  44. }
  45. let res = await WelfareMall.getIndexList();
  46. //颜色存到缓存中
  47. wx.setStorageSync('configinfo',res.data);
  48. return res.data;
  49. }
  50. module.exports = {
  51. getUserInfo,
  52. getMobileCache,
  53. getPhoneNumber,
  54. getPhoneNumberNew,
  55. getColor
  56. }