mirror of https://github.com/halo-dev/halo
fix: ts error in components package (#4621)
#### What type of PR is this? /kind cleanup /area console #### What this PR does / why we need it: 修复 `@halo-dev/components` 包编译时有 error 级异常的问题。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/4544 #### Special notes for your reviewer: 观察此 PR 的 ci 中是否有异常输出即可。 #### Does this PR introduce a user-facing change? ```release-note None ```pull/4622/head^2
parent
da2d56e7d3
commit
dd55a0f490
|
@ -8,7 +8,7 @@ import {
|
|||
IconForbidLine,
|
||||
IconInformation,
|
||||
} from "../../icons/icons";
|
||||
import { computed, ref } from "vue";
|
||||
import { ref, type Component, markRaw, type Raw } from "vue";
|
||||
import type { Type } from "@/components/dialog/interface";
|
||||
import type { Type as ButtonType } from "@/components/button/interface";
|
||||
|
||||
|
@ -48,25 +48,24 @@ const emit = defineEmits<{
|
|||
(event: "close"): void;
|
||||
}>();
|
||||
|
||||
const icons = {
|
||||
const icons: Record<Type, { icon: Raw<Component>; color: string }> = {
|
||||
success: {
|
||||
icon: IconCheckboxCircle,
|
||||
icon: markRaw(IconCheckboxCircle),
|
||||
color: "green",
|
||||
},
|
||||
info: {
|
||||
icon: IconInformation,
|
||||
icon: markRaw(IconInformation),
|
||||
color: "blue",
|
||||
},
|
||||
warning: {
|
||||
icon: IconErrorWarning,
|
||||
icon: markRaw(IconErrorWarning),
|
||||
color: "orange",
|
||||
},
|
||||
error: {
|
||||
icon: IconForbidLine,
|
||||
icon: markRaw(IconForbidLine),
|
||||
color: "red",
|
||||
},
|
||||
};
|
||||
const icon = computed(() => icons[props.type]);
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
|
@ -108,8 +107,8 @@ const handleClose = () => {
|
|||
<div class="flex justify-between items-start py-2 mb-2">
|
||||
<div class="flex flex-row items-center gap-3">
|
||||
<component
|
||||
:is="icon.icon"
|
||||
:class="`text-${icon.color}-500`"
|
||||
:is="icons[type].icon"
|
||||
:class="`text-${icons[type].color}-500`"
|
||||
class="w-6 h-6"
|
||||
></component>
|
||||
<div class="text-base text-gray-900 font-bold">{{ title }}</div>
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
<script lang="ts" setup>
|
||||
import type { Type } from "./interface";
|
||||
import { computed, onMounted, ref, watchEffect } from "vue";
|
||||
import {
|
||||
onMounted,
|
||||
ref,
|
||||
watchEffect,
|
||||
type Raw,
|
||||
type Component,
|
||||
markRaw,
|
||||
} from "vue";
|
||||
import {
|
||||
IconCheckboxCircle,
|
||||
IconErrorWarning,
|
||||
|
@ -36,27 +43,25 @@ const emit = defineEmits<{
|
|||
(event: "close"): void;
|
||||
}>();
|
||||
|
||||
const icons = {
|
||||
const icons: Record<Type, { icon: Raw<Component>; color: string }> = {
|
||||
success: {
|
||||
icon: IconCheckboxCircle,
|
||||
icon: markRaw(IconCheckboxCircle),
|
||||
color: "text-green-500",
|
||||
},
|
||||
info: {
|
||||
icon: IconInformation,
|
||||
icon: markRaw(IconInformation),
|
||||
color: "text-sky-500",
|
||||
},
|
||||
warning: {
|
||||
icon: IconErrorWarning,
|
||||
icon: markRaw(IconErrorWarning),
|
||||
color: "text-orange-500",
|
||||
},
|
||||
error: {
|
||||
icon: IconForbidLine,
|
||||
icon: markRaw(IconForbidLine),
|
||||
color: "text-red-500",
|
||||
},
|
||||
};
|
||||
|
||||
const icon = computed(() => icons[props.type]);
|
||||
|
||||
const createTimer = () => {
|
||||
if (props.duration < 0) return;
|
||||
timer.value = setTimeout(() => {
|
||||
|
@ -115,7 +120,7 @@ defineExpose({ close });
|
|||
>
|
||||
<div class="toast-body">
|
||||
<div class="toast-icon">
|
||||
<component :is="icon.icon" :class="[icon.color]" />
|
||||
<component :is="icons[type].icon" :class="icons[type].color" />
|
||||
</div>
|
||||
<div class="toast-content">
|
||||
<div class="toast-description">
|
||||
|
|
Loading…
Reference in New Issue