cookie.js 901 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const doc = null
  2. const CACHE_KEY = 'clear_0.0.1'
  3. // const doc = window.document;
  4. function get(key) {
  5. return uni.getStorageSync(key)
  6. }
  7. function all() {
  8. return uni.getStorageInfoSync()
  9. }
  10. function set(key, data, time) {
  11. console.log("--> % set % key:\n", key)
  12. console.log("--> % set % data:\n", data)
  13. if (!key) {
  14. return
  15. }
  16. uni.setStorageSync(key, data)
  17. }
  18. function remove(key) {
  19. if (!key || !_has(key)) {
  20. return
  21. }
  22. uni.removeStorageSync(key)
  23. }
  24. function clearAll() {
  25. const res = uni.getStorageInfoSync()
  26. res.keys.map(item => {
  27. if (item == 'redirect' || item == 'spread' || item == CACHE_KEY) {
  28. return
  29. }
  30. remove(item)
  31. })
  32. }
  33. function _has(key) {
  34. if (!key) {
  35. return
  36. }
  37. let value = uni.getStorageSync(key)
  38. if (value) {
  39. return true
  40. }
  41. return false
  42. }
  43. export default {
  44. get,
  45. all,
  46. set,
  47. remove,
  48. clearAll,
  49. has: _has,
  50. CACHE_KEY,
  51. }