examTools.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. useUserCache
  3. } from "@/utils/userCache.js"
  4. // 身份确认缓存
  5. const identificationKey = 'ShenFenQueRen'
  6. export function useIdentificationTools() {
  7. const {saveCache,getCache,removeCache} = useUserCache();
  8. function saveIdentCache(key,data) {
  9. saveCache(identificationKey,key, data)
  10. }
  11. function getIdentCache(key) {
  12. return getCache(identificationKey, key)
  13. }
  14. function removeIdentCache(key) {
  15. removeCache(identificationKey,key)
  16. }
  17. return {
  18. saveIdentCache,
  19. getIdentCache,
  20. removeIdentCache
  21. }
  22. }
  23. const ksCache = 'kaoshiCache'
  24. export function useKaoShiCache() {
  25. const {saveCache,getCache,removeCache,getCacheOtherNotKey} = useUserCache();
  26. function saveCacheKs(key,data) {
  27. saveCache(ksCache,key, data)
  28. }
  29. function getCacheKs(key) {
  30. return getCache(ksCache, key)
  31. }
  32. function removeCacheKs(key) {
  33. removeCache(ksCache,key)
  34. }
  35. // 清理考试缓存其他,保留目标缓存 务必使考试缓存保持唯一
  36. function removeCacheKsOther(key) {
  37. const data = getCacheOtherNotKey(ksCache)
  38. if (data) {
  39. Object.keys(data).forEach(item => {
  40. if (item != key) {
  41. removeCacheKs(item)
  42. }
  43. })
  44. }
  45. }
  46. return {
  47. saveCacheKs,
  48. getCacheKs,
  49. removeCacheKs,
  50. removeCacheKsOther
  51. }
  52. }