import { defineStore } from 'pinia' import { ref } from 'vue' import axios from 'axios' export const useSystem = defineStore('system', () => { const systemInfo = ref({ timeDifference: undefined, // 服务器时间 - 浏览器时间 beijingTimestamp: 0 }) const setTimeDifference = (Difference) => { systemInfo.value.timeDifference = Number(Difference) || 0 } const getTimeDifference = () => { const baseUrl = import.meta.env.VITE_ACCESS_BASE_URL const tenantId = import.meta.env?.VITE_TENANTCODE return new Promise((resolve, reject) => { axios.get(`${baseUrl}/app-api/menduner/system/get/version`, { headers: { ['tenant-id']: tenantId }, cache: 'no-store' // 禁用缓存 }).then(({ data }) => { const { time } = data?.data const _now = new Date().getTime() const _tem = time - _now resolve(_tem) }) }) } const breadcrumbs = ref([]) const setBreadcrumbs = (matched, fullPath) => { const _fullPath = fullPath.split('/') const arr = matched.map((item, index) => { // 重组路径 if (item.path === matched[index - 1]?.path) return false const text = item.meta.title const _path = item.path.split('/') const obj = { text, to: _path.map((e, i) => _fullPath[i]).join('/') } return obj }).filter(e => e) || [] if (arr?.length) { arr[arr.length - 1].disabled = true arr[arr.length - 1].link = true } breadcrumbs.value = arr } // 教师 const teacherBreadcrumbs = ref([]) const setTeacherBreadcrumbs = (matched, fullPath) => { const _fullPath = fullPath.split('/') const arr = matched.map((item, index) => { // 重组路径 if (item.path === matched[index - 1]?.path) return false const text = item.meta.title const _path = item.path.split('/') const obj = { text, to: _path.map((e, i) => _fullPath[i]).join('/') } if (item.children && item.children.length) { if (!item.children.find(e => e.path === 'index')) { obj.to += `/${item.children[0].path}` return obj } obj.to += '/index' return obj } return obj }).filter(e => e) || [] if (arr?.length) { arr[arr.length - 1].disabled = true arr[arr.length - 1].link = true } teacherBreadcrumbs.value = arr } return { systemInfo, setTimeDifference, getTimeDifference, setTeacherBreadcrumbs, teacherBreadcrumbs, setBreadcrumbs, breadcrumbs } } )