Files
timi-tdesign-pc/docs/demos/notify-editor/basic.vue
T
2026-10-30 14:28:27 +08:00

77 lines
1.7 KiB
Vue

<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>