add docs
This commit is contained in:
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user