@sy-common/wang-editor 1.0.0-beta.2
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.
- package/index.js +3 -0
- package/package.json +25 -0
- package/src/index.vue +189 -0
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sy-common/wang-editor",
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "lambo",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"registry": "https://registry.npmjs.org/"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@lambo-design/core": "^4.7.1-beta.140",
|
|
14
|
+
"@wangeditor-next/editor": "^5.6.0",
|
|
15
|
+
"@wangeditor-next/editor-for-vue2": "^1.0.2"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"release-upload-file": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
|
|
19
|
+
"release-major": "standard-version --release-as major",
|
|
20
|
+
"release-minor": "standard-version --release-as minor",
|
|
21
|
+
"release-patch": "standard-version --release-as patch",
|
|
22
|
+
"release-beta": "standard-version --prerelease beta",
|
|
23
|
+
"re-publish": "pnpm publish --access public --no-git-checks"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/index.vue
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div >
|
|
3
|
+
<!-- 工具栏 -->
|
|
4
|
+
<Toolbar
|
|
5
|
+
:editor="editor"
|
|
6
|
+
:defaultConfig="toolbarConfig"
|
|
7
|
+
/>
|
|
8
|
+
<!-- 编辑器 -->
|
|
9
|
+
<Editor
|
|
10
|
+
style="height: 400px; overflow-y: hidden;"
|
|
11
|
+
:defaultConfig="editorConfig"
|
|
12
|
+
v-model="html"
|
|
13
|
+
@onChange="onChange"
|
|
14
|
+
@onCreated="onCreated"
|
|
15
|
+
/>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script>
|
|
20
|
+
import '@wangeditor-next/editor/dist/css/style.css'
|
|
21
|
+
import {oneOf} from '@lambo-design/shared/utils/platform';
|
|
22
|
+
import { Editor, Toolbar } from '@wangeditor-next/editor-for-vue2'
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
name: 'WangEditor',
|
|
26
|
+
components: { Editor, Toolbar },
|
|
27
|
+
props: {
|
|
28
|
+
value: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: ''
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* 绑定的值的类型, enum: ['html', 'text']
|
|
34
|
+
*/
|
|
35
|
+
valueType: {
|
|
36
|
+
type: String,
|
|
37
|
+
default: 'html',
|
|
38
|
+
validator: (val) => {
|
|
39
|
+
return oneOf(val, ['html', 'text'])
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* @description 设置change事件触发时间间隔
|
|
44
|
+
*/
|
|
45
|
+
changeInterval: {
|
|
46
|
+
type: Number,
|
|
47
|
+
default: 200
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* @description 是否开启本地存储
|
|
51
|
+
*/
|
|
52
|
+
cache: {
|
|
53
|
+
type: Boolean,
|
|
54
|
+
default: true
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* @description 是否使用 base64 保存图片
|
|
58
|
+
*/
|
|
59
|
+
uploadImgShowBase64: {
|
|
60
|
+
type: Boolean,
|
|
61
|
+
default: false
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* 上传图片上下文
|
|
65
|
+
*/
|
|
66
|
+
ossServerContext: {
|
|
67
|
+
type: String,
|
|
68
|
+
default: ''
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* 上传图片Url地址
|
|
72
|
+
*/
|
|
73
|
+
ossFilePutUrl: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: "/oss/file/put"
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* 获取图片url地址
|
|
79
|
+
*/
|
|
80
|
+
ossFileGetImgUrl: {
|
|
81
|
+
type: String,
|
|
82
|
+
default: "/oss/file/get/"
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* @description 是否保留粘贴内容的样式
|
|
86
|
+
*/
|
|
87
|
+
preservePasteStyle: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
default: false
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
},
|
|
93
|
+
data() {
|
|
94
|
+
return {
|
|
95
|
+
editor: null,
|
|
96
|
+
html: '',
|
|
97
|
+
toolbarConfig: {
|
|
98
|
+
// toolbarKeys: [ /* 显示哪些菜单,如何排序、分组 */ ],
|
|
99
|
+
// excludeKeys: [ /* 隐藏哪些菜单 */ ],
|
|
100
|
+
},
|
|
101
|
+
editorConfig: {
|
|
102
|
+
placeholder: '请输入内容...',
|
|
103
|
+
MENU_CONF: {
|
|
104
|
+
|
|
105
|
+
uploadImage: {
|
|
106
|
+
//上传图片配置
|
|
107
|
+
server: this.ossServerContext+this.ossFilePutUrl, //上传接口地址
|
|
108
|
+
fieldName: 'file', //上传文件名
|
|
109
|
+
methods: 'post',
|
|
110
|
+
metaWithUrl: true, // 参数拼接到 url 上
|
|
111
|
+
//自定义插入图片
|
|
112
|
+
customInsert:(res, insertFn)=>{
|
|
113
|
+
let self = this;
|
|
114
|
+
const imgInfo = res.data[0] || {}
|
|
115
|
+
const { fileId, fileName, contentType } = imgInfo
|
|
116
|
+
insertFn(self.ossServerContext + self.ossFileGetImgUrl + fileId, fileName, self.ossServerContext + self.ossFileGetImgUrl + fileId)
|
|
117
|
+
} ,
|
|
118
|
+
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
watch: {
|
|
125
|
+
value: {
|
|
126
|
+
handler: function (newVal, oldVal) {
|
|
127
|
+
// console.log('watch',newVal+" "+oldVal)
|
|
128
|
+
if (oldVal === '') {
|
|
129
|
+
if (this.valueType === 'html') {
|
|
130
|
+
this.editor.setHtml(newVal)
|
|
131
|
+
} else {
|
|
132
|
+
this.editor.insertText(newVal)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
computed: {
|
|
139
|
+
// editorId() {
|
|
140
|
+
// return `editor${this._uid}`
|
|
141
|
+
// }
|
|
142
|
+
},
|
|
143
|
+
methods: {
|
|
144
|
+
|
|
145
|
+
onCreated(editor) {
|
|
146
|
+
this.editor = Object.seal(editor) // 【注意】一定要用 Object.seal() 否则会报错
|
|
147
|
+
// 如果本地有存储加载本地存储内容
|
|
148
|
+
let html = this.value
|
|
149
|
+
if (html) this.editor.setHtml(html)
|
|
150
|
+
},
|
|
151
|
+
onChange(editor) {
|
|
152
|
+
let self = this;
|
|
153
|
+
let html = this.editor.getHtml()
|
|
154
|
+
if (html.includes('table')){
|
|
155
|
+
html = html.replace(/<table /g,'<table class="wangeditor-styled-table" style= "border-collapse: collapse;"'); // 添加边框)
|
|
156
|
+
}
|
|
157
|
+
console.log(html)
|
|
158
|
+
this.$emit('input', self.valueType === 'html' ? html : editor.getText())
|
|
159
|
+
this.$emit('on-change', html, editor.getText())
|
|
160
|
+
},
|
|
161
|
+
customPaste(editor, event, callback) {
|
|
162
|
+
//console.log('ClipboardEvent 粘贴事件对象', event)
|
|
163
|
+
const html = event.clipboardData.getData('text/html') // 获取粘贴的 html
|
|
164
|
+
const text = event.clipboardData.getData('text/plain') // 获取粘贴的纯文本
|
|
165
|
+
const rtf = event.clipboardData.getData('text/rtf') // 获取 rtf 数据(如从 word wsp 复制粘贴)
|
|
166
|
+
|
|
167
|
+
//console.log("customPaste-html",rtf)
|
|
168
|
+
// 自定义插入内容
|
|
169
|
+
editor.setHtml(html)
|
|
170
|
+
|
|
171
|
+
// 返回 false ,阻止默认粘贴行为
|
|
172
|
+
event.preventDefault()
|
|
173
|
+
callback(false) // 返回值(注意,vue 事件的返回值,不能用 return)
|
|
174
|
+
|
|
175
|
+
// 返回 true ,继续默认的粘贴行为
|
|
176
|
+
// callback(true)
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
mounted() {
|
|
180
|
+
|
|
181
|
+
},
|
|
182
|
+
beforeDestroy() {
|
|
183
|
+
const editor = this.editor
|
|
184
|
+
if (editor == null) return
|
|
185
|
+
editor.destroy() // 组件销毁时,及时销毁 editor ,重要!!!
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
</script>
|