keepAlive.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright [2022] [https://www.xiaonuo.vip]
  3. * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
  4. * 1.请不要删除和修改根目录下的LICENSE文件。
  5. * 2.请不要删除和修改Snowy源码头部的版权声明。
  6. * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
  7. * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
  8. * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
  9. * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
  10. */
  11. import { defineStore } from 'pinia'
  12. export const keepAliveStore = defineStore('keepAlive', () => {
  13. // 定义state
  14. const keepLiveRoute = ref([])
  15. const routeKey = ref(null)
  16. const routeShow = ref(true)
  17. // 定义action
  18. const pushKeepLive = (component) => {
  19. if (!keepLiveRoute.value.includes(component)) {
  20. keepLiveRoute.value.push(component)
  21. }
  22. }
  23. const removeKeepLive = (component) => {
  24. const index = keepLiveRoute.value.indexOf(component)
  25. if (index !== -1) {
  26. keepLiveRoute.value.splice(index, 1)
  27. }
  28. }
  29. const clearKeepLive = () => {
  30. keepLiveRoute.value = []
  31. }
  32. const setRouteKey = (key) => {
  33. routeKey.value = key
  34. }
  35. const setRouteShow = (key) => {
  36. routeShow.value = key
  37. }
  38. const setRouteKeyAction = (key) => {
  39. setRouteKey(key)
  40. }
  41. return {
  42. keepLiveRoute,
  43. routeKey,
  44. routeShow,
  45. pushKeepLive,
  46. removeKeepLive,
  47. clearKeepLive,
  48. setRouteKey,
  49. setRouteShow,
  50. setRouteKeyAction
  51. }
  52. })