cache.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import { isFunc, isEmpty } from "./base";
  2. function getUserInfo() {
  3. return wx.getStorageSync('userInfo') || null;
  4. }
  5. function setUserInfo(user) {
  6. wx.setStorageSync('userInfo', user)
  7. }
  8. function setaddress(address) {
  9. wx.setStorageSync('address', address)
  10. }
  11. function getaddress() {
  12. return wx.getStorageSync('address')
  13. }
  14. function setUserInfoPart(userPart) {
  15. let user = getUserInfo()
  16. if (user == null) {
  17. user = userPart
  18. } else {
  19. for(let k in userPart) {
  20. user[k] = userPart[k]
  21. }
  22. }
  23. setUserInfo(user)
  24. }
  25. /**
  26. * 获取用户当前选中的店铺
  27. */
  28. function getCurrStore() {
  29. return wx.getStorageSync('store') || null
  30. }
  31. /**
  32. * 获取用户当前选中的桌位
  33. */
  34. function getCurrTable() {
  35. return wx.getStorageSync('table') || null
  36. }
  37. function getChooseStore() {
  38. return wx.getStorageSync('chooseStore') || null
  39. }
  40. function setChooseStore(chooseStore) {
  41. wx.setStorageSync('chooseStore', chooseStore)
  42. }
  43. function getMobile() {
  44. const userInfo = getUserInfo()
  45. if (userInfo != null) {
  46. return userInfo.mobile || ''
  47. }
  48. return ''
  49. }
  50. function getStoreId() {
  51. const store = getCurrStore()
  52. if (store != null) {
  53. return store.id || null;
  54. }
  55. return null
  56. }
  57. // 缓存门店取餐方式
  58. function setStoreWay(storeway) {
  59. wx.setStorageSync('storeway', storeway)
  60. }
  61. function getStoreWay(storeway) {
  62. return wx.getStorageSync('storeway')||null;
  63. }
  64. function setCurrStore(store) {
  65. wx.setStorageSync('store', store)
  66. }
  67. function setCurrTable(table) {
  68. wx.setStorageSync('table', table)
  69. }
  70. //存储最近的经纬度
  71. function setNearLocation(longitude,latitude) {
  72. wx.setStorageSync('nearLocation', {
  73. longitude:longitude,
  74. latitude:latitude
  75. })
  76. }
  77. //获取最近的经纬度
  78. function getNearLocation() {
  79. return wx.getStorageSync('nearLocation')||null;
  80. }
  81. function getTableId() {
  82. const table = getCurrTable()
  83. if (table != null) {
  84. return table.tableId || null
  85. }
  86. return null
  87. }
  88. function getSessionKey() {
  89. return wx.getStorageSync('loginInfo').sessionKey
  90. }
  91. function getOpenId() {
  92. return wx.getStorageSync('loginInfo').openId
  93. }
  94. function getLoginInfo() {
  95. wx.getStorageSync('loginInfo')||null;
  96. }
  97. /**
  98. * 授权手机号
  99. * @param {*} e
  100. * @param {*} func
  101. */
  102. function getPhoneNumber(e, func) {
  103. console.log(e)
  104. let code = e.detail.code;
  105. //获取手机号
  106. if (isEmpty(code)) {
  107. // 兼容老版本
  108. var encryptedData = e.detail.encryptedData;
  109. // console.log(encryptedData);
  110. var iv = e.detail.iv;
  111. if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
  112. return;
  113. }
  114. //获取手机号
  115. doDecodePhoneOld(encryptedData, iv, function (mobile) {
  116. func(mobile)
  117. });
  118. } else {
  119. doDecodePhone(code, function (mobile) {
  120. func(mobile)
  121. });
  122. }
  123. }
  124. function checkInvalid(param = {}, callBack) {
  125. // wx.checkSession({
  126. // success() {
  127. // if (isFunc(callBack)) {
  128. // callBack(param)
  129. // }
  130. // },
  131. // fail() {
  132. // login(callBack)
  133. // }
  134. // })
  135. login(callBack)
  136. }
  137. module.exports = {
  138. getMobile,
  139. getPhoneNumber,
  140. getStoreId,
  141. getTableId,
  142. setCurrStore,
  143. getCurrStore,
  144. getCurrTable,
  145. setCurrTable,
  146. setUserInfo,
  147. getUserInfo,
  148. setUserInfoPart,
  149. getLoginInfo,
  150. setNearLocation,
  151. getNearLocation,
  152. setStoreWay,
  153. getStoreWay,
  154. setaddress,
  155. getaddress,
  156. setChooseStore,
  157. getChooseStore,
  158. }