@lambo-design/wang-editor 2.0.0-beta.3 → 2.0.0-beta.6
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/package.json +3 -3
- package/src/index.vue +34 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lambo-design/wang-editor",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "lambo",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"registry": "https://registry.npmjs.org/"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@lambo-design/shared": "^1.0.0-beta.
|
|
14
|
-
"@lambo-design/core": "^4.7.1-beta.
|
|
13
|
+
"@lambo-design/shared": "^1.0.0-beta.346",
|
|
14
|
+
"@lambo-design/core": "^4.7.1-beta.176"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@wangeditor/editor": "5.1.23",
|
package/src/index.vue
CHANGED
|
@@ -120,6 +120,20 @@ export default {
|
|
|
120
120
|
excludeKeys: {
|
|
121
121
|
type: Array,
|
|
122
122
|
default: () => []
|
|
123
|
+
},
|
|
124
|
+
/**
|
|
125
|
+
* @description 是否使用自定义图片样式插入
|
|
126
|
+
*/
|
|
127
|
+
useCustomImageStyle: {
|
|
128
|
+
type: Boolean,
|
|
129
|
+
default: false
|
|
130
|
+
},
|
|
131
|
+
/**
|
|
132
|
+
* @description 自定义图片宽度比例或像素值
|
|
133
|
+
*/
|
|
134
|
+
customImageWidth: {
|
|
135
|
+
type: String,
|
|
136
|
+
default: '30%'
|
|
123
137
|
}
|
|
124
138
|
|
|
125
139
|
},
|
|
@@ -151,11 +165,19 @@ export default {
|
|
|
151
165
|
handleChange(editor) {
|
|
152
166
|
const html = editor.getHtml();
|
|
153
167
|
const text = editor.getText();
|
|
168
|
+
|
|
169
|
+
// 判断是否为空内容
|
|
170
|
+
const isEmpty = html === '<p><br></p>' || html.trim() === '';
|
|
171
|
+
|
|
172
|
+
// 如果为空,返回空字符串;否则返回原始 HTML 或文本
|
|
173
|
+
const finalValue = isEmpty ? '' : (this.valueType === 'html' ? html : text);
|
|
174
|
+
|
|
154
175
|
if (this.cache) {
|
|
155
|
-
localStorage.editorCache =
|
|
176
|
+
localStorage.editorCache = finalValue;
|
|
156
177
|
}
|
|
157
|
-
|
|
158
|
-
this.$emit('
|
|
178
|
+
|
|
179
|
+
this.$emit('input', finalValue);
|
|
180
|
+
this.$emit('on-change', finalValue, text);
|
|
159
181
|
},
|
|
160
182
|
onCreated(editor) {
|
|
161
183
|
this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
|
|
@@ -241,7 +263,15 @@ export default {
|
|
|
241
263
|
}));
|
|
242
264
|
// 循环插入每张图片
|
|
243
265
|
imageList.forEach(imageData => {
|
|
244
|
-
|
|
266
|
+
if (self.useCustomImageStyle) {
|
|
267
|
+
// 使用自定义样式插入
|
|
268
|
+
const imgUrl = imageData.url;
|
|
269
|
+
const imgHtml = `<img src="${imgUrl}" alt="${imageData.alt}" style="width: ${self.customImageWidth};"/>`;
|
|
270
|
+
self.editor.dangerouslyInsertHtml(imgHtml);
|
|
271
|
+
} else {
|
|
272
|
+
// 使用默认方式插入
|
|
273
|
+
insertFn(imageData.url, imageData.alt, imageData.url);
|
|
274
|
+
}
|
|
245
275
|
});
|
|
246
276
|
}
|
|
247
277
|
} catch (error) {
|