storage.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. iconUrl: `${QINIU_URL}FmbcjmvoB4J3CT1hrbjNX4kxv9Zq`
  55. },
  56. {
  57. name: i18n.t('电池信息'),
  58. type:'batteryInfo',
  59. iconUrl: `${QINIU_URL}Fnx_4tLoq1ytvVA0UemepWisI73A`
  60. },
  61. {
  62. name: i18n.t('导航'),
  63. type:'navigation',
  64. iconUrl: `${QINIU_URL}FrA_ouJtDp-39g7rMBI0EYr2czVE`
  65. }
  66. ]
  67. function setFunctionTag(tag = {}) {
  68. uni.setStorageSync(FUNCTIONTAG, tag);
  69. }
  70. function getFunctionTag() {
  71. let list = uni.getStorageSync(FUNCTIONTAG) || {
  72. activeTag:activeTabs,
  73. tag:toBeSelectTabs,
  74. }
  75. return list
  76. }
  77. function setIsLocationAuth(location_auth) {
  78. uni.setStorageSync(IS_LOCATION_AUTH, location_auth);
  79. }
  80. function getIsLocationAuth() {
  81. return uni.getStorageSync(IS_LOCATION_AUTH);
  82. }
  83. function setUserToken(user_token) {
  84. uni.setStorageSync(STORAGE_USER_TOKEN, user_token);
  85. }
  86. function getUserToken() {
  87. return uni.getStorageSync(STORAGE_USER_TOKEN);
  88. }
  89. function clearStorage() {
  90. const appConfig = getAppConfig();
  91. uni.clearStorageSync();
  92. setAppConfig(appConfig);
  93. }
  94. function productsToOrder(productArr) {
  95. uni.setStorageSync(PRODUCTS_TO_ORDER, productArr);
  96. }
  97. function getProductsToOrder() {
  98. return uni.getStorageSync(PRODUCTS_TO_ORDER);
  99. }
  100. function setBaseUserInfo(baseUserInfo) {
  101. uni.setStorageSync(USER_BASE_INFO, baseUserInfo);
  102. }
  103. function getBaseUserInfo() {
  104. return uni.getStorageSync(USER_BASE_INFO);
  105. }
  106. function cleanBaseUserInfo() {
  107. uni.removeStorageSync(USER_BASE_INFO);
  108. }
  109. function setUserInfoData(baseUserInfo) {
  110. uni.setStorageSync(USER_INFO_DATA, baseUserInfo);
  111. }
  112. function getUserInfoData() {
  113. return uni.getStorageSync(USER_INFO_DATA);
  114. }
  115. function cleanUserInfoData() {
  116. uni.removeStorageSync(USER_INFO_DATA);
  117. }
  118. function setMacid(macid) {
  119. uni.setStorageSync(POSITION_MACID, macid);
  120. }
  121. function getMacid() {
  122. return uni.getStorageSync(POSITION_MACID);
  123. }
  124. function setAppConfig(app_config) {
  125. uni.setStorageSync(APP_CONFIG, app_config);
  126. }
  127. function getAppConfig() {
  128. return uni.getStorageSync(APP_CONFIG);
  129. }
  130. function setCarImages(car_imgs) {
  131. uni.setStorageSync(CAR_IMAGES, car_imgs);
  132. }
  133. function getCarImages() {
  134. return uni.getStorageSync(CAR_IMAGES);
  135. }
  136. function setSelectedDeviceInfo(device_info) {
  137. uni.setStorageSync(SELECTED_DEVICE_INFO, device_info);
  138. }
  139. function getSelectedDeviceInfo() {
  140. return uni.getStorageSync(SELECTED_DEVICE_INFO);
  141. }
  142. function setCabinetInfo(cb_info) {
  143. uni.setStorageSync(CB_BLUETOOTH_INFO, cb_info);
  144. }
  145. function getCabinetInfo() {
  146. return uni.getStorageSync(CB_BLUETOOTH_INFO);
  147. }
  148. function setUserCurrentLocation(
  149. location_info = {
  150. longitude: '',
  151. latitude: ''
  152. }
  153. ) {
  154. uni.setStorageSync(USER_CURRENT_LOCATION, location_info);
  155. }
  156. function getUserCurrentLocation() {
  157. return uni.getStorageSync(USER_CURRENT_LOCATION);
  158. }
  159. function setIsScan(isScan) {
  160. uni.setStorageSync(IS_SCAN, isScan);
  161. }
  162. function getIsScan() {
  163. return uni.getStorageSync(IS_SCAN);
  164. }
  165. function setIsAgreement(isAgree) {
  166. uni.setStorageSync(IS_AGREEMENT, isAgree);
  167. }
  168. function getIsAgreement() {
  169. return uni.getStorageSync(IS_AGREEMENT);
  170. }
  171. function setShareCode(shareCode) {
  172. uni.setStorageSync(SHARE_CODE, shareCode);
  173. }
  174. function getShareCode() {
  175. return uni.getStorageSync(SHARE_CODE);
  176. }
  177. function setIsBuyModel(check = false) {
  178. uni.setStorageSync(IS_BUY_MODEL, check);
  179. }
  180. function getIsBuyModel() {
  181. return uni.getStorageSync(IS_BUY_MODEL);
  182. }
  183. module.exports = {
  184. setFunctionTag,
  185. getFunctionTag,
  186. setUserToken: setUserToken,
  187. getUserToken: getUserToken,
  188. clearStorage: clearStorage,
  189. productsToOrder: productsToOrder,
  190. getProductsToOrder: getProductsToOrder,
  191. setUserInfo: setBaseUserInfo,
  192. getUserInfo: getBaseUserInfo,
  193. cleanUserInfo: cleanBaseUserInfo,
  194. setUserInfoData: setUserInfoData,
  195. getUserInfoData: getUserInfoData,
  196. cleanUserInfoData: cleanUserInfoData,
  197. setIsScan: setIsScan,
  198. getIsScan: getIsScan,
  199. setIsAgreement: setIsAgreement,
  200. getIsAgreement: getIsAgreement,
  201. setMacid: setMacid,
  202. getMacid: getMacid,
  203. setAppConfig: setAppConfig,
  204. getAppConfig: getAppConfig,
  205. setCarImages: setCarImages,
  206. getCarImages: getCarImages,
  207. setSelectedDeviceInfo: setSelectedDeviceInfo,
  208. getSelectedDeviceInfo: getSelectedDeviceInfo,
  209. setCabinetInfo: setCabinetInfo,
  210. getCabinetInfo: getCabinetInfo,
  211. setUserCurrentLocation: setUserCurrentLocation,
  212. getUserCurrentLocation: getUserCurrentLocation,
  213. setShareCode: setShareCode,
  214. getShareCode: getShareCode,
  215. setIsLocationAuth: setIsLocationAuth,
  216. getIsLocationAuth: getIsLocationAuth,
  217. getIsBuyModel: getIsBuyModel,
  218. setIsBuyModel: setIsBuyModel
  219. };