index.vue
1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<script setup lang="ts">
/**
* 富文本
* @module Tinymce
*/
import { ref, reactive, onMounted } from 'vue'
import { uploadPicSource } from '@/api/user/login'
import { toolbar, plugins } from './settings/index'
/**
* @description 组件属性
* @prop {string | null} tagName 标签
* @prop {string | null} moduleName 上传接口需要传的module值
*/
interface Props {
tagName?: string;
moduleName?: string;
}
let content = ref('')
const props = withDefaults(defineProps<Props>(), {
moduleName: "test",
});
const emit = defineEmits<{
(e: "contentChange", contents: string, tagName: string): void;
}>();
onMounted (() => {
tinymce.init({
selector: '#mytextarea',
height: 404,
language_url : 'http://testweb.community.cnlive.com/languages/zh_CN.js',
language:'zh_CN',
plugins: plugins,
toolbar: toolbar,
images_upload_url: `${import.meta.env.VITE_BASE_URL}upload/uploadPicSource`,
images_upload_handler: function (blobInfo, succFun, failFun, progress) {
const files = new window.File([blobInfo.blob()], '图片');
const fd = new FormData()
fd.append('multipartFile', files)
uploadPicSource({
module: props.moduleName
}, fd).then(res => {
succFun(res.data.data)
}).catch(error => {
failFun(error)
})
},
// setup: (ed) => {
// // ed.onKeyPress.add(
// // function (ed, evt) {
// console.log(ed)
// // console.log(evt)
// // }
// // )
// }
});
console.log(tinymce.editors['mytextarea'].getContent())
})
</script>
<template>
<textarea id="mytextarea"></textarea>
</template>