system.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { defineStore } from 'pinia'
  2. import { ref } from 'vue'
  3. import axios from 'axios'
  4. export const useSystem = defineStore('system',
  5. () => {
  6. const systemInfo = ref({
  7. timeDifference: undefined, // 服务器时间 - 浏览器时间
  8. beijingTimestamp: 0
  9. })
  10. const setTimeDifference = (Difference) => {
  11. systemInfo.value.timeDifference = Difference
  12. }
  13. const getTimeDifference = () => {
  14. const baseUrl = import.meta.env.VITE_BASE_URL
  15. const tenantId = import.meta.env?.VITE_TENANTCODE
  16. return new Promise((resolve, reject) => {
  17. axios.get(`${baseUrl}/app-api/menduner/system/get/version`, {
  18. headers: { ['tenant-id']: tenantId },
  19. cache: 'no-store' // 禁用缓存
  20. }).then(({ data }) => {
  21. const { time } = data?.data
  22. const _now = new Date().getTime()
  23. const _tem = time - _now
  24. resolve(_tem)
  25. })
  26. })
  27. }
  28. const breadcrumbs = ref([])
  29. const setBreadcrumbs = (matched, fullPath) => {
  30. const _fullPath = fullPath.split('/')
  31. const arr = matched.map((item, index) => {
  32. // 重组路径
  33. if (item.path === matched[index - 1]?.path) return false
  34. const text = item.meta.title
  35. const _path = item.path.split('/')
  36. const obj = {
  37. text,
  38. to: _path.map((e, i) => _fullPath[i]).join('/')
  39. }
  40. if (item.children && item.children.length) {
  41. if (!item.children.find(e => e.path === 'index')) {
  42. obj.to += `/${item.children[0].path}`
  43. return obj
  44. }
  45. obj.to += '/index'
  46. return obj
  47. }
  48. return obj
  49. }).filter(e => e) || []
  50. if (arr?.length) {
  51. arr[arr.length - 1].disabled = true
  52. arr[arr.length - 1].link = true
  53. }
  54. breadcrumbs.value = arr
  55. }
  56. // 教师
  57. const teacherBreadcrumbs = ref([])
  58. const setTeacherBreadcrumbs = (matched, fullPath) => {
  59. const _fullPath = fullPath.split('/')
  60. const arr = matched.map((item, index) => {
  61. // 重组路径
  62. if (item.path === matched[index - 1]?.path) return false
  63. const text = item.meta.title
  64. const _path = item.path.split('/')
  65. const obj = {
  66. text,
  67. to: _path.map((e, i) => _fullPath[i]).join('/')
  68. }
  69. if (item.children && item.children.length) {
  70. if (!item.children.find(e => e.path === 'index')) {
  71. obj.to += `/${item.children[0].path}`
  72. return obj
  73. }
  74. obj.to += '/index'
  75. return obj
  76. }
  77. return obj
  78. }).filter(e => e) || []
  79. if (arr?.length) {
  80. arr[arr.length - 1].disabled = true
  81. arr[arr.length - 1].link = true
  82. }
  83. teacherBreadcrumbs.value = arr
  84. }
  85. return {
  86. systemInfo,
  87. setTimeDifference,
  88. getTimeDifference,
  89. setTeacherBreadcrumbs,
  90. teacherBreadcrumbs,
  91. setBreadcrumbs,
  92. breadcrumbs
  93. }
  94. }
  95. )