fx-platform-ui 0.0.13-alpha6 → 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,11 +1,14 @@
1
1
  <template>
2
- <div class="fx-editor">
3
- <editor v-model="modelValue" :init="init" :disabled="disabled"></editor>
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>
8
- import { onMounted, watch, ref } from 'vue'
10
+ <script setup lang="ts">
11
+ //JS部分
9
12
  //在js中引入所需的主题和组件
10
13
  import tinymce from 'tinymce/tinymce'
11
14
  import 'tinymce/skins/content/default/content.css'
@@ -17,69 +20,148 @@ import 'tinymce/models/dom' // 这里是个坑 一定要引入
17
20
 
18
21
  //在TinyMce.vue中接着引入相关插件
19
22
  import 'tinymce/icons/default/icons'
20
- import 'tinymce/plugins/image' // 插入上传图片插件
21
- import 'tinymce/plugins/media' // 插入视频插件
23
+ // import "tinymce/plugins/image" // 插入上传图片插件
24
+ // import "tinymce/plugins/media" // 插入视频插件
22
25
  import 'tinymce/plugins/table' // 插入表格插件
23
26
  import 'tinymce/plugins/lists' // 列表插件
24
27
  import 'tinymce/plugins/wordcount' // 字数统计插件
25
28
  import 'tinymce/plugins/code' // 源码
26
- import 'tinymce/plugins/fullscreen' //全屏
27
- import 'tinymce/plugins/pagebreak' //插入分页符
28
- import 'tinymce/plugins/codesample'
29
- import 'tinymce/plugins/searchreplace'
30
- import 'tinymce/plugins/link'
31
- import 'tinymce/plugins/autolink'
32
- import 'tinymce/plugins/anchor'
29
+ // import "tinymce/plugins/fullscreen" //全屏
33
30
 
34
- import { platEditorProps } from './plat-editor-props'
35
- import { platEditorEmits } from './plat-editor-emits'
36
- import { useEditorState } from './hook'
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'
37
36
  defineOptions({
38
37
  name: 'PlEditor'
39
38
  })
40
- const props = defineProps(platEditorProps)
41
- const emit = defineEmits(platEditorEmits)
42
-
43
- const { init, modelValue } = useEditorState(props)
44
- const editorBorder = ref('1px solid #d9d9d9')
45
-
46
- watch(
47
- () => modelValue.value,
48
- (val) => {
49
- emit('update:value', val)
50
- emit('change', val)
51
- }
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)}`
52
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())
105
+
106
+ const config = {
107
+ headers: {
108
+ 'Content-Type': 'multipart/form-data'
109
+ }
110
+ }
53
111
 
54
- // 添加红色边框
55
- const addValidate = (border = '1px solid #ff4d4f') => {
56
- editorBorder.value = border
57
- }
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
+ }),
58
128
 
59
- // 取消红色边框
60
- const removeValidate = (border = '1px solid #d9d9d9') => {
61
- editorBorder.value = border
62
- }
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
+ }
63
135
 
64
- const instance = {
65
- ...props,
66
- addValidate,
67
- removeValidate
68
- }
136
+ // Provide image and alt text for the image dialog
137
+ if (meta.filetype == 'image') {
138
+ callback('myimage.jpg', { alt: 'My alt text' })
139
+ }
69
140
 
70
- defineExpose(instance)
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
+ })
71
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
+ )
72
163
  //在onMounted中初始化编辑器
73
164
  onMounted(() => {
74
165
  tinymce.init({})
75
166
  })
76
167
  </script>
77
- <style lang="less" scoped>
78
- //:deep(.tox-tinymce) {
79
- // border: v-bind(editorBorder);
80
- // border-radius: 2px;
81
- //}
82
- :deep(.tox-tinymce-aux) {
83
- z-index: 1000;
84
- }
85
- </style>
@@ -1 +0,0 @@
1
- export * from './useEditorState';
@@ -1,28 +0,0 @@
1
- import { PlatEditorProps } from '../plat-editor-props';
2
- export declare const useEditorState: (props: PlatEditorProps) => {
3
- init: import("vue").ComputedRef<{
4
- images_upload_handler: (blobInfo: any) => Promise<unknown>;
5
- file_picker_callback: (callback: any) => void;
6
- selector: string;
7
- placeholder: string;
8
- language_url: string;
9
- language: string;
10
- skin_url: string;
11
- height: number;
12
- branding: boolean;
13
- menubar: boolean;
14
- image_dimensions: boolean;
15
- promotion: boolean;
16
- plugins: string;
17
- toolbar: string;
18
- paste_webkit_styles: string;
19
- paste_merge_formats: boolean;
20
- nonbreaking_force_tab: boolean;
21
- paste_auto_cleanup_on_paste: boolean;
22
- file_picker_types: string;
23
- fontsize_formats: string;
24
- font_formats: string;
25
- content_css: string;
26
- }>;
27
- modelValue: import("vue").Ref<any>;
28
- };
@@ -1 +0,0 @@
1
- export declare const platEditorEmits: string[];
@@ -1,37 +0,0 @@
1
- import { ExtractPropTypes } from 'vue';
2
- import { MediaSetting, ImageSetting } from './type';
3
- export declare const platEditorProps: {
4
- editorSetting: {
5
- type: ObjectConstructor;
6
- default: () => {};
7
- };
8
- mediaSetting: {
9
- type: PropType<MediaSetting>;
10
- default: () => {
11
- fileSizeLimit: number;
12
- fileTypeLimit: string[];
13
- fileNameLength: number;
14
- };
15
- };
16
- imageSetting: {
17
- type: PropType<ImageSetting>;
18
- default: () => {
19
- fileSizeLimit: number;
20
- fileTypeLimit: string[];
21
- fileNameLength: number;
22
- };
23
- };
24
- value: {
25
- type: StringConstructor;
26
- default: string;
27
- };
28
- disabled: {
29
- type: BooleanConstructor;
30
- default: boolean;
31
- };
32
- /** 附件请求函数 */
33
- fileRequest: {
34
- type: PropType<(file: any) => Promise<any>>;
35
- };
36
- };
37
- export declare type PlatEditorProps = ExtractPropTypes<typeof platEditorProps>;
@@ -1,10 +0,0 @@
1
- export interface MediaSetting {
2
- fileSizeLimit: number;
3
- fileTypeLimit: string;
4
- fileNameLength: string | number;
5
- }
6
- export interface ImageSetting {
7
- fileSizeLimit: number;
8
- fileTypeLimit: string;
9
- fileNameLength: string | number;
10
- }