style(projects): sort defineProps, defineEmits with TS type

This commit is contained in:
Soybean 2024-01-25 23:24:35 +08:00
parent b2c61f0306
commit 123fd4f96c
25 changed files with 100 additions and 97 deletions

View File

@ -28,15 +28,13 @@ const props = withDefaults(defineProps<AdminLayoutProps>(), {
rightFooter: false rightFooter: false
}); });
const emit = defineEmits<Emits>();
const slots = defineSlots<Slots>();
interface Emits { interface Emits {
/** Update siderCollapse */ /** Update siderCollapse */
(e: 'update:siderCollapse', collapse: boolean): void; (e: 'update:siderCollapse', collapse: boolean): void;
} }
const emit = defineEmits<Emits>();
type SlotFn = (props?: Record<string, unknown>) => any; type SlotFn = (props?: Record<string, unknown>) => any;
type Slots = { type Slots = {
@ -51,6 +49,9 @@ type Slots = {
/** Footer */ /** Footer */
footer?: SlotFn; footer?: SlotFn;
}; };
const slots = defineSlots<Slots>();
const cssVars = computed(() => createLayoutCssVars(props)); const cssVars = computed(() => createLayoutCssVars(props));
// config visible // config visible

View File

@ -8,8 +8,6 @@ defineOptions({
defineProps<PageTabProps>(); defineProps<PageTabProps>();
defineSlots<Slots>();
type SlotFn = (props?: Record<string, unknown>) => any; type SlotFn = (props?: Record<string, unknown>) => any;
type Slots = { type Slots = {
@ -32,6 +30,8 @@ type Slots = {
*/ */
suffix?: SlotFn; suffix?: SlotFn;
}; };
defineSlots<Slots>();
</script> </script>
<template> <template>

View File

@ -9,8 +9,6 @@ defineOptions({
defineProps<PageTabProps>(); defineProps<PageTabProps>();
defineSlots<Slots>();
type SlotFn = (props?: Record<string, unknown>) => any; type SlotFn = (props?: Record<string, unknown>) => any;
type Slots = { type Slots = {
@ -33,6 +31,8 @@ type Slots = {
*/ */
suffix?: SlotFn; suffix?: SlotFn;
}; };
defineSlots<Slots>();
</script> </script>
<template> <template>

View File

@ -19,14 +19,12 @@ const props = withDefaults(defineProps<PageTabProps>(), {
closable: true closable: true
}); });
const emit = defineEmits<Emits>();
defineSlots<Slots>();
interface Emits { interface Emits {
(e: 'close'): void; (e: 'close'): void;
} }
const emit = defineEmits<Emits>();
type SlotFn = (props?: Record<string, unknown>) => any; type SlotFn = (props?: Record<string, unknown>) => any;
type Slots = { type Slots = {
@ -50,6 +48,8 @@ type Slots = {
suffix?: SlotFn; suffix?: SlotFn;
}; };
defineSlots<Slots>();
const activeTabComponent = computed(() => { const activeTabComponent = computed(() => {
const { mode, chromeClass, buttonClass } = props; const { mode, chromeClass, buttonClass } = props;

View File

@ -1,11 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
defineOptions({ name: 'DarkModeContainer' }); defineOptions({ name: 'DarkModeContainer' });
defineProps<Props>();
interface Props { interface Props {
inverted?: boolean; inverted?: boolean;
} }
defineProps<Props>();
</script> </script>
<template> <template>

View File

@ -4,8 +4,6 @@ import { $t } from '@/locales';
defineOptions({ name: 'ExceptionBase' }); defineOptions({ name: 'ExceptionBase' });
const props = defineProps<Props>();
type ExceptionType = '403' | '404' | '500'; type ExceptionType = '403' | '404' | '500';
interface Props { interface Props {
@ -19,6 +17,8 @@ interface Props {
type: ExceptionType; type: ExceptionType;
} }
const props = defineProps<Props>();
const iconMap: Record<ExceptionType, string> = { const iconMap: Record<ExceptionType, string> = {
'403': 'no-permission', '403': 'no-permission',
'404': 'not-found', '404': 'not-found',

View File

@ -5,11 +5,11 @@ defineOptions({
name: 'FullScreen' name: 'FullScreen'
}); });
defineProps<Props>();
interface Props { interface Props {
full?: boolean; full?: boolean;
} }
defineProps<Props>();
</script> </script>
<template> <template>

View File

@ -6,12 +6,6 @@ defineOptions({
name: 'LangSwitch' name: 'LangSwitch'
}); });
const props = withDefaults(defineProps<Props>(), {
showTooltip: true
});
const emit = defineEmits<Emits>();
interface Props { interface Props {
/** Current language */ /** Current language */
lang: App.I18n.LangType; lang: App.I18n.LangType;
@ -21,10 +15,16 @@ interface Props {
showTooltip?: boolean; showTooltip?: boolean;
} }
const props = withDefaults(defineProps<Props>(), {
showTooltip: true
});
type Emits = { type Emits = {
(e: 'changeLang', lang: App.I18n.LangType): void; (e: 'changeLang', lang: App.I18n.LangType): void;
}; };
const emit = defineEmits<Emits>();
const tooltipContent = computed(() => { const tooltipContent = computed(() => {
if (!props.showTooltip) return ''; if (!props.showTooltip) return '';

View File

@ -4,8 +4,6 @@ import { $t } from '@/locales';
defineOptions({ name: 'MenuToggler' }); defineOptions({ name: 'MenuToggler' });
const props = defineProps<Props>();
interface Props { interface Props {
/** Show collapsed icon */ /** Show collapsed icon */
collapsed?: boolean; collapsed?: boolean;
@ -13,6 +11,8 @@ interface Props {
arrowIcon?: boolean; arrowIcon?: boolean;
} }
const props = defineProps<Props>();
type NumberBool = 0 | 1; type NumberBool = 0 | 1;
const icon = computed(() => { const icon = computed(() => {

View File

@ -4,12 +4,12 @@ import { $t } from '@/locales';
defineOptions({ name: 'PinToggler' }); defineOptions({ name: 'PinToggler' });
const props = defineProps<Props>();
interface Props { interface Props {
pin?: boolean; pin?: boolean;
} }
const props = defineProps<Props>();
const icon = computed(() => (props.pin ? 'mdi-pin-off' : 'mdi-pin')); const icon = computed(() => (props.pin ? 'mdi-pin-off' : 'mdi-pin'));
</script> </script>

View File

@ -5,11 +5,11 @@ defineOptions({
name: 'ReloadButton' name: 'ReloadButton'
}); });
defineProps<Props>();
interface Props { interface Props {
loading?: boolean; loading?: boolean;
} }
defineProps<Props>();
</script> </script>
<template> <template>

View File

@ -5,13 +5,6 @@ import { $t } from '@/locales';
defineOptions({ name: 'ThemeSchemaSwitch' }); defineOptions({ name: 'ThemeSchemaSwitch' });
const props = withDefaults(defineProps<Props>(), {
showTooltip: true,
tooltipPlacement: 'bottom'
});
const emit = defineEmits<Emits>();
interface Props { interface Props {
/** Theme schema */ /** Theme schema */
themeSchema: UnionKey.ThemeScheme; themeSchema: UnionKey.ThemeScheme;
@ -21,10 +14,17 @@ interface Props {
tooltipPlacement?: PopoverPlacement; tooltipPlacement?: PopoverPlacement;
} }
const props = withDefaults(defineProps<Props>(), {
showTooltip: true,
tooltipPlacement: 'bottom'
});
interface Emits { interface Emits {
(e: 'switch'): void; (e: 'switch'): void;
} }
const emit = defineEmits<Emits>();
function handleSwitch() { function handleSwitch() {
emit('switch'); emit('switch');
} }

View File

@ -6,8 +6,6 @@ import type { Options } from '@better-scroll/core';
defineOptions({ name: 'BetterScroll' }); defineOptions({ name: 'BetterScroll' });
const props = defineProps<Props>();
interface Props { interface Props {
/** /**
* BetterScroll options * BetterScroll options
@ -17,6 +15,8 @@ interface Props {
options: Options; options: Options;
} }
const props = defineProps<Props>();
const bsWrap = ref<HTMLElement>(); const bsWrap = ref<HTMLElement>();
const bsContent = ref<HTMLElement>(); const bsContent = ref<HTMLElement>();
const { width: wrapWidth } = useElementSize(bsWrap); const { width: wrapWidth } = useElementSize(bsWrap);

View File

@ -8,13 +8,6 @@ defineOptions({
inheritAttrs: false inheritAttrs: false
}); });
const props = withDefaults(defineProps<Props>(), {
class: 'h-36px text-icon',
icon: '',
tooltipContent: '',
tooltipPlacement: 'bottom'
});
interface Props { interface Props {
/** Button class */ /** Button class */
class?: string; class?: string;
@ -26,6 +19,13 @@ interface Props {
tooltipPlacement?: PopoverPlacement; tooltipPlacement?: PopoverPlacement;
} }
const props = withDefaults(defineProps<Props>(), {
class: 'h-36px text-icon',
icon: '',
tooltipContent: '',
tooltipPlacement: 'bottom'
});
interface ButtonProps { interface ButtonProps {
className: string; className: string;
} }

View File

@ -6,6 +6,20 @@ defineOptions({
name: 'CountTo' name: 'CountTo'
}); });
interface Props {
startValue?: number;
endValue?: number;
duration?: number;
autoplay?: boolean;
decimals?: number;
prefix?: string;
suffix?: string;
separator?: string;
decimal?: string;
useEasing?: boolean;
transition?: keyof typeof TransitionPresets;
}
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
startValue: 0, startValue: 0,
endValue: 2021, endValue: 2021,
@ -20,22 +34,6 @@ const props = withDefaults(defineProps<Props>(), {
transition: 'linear' transition: 'linear'
}); });
type TransitionKey = keyof typeof TransitionPresets;
interface Props {
startValue?: number;
endValue?: number;
duration?: number;
autoplay?: boolean;
decimals?: number;
prefix?: string;
suffix?: string;
separator?: string;
decimal?: string;
useEasing?: boolean;
transition?: TransitionKey;
}
const source = ref(props.startValue); const source = ref(props.startValue);
const transition = computed(() => (props.useEasing ? TransitionPresets[props.transition] : undefined)); const transition = computed(() => (props.useEasing ? TransitionPresets[props.transition] : undefined));

View File

@ -4,8 +4,6 @@ import { Icon } from '@iconify/vue';
defineOptions({ name: 'SvgIcon' }); defineOptions({ name: 'SvgIcon' });
const props = defineProps<Props>();
/** /**
* Props * Props
* *
@ -19,6 +17,8 @@ interface Props {
localIcon?: string; localIcon?: string;
} }
const props = defineProps<Props>();
const attrs = useAttrs(); const attrs = useAttrs();
const bindAttrs = computed<{ class: string; style: string }>(() => ({ const bindAttrs = computed<{ class: string; style: string }>(() => ({

View File

@ -2,6 +2,8 @@
import { computed } from 'vue'; import { computed } from 'vue';
import { getColorPalette } from '@sa/utils'; import { getColorPalette } from '@sa/utils';
defineOptions({ name: 'WaveBg' });
interface Props { interface Props {
/** Theme color */ /** Theme color */
themeColor: string; themeColor: string;

View File

@ -7,15 +7,15 @@ defineOptions({
name: 'GlobalContent' name: 'GlobalContent'
}); });
withDefaults(defineProps<Props>(), {
showPadding: true
});
interface Props { interface Props {
/** Show padding for content */ /** Show padding for content */
showPadding?: boolean; showPadding?: boolean;
} }
withDefaults(defineProps<Props>(), {
showPadding: true
});
const appStore = useAppStore(); const appStore = useAppStore();
const themeStore = useThemeStore(); const themeStore = useThemeStore();
const routeStore = useRouteStore(); const routeStore = useRouteStore();

View File

@ -14,12 +14,6 @@ import UserAvatar from './components/user-avatar.vue';
defineOptions({ defineOptions({
name: 'GlobalHeader' name: 'GlobalHeader'
}); });
defineProps<Props>();
const appStore = useAppStore();
const themeStore = useThemeStore();
const routeStore = useRouteStore();
const { isFullscreen, toggle } = useFullscreen();
const { menus } = useMixMenuContext();
interface Props { interface Props {
/** Whether to show the logo */ /** Whether to show the logo */
@ -30,6 +24,14 @@ interface Props {
showMenu?: App.Global.HeaderProps['showMenu']; showMenu?: App.Global.HeaderProps['showMenu'];
} }
defineProps<Props>();
const appStore = useAppStore();
const themeStore = useThemeStore();
const routeStore = useRouteStore();
const { isFullscreen, toggle } = useFullscreen();
const { menus } = useMixMenuContext();
const headerMenus = computed(() => { const headerMenus = computed(() => {
if (themeStore.layout.mode === 'horizontal') { if (themeStore.layout.mode === 'horizontal') {
return routeStore.menus; return routeStore.menus;

View File

@ -5,14 +5,14 @@ defineOptions({
name: 'GlobalLogo' name: 'GlobalLogo'
}); });
withDefaults(defineProps<Props>(), {
showTitle: true
});
interface Props { interface Props {
/** Whether to show the title */ /** Whether to show the title */
showTitle?: boolean; showTitle?: boolean;
} }
withDefaults(defineProps<Props>(), {
showTitle: true
});
</script> </script>
<template> <template>

View File

@ -13,16 +13,16 @@ defineOptions({
name: 'BaseMenu' name: 'BaseMenu'
}); });
const props = withDefaults(defineProps<Props>(), {
mode: 'vertical'
});
interface Props { interface Props {
darkTheme?: boolean; darkTheme?: boolean;
mode?: MenuProps['mode']; mode?: MenuProps['mode'];
menus: App.Global.Menu[]; menus: App.Global.Menu[];
} }
const props = withDefaults(defineProps<Props>(), {
mode: 'vertical'
});
const route = useRoute(); const route = useRoute();
const appStore = useAppStore(); const appStore = useAppStore();
const themeStore = useThemeStore(); const themeStore = useThemeStore();

View File

@ -11,19 +11,19 @@ defineOptions({
name: 'FirstLevelMenu' name: 'FirstLevelMenu'
}); });
defineProps<Props>();
const emit = defineEmits<Emits>();
interface Props { interface Props {
activeMenuKey?: string; activeMenuKey?: string;
inverted?: boolean; inverted?: boolean;
} }
defineProps<Props>();
interface Emits { interface Emits {
(e: 'select', menu: App.Global.Menu): boolean; (e: 'select', menu: App.Global.Menu): boolean;
} }
const emit = defineEmits<Emits>();
const appStore = useAppStore(); const appStore = useAppStore();
const themeStore = useThemeStore(); const themeStore = useThemeStore();
const routeStore = useRouteStore(); const routeStore = useRouteStore();

View File

@ -10,11 +10,6 @@ defineOptions({
name: 'ContextMenu' name: 'ContextMenu'
}); });
const props = withDefaults(defineProps<Props>(), {
excludeKeys: () => [],
disabledKeys: () => []
});
interface Props { interface Props {
/** ClientX */ /** ClientX */
x: number; x: number;
@ -25,6 +20,11 @@ interface Props {
disabledKeys?: App.Global.DropdownKey[]; disabledKeys?: App.Global.DropdownKey[];
} }
const props = withDefaults(defineProps<Props>(), {
excludeKeys: () => [],
disabledKeys: () => []
});
const visible = defineModel<boolean>('visible'); const visible = defineModel<boolean>('visible');
const { removeTab, clearTabs, clearLeftTabs, clearRightTabs } = useTabStore(); const { removeTab, clearTabs, clearLeftTabs, clearRightTabs } = useTabStore();

View File

@ -7,10 +7,6 @@ defineOptions({
name: 'LayoutModeCard' name: 'LayoutModeCard'
}); });
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
interface Props { interface Props {
/** Layout mode */ /** Layout mode */
mode: UnionKey.ThemeLayoutMode; mode: UnionKey.ThemeLayoutMode;
@ -18,11 +14,15 @@ interface Props {
disabled?: boolean; disabled?: boolean;
} }
const props = defineProps<Props>();
interface Emits { interface Emits {
/** Layout mode change */ /** Layout mode change */
(e: 'update:mode', mode: UnionKey.ThemeLayoutMode): void; (e: 'update:mode', mode: UnionKey.ThemeLayoutMode): void;
} }
const emit = defineEmits<Emits>();
type LayoutConfig = Record< type LayoutConfig = Record<
UnionKey.ThemeLayoutMode, UnionKey.ThemeLayoutMode,
{ {

View File

@ -3,12 +3,12 @@ defineOptions({
name: 'SettingItem' name: 'SettingItem'
}); });
defineProps<Props>();
interface Props { interface Props {
/** Label */ /** Label */
label: string; label: string;
} }
defineProps<Props>();
</script> </script>
<template> <template>