fx-platform-ui 0.0.13-alpha5 → 0.0.13-alpha7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,167 @@
1
1
  <template>
2
- <div class="fx-editor">
3
- 123
4
- </div>
2
+ <editor
3
+ :id="tinymceId"
4
+ v-model="myValue"
5
+ :init="init"
6
+ :disabled="disabled"
7
+ ></editor>
5
8
  </template>
6
9
 
7
- <script lang="ts" setup>
10
+ <script setup lang="ts">
11
+ //JS部分
12
+ //在js中引入所需的主题和组件
13
+ import tinymce from 'tinymce/tinymce'
14
+ import 'tinymce/skins/content/default/content.css'
15
+ import Editor from '@tinymce/tinymce-vue'
16
+ import 'tinymce/themes/silver'
17
+ import 'tinymce/themes/silver/theme'
18
+ import 'tinymce/icons/default' //引入编辑器图标icon,不引入则不显示对应图标
19
+ import 'tinymce/models/dom' // 这里是个坑 一定要引入
20
+
21
+ //在TinyMce.vue中接着引入相关插件
22
+ import 'tinymce/icons/default/icons'
23
+ // import "tinymce/plugins/image" // 插入上传图片插件
24
+ // import "tinymce/plugins/media" // 插入视频插件
25
+ import 'tinymce/plugins/table' // 插入表格插件
26
+ import 'tinymce/plugins/lists' // 列表插件
27
+ import 'tinymce/plugins/wordcount' // 字数统计插件
28
+ import 'tinymce/plugins/code' // 源码
29
+ // import "tinymce/plugins/fullscreen" //全屏
30
+
31
+ //接下来定义编辑器所需要的插件数据
32
+ import { reactive, ref } from 'vue'
33
+ import { onMounted, defineEmits, watch } from 'vue'
34
+ import axios from 'axios'
35
+ // import { updateImg } from '@/api/order/order'
8
36
  defineOptions({
9
37
  name: 'PlEditor'
10
38
  })
39
+ const emits = defineEmits(['getContent'])
40
+ //这里我选择将数据定义在props里面,方便在不同的页面也可以配置出不同的编辑器,当然也可以直接在组件中直接定义
41
+ const props = defineProps({
42
+ value: {
43
+ type: String,
44
+ default: () => {
45
+ return ''
46
+ }
47
+ },
48
+ baseUrl: {
49
+ type: String,
50
+ default: ''
51
+ },
52
+ disabled: {
53
+ type: Boolean,
54
+ default: false
55
+ },
56
+ plugins: {
57
+ type: [String, Array],
58
+ default: 'lists table'
59
+ }, //必填
60
+ toolbar: {
61
+ type: [String, Array],
62
+ default:
63
+ 'codesample bold italic underline alignleft aligncenter alignright alignjustify | undo redo | formatselect | fontselect | fontsizeselect | forecolor backcolor | bullist numlist outdent indent | lists link table code | removeformat '
64
+ } //必填
65
+ })
66
+ //用于接收外部传递进来的富文本
67
+ const myValue = ref(props.value)
68
+ const tinymceId = ref(
69
+ `vue-tinymce-${+new Date()}${(Math.random() * 1000).toFixed(0)}`
70
+ )
71
+ //定义一个对象 init初始化
72
+ const init = reactive({
73
+ selector: `#${tinymceId.value}`, //富文本编辑器的id,
74
+ language_url: '/tinymce/langs/zh_CN.js', // 语言包的路径,具体路径看自己的项目,文档后面附上中文js文件
75
+ language: 'zh_CN', //语言
76
+ skin_url: '/tinymce/skins/ui/oxide', // skin路径,具体路径看自己的项目
77
+ height: 400, //编辑器高度
78
+ branding: false, //是否禁用“Powered by TinyMCE”
79
+ menubar: true, //顶部菜单栏显示
80
+ image_dimensions: false, //去除宽高属性
81
+ plugins: props.plugins, //这里的数据是在props里面就定义好了的
82
+ toolbar: props.toolbar, //这里的数据是在props里面就定义好了的
83
+ font_formats:
84
+ 'Arial=arial,helvetica,sans-serif; 宋体=SimSun; 微软雅黑=Microsoft Yahei; Impact=impact,chicago;', //字体
85
+ fontsize_formats: '11px 12px 14px 16px 18px 24px 36px 48px 64px 72px', //文字大小
86
+ // paste_convert_word_fake_lists: false, // 插入word文档需要该属性
87
+ paste_webkit_styles: 'all',
88
+ paste_merge_formats: true,
89
+ nonbreaking_force_tab: false,
90
+ paste_auto_cleanup_on_paste: false,
91
+ file_picker_types: 'file',
92
+ content_css: '/tinymce/skins/content/default/content.css', //以css文件方式自定义可编辑区域的css样式,css文件需自己创建并引入
93
+ //图片上传
94
+ images_upload_handler: (blobInfo, progress) =>
95
+ new Promise((resolve, reject) => {
96
+ if (blobInfo.blob().size / 1024 / 1024 > 2) {
97
+ reject({ message: '上传失败,图片大小请控制在 2M 以内', remove: true })
98
+ return
99
+ } else {
100
+ const ph = `${import.meta.env.VITE_BASE_PATH}:${
101
+ import.meta.env.VITE_SERVER_PORT
102
+ }/`
103
+ const params = new FormData()
104
+ params.append('file', blobInfo.blob())
11
105
 
12
- </script>
13
- <style lang="less" scoped>
106
+ const config = {
107
+ headers: {
108
+ 'Content-Type': 'multipart/form-data'
109
+ }
110
+ }
111
+
112
+ axios
113
+ .post('xxxx', params, config)
114
+ .then((res) => {
115
+ if (res.data.code == 200) {
116
+ resolve(ph + res.data.msg) //上传成功,在成功函数里填入图片路径
117
+ } else {
118
+ reject(`HTTP Error: 上传失败${res.data.code}`)
119
+ return
120
+ }
121
+ })
122
+ .catch(() => {
123
+ reject('上传出错,服务器开小差了呢')
124
+ return
125
+ })
126
+ }
127
+ }),
128
+
129
+ // 文件上传
130
+ file_picker_callback: (callback, value, meta) => {
131
+ // Provide file and text for the link dialog
132
+ if (meta.filetype == 'file') {
133
+ callback('mypage.html', { text: 'My text' })
134
+ }
14
135
 
15
- :deep(.tox-tinymce-aux) {
16
- z-index: 1000;
17
- }
18
- </style>
136
+ // Provide image and alt text for the image dialog
137
+ if (meta.filetype == 'image') {
138
+ callback('myimage.jpg', { alt: 'My alt text' })
139
+ }
140
+
141
+ // Provide alternative source and posted for the media dialog
142
+ if (meta.filetype == 'media') {
143
+ callback('movie.mp4', { source2: 'alt.ogg', poster: 'image.jpg' })
144
+ }
145
+ }
146
+ })
147
+
148
+ //监听外部传递进来的的数据变化
149
+ watch(
150
+ () => props.value,
151
+ () => {
152
+ myValue.value = props.value
153
+ emits('getContent', myValue.value)
154
+ }
155
+ )
156
+ //监听富文本中的数据变化
157
+ watch(
158
+ () => myValue.value,
159
+ () => {
160
+ emits('getContent', myValue.value)
161
+ }
162
+ )
163
+ //在onMounted中初始化编辑器
164
+ onMounted(() => {
165
+ tinymce.init({})
166
+ })
167
+ </script>