iframe.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 iframeStore = defineStore('iframe', () => {
  13. // 定义state
  14. const iframeList = ref([])
  15. const setIframeList = (route) => {
  16. iframeList.value = []
  17. iframeList.value.push(route)
  18. }
  19. // 定义action
  20. const pushIframeList = (route) => {
  21. const target = iframeList.value.find((item) => item.path === route.path)
  22. if (!target) {
  23. iframeList.value.push(route)
  24. }
  25. }
  26. const removeIframeList = (route) => {
  27. iframeList.value.forEach((item, index) => {
  28. if (item.path === route.path) {
  29. iframeList.value.splice(index, 1)
  30. }
  31. })
  32. }
  33. const refreshIframe = (route) => {
  34. iframeList.value.forEach((item) => {
  35. if (item.path === route.path) {
  36. const url = route.meta.url
  37. item.meta.url = ''
  38. setTimeout(() => {
  39. item.meta.url = url
  40. }, 200)
  41. }
  42. })
  43. }
  44. const clearIframeList = () => {
  45. iframeList.value = []
  46. }
  47. return {
  48. iframeList,
  49. setIframeList,
  50. pushIframeList,
  51. removeIframeList,
  52. refreshIframe,
  53. clearIframeList
  54. }
  55. })