# Tinymce

富文本组件位于 [packages/ui/share-ui/src/tinymce](http://192.168.9.192/eci-frontend/base-framework/-/tree/main/packages/ui/share-ui/src/tinymce)

## 代码演示

### 基础使用

<CodePreview src="/doc-comp/editor/tinymce/index" :height="500">
<details>
<summary>展开查看</summary>

```vue
<template>
  <PageWrapper title="富文本组件示例">
    <Tinymce v-model="value" width="100%" @change="handleChange" />
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { PageWrapper } from '@eciol/ant-ui';
  import { Tinymce } from '@eciol/share-ui';

  const value = ref('hello world!');
  function handleChange(value: string) {
    console.log(value);
  }
</script>

```
</details>
</CodePreview>

### 嵌入form

<CodePreview src="/doc-comp/editor/tinymce/editor" :height="700">
<details>
<summary>展开查看</summary>

```vue
<template>
  <PageWrapper title="富文本嵌入表单示例">
    <CollapseContainer title="富文本表单">
      <BasicForm
        :labelWidth="100"
        :schemas="schemas"
        :actionColOptions="{ span: 24 }"
        :baseColProps="{ span: 24 }"
        @submit="handleSubmit"
      />
    </CollapseContainer>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { BasicForm, FormSchema, PageWrapper, useMessage } from '@eciol/ant-ui';
  import { CollapseContainer, Tinymce } from '@eciol/share-ui';

  const schemas: FormSchema[] = [
    {
      field: 'title',
      component: 'Input',
      label: 'title',
      defaultValue: 'defaultValue',
      rules: [{ required: true }],
    },
    {
      field: 'tinymce',
      component: 'Input',
      label: 'tinymce',
      defaultValue: 'defaultValue',
      rules: [{ required: true }],
      render: ({ model, field }) => {
        return h(Tinymce, {
          value: model[field],
          onChange: (value: string) => {
            model[field] = value;
          },
        });
      },
    },
  ];
  const { createMessage } = useMessage();
  const handleSubmit = (values: any) => {
    createMessage.success('click search,values:' + JSON.stringify(values));
  };
</script>

```
</details>
</CodePreview>

## Usage

```vue
<template>
  <Tinymce v-model="value" @change="handleChange" width="100%" />
</template>
<script lang="ts" setup>
  import { Tinymce } from '@eciol/share-ui';

  const value = ref('hello world!');
  function handleChange(value: string) {
    console.log(value);
  }
</script>
```

## Props

| 属性            | 类型              | 默认值 | 说明             |
| --------------- | ----------------- | ------ | ---------------- |
| options         | `any`             | {}     | tinymce 的配置项 |
| value(v-model)  | `string`          | -      | 双向绑定值       |
| height          | `number , string` | 400    | 高度             |
| width           | `number , string` | auto   | 宽度             |
| toolbar         | `string[]`        | -      | 工具栏           |
| plugins         | `string[]`        | -      | 插件             |
| showImageUpload | `boolean`         | true   | 是否显示上传按钮 |

## Events

| 事件   | 回调参数           | 返回值 | 说明                   |
| ------ | ------------------ | ------ | ---------------------- |
| change | `(str:string)=>{}` |        | 富文本内容改变触发事件 |
