1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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 = Difference
- }
- const getTimeDifference = () => {
- const baseUrl = import.meta.env.VITE_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
- }
- return {
- systemInfo,
- setTimeDifference,
- getTimeDifference,
- setBreadcrumbs,
- breadcrumbs
- }
- }
- )
|