system.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. return obj
  41. }).filter(e => e) || []
  42. if (arr?.length) {
  43. arr[arr.length - 1].disabled = true
  44. arr[arr.length - 1].link = true
  45. }
  46. breadcrumbs.value = arr
  47. }
  48. return {
  49. systemInfo,
  50. setTimeDifference,
  51. getTimeDifference,
  52. setBreadcrumbs,
  53. breadcrumbs
  54. }
  55. }
  56. )