zhou zhou
3 小时以前 46d872c1a5b77aa8799de4a64888a0a24a1422d6
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 }