storage.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import {
  2. QINIU_URL
  3. } from '@/common/constant'
  4. import i18n from '../locale/index.js'
  5. // 存储
  6. const STORAGE_USER_TOKEN = 'storage_user_token';
  7. const PRODUCTS_TO_ORDER = 'products_to_order';
  8. const USER_BASE_INFO = 'user_base_info';
  9. const POSITION_MACID = 'position_macid'; // 暂存macid 用于页面跳转
  10. const APP_CONFIG = 'app_config';
  11. const CAR_IMAGES = 'car_images'; // 现场拍摄车辆照片
  12. const SELECTED_DEVICE_INFO = 'selected_device_info';
  13. const CB_BLUETOOTH_INFO = 'cb_bluetooth_info';
  14. const USER_CURRENT_LOCATION = 'user_current_location'; // 用户当前位置
  15. const IS_SCAN = 'is_scan';
  16. const SHARE_CODE = 'share_code';
  17. const IS_AGREEMENT = 'agreement'
  18. const IS_LOCATION_AUTH = 'is_location_auth'
  19. const USER_INFO_DATA = 'USER_INFO_DATA';
  20. const IS_BUY_MODEL = 'IS_BUY_MODEL';
  21. const FUNCTIONTAG = 'FUNCTIONTAG'
  22. const ICONS = {
  23. lock: `${QINIU_URL}FgMCTZCySvEgLYgkzU65BUR4f4Ls`,
  24. edit: `${QINIU_URL}Fq3V1Zi5tKH7ibTwG1nO7N96CU8m`,
  25. add: `${QINIU_URL}FqLEWbMe8DcnQtNz6GdDDD87ObZK`,
  26. placeholder: `${QINIU_URL}FpKvfFNSDbx0d9RDwyGAQdFb7Kt6`
  27. }
  28. const activeTabs = [{
  29. name: i18n.t('开机'),
  30. type:'tronOnOrOff',
  31. iconUrl: `${QINIU_URL}Fp5T9lSNakoiioji6S7W4DmFQ_ys`,
  32. isLock: true,
  33. isTurnOn:1
  34. },
  35. {
  36. name: i18n.t('闪灯鸣笛'),
  37. type:'findCar',
  38. iconUrl: `${QINIU_URL}FpeQsDh2dbeTullNLI-HhWj4WAQS`
  39. },
  40. {
  41. name: i18n.t('打开座桶'),
  42. type:'openSeatBag',
  43. iconUrl: `${QINIU_URL}FppwhbFzrEmDeJQgZJtDTu6WOoMZ`
  44. },
  45. {
  46. name: i18n.t('打开尾箱'),
  47. type:'openTailBox',
  48. iconUrl: `${QINIU_URL}Fv3KLuYWEeV5IM4_2sMbmur7yZtz`
  49. }
  50. ]
  51. const toBeSelectTabs = [{
  52. name:i18n.t('胎压'),
  53. type:'tirePressure',
  54. url:'',
  55. iconUrl: `${QINIU_URL}FmbcjmvoB4J3CT1hrbjNX4kxv9Zq`
  56. },
  57. {
  58. name: i18n.t('电池信息'),
  59. type:'batteryInfo',
  60. url:'/pages/batteryDetail/batteryDetail',
  61. iconUrl: `${QINIU_URL}Fnx_4tLoq1ytvVA0UemepWisI73A`
  62. },
  63. {
  64. name: i18n.t('导航'),
  65. type:'navigation',
  66. url:'',
  67. iconUrl: `${QINIU_URL}FrA_ouJtDp-39g7rMBI0EYr2czVE`
  68. }
  69. ]
  70. function setFunctionTag(tag = {}) {
  71. uni.setStorageSync(FUNCTIONTAG, tag);
  72. }
  73. function getFunctionTag() {
  74. let list = uni.getStorageSync(FUNCTIONTAG) || {
  75. activeTag:activeTabs,
  76. tag:toBeSelectTabs,
  77. }
  78. return list
  79. }
  80. function setIsLocationAuth(location_auth) {
  81. uni.setStorageSync(IS_LOCATION_AUTH, location_auth);
  82. }
  83. function getIsLocationAuth() {
  84. return uni.getStorageSync(IS_LOCATION_AUTH);
  85. }
  86. function setUserToken(user_token) {
  87. uni.setStorageSync(STORAGE_USER_TOKEN, user_token);
  88. }
  89. function getUserToken() {
  90. return uni.getStorageSync(STORAGE_USER_TOKEN);
  91. }
  92. function clearStorage() {
  93. const appConfig = getAppConfig();
  94. uni.clearStorageSync();
  95. setAppConfig(appConfig);
  96. }
  97. function productsToOrder(productArr) {
  98. uni.setStorageSync(PRODUCTS_TO_ORDER, productArr);
  99. }
  100. function getProductsToOrder() {
  101. return uni.getStorageSync(PRODUCTS_TO_ORDER);
  102. }
  103. function setBaseUserInfo(baseUserInfo) {
  104. uni.setStorageSync(USER_BASE_INFO, baseUserInfo);
  105. }
  106. function getBaseUserInfo() {
  107. return uni.getStorageSync(USER_BASE_INFO);
  108. }
  109. function cleanBaseUserInfo() {
  110. uni.removeStorageSync(USER_BASE_INFO);
  111. }
  112. function setUserInfoData(baseUserInfo) {
  113. uni.setStorageSync(USER_INFO_DATA, baseUserInfo);
  114. }
  115. function getUserInfoData() {
  116. return uni.getStorageSync(USER_INFO_DATA);
  117. }
  118. function cleanUserInfoData() {
  119. uni.removeStorageSync(USER_INFO_DATA);
  120. }
  121. function setMacid(macid) {
  122. uni.setStorageSync(POSITION_MACID, macid);
  123. }
  124. function getMacid() {
  125. return uni.getStorageSync(POSITION_MACID);
  126. }
  127. function setAppConfig(app_config) {
  128. uni.setStorageSync(APP_CONFIG, app_config);
  129. }
  130. function getAppConfig() {
  131. return uni.getStorageSync(APP_CONFIG);
  132. }
  133. function setCarImages(car_imgs) {
  134. uni.setStorageSync(CAR_IMAGES, car_imgs);
  135. }
  136. function getCarImages() {
  137. return uni.getStorageSync(CAR_IMAGES);
  138. }
  139. function setSelectedDeviceInfo(device_info) {
  140. uni.setStorageSync(SELECTED_DEVICE_INFO, device_info);
  141. }
  142. function getSelectedDeviceInfo() {
  143. return uni.getStorageSync(SELECTED_DEVICE_INFO);
  144. }
  145. function setCabinetInfo(cb_info) {
  146. uni.setStorageSync(CB_BLUETOOTH_INFO, cb_info);
  147. }
  148. function getCabinetInfo() {
  149. return uni.getStorageSync(CB_BLUETOOTH_INFO);
  150. }
  151. function setUserCurrentLocation(
  152. location_info = {
  153. longitude: '',
  154. latitude: ''
  155. }
  156. ) {
  157. uni.setStorageSync(USER_CURRENT_LOCATION, location_info);
  158. }
  159. function getUserCurrentLocation() {
  160. return uni.getStorageSync(USER_CURRENT_LOCATION);
  161. }
  162. function setIsScan(isScan) {
  163. uni.setStorageSync(IS_SCAN, isScan);
  164. }
  165. function getIsScan() {
  166. return uni.getStorageSync(IS_SCAN);
  167. }
  168. function setIsAgreement(isAgree) {
  169. uni.setStorageSync(IS_AGREEMENT, isAgree);
  170. }
  171. function getIsAgreement() {
  172. return uni.getStorageSync(IS_AGREEMENT);
  173. }
  174. function setShareCode(shareCode) {
  175. uni.setStorageSync(SHARE_CODE, shareCode);
  176. }
  177. function getShareCode() {
  178. return uni.getStorageSync(SHARE_CODE);
  179. }
  180. function setIsBuyModel(check = false) {
  181. uni.setStorageSync(IS_BUY_MODEL, check);
  182. }
  183. function getIsBuyModel() {
  184. return uni.getStorageSync(IS_BUY_MODEL);
  185. }
  186. module.exports = {
  187. setFunctionTag,
  188. getFunctionTag,
  189. setUserToken: setUserToken,
  190. getUserToken: getUserToken,
  191. clearStorage: clearStorage,
  192. productsToOrder: productsToOrder,
  193. getProductsToOrder: getProductsToOrder,
  194. setUserInfo: setBaseUserInfo,
  195. getUserInfo: getBaseUserInfo,
  196. cleanUserInfo: cleanBaseUserInfo,
  197. setUserInfoData: setUserInfoData,
  198. getUserInfoData: getUserInfoData,
  199. cleanUserInfoData: cleanUserInfoData,
  200. setIsScan: setIsScan,
  201. getIsScan: getIsScan,
  202. setIsAgreement: setIsAgreement,
  203. getIsAgreement: getIsAgreement,
  204. setMacid: setMacid,
  205. getMacid: getMacid,
  206. setAppConfig: setAppConfig,
  207. getAppConfig: getAppConfig,
  208. setCarImages: setCarImages,
  209. getCarImages: getCarImages,
  210. setSelectedDeviceInfo: setSelectedDeviceInfo,
  211. getSelectedDeviceInfo: getSelectedDeviceInfo,
  212. setCabinetInfo: setCabinetInfo,
  213. getCabinetInfo: getCabinetInfo,
  214. setUserCurrentLocation: setUserCurrentLocation,
  215. getUserCurrentLocation: getUserCurrentLocation,
  216. setShareCode: setShareCode,
  217. getShareCode: getShareCode,
  218. setIsLocationAuth: setIsLocationAuth,
  219. getIsLocationAuth: getIsLocationAuth,
  220. getIsBuyModel: getIsBuyModel,
  221. setIsBuyModel: setIsBuyModel
  222. };