mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
✏️ 完善其余函数式组件类型
This commit is contained in:
@@ -4,12 +4,26 @@
|
|||||||
* @since Beta v0.3.3
|
* @since Beta v0.3.3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { h, render, type VNode } from "vue";
|
import { h, render } from "vue";
|
||||||
|
import type { ComponentInternalInstance, VNode } from "vue";
|
||||||
|
|
||||||
import geetest from "./geetest.vue";
|
import geetest from "./geetest.vue";
|
||||||
|
|
||||||
const geetestId = "tg-func-geetest";
|
const geetestId = "tg-func-geetest";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 自定义 geetest 组件
|
||||||
|
* @since Beta v0.3.3
|
||||||
|
* @extends ComponentInternalInstance
|
||||||
|
* @property {Function} exposeProxy.displayBox 弹出 geetest 验证
|
||||||
|
* @return GeetestInstance
|
||||||
|
*/
|
||||||
|
interface GeetestInstance extends ComponentInternalInstance {
|
||||||
|
exposeProxy: {
|
||||||
|
displayBox: () => boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const renderBox = (): VNode => {
|
const renderBox = (): VNode => {
|
||||||
const container = document.createElement("div");
|
const container = document.createElement("div");
|
||||||
container.id = geetestId;
|
container.id = geetestId;
|
||||||
@@ -21,14 +35,14 @@ const renderBox = (): VNode => {
|
|||||||
|
|
||||||
let geetestInstance: VNode;
|
let geetestInstance: VNode;
|
||||||
|
|
||||||
const showGeetest = async (): Promise<boolean> => {
|
async function showGeetest(): Promise<boolean> {
|
||||||
if (geetestInstance !== undefined) {
|
if (geetestInstance !== undefined) {
|
||||||
const boxVue = geetestInstance.component;
|
const boxVue = <GeetestInstance>geetestInstance.component;
|
||||||
return boxVue?.exposeProxy?.displayBox();
|
return boxVue.exposeProxy.displayBox();
|
||||||
} else {
|
} else {
|
||||||
geetestInstance = renderBox();
|
geetestInstance = renderBox();
|
||||||
return await showGeetest();
|
return await showGeetest();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export default showGeetest;
|
export default showGeetest;
|
||||||
|
|||||||
@@ -4,12 +4,26 @@
|
|||||||
* @since Beta v0.3.3
|
* @since Beta v0.3.3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { h, render, type VNode } from "vue";
|
import type { ComponentInternalInstance, VNode } from "vue";
|
||||||
|
import { h, render } from "vue";
|
||||||
|
|
||||||
import snackbar from "./snackbar.vue";
|
import snackbar from "./snackbar.vue";
|
||||||
|
|
||||||
const snackbarId = "tg-func-snackbar";
|
const snackbarId = "tg-func-snackbar";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 自定义 snackbar 组件
|
||||||
|
* @since Beta v0.3.3
|
||||||
|
* @extends ComponentInternalInstance
|
||||||
|
* @property {Function} exposeProxy.displayBox 显示 snackbar
|
||||||
|
* @return SnackbarInstance
|
||||||
|
*/
|
||||||
|
interface SnackbarInstance extends ComponentInternalInstance {
|
||||||
|
exposeProxy: {
|
||||||
|
displayBox: typeof TGApp.Component.Snackbar.displayBox;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const renderBox = (props: TGApp.Component.Snackbar.Params): VNode => {
|
const renderBox = (props: TGApp.Component.Snackbar.Params): VNode => {
|
||||||
const container = document.createElement("div");
|
const container = document.createElement("div");
|
||||||
container.id = snackbarId;
|
container.id = snackbarId;
|
||||||
@@ -21,14 +35,14 @@ const renderBox = (props: TGApp.Component.Snackbar.Params): VNode => {
|
|||||||
|
|
||||||
let snackbarInstance: VNode;
|
let snackbarInstance: VNode;
|
||||||
|
|
||||||
const showSnackbar = (props: TGApp.Component.Snackbar.Params): void => {
|
function showSnackbar(props: TGApp.Component.Snackbar.Params): void {
|
||||||
if (snackbarInstance !== undefined) {
|
if (snackbarInstance !== undefined) {
|
||||||
const boxVue = snackbarInstance.component;
|
const boxVue = <SnackbarInstance>snackbarInstance.component;
|
||||||
boxVue?.exposeProxy?.displayBox(props);
|
boxVue.exposeProxy.displayBox(props);
|
||||||
} else {
|
} else {
|
||||||
snackbarInstance = renderBox(props);
|
snackbarInstance = renderBox(props);
|
||||||
showSnackbar(props);
|
showSnackbar(props);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export default showSnackbar;
|
export default showSnackbar;
|
||||||
|
|||||||
@@ -8,16 +8,9 @@
|
|||||||
</transition>
|
</transition>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// vue
|
|
||||||
import { ref, reactive, onMounted } from "vue";
|
import { ref, reactive, onMounted } from "vue";
|
||||||
|
|
||||||
interface SnackbarProps {
|
const props = withDefaults(defineProps<TGApp.Component.Snackbar.Params>(), {
|
||||||
text: string;
|
|
||||||
color?: string;
|
|
||||||
timeout?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = withDefaults(defineProps<SnackbarProps>(), {
|
|
||||||
text: "",
|
text: "",
|
||||||
color: "success",
|
color: "success",
|
||||||
timeout: 1500,
|
timeout: 1500,
|
||||||
|
|||||||
14
src/types/Component/Snackbar.d.ts
vendored
14
src/types/Component/Snackbar.d.ts
vendored
@@ -1,8 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file types Component Snackbar.d.ts
|
* @file types Component Snackbar.d.ts
|
||||||
* @description Component Snackbar 类型声明文件
|
* @description Component Snackbar 类型声明文件
|
||||||
* @author BTMuli <bt-muli@outlook.com>
|
* @since Beta v0.3.3
|
||||||
* @since Alpha v0.2.3
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare namespace TGApp.Component.Snackbar {
|
declare namespace TGApp.Component.Snackbar {
|
||||||
@@ -16,9 +15,18 @@ declare namespace TGApp.Component.Snackbar {
|
|||||||
* @property {boolean} show 是否显示
|
* @property {boolean} show 是否显示
|
||||||
* @return Params
|
* @return Params
|
||||||
*/
|
*/
|
||||||
export interface Params {
|
interface Params {
|
||||||
text: string;
|
text: string;
|
||||||
color?: string;
|
color?: string;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Snackbar 方法 - displayBox
|
||||||
|
* @since Beta v0.3.3
|
||||||
|
* @function displayBox
|
||||||
|
* @param {Params} props
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function displayBox(props: Params): void;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user