mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-08-19 16:29:53 +08:00
fix: type error
This commit is contained in:
parent
a5c3697a6b
commit
f0647c7697
@ -1,11 +1,12 @@
|
||||
import { useAuthStore } from '@/store'
|
||||
import { isArray, isString } from 'radash'
|
||||
|
||||
/** 权限判断 */
|
||||
export function usePermission() {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
function hasPermission(
|
||||
permission?: Entity.RoleType[],
|
||||
permission?: Entity.RoleType | Entity.RoleType[],
|
||||
) {
|
||||
if (!permission)
|
||||
return true
|
||||
@ -14,9 +15,16 @@ export function usePermission() {
|
||||
return false
|
||||
const { role } = authStore.userInfo
|
||||
|
||||
// 角色为super可直接通过
|
||||
let has = role.includes('super')
|
||||
if (!has) {
|
||||
has = permission.every(i => role.includes(i))
|
||||
if (isArray(permission))
|
||||
// 角色为数组, 判断是否有交集
|
||||
has = permission.some(i => role.includes(i))
|
||||
|
||||
if (isString(permission))
|
||||
// 角色为字符串, 判断是否包含
|
||||
has = role.includes(permission)
|
||||
}
|
||||
return has
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import Reload from './Reload.vue'
|
||||
import TabBarItem from './TabBarItem.vue'
|
||||
|
||||
const tabStore = useTabStore()
|
||||
const { tabs } = storeToRefs(useTabStore())
|
||||
const appStore = useAppStore()
|
||||
|
||||
const router = useRouter()
|
||||
@ -101,11 +102,9 @@ function onClickoutside() {
|
||||
showDropdown.value = false
|
||||
}
|
||||
|
||||
// const [DefineTabItem, ReuseTabItem] = createReusableTemplate<{ route: RouteLocationNormalized }>()
|
||||
|
||||
const el = ref()
|
||||
|
||||
useDraggable(el, tabStore.tabs, {
|
||||
useDraggable(el, tabs, {
|
||||
animation: 150,
|
||||
ghostClass: 'ghost',
|
||||
})
|
||||
|
@ -38,4 +38,4 @@ const emit = defineEmits<{
|
||||
</button>
|
||||
</div>
|
||||
</n-el>
|
||||
</template>
|
||||
</template>
|
||||
|
@ -21,5 +21,5 @@ export function fetchUpdateToken(data: any) {
|
||||
}
|
||||
|
||||
export function fetchUserRoutes(params: { id: number }) {
|
||||
return request.Get<Service.ResponseResult<AppRoute.RowRoute[]> >('/getUserRoutes', { params })
|
||||
return request.Get<Service.ResponseResult<AppRoute.RowRoute[]>>('/getUserRoutes', { params })
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ import { local } from '@/utils'
|
||||
import { createAlova } from 'alova'
|
||||
import { createServerTokenAuthentication } from 'alova/client'
|
||||
import adapterFetch from 'alova/fetch'
|
||||
import VueHook, { type VueHookType } from 'alova/vue'
|
||||
import VueHook from 'alova/vue'
|
||||
import type { VueHookType } from 'alova/vue'
|
||||
import {
|
||||
DEFAULT_ALOVA_OPTIONS,
|
||||
DEFAULT_BACKEND_OPTIONS,
|
||||
|
6
src/typings/global.d.ts
vendored
6
src/typings/global.d.ts
vendored
@ -28,6 +28,12 @@ declare namespace NaiveUI {
|
||||
type ThemeColor = 'default' | 'error' | 'primary' | 'info' | 'success' | 'warning'
|
||||
}
|
||||
|
||||
// 修复naive-ui的TabPane组件的slots类型 https://github.com/tusen-ai/naive-ui/issues/6779 ,但是直接这样会导致更多类型报错,也无法查看naive-ui的源码
|
||||
// declare module 'naive-ui' {
|
||||
// interface TabPaneSlots {
|
||||
// tab?: () => VNode[]
|
||||
// }
|
||||
// }
|
||||
declare namespace Storage {
|
||||
interface Session {
|
||||
dict: DictMap
|
||||
|
@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { type ECOption, useEcharts } from '@/hooks'
|
||||
import { useEcharts } from '@/hooks'
|
||||
import type { ECOption } from '@/hooks'
|
||||
import { graphic } from 'echarts'
|
||||
|
||||
const lineOptions = ref<ECOption>({
|
||||
|
@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { type ECOption, useEcharts } from '@/hooks'
|
||||
import { useEcharts } from '@/hooks'
|
||||
import type { ECOption } from '@/hooks'
|
||||
import { graphic } from 'echarts'
|
||||
|
||||
const chartData = [
|
||||
|
@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { type ECOption, useEcharts } from '@/hooks'
|
||||
import { useEcharts } from '@/hooks'
|
||||
import type { ECOption } from '@/hooks'
|
||||
|
||||
const option = ref<ECOption>({
|
||||
tooltip: {
|
||||
@ -47,8 +48,7 @@ const option = ref<ECOption>({
|
||||
name: '小红书',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}],
|
||||
}) as Ref<ECOption>
|
||||
useEcharts('lineRef', option)
|
||||
</script>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { type ECOption, useEcharts } from '@/hooks'
|
||||
import { useEcharts } from '@/hooks'
|
||||
import type { ECOption } from '@/hooks'
|
||||
// 折线图
|
||||
const lineOptions = ref<ECOption>({
|
||||
tooltip: {
|
||||
|
@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { type ECOption, useEcharts } from '@/hooks'
|
||||
import { useEcharts } from '@/hooks'
|
||||
import type { ECOption } from '@/hooks'
|
||||
import { graphic } from 'echarts'
|
||||
|
||||
// 饼状图
|
||||
|
@ -4,7 +4,6 @@ import { useAuthStore } from '@/store'
|
||||
|
||||
const authStore = useAuthStore()
|
||||
const { hasPermission } = usePermission()
|
||||
const { role } = authStore.userInfo
|
||||
|
||||
const roleList: Entity.RoleType[] = ['super', 'admin', 'user']
|
||||
|
||||
@ -15,7 +14,7 @@ function toggleUserRole(role: Entity.RoleType) {
|
||||
|
||||
<template>
|
||||
<n-card title="权限示例">
|
||||
<n-h1> 当前权限:{{ role }}</n-h1>
|
||||
<n-h1> 当前权限:{{ authStore.userInfo!.role }}</n-h1>
|
||||
<n-button-group>
|
||||
<n-button v-for="item in roleList" :key="item" type="default" @click="toggleUserRole(item)">
|
||||
{{ item }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user