This commit is contained in:
Timi
2026-10-30 14:28:27 +08:00
parent ef71681bd5
commit 1909587a0b
68 changed files with 6616 additions and 772 deletions
+93
View File
@@ -0,0 +1,93 @@
<template>
<div class="demo">
<div class="bar">
<t-button size="small" variant="outline" @click="collapsed = !collapsed">
{{ collapsed ? "展开菜单" : "收起菜单" }}
</t-button>
<span class="status" v-text="`当前选中:${active}`" />
</div>
<div class="frame">
<admin-layout
v-model="active"
:menu-items="menuItems"
:collapsed="collapsed"
>
<template #logo>
<span class="logo" v-text="'Timi'" />
</template>
<template #menu>
<t-tag theme="primary" variant="light">管理台</t-tag>
</template>
<div class="content">
<h3 v-text="`内容区:${active}`" />
<p v-text="'主体区域由默认插槽填充,顶部栏与侧边菜单各自独立成插槽。'" />
</div>
</admin-layout>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { AdminLayout } from "timi-tdesign-pc";
import type { AdminMenuItem } from "timi-tdesign-pc";
const menuItems: AdminMenuItem[] = [
{ value: "dashboard", label: "工作台" },
{ value: "article", label: "文章管理" },
{ value: "notify", label: "通知管理" },
{ value: "setting", label: "系统设置", disabled: true }
];
const active = ref<string | number>("dashboard");
const collapsed = ref(false);
</script>
<style lang="less" scoped>
.demo {
.bar {
display: flex;
gap: .75rem;
align-items: center;
margin-bottom: 1rem;
}
.status {
font-size: .75rem;
color: var(--td-text-color-secondary);
}
// 组件自身按 100vh 撑满,这里压缩到可视范围内便于演示
.frame {
height: 28rem;
overflow: hidden;
border: 1px solid var(--td-component-stroke);
border-radius: .75rem;
:deep(.tui-admin-layout) {
height: 100%;
}
}
.logo {
font-size: 1.25rem;
font-weight: 700;
color: var(--td-brand-color);
}
.content {
padding: 1.5rem;
h3 {
margin: 0 0 .5rem;
}
p {
margin: 0;
color: var(--td-text-color-secondary);
}
}
}
</style>
+115
View File
@@ -0,0 +1,115 @@
<template>
<div class="demo">
<div class="bar">
<t-button
v-for="item in contentTypeList"
:key="item.value"
size="small"
variant="outline"
:theme="value.contentType === item.value ? 'primary' : 'default'"
@click="switchContentType(item.value)"
>
{{ item.label }}
</t-button>
<t-button size="small" theme="primary" @click="submit">提交</t-button>
</div>
<t-input v-model="value.title" class="field" placeholder="文章标题" />
<article-editor
ref="editorRef"
:model-value="value"
:upload-image="uploadMedia"
:upload-video="uploadMedia"
@change="onChange"
@update:model-value="onChange"
/>
<p class="status" v-text="status" />
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { ArticleEditor } from "timi-tdesign-pc";
import type {
Article,
ArticleContentType,
ArticleEditorExpose,
UploadResult
} from "timi-tdesign-pc";
const RICH_CONTENT = `<h2>正文类型可切换</h2>
<p>同一份 <code>Article</code> 数据,按 <code>contentType</code> 切换三种编辑形态。</p>`;
const contentTypeList: Array<{ label: string; value: ArticleContentType }> = [
{ label: "纯文本", value: "TEXT" },
{ label: "Markdown", value: "MARKDOWN" },
{ label: "富文本", value: "TIP_TAP" }
];
const value = ref<Article>({
title: "编辑器演示文章",
contentType: "TIP_TAP",
content: RICH_CONTENT,
attachmentList: []
});
const status = ref("等待提交");
const editorRef = ref<ArticleEditorExpose>();
/** 切换正文类型时同步替换内容,避免不同格式互相污染。 */
function switchContentType(contentType: ArticleContentType) {
const content = contentType === "TEXT"
? "这是一段纯文本正文。"
: contentType === "MARKDOWN"
? "## Markdown 标题\n\n这是一段 Markdown 正文。"
: RICH_CONTENT;
value.value = {
...value.value,
contentType,
content
};
}
function onChange(article: Article) {
value.value = article;
}
async function submit() {
const article = await editorRef.value?.submit();
if (article) {
value.value = article;
status.value = `已提交,标题为「${article.title}」`;
}
}
async function uploadMedia(file: File): Promise<UploadResult> {
return {
id: `demo-${Date.now()}-${file.name}`,
name: file.name,
url: URL.createObjectURL(file)
};
}
</script>
<style lang="less" scoped>
.demo {
.bar {
display: flex;
flex-wrap: wrap;
gap: .5rem;
margin-bottom: 1rem;
}
.field {
margin-bottom: 1rem;
}
.status {
margin: 1rem 0 0;
font-size: .75rem;
color: var(--td-text-color-secondary);
}
}
</style>
+20
View File
@@ -0,0 +1,20 @@
<template>
<div class="demo">
<article-view :article="article" />
</div>
</template>
<script lang="ts" setup>
import { ArticleView } from "timi-tdesign-pc";
import type { Article } from "timi-tdesign-pc";
/** ArticleView 按 contentType 选择渲染方式,这里演示富文本形态。 */
const article: Article = {
title: "文章视图",
contentType: "TIP_TAP",
content: `<h2>文章视图</h2>
<p>标题与正文按 <code>Article</code> 结构渲染,空内容时显示占位文案。</p>
<blockquote><p>把 <code>contentType</code> 换成 TEXT 或 MARKDOWN 会切换渲染分支。</p></blockquote>`,
attachmentList: []
};
</script>
+68
View File
@@ -0,0 +1,68 @@
<template>
<div class="demo">
<authorize-form
:captcha="requestCaptcha"
:login="handleLogin"
:register="handleRegister"
@login-success="onLoginSuccess"
@register-success="onRegisterSuccess"
/>
<p class="status" v-text="status" />
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { AuthorizeForm } from "timi-tdesign-pc";
import type {
CaptchaData,
CaptchaResult,
LoginRequest,
RegisterRequest
} from "timi-tdesign-pc";
const status = ref("等待操作");
/** 演示用验证码:直接生成一张 SVG 图片,无需后端接口。 */
async function requestCaptcha(width: number, height: number): Promise<CaptchaResult> {
const text = String(Math.floor(1000 + Math.random() * 9000));
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">` +
`<rect width="100%" height="100%" fill="#f3f3f3"/>` +
`<text x="50%" y="50%" font-family="monospace" font-size="24" fill="#0052d9" ` +
`text-anchor="middle" dominant-baseline="central">${text}</text></svg>`;
return {
id: `demo-${Date.now()}`,
data: `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`
};
}
/** 真实项目里在这里调用登录接口。 */
async function handleLogin(request: CaptchaData<LoginRequest>) {
await new Promise(resolve => setTimeout(resolve, 300));
status.value = `登录请求:${request.data.user}`;
}
async function handleRegister(request: CaptchaData<RegisterRequest>) {
await new Promise(resolve => setTimeout(resolve, 300));
status.value = `注册请求:${request.data.name}`;
}
async function onLoginSuccess() {
status.value = "登录成功,由外层处理跳转与状态刷新";
}
async function onRegisterSuccess() {
status.value = "注册成功,由外层处理后续流程";
}
</script>
<style lang="less" scoped>
.demo {
.status {
margin: 1rem 0 0;
font-size: .75rem;
text-align: center;
color: var(--td-text-color-secondary);
}
}
</style>
+72
View File
@@ -0,0 +1,72 @@
<template>
<div class="demo">
<div class="bar">
<t-button size="small" theme="primary" @click="readValue">读取内容</t-button>
<t-button size="small" variant="outline" @click="openSearch">打开查找</t-button>
<span class="status" v-text="status" />
</div>
<div class="box">
<code-editor
ref="editorRef"
v-model="code"
language="typescript"
placeholder="请输入代码"
@change="onChange"
/>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { CodeEditor } from "timi-tdesign-pc";
import type { CodeEditorExpose } from "timi-tdesign-pc";
const DEMO_CODE = `type DemoUser = {
id: string;
name: string;
};
const user: DemoUser = {
id: "demo-001",
name: "Timi"
};
console.log(user.name);`;
const code = ref(DEMO_CODE);
const status = ref("等待操作");
const editorRef = ref<CodeEditorExpose>();
function onChange(value: string) {
status.value = `内容已更新,${value.length} 个字符`;
}
function readValue() {
status.value = `当前共 ${code.value.length} 个字符`;
}
function openSearch() {
editorRef.value?.openSearch(true);
}
</script>
<style lang="less" scoped>
.demo {
.bar {
display: flex;
gap: .5rem;
align-items: center;
margin-bottom: 1rem;
}
.status {
font-size: .75rem;
color: var(--td-text-color-secondary);
}
.box {
height: 20rem;
}
}
</style>
+76
View File
@@ -0,0 +1,76 @@
<template>
<div class="demo">
<t-input v-model="value.subject" class="field" placeholder="通知主题" />
<notify-editor
ref="editorRef"
:model-value="value"
:upload-image="uploadMedia"
:upload-video="uploadMedia"
@change="onChange"
@update:model-value="onChange"
/>
<div class="footer">
<t-button size="small" theme="primary" @click="submit">提交</t-button>
<span class="status" v-text="status" />
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { NotifyEditor } from "timi-tdesign-pc";
import type { NotifyDetail, NotifyEditorExpose, UploadResult } from "timi-tdesign-pc";
const value = ref<NotifyDetail>({
subject: "编辑器通知演示",
contentType: "TIP_TAP",
content: `<h2>通知内容</h2>
<p>通知复用文章编辑器,同时保留自己的元数据字段(如 <code>subject</code>)。</p>`,
attachmentList: []
});
const status = ref("等待提交");
const editorRef = ref<NotifyEditorExpose>();
function onChange(detail: NotifyDetail) {
value.value = detail;
}
async function submit() {
const detail = await editorRef.value?.submit();
if (detail) {
value.value = detail;
status.value = `已提交,正文 ${detail.content?.length || 0} 个字符`;
}
}
async function uploadMedia(file: File): Promise<UploadResult> {
return {
id: `demo-${Date.now()}-${file.name}`,
name: file.name,
url: URL.createObjectURL(file)
};
}
</script>
<style lang="less" scoped>
.demo {
.field {
margin-bottom: 1rem;
}
.footer {
display: flex;
gap: .75rem;
align-items: center;
margin-top: 1rem;
}
.status {
font-size: .75rem;
color: var(--td-text-color-secondary);
}
}
</style>
+19
View File
@@ -0,0 +1,19 @@
<template>
<div class="demo">
<notify-view :detail="detail" />
</div>
</template>
<script lang="ts" setup>
import { NotifyView } from "timi-tdesign-pc";
import type { NotifyDetail } from "timi-tdesign-pc";
/** NotifyView 只关心正文相关字段,主题与状态由业务页面自行呈现。 */
const detail: NotifyDetail = {
subject: "系统维护通知",
contentType: "TIP_TAP",
content: `<h2>系统维护通知</h2>
<p>本周六 02:00 - 04:00 进行数据库升级,期间服务不可用。</p>
<ul><li>请提前保存工作内容</li><li>升级完成后会同步通知</li></ul>`
};
</script>
+32
View File
@@ -0,0 +1,32 @@
<template>
<root-layout
icp="京ICP备 00000000 号"
domain="example.com"
author="Timi"
text="组件演示"
>
<div class="body">
<h3 v-text="'RootLayout'" />
<p v-text="'页面级骨架:插槽填充主体内容,底部自动渲染版权与备案信息。'" />
</div>
</root-layout>
</template>
<script lang="ts" setup>
import { RootLayout } from "timi-tdesign-pc";
</script>
<style lang="less" scoped>
.body {
padding: 2rem;
h3 {
margin: 0 0 .5rem;
}
p {
margin: 0;
color: var(--td-text-color-secondary);
}
}
</style>
+147
View File
@@ -0,0 +1,147 @@
<template>
<div class="demo">
<div class="bar">
<t-button
v-for="item in contentTypeList"
:key="item.value"
size="small"
variant="outline"
:theme="article.contentType === item.value ? 'primary' : 'default'"
@click="switchContentType(item.value)"
>
{{ item.label }}
</t-button>
<t-button size="small" theme="primary" @click="submit">提交文章</t-button>
</div>
<div class="grid">
<section class="pane">
<h4 v-text="'编辑'" />
<t-input v-model="article.title" class="title" placeholder="文章标题" />
<article-editor
ref="editorRef"
:model-value="article"
:upload-image="uploadMedia"
:upload-video="uploadMedia"
@change="onChange"
@update:model-value="onChange"
/>
</section>
<section class="pane">
<h4 v-text="'预览'" />
<article-view :article="article" />
</section>
</div>
<p class="status" v-text="status" />
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { ArticleEditor, ArticleView } from "timi-tdesign-pc";
import type {
Article,
ArticleContentType,
ArticleEditorExpose,
UploadResult
} from "timi-tdesign-pc";
/** 本场景验证「同一份 Article 数据,编辑与预览实时联动」。 */
const RICH_CONTENT = `<h2>文章编辑与预览</h2>
<p>左侧改动会立刻反映到右侧,两侧共用同一个 <code>Article</code> 对象。</p>
<blockquote><p>切换正文类型时,编辑区与预览区会同时切换渲染分支。</p></blockquote>`;
const contentTypeList: Array<{ label: string; value: ArticleContentType }> = [
{ label: "纯文本", value: "TEXT" },
{ label: "Markdown", value: "MARKDOWN" },
{ label: "富文本", value: "TIP_TAP" }
];
const article = ref<Article>({
title: "编辑器组件演示文章",
contentType: "TIP_TAP",
content: RICH_CONTENT,
attachmentList: []
});
const status = ref("等待提交");
const editorRef = ref<ArticleEditorExpose>();
function switchContentType(contentType: ArticleContentType) {
const content = contentType === "TEXT"
? "这是一段纯文本示例。"
: contentType === "MARKDOWN"
? "## Markdown 示例\n\n这是一段 Markdown 正文。"
: RICH_CONTENT;
article.value = {
...article.value,
contentType,
content
};
status.value = `已切换到 ${contentType}`;
}
function onChange(value: Article) {
article.value = value;
}
async function submit() {
const value = await editorRef.value?.submit();
if (value) {
article.value = value;
status.value = `已提交,${value.attachmentList?.length || 0} 个附件`;
}
}
async function uploadMedia(file: File): Promise<UploadResult> {
return {
id: `demo-${Date.now()}-${file.name}`,
name: file.name,
url: URL.createObjectURL(file)
};
}
</script>
<style lang="less" scoped>
.demo {
.bar {
display: flex;
flex-wrap: wrap;
gap: .5rem;
margin-bottom: 1rem;
}
.grid {
display: grid;
gap: 1rem;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.pane {
min-width: 0;
h4 {
margin: 0 0 .75rem;
font-size: .875rem;
}
}
.title {
margin-bottom: .75rem;
}
.status {
margin: 1rem 0 0;
font-size: .75rem;
color: var(--td-text-color-secondary);
}
@media (max-width: 60rem) {
.grid {
grid-template-columns: 1fr;
}
}
}
</style>
+179
View File
@@ -0,0 +1,179 @@
<template>
<div class="demo">
<div class="bar">
<t-button size="small" theme="primary" @click="openSearch">
同时打开两处查找
</t-button>
<t-button size="small" variant="outline" @click="submitRich">
提交富文本
</t-button>
<span class="status" v-text="status" />
</div>
<section class="block">
<div class="head">
<h4 v-text="'富文本编辑器'" />
<span v-text="'支持拖入图片与视频'" />
</div>
<div class="box rich">
<tiptap-editor
ref="tiptapRef"
v-model="rich"
:upload-image="uploadMedia"
:upload-video="uploadMedia"
@change="onRichChange"
/>
</div>
</section>
<section class="block">
<div class="head">
<h4 v-text="'只读视图'" />
<t-input
v-model="maxHeight"
class="height-input"
placeholder="最大高度,如 20rem"
/>
</div>
<tiptap-view :content="rich" :max-height="maxHeight" />
</section>
<section class="block">
<div class="head">
<h4 v-text="'代码编辑器'" />
<t-button size="small" variant="text" @click="resetCode">
恢复示例
</t-button>
</div>
<div class="box code">
<code-editor
ref="codeRef"
v-model="code"
language="typescript"
placeholder="请输入代码"
/>
</div>
</section>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { CodeEditor, TiptapEditor, TiptapView } from "timi-tdesign-pc";
import type {
CodeEditorExpose,
TiptapEditorExpose,
UploadResult
} from "timi-tdesign-pc";
/** 本场景把三类编辑器放在一起,验证它们共用同一套内容与检索能力。 */
const DEMO_CODE = `type DemoUser = {
id: string;
name: string;
};
const user: DemoUser = {
id: "demo-001",
name: "Timi"
};
console.log(user.name);`;
const rich = ref(`<h2>跨平台编辑器</h2>
<p>这段内容同时验证标题、段落、链接、表格和代码块的渲染。</p>
<blockquote><p>移动端和 PC 端只替换交互层,共享文档模型。</p></blockquote>`);
const code = ref(DEMO_CODE);
const maxHeight = ref("20rem");
const status = ref("等待操作");
const tiptapRef = ref<TiptapEditorExpose>();
const codeRef = ref<CodeEditorExpose>();
function onRichChange(value: string) {
status.value = `富文本已更新,${value.length} 个字符`;
}
function resetCode() {
code.value = DEMO_CODE;
status.value = "代码已恢复为示例内容";
}
/** 两个编辑器各有独立的查找栏,这里一次性把它们都唤起来。 */
function openSearch() {
tiptapRef.value?.openSearch(true);
codeRef.value?.openSearch(true);
status.value = "已打开查找栏";
}
async function submitRich() {
const value = await tiptapRef.value?.submit();
if (value !== undefined) {
rich.value = value;
status.value = `富文本已提交,${value.length} 个字符`;
}
}
async function uploadMedia(file: File): Promise<UploadResult> {
return {
id: `demo-${Date.now()}-${file.name}`,
name: file.name,
url: URL.createObjectURL(file)
};
}
</script>
<style lang="less" scoped>
.demo {
.bar {
display: flex;
flex-wrap: wrap;
gap: .5rem;
align-items: center;
margin-bottom: 1.25rem;
}
.status {
font-size: .75rem;
color: var(--td-text-color-secondary);
}
.block {
margin-bottom: 1.5rem;
&:last-child {
margin-bottom: 0;
}
}
.head {
display: flex;
gap: .75rem;
align-items: center;
justify-content: space-between;
margin-bottom: .75rem;
h4 {
margin: 0;
font-size: .875rem;
}
span {
font-size: .75rem;
color: var(--td-text-color-secondary);
}
}
.height-input {
width: 12rem;
}
.box {
height: 20rem;
}
.rich {
height: 24rem;
}
}
</style>
+137
View File
@@ -0,0 +1,137 @@
<template>
<div class="demo">
<div class="bar">
<t-button size="small" variant="outline" @click="switchStatus">
切换状态
</t-button>
<t-button size="small" theme="primary" @click="submit">提交通知</t-button>
<t-tag variant="light">{{ detail.status }}</t-tag>
</div>
<div class="grid">
<section class="pane">
<h4 v-text="'编辑'" />
<t-input
v-model="detail.subject"
class="subject"
placeholder="通知主题"
/>
<notify-editor
ref="editorRef"
:model-value="detail"
:upload-image="uploadMedia"
:upload-video="uploadMedia"
@change="onChange"
@update:model-value="onChange"
/>
</section>
<section class="pane">
<h4 v-text="'预览'" />
<notify-view :detail="detail" />
</section>
</div>
<p class="status" v-text="status" />
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { NotifyEditor, NotifyView } from "timi-tdesign-pc";
import type {
NotifyDetail,
NotifyEditorExpose,
UploadResult
} from "timi-tdesign-pc";
/** 本场景验证通知复用文章编辑能力,同时保留自己的元数据字段。 */
const RICH_CONTENT = `<h2>系统维护通知</h2>
<p>本周六 02:00 - 04:00 进行数据库升级,期间服务不可用。</p>
<ul><li>请提前保存工作内容</li><li>升级完成后会同步通知</li></ul>`;
const statusList = ["WAITING", "SENT", "FAILED"];
const detail = ref<NotifyDetail>({
subject: "编辑器通知演示",
contentType: "TIP_TAP",
content: RICH_CONTENT,
status: "WAITING",
attachmentList: []
});
const status = ref("等待提交");
const editorRef = ref<NotifyEditorExpose>();
function switchStatus() {
const index = statusList.indexOf(detail.value.status);
const next = statusList[(index + 1) % statusList.length];
detail.value = {
...detail.value,
status: next
};
}
function onChange(value: NotifyDetail) {
detail.value = value;
}
async function submit() {
const value = await editorRef.value?.submit();
if (value) {
detail.value = value;
status.value = `已提交,正文 ${value.content?.length || 0} 个字符`;
}
}
async function uploadMedia(file: File): Promise<UploadResult> {
return {
id: `demo-${Date.now()}-${file.name}`,
name: file.name,
url: URL.createObjectURL(file)
};
}
</script>
<style lang="less" scoped>
.demo {
.bar {
display: flex;
flex-wrap: wrap;
gap: .5rem;
align-items: center;
margin-bottom: 1rem;
}
.grid {
display: grid;
gap: 1rem;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.pane {
min-width: 0;
h4 {
margin: 0 0 .75rem;
font-size: .875rem;
}
}
.subject {
margin-bottom: .75rem;
}
.status {
margin: 1rem 0 0;
font-size: .75rem;
color: var(--td-text-color-secondary);
}
@media (max-width: 60rem) {
.grid {
grid-template-columns: 1fr;
}
}
}
</style>
+76
View File
@@ -0,0 +1,76 @@
<template>
<div class="demo">
<div class="bar">
<t-button size="small" theme="primary" @click="submit">提交</t-button>
<t-button size="small" variant="outline" @click="openSearch">打开查找</t-button>
<span class="status" v-text="status" />
</div>
<div class="box">
<tiptap-editor
ref="editorRef"
v-model="content"
:upload-image="uploadMedia"
:upload-video="uploadMedia"
@change="onChange"
/>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { TiptapEditor } from "timi-tdesign-pc";
import type { TiptapEditorExpose, UploadResult } from "timi-tdesign-pc";
const content = ref(`<h2>富文本编辑器</h2>
<p>工具栏覆盖标题、颜色、列表、表格、链接、代码块与媒体插入。</p>
<blockquote><p>把图片或视频拖进正文即可触发上传回调。</p></blockquote>`);
const status = ref("等待操作");
const editorRef = ref<TiptapEditorExpose>();
function onChange(value: string) {
status.value = `内容已更新,${value.length} 个字符`;
}
async function submit() {
const value = await editorRef.value?.submit();
if (value !== undefined) {
content.value = value;
status.value = `已提交,${value.length} 个字符`;
}
}
function openSearch() {
editorRef.value?.openSearch(true);
}
/** 演示用上传:直接把本地文件转成临时地址,无需后端。 */
async function uploadMedia(file: File): Promise<UploadResult> {
return {
id: `demo-${Date.now()}-${file.name}`,
name: file.name,
url: URL.createObjectURL(file)
};
}
</script>
<style lang="less" scoped>
.demo {
.bar {
display: flex;
gap: .5rem;
align-items: center;
margin-bottom: 1rem;
}
.status {
font-size: .75rem;
color: var(--td-text-color-secondary);
}
.box {
height: 28rem;
}
}
</style>
+30
View File
@@ -0,0 +1,30 @@
<template>
<div class="demo">
<t-input
v-model="maxHeight"
class="field"
placeholder="最大高度,如 20rem"
/>
<tiptap-view :content="content" :max-height="maxHeight" />
</div>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { TiptapView } from "timi-tdesign-pc";
const content = `<h2>只读视图</h2>
<p>与编辑器共用同一套渲染规则,内容超出 <code>maxHeight</code> 时可滚动查看。</p>
<blockquote><p>适合详情页、审批流等只需要阅读的场景。</p></blockquote>`;
const maxHeight = ref("20rem");
</script>
<style lang="less" scoped>
.demo {
.field {
width: 16rem;
margin-bottom: 1rem;
}
}
</style>
+37
View File
@@ -0,0 +1,37 @@
<template>
<div class="demo">
<div v-for="item in levelList" :key="item.value" class="item">
<user-level :value="item.value" />
<span class="label" v-text="item.label" />
</div>
</div>
</template>
<script lang="ts" setup>
import { UserLevel } from "timi-tdesign-pc";
/** 等级图标是一张纵向雪碧图,每个等级对应一行。 */
const levelList = Array.from({ length: 10 }, (_, index) => ({
value: index,
label: `Lv.${index}`
}));
</script>
<style lang="less" scoped>
.demo {
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
}
.item {
display: flex;
gap: .5rem;
align-items: center;
}
.label {
font-size: .75rem;
color: var(--td-text-color-secondary);
}
</style>
+87
View File
@@ -0,0 +1,87 @@
<template>
<div class="demo">
<div class="bar">
<t-button size="small" theme="primary" @click="switchUser">切换用户</t-button>
<span class="status" v-text="`当前:${currentName}`" />
</div>
<p class="tip">
<span v-popup="popupUserStore.config" v-text="'把鼠标移到这段文字上查看用户资料'" />
</p>
<user-profile-popup />
<popup />
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from "vue";
import { Popup } from "timi-web";
import { UserProfilePopup, popupUserStore } from "timi-tdesign-pc";
import type { UserView } from "timi-tdesign-pc";
/**
* 演示用数据。
*
* popup 内容是真实 DOM 节点,通过 PopupType.EL 挂到 timi-web 的弹层容器里,
* 所以每次切换用户后直接悬停即可看到最新资料。
*/
const userList: UserView[] = [
{
id: "demo-001",
name: "Timi",
profile: {
exp: 96,
sex: 1,
description: "全栈开发,关注前端工程化。"
}
},
{
id: "demo-002",
name: "Mia",
profile: {
exp: 32,
sex: 2,
description: "产品设计,负责交互与视觉。"
}
}
];
const activeIndex = ref(0);
const currentName = computed(() => userList[activeIndex.value].name);
function switchUser() {
activeIndex.value = (activeIndex.value + 1) % userList.length;
popupUserStore.user.value = userList[activeIndex.value];
}
onMounted(() => {
popupUserStore.user.value = userList[activeIndex.value];
});
</script>
<style lang="less" scoped>
.demo {
.bar {
display: flex;
gap: .75rem;
align-items: center;
}
.status {
font-size: .75rem;
color: var(--td-text-color-secondary);
}
.tip {
margin: 1rem 0 0;
}
.tip span {
cursor: help;
border-bottom: 1px dashed var(--td-brand-color);
color: var(--td-brand-color);
}
}
</style>
+33
View File
@@ -0,0 +1,33 @@
<template>
<div class="demo">
<user-profile :user="user" />
</div>
</template>
<script lang="ts" setup>
import { UserProfile } from "timi-tdesign-pc";
import type { UserView } from "timi-tdesign-pc";
/** 演示用图片:内联 SVG,避免依赖外部图床。 */
function buildImage(label: string, background: string, width = 320, height = 120) {
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">` +
`<rect width="100%" height="100%" fill="${background}"/>` +
`<text x="50%" y="50%" font-size="20" fill="#ffffff" text-anchor="middle" ` +
`dominant-baseline="central">${label}</text></svg>`;
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
}
const user: UserView = {
id: "demo-001",
name: "Timi",
profile: {
exp: 96,
sex: 1,
description: "全栈开发,关注前端工程化与组件沉淀。",
avatarType: "IR-AUTO",
wrapperType: "IR-AUTO",
avatarUrl: buildImage("T", "#0052d9", 64, 64),
wrapperUrl: buildImage("背景图", "#0594fa")
}
};
</script>