zhou zhou
4 小时以前 fec285d150b377d004e47f0973d298b92fe4c711
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { useRoute } from 'vue-router'
import { storeToRefs } from 'pinia'
import { useUserStore } from '@/store/modules/user'
import { useAppMode } from '@/hooks/core/useAppMode'
const userStore = useUserStore()
const useAuth = () => {
  const route = useRoute()
  const { isFrontendMode } = useAppMode()
  const { info } = storeToRefs(userStore)
  const frontendAuthList = info.value?.buttons ?? []
  const backendAuthList = Array.isArray(route.meta.authList) ? route.meta.authList : []
  const hasAuth = (auth) => {
    if (isFrontendMode.value) {
      return frontendAuthList.includes(auth)
    }
    return backendAuthList.some((item) => item?.authMark === auth)
  }
  return {
    hasAuth
  }
}
export { useAuth }