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 { useAuthStore } from '@/store'
import { isArray, isString } from 'radash'
/** 权限判断 */ /** 权限判断 */
export function usePermission() { export function usePermission() {
const authStore = useAuthStore() const authStore = useAuthStore()
function hasPermission( function hasPermission(
permission?: Entity.RoleType[], permission?: Entity.RoleType | Entity.RoleType[],
) { ) {
if (!permission) if (!permission)
return true return true
@ -14,9 +15,16 @@ export function usePermission() {
return false return false
const { role } = authStore.userInfo const { role } = authStore.userInfo
// 角色为super可直接通过
let has = role.includes('super') let has = role.includes('super')
if (!has) { 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 return has
} }

View File

@ -14,6 +14,7 @@ import Reload from './Reload.vue'
import TabBarItem from './TabBarItem.vue' import TabBarItem from './TabBarItem.vue'
const tabStore = useTabStore() const tabStore = useTabStore()
const { tabs } = storeToRefs(useTabStore())
const appStore = useAppStore() const appStore = useAppStore()
const router = useRouter() const router = useRouter()
@ -101,11 +102,9 @@ function onClickoutside() {
showDropdown.value = false showDropdown.value = false
} }
// const [DefineTabItem, ReuseTabItem] = createReusableTemplate<{ route: RouteLocationNormalized }>()
const el = ref() const el = ref()
useDraggable(el, tabStore.tabs, { useDraggable(el, tabs, {
animation: 150, animation: 150,
ghostClass: 'ghost', ghostClass: 'ghost',
}) })

View File

@ -21,5 +21,5 @@ export function fetchUpdateToken(data: any) {
} }
export function fetchUserRoutes(params: { id: number }) { 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 { createAlova } from 'alova'
import { createServerTokenAuthentication } from 'alova/client' import { createServerTokenAuthentication } from 'alova/client'
import adapterFetch from 'alova/fetch' import adapterFetch from 'alova/fetch'
import VueHook, { type VueHookType } from 'alova/vue' import VueHook from 'alova/vue'
import type { VueHookType } from 'alova/vue'
import { import {
DEFAULT_ALOVA_OPTIONS, DEFAULT_ALOVA_OPTIONS,
DEFAULT_BACKEND_OPTIONS, DEFAULT_BACKEND_OPTIONS,

View File

@ -28,6 +28,12 @@ declare namespace NaiveUI {
type ThemeColor = 'default' | 'error' | 'primary' | 'info' | 'success' | 'warning' 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 { declare namespace Storage {
interface Session { interface Session {
dict: DictMap dict: DictMap

View File

@ -1,5 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { type ECOption, useEcharts } from '@/hooks' import { useEcharts } from '@/hooks'
import type { ECOption } from '@/hooks'
import { graphic } from 'echarts' import { graphic } from 'echarts'
const lineOptions = ref<ECOption>({ const lineOptions = ref<ECOption>({

View File

@ -1,5 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { type ECOption, useEcharts } from '@/hooks' import { useEcharts } from '@/hooks'
import type { ECOption } from '@/hooks'
import { graphic } from 'echarts' import { graphic } from 'echarts'
const chartData = [ const chartData = [

View File

@ -1,5 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { type ECOption, useEcharts } from '@/hooks' import { useEcharts } from '@/hooks'
import type { ECOption } from '@/hooks'
const option = ref<ECOption>({ const option = ref<ECOption>({
tooltip: { tooltip: {
@ -47,8 +48,7 @@ const option = ref<ECOption>({
name: '小红书', name: '小红书',
}, },
], ],
}, }],
],
}) as Ref<ECOption> }) as Ref<ECOption>
useEcharts('lineRef', option) useEcharts('lineRef', option)
</script> </script>

View File

@ -1,5 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { type ECOption, useEcharts } from '@/hooks' import { useEcharts } from '@/hooks'
import type { ECOption } from '@/hooks'
// 线 // 线
const lineOptions = ref<ECOption>({ const lineOptions = ref<ECOption>({
tooltip: { tooltip: {

View File

@ -1,5 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { type ECOption, useEcharts } from '@/hooks' import { useEcharts } from '@/hooks'
import type { ECOption } from '@/hooks'
import { graphic } from 'echarts' import { graphic } from 'echarts'
// //

View File

@ -4,7 +4,6 @@ import { useAuthStore } from '@/store'
const authStore = useAuthStore() const authStore = useAuthStore()
const { hasPermission } = usePermission() const { hasPermission } = usePermission()
const { role } = authStore.userInfo
const roleList: Entity.RoleType[] = ['super', 'admin', 'user'] const roleList: Entity.RoleType[] = ['super', 'admin', 'user']
@ -15,7 +14,7 @@ function toggleUserRole(role: Entity.RoleType) {
<template> <template>
<n-card title="权限示例"> <n-card title="权限示例">
<n-h1> 当前权限{{ role }}</n-h1> <n-h1> 当前权限{{ authStore.userInfo!.role }}</n-h1>
<n-button-group> <n-button-group>
<n-button v-for="item in roleList" :key="item" type="default" @click="toggleUserRole(item)"> <n-button v-for="item in roleList" :key="item" type="default" @click="toggleUserRole(item)">
{{ item }} {{ item }}