fix: type error

This commit is contained in:
chansee97 2025-04-09 19:20:02 +08:00
parent a5c3697a6b
commit f0647c7697
12 changed files with 34 additions and 17 deletions

View File

@ -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
}

View File

@ -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',
})

View File

@ -38,4 +38,4 @@ const emit = defineEmits<{
</button>
</div>
</n-el>
</template>
</template>

View File

@ -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 })
}

View File

@ -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,

View File

@ -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

View File

@ -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>({

View File

@ -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 = [

View File

@ -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>

View File

@ -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: {

View File

@ -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'
//

View File

@ -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 }}