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,
|
IconForbidLine,
|
||||||
IconInformation,
|
IconInformation,
|
||||||
} from "../../icons/icons";
|
} 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 } from "@/components/dialog/interface";
|
||||||
import type { Type as ButtonType } from "@/components/button/interface";
|
import type { Type as ButtonType } from "@/components/button/interface";
|
||||||
|
|
||||||
|
@ -48,25 +48,24 @@ const emit = defineEmits<{
|
||||||
(event: "close"): void;
|
(event: "close"): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const icons = {
|
const icons: Record<Type, { icon: Raw<Component>; color: string }> = {
|
||||||
success: {
|
success: {
|
||||||
icon: IconCheckboxCircle,
|
icon: markRaw(IconCheckboxCircle),
|
||||||
color: "green",
|
color: "green",
|
||||||
},
|
},
|
||||||
info: {
|
info: {
|
||||||
icon: IconInformation,
|
icon: markRaw(IconInformation),
|
||||||
color: "blue",
|
color: "blue",
|
||||||
},
|
},
|
||||||
warning: {
|
warning: {
|
||||||
icon: IconErrorWarning,
|
icon: markRaw(IconErrorWarning),
|
||||||
color: "orange",
|
color: "orange",
|
||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
icon: IconForbidLine,
|
icon: markRaw(IconForbidLine),
|
||||||
color: "red",
|
color: "red",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const icon = computed(() => icons[props.type]);
|
|
||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
|
||||||
|
@ -108,8 +107,8 @@ const handleClose = () => {
|
||||||
<div class="flex justify-between items-start py-2 mb-2">
|
<div class="flex justify-between items-start py-2 mb-2">
|
||||||
<div class="flex flex-row items-center gap-3">
|
<div class="flex flex-row items-center gap-3">
|
||||||
<component
|
<component
|
||||||
:is="icon.icon"
|
:is="icons[type].icon"
|
||||||
:class="`text-${icon.color}-500`"
|
:class="`text-${icons[type].color}-500`"
|
||||||
class="w-6 h-6"
|
class="w-6 h-6"
|
||||||
></component>
|
></component>
|
||||||
<div class="text-base text-gray-900 font-bold">{{ title }}</div>
|
<div class="text-base text-gray-900 font-bold">{{ title }}</div>
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { Type } from "./interface";
|
import type { Type } from "./interface";
|
||||||
import { computed, onMounted, ref, watchEffect } from "vue";
|
import {
|
||||||
|
onMounted,
|
||||||
|
ref,
|
||||||
|
watchEffect,
|
||||||
|
type Raw,
|
||||||
|
type Component,
|
||||||
|
markRaw,
|
||||||
|
} from "vue";
|
||||||
import {
|
import {
|
||||||
IconCheckboxCircle,
|
IconCheckboxCircle,
|
||||||
IconErrorWarning,
|
IconErrorWarning,
|
||||||
|
@ -36,27 +43,25 @@ const emit = defineEmits<{
|
||||||
(event: "close"): void;
|
(event: "close"): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const icons = {
|
const icons: Record<Type, { icon: Raw<Component>; color: string }> = {
|
||||||
success: {
|
success: {
|
||||||
icon: IconCheckboxCircle,
|
icon: markRaw(IconCheckboxCircle),
|
||||||
color: "text-green-500",
|
color: "text-green-500",
|
||||||
},
|
},
|
||||||
info: {
|
info: {
|
||||||
icon: IconInformation,
|
icon: markRaw(IconInformation),
|
||||||
color: "text-sky-500",
|
color: "text-sky-500",
|
||||||
},
|
},
|
||||||
warning: {
|
warning: {
|
||||||
icon: IconErrorWarning,
|
icon: markRaw(IconErrorWarning),
|
||||||
color: "text-orange-500",
|
color: "text-orange-500",
|
||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
icon: IconForbidLine,
|
icon: markRaw(IconForbidLine),
|
||||||
color: "text-red-500",
|
color: "text-red-500",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const icon = computed(() => icons[props.type]);
|
|
||||||
|
|
||||||
const createTimer = () => {
|
const createTimer = () => {
|
||||||
if (props.duration < 0) return;
|
if (props.duration < 0) return;
|
||||||
timer.value = setTimeout(() => {
|
timer.value = setTimeout(() => {
|
||||||
|
@ -115,7 +120,7 @@ defineExpose({ close });
|
||||||
>
|
>
|
||||||
<div class="toast-body">
|
<div class="toast-body">
|
||||||
<div class="toast-icon">
|
<div class="toast-icon">
|
||||||
<component :is="icon.icon" :class="[icon.color]" />
|
<component :is="icons[type].icon" :class="icons[type].color" />
|
||||||
</div>
|
</div>
|
||||||
<div class="toast-content">
|
<div class="toast-content">
|
||||||
<div class="toast-description">
|
<div class="toast-description">
|
||||||
|
|
Loading…
Reference in New Issue