mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
✏️ 完善 showConfirm 类型
This commit is contained in:
@@ -4,12 +4,26 @@
|
||||
* @since Beta v0.3.3
|
||||
*/
|
||||
|
||||
import { h, render, type VNode } from "vue";
|
||||
import { h, render } from "vue";
|
||||
import type { ComponentInternalInstance, VNode } from "vue";
|
||||
|
||||
import confirm from "./confirm.vue";
|
||||
|
||||
const confirmId = "tg-func-confirm";
|
||||
|
||||
/**
|
||||
* @description 自定义 confirm 组件
|
||||
* @since Beta v0.3.3
|
||||
* @extends ComponentInternalInstance
|
||||
* @property {Function} exposeProxy.displayBox 显示 confirm
|
||||
* @return ConfirmInstance
|
||||
*/
|
||||
interface ConfirmInstance extends ComponentInternalInstance {
|
||||
exposeProxy: {
|
||||
displayBox: typeof TGApp.Component.Confirm.displayBox;
|
||||
};
|
||||
}
|
||||
|
||||
const renderBox = (props: TGApp.Component.Confirm.Params): VNode => {
|
||||
const container = document.createElement("div");
|
||||
container.id = confirmId;
|
||||
@@ -21,14 +35,17 @@ const renderBox = (props: TGApp.Component.Confirm.Params): VNode => {
|
||||
|
||||
let confirmInstance: VNode;
|
||||
|
||||
const showConfirm = async (props: TGApp.Component.Confirm.Params): Promise<string | boolean> => {
|
||||
async function showConfirm(props: TGApp.Component.Confirm.ParamsConfirm): Promise<boolean>;
|
||||
async function showConfirm(props: TGApp.Component.Confirm.ParamsInput): Promise<string>;
|
||||
async function showConfirm(props: TGApp.Component.Confirm.Params): Promise<string | boolean>;
|
||||
async function showConfirm(props: TGApp.Component.Confirm.Params): Promise<string | boolean> {
|
||||
if (confirmInstance !== undefined) {
|
||||
const boxVue = confirmInstance.component;
|
||||
return boxVue?.exposeProxy?.displayBox(props);
|
||||
const boxVue = <ConfirmInstance>confirmInstance.component;
|
||||
return boxVue.exposeProxy.displayBox(props);
|
||||
} else {
|
||||
confirmInstance = renderBox(props);
|
||||
return await showConfirm(props);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default showConfirm;
|
||||
|
||||
@@ -34,17 +34,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
// vue
|
||||
import { onMounted, reactive, ref, watch } from "vue";
|
||||
|
||||
interface ConfirmProps {
|
||||
title: string;
|
||||
text?: string;
|
||||
mode?: "confirm" | "input";
|
||||
otcancel?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<ConfirmProps>(), {
|
||||
const props = withDefaults(defineProps<TGApp.Component.Confirm.Params>(), {
|
||||
title: "",
|
||||
text: "",
|
||||
mode: "confirm",
|
||||
|
||||
Reference in New Issue
Block a user