77 lines
1.8 KiB
Vue
77 lines
1.8 KiB
Vue
<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>
|