Files
2026-09-21 15:32:12 +08:00

150 lines
3.1 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div v-if="api" class="tui-utils-api">
<section v-if="api.members.length > 0">
<h3>成员</h3>
<table>
<thead>
<tr>
<th>名称</th>
<th>签名</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr v-for="row in api.members" :key="row.name">
<td class="name"><code v-text="row.name" /></td>
<td class="signature"><code v-text="row.signature" /></td>
<td class="desc" v-text="row.description" />
</tr>
</tbody>
</table>
</section>
<section v-if="api.types.length > 0">
<h3>类型</h3>
<div v-for="item in api.types" :key="item.name" class="type">
<p class="head">
<code v-text="item.name" />
<span class="kind" v-text="item.kind" />
</p>
<p v-if="item.description" class="desc" v-text="item.description" />
<pre class="body"><code v-text="item.text" /></pre>
</div>
</section>
<p v-if="isEmpty && !api.parsed" class="notice warn">
未能从源码中解析出该模块的成员,请检查文件是否为合法的 TypeScript 模块。
</p>
<p v-else-if="isEmpty" class="notice">
该模块没有可列出的导出成员。
</p>
</div>
<p v-else class="notice warn" v-text="`未找到模块 ${name} 的数据,请检查 utils.ts 中的 name 与 entry 是否正确`" />
</template>
<script lang="ts" setup>
import { computed } from "vue";
import utilsMap from "virtual:timi-utils";
/**
* 工具模块成员表。
*
* 数据由构建期 `plugins/tsdocgen.ts` 解析 TS 源码得到,通过虚拟模块
* `virtual:timi-utils` 交给页面渲染。`vue-docgen-api` 只支持 SFC,
* 因此工具模块走的是 TypeScript 自带的 AST 解析。
*/
const props = defineProps<{
/** 模块名,需与 utils.ts 中的 name 一致。 */
name: string;
}>();
const api = computed(() => utilsMap[props.name]);
const isEmpty = computed(() => {
if (!api.value) {
return false;
}
return api.value.members.length === 0 && api.value.types.length === 0;
});
</script>
<style lang="less" scoped>
.tui-utils-api {
section {
margin-bottom: 1.5rem;
&:last-child {
margin-bottom: 0;
}
}
h3 {
margin: 1.5rem 0 .75rem;
font-size: 1rem;
}
.name,
.signature {
white-space: nowrap;
}
// 说明里保留了 JSDoc 的段落结构
.desc {
white-space: pre-line;
}
.type {
margin-bottom: 1rem;
&:last-child {
margin-bottom: 0;
}
.head {
display: flex;
gap: .5rem;
align-items: center;
margin: 0 0 .25rem;
}
.desc {
margin: 0 0 .5rem;
font-size: .875rem;
color: var(--vp-c-text-2);
}
.kind {
padding: .0625rem .375rem;
font-size: .75rem;
border-radius: .25rem;
color: var(--vp-c-text-2);
background: var(--vp-c-bg-soft);
}
.body {
margin: 0;
padding: .75rem 1rem;
overflow-x: auto;
font-size: .8125rem;
border-radius: .5rem;
background: var(--vp-c-bg-soft);
}
}
.notice {
margin: 1rem 0;
padding: .75rem 1rem;
font-size: .875rem;
border-radius: .5rem;
color: var(--vp-c-text-2);
background: var(--vp-c-bg-soft);
&.warn {
color: var(--vp-c-warning-1);
background: var(--vp-c-warning-soft);
}
}
}
</style>