@ajaxjs/ui 1.1.2 → 1.1.3
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/README.md +4 -24
- package/dist/css/app.11ca79dd.css +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.html +1 -0
- package/dist/index.js +56 -3
- package/dist/index.js.map +1 -1
- package/dist/js/app.44da9bce.js +2 -0
- package/dist/js/app.44da9bce.js.map +1 -0
- package/dist/js/chunk-vendors.0d9e9c3a.js +8 -0
- package/dist/js/chunk-vendors.0d9e9c3a.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +14 -9
- package/dist/main.js.map +1 -1
- package/dist/router/index.d.ts +3 -0
- package/dist/router/index.js +36 -28
- package/dist/router/index.js.map +1 -1
- package/dist/shims-vue.d.ts +4 -0
- package/dist/util/cookies.d.ts +18 -0
- package/dist/util/cookies.js +46 -0
- package/dist/util/cookies.js.map +1 -0
- package/dist/util/dom.d.ts +17 -0
- package/dist/util/dom.js +44 -0
- package/dist/util/dom.js.map +1 -0
- package/dist/util/system/config.d.ts +13 -0
- package/dist/util/system/config.js +84 -0
- package/dist/util/system/config.js.map +1 -0
- package/dist/util/utils.d.ts +44 -0
- package/dist/util/utils.js +140 -0
- package/dist/util/utils.js.map +1 -0
- package/dist/util/xhr-config.d.ts +22 -0
- package/dist/util/xhr-config.js +3 -0
- package/dist/util/xhr-config.js.map +1 -0
- package/dist/util/xhr.d.ts +71 -0
- package/dist/util/xhr.js +262 -0
- package/dist/util/xhr.js.map +1 -0
- package/dist/{components/widgets → widget}/AccordionMenu.vue +139 -137
- package/dist/{components/widgets → widget}/AdjustFontSize.vue +65 -65
- package/dist/{components/widgets → widget}/Article.vue +58 -48
- package/dist/{components/widgets → widget}/BaiduSearch.vue +49 -49
- package/dist/widget/EmptyContent.d.ts +5 -0
- package/dist/widget/EmptyContent.js +7 -0
- package/dist/widget/EmptyContent.js.map +1 -0
- package/dist/{components/widgets → widget}/Expander.vue +64 -64
- package/dist/widget/FileUploader/FileUploader.d.ts +70 -0
- package/dist/{components/form → widget}/FileUploader/FileUploader.js +40 -5
- package/dist/widget/FileUploader/FileUploader.js.map +1 -0
- package/dist/{components/form → widget}/FileUploader/FileUploader.less +67 -54
- package/dist/{components/form → widget}/FileUploader/FileUploader.ts +155 -120
- package/dist/widget/FileUploader/FileUploader.vue +43 -0
- package/dist/widget/HtmlEditor/HtmlEditor.d.ts +70 -0
- package/dist/{components/form → widget}/HtmlEditor/HtmlEditor.js +10 -7
- package/dist/widget/HtmlEditor/HtmlEditor.js.map +1 -0
- package/dist/{components/form → widget}/HtmlEditor/HtmlEditor.less +344 -344
- package/dist/{components/form → widget}/HtmlEditor/HtmlEditor.ts +338 -336
- package/dist/{components/form → widget}/HtmlEditor/HtmlEditor.vue +69 -69
- package/dist/{components/form → widget}/HtmlEditor/html-editor-HtmlSanitizer.js +102 -102
- package/dist/{components/widgets → widget}/ImageEnlarger.vue +104 -98
- package/dist/{components/widgets → widget}/OpacityBanner.vue +124 -123
- package/dist/{components/widgets → widget}/ProcessLine.vue +132 -132
- package/dist/widget/Resize.d.ts +51 -0
- package/dist/widget/Resize.js +133 -0
- package/dist/widget/Resize.js.map +1 -0
- package/dist/widget/Resize.ts +152 -0
- package/dist/widget/Resize.vue +104 -0
- package/dist/widget/TreeSelector.vue +4 -0
- package/dist/widget/calendar/BetweenDate.vue +63 -0
- package/dist/widget/calendar/Calendar.d.ts +55 -0
- package/dist/widget/calendar/Calendar.js +145 -0
- package/dist/widget/calendar/Calendar.js.map +1 -0
- package/dist/widget/calendar/Calendar.less +208 -0
- package/dist/widget/calendar/Calendar.ts +167 -0
- package/dist/widget/calendar/Calendar.vue +52 -0
- package/dist/widget/calendar/CalendarInput.vue +71 -0
- package/dist/widget/form/validator.d.ts +72 -0
- package/dist/widget/form/validator.js +222 -0
- package/dist/widget/form/validator.js.map +1 -0
- package/dist/widget/form/validator.ts +290 -0
- package/dist/widget/play-ground/sku.vue +93 -0
- package/package.json +36 -33
- package/dist/components/form/AjSelect.vue +0 -33
- package/dist/components/form/FileUploader/FileUploader.js.map +0 -1
- package/dist/components/form/FileUploader/FileUploader.vue +0 -26
- package/dist/components/form/HtmlEditor/HtmlEditor.js.map +0 -1
- package/dist/components/form/TreeLikeSelect.vue +0 -125
|
@@ -1,337 +1,339 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
props: {
|
|
3
|
-
vModel: String,
|
|
4
|
-
uploadImageActionUrl: String,
|
|
5
|
-
isIonicons: Boolean
|
|
6
|
-
},
|
|
7
|
-
data(): any {
|
|
8
|
-
return {
|
|
9
|
-
isShowCode: false, // 是否显示 HTML 源码
|
|
10
|
-
iframeEl: null,
|
|
11
|
-
sourceEditor: null,
|
|
12
|
-
};
|
|
13
|
-
},
|
|
14
|
-
mounted(): void {
|
|
15
|
-
this.iframeEl = <HTMLIFrameElement>this.$el.querySelector('iframe');
|
|
16
|
-
this.sourceEditor = <HTMLTextAreaElement>this.$el.querySelector('textarea');
|
|
17
|
-
|
|
18
|
-
(<Window>this.iframeEl.contentWindow).onload = (ev: Event) => { // 这个方法只能写在 onload 事件里面, 不写 onload 里还不执行
|
|
19
|
-
this.iframeDoc = (<Window>this.iframeEl.contentWindow).document;
|
|
20
|
-
this.iframeDoc.designMode = 'on';
|
|
21
|
-
this.iframeDoc.addEventListener('paste', onImagePaste.bind(this));// 直接剪切板粘贴上传图片
|
|
22
|
-
|
|
23
|
-
new MutationObserver((mutationsList: MutationRecord[], observer: MutationObserver) => {// 监听DOM树变化
|
|
24
|
-
if (!this.isShowCode) {
|
|
25
|
-
this.sourceEditor.value = this.iframeDoc.body.innerHTML;
|
|
26
|
-
this.$emit('on-change', this.sourceEditor.value)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}).observe(this.iframeDoc.body, { attributes: true, childList: true, subtree: true, characterData: true });
|
|
30
|
-
|
|
31
|
-
this.vModel && this.setIframeBody(this.vModel);
|
|
32
|
-
// this.sourceEditor.value && this.setIframeBody(this.sourceEditor.value);// 有内容
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.sourceEditor.oninput = (ev: Event) => {
|
|
36
|
-
if (this.isShowCode && this.sourceEditor.value) {
|
|
37
|
-
this.setIframeBody(this.sourceEditor.value);
|
|
38
|
-
this.$emit('on-change', this.sourceEditor.value)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// this.uploadImgMgr = this.$refs.uploadLayer;
|
|
43
|
-
},
|
|
44
|
-
methods: {
|
|
45
|
-
/**
|
|
46
|
-
* 输入 HTML 内容
|
|
47
|
-
*
|
|
48
|
-
* @param html
|
|
49
|
-
*/
|
|
50
|
-
setIframeBody(html: string): void {
|
|
51
|
-
if (this.iframeDoc && this.iframeDoc.body)
|
|
52
|
-
this.iframeDoc.body.innerHTML = html;
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 获取内容的 HTML
|
|
57
|
-
*
|
|
58
|
-
* @param cleanWord 是否清理冗余标签
|
|
59
|
-
* @param encode 是否 URL 编码
|
|
60
|
-
*/
|
|
61
|
-
getValue(cleanWord: boolean, encode: boolean): string {
|
|
62
|
-
let result: string = this.iframeDoc.body.innerHTML;
|
|
63
|
-
|
|
64
|
-
if (cleanWord)
|
|
65
|
-
result = cleanPaste(result);
|
|
66
|
-
|
|
67
|
-
if (encode)
|
|
68
|
-
result = encodeURIComponent(result);
|
|
69
|
-
|
|
70
|
-
return result;
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
createLink(): void {
|
|
74
|
-
let result: string = prompt("请输入 URL 地址");
|
|
75
|
-
if (result)
|
|
76
|
-
this.format("createLink", result);
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
insertImage(): void {
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
if (window.isCreate)
|
|
82
|
-
alert('请保存记录后再上传图片。');
|
|
83
|
-
else {
|
|
84
|
-
this.uploadImgMgr.show((json: any) => {
|
|
85
|
-
if (json && json.isOk)
|
|
86
|
-
this.format("insertImage", json.fullUrl);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 清理冗余 HTML
|
|
93
|
-
*/
|
|
94
|
-
cleanHTML(): void {
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
this.setIframeBody(HtmlSanitizer.SanitizeHtml(this.iframeDoc.body.innerHTML));
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
saveRemoteImage2Local(): void {
|
|
100
|
-
saveRemoteImage2Local.call(this);
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 当工具条点击的时候触发
|
|
105
|
-
*
|
|
106
|
-
* @param ev
|
|
107
|
-
*/
|
|
108
|
-
onCmdClk(ev: Event): void {
|
|
109
|
-
let el: HTMLElement = <HTMLElement>ev.target,
|
|
110
|
-
clsName = <string>el.className.split(' ').shift();
|
|
111
|
-
|
|
112
|
-
this.format(clsName);
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* 通过 document.execCommand() 来操纵可编辑内容区域的元素
|
|
117
|
-
*
|
|
118
|
-
* @param type 命令的名称
|
|
119
|
-
* @param para 一些命令(例如 insertImage)需要额外的参数(insertImage 需要提供插入 image 的 url),默认为 null
|
|
120
|
-
*/
|
|
121
|
-
format(type: string, para?: string): void {
|
|
122
|
-
if (para)
|
|
123
|
-
this.iframeDoc.execCommand(type, false, para);
|
|
124
|
-
else
|
|
125
|
-
this.iframeDoc.execCommand(type, false);
|
|
126
|
-
|
|
127
|
-
(<Window>this.iframeEl.contentWindow).focus();
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* 选择字号大小
|
|
132
|
-
*
|
|
133
|
-
* @param ev
|
|
134
|
-
*/
|
|
135
|
-
onFontsizeChoserClk(ev: Event): void {
|
|
136
|
-
let el: HTMLElement = <HTMLElement>ev.target,
|
|
137
|
-
els = (<HTMLElement>ev.currentTarget).children;
|
|
138
|
-
|
|
139
|
-
let i: number, j: number;
|
|
140
|
-
for (i = 0, j = els.length; i < j; i++)
|
|
141
|
-
if (el == els[i])
|
|
142
|
-
break;
|
|
143
|
-
|
|
144
|
-
this.format('fontsize', i + "");
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 选择字体
|
|
149
|
-
*
|
|
150
|
-
* @param ev
|
|
151
|
-
*/
|
|
152
|
-
onFontfamilyChoserClk(ev: Event): void {
|
|
153
|
-
let el: HTMLElement = <HTMLElement>ev.target;
|
|
154
|
-
this.format('fontname', el.innerHTML);
|
|
155
|
-
|
|
156
|
-
/* 如何解决点击之后马上隐藏面板?由于 js(单击事件) 没有控制 CSS 的 :hover 伪类的方法,故所以必须使用以下技巧:*/
|
|
157
|
-
let menuPanel: HTMLElement = <HTMLElement>el.parentNode;
|
|
158
|
-
menuPanel.style.display = 'none';
|
|
159
|
-
setTimeout(() => menuPanel.style.display = '', 300);
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 创建颜色选择器
|
|
164
|
-
*/
|
|
165
|
-
createColorPickerHTML(): string {
|
|
166
|
-
let cl: string[] = ['00', '33', '66', '99', 'CC', 'FF'],
|
|
167
|
-
b: string, d: string, e: string, f: string,
|
|
168
|
-
h: string[] = ['<div class="colorhead"><span class="colortitle">颜色选择</span></div><div class="colorbody"><table cellspaci="0" cellpadding="0"><tr>'];
|
|
169
|
-
|
|
170
|
-
// 创建 body [6 x 6的色盘]
|
|
171
|
-
for (let i = 0; i < 6; ++i) {
|
|
172
|
-
h.push('<td><table class="colorpanel" cellspacing="0" cellpadding="0">');
|
|
173
|
-
|
|
174
|
-
for (let j = 0, a = cl[i]; j < 6; ++j) {
|
|
175
|
-
h.push('<tr>');
|
|
176
|
-
|
|
177
|
-
for (let k = 0, c = cl[j]; k < 6; ++k) {
|
|
178
|
-
b = cl[k];
|
|
179
|
-
e = (k == 5 && i != 2 && i != 5) ? ';border-right:none;' : '';
|
|
180
|
-
f = (j == 5 && i < 3) ? ';border-bottom:none' : '';
|
|
181
|
-
d = '#' + a + b + c;
|
|
182
|
-
// T = document.all ? ' ' : '';
|
|
183
|
-
h.push('<td unselectable="on" style="background-color: ' + d + e + f + '" title="' + d + '"></td>');
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
h.push('</tr>');
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
h.push('</table></td>');
|
|
190
|
-
|
|
191
|
-
if (cl[i] == '66')
|
|
192
|
-
h.push('</tr><tr>');
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
h.push('</tr></table></div>');
|
|
196
|
-
|
|
197
|
-
return h.join('');
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
*
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
//
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
//
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
//
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
*
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
//
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
item.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
html = html.replace(/<
|
|
333
|
-
html = html.replace(
|
|
334
|
-
html = html.replace(
|
|
335
|
-
|
|
336
|
-
|
|
1
|
+
export default {
|
|
2
|
+
props: {
|
|
3
|
+
vModel: String, // 双向绑定
|
|
4
|
+
uploadImageActionUrl: String, // 图片上传路径
|
|
5
|
+
isIonicons: Boolean // 是否使用 ionicons 图标
|
|
6
|
+
},
|
|
7
|
+
data(): any {
|
|
8
|
+
return {
|
|
9
|
+
isShowCode: false, // 是否显示 HTML 源码
|
|
10
|
+
iframeEl: null,
|
|
11
|
+
sourceEditor: null,
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
mounted(): void {
|
|
15
|
+
this.iframeEl = <HTMLIFrameElement>this.$el.querySelector('iframe');
|
|
16
|
+
this.sourceEditor = <HTMLTextAreaElement>this.$el.querySelector('textarea');
|
|
17
|
+
|
|
18
|
+
(<Window>this.iframeEl.contentWindow).onload = (ev: Event) => { // 这个方法只能写在 onload 事件里面, 不写 onload 里还不执行
|
|
19
|
+
this.iframeDoc = (<Window>this.iframeEl.contentWindow).document;
|
|
20
|
+
this.iframeDoc.designMode = 'on';
|
|
21
|
+
this.iframeDoc.addEventListener('paste', onImagePaste.bind(this));// 直接剪切板粘贴上传图片
|
|
22
|
+
|
|
23
|
+
new MutationObserver((mutationsList: MutationRecord[], observer: MutationObserver) => {// 监听DOM树变化
|
|
24
|
+
if (!this.isShowCode) {
|
|
25
|
+
this.sourceEditor.value = this.iframeDoc.body.innerHTML;
|
|
26
|
+
this.$emit('on-change', this.sourceEditor.value)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}).observe(this.iframeDoc.body, { attributes: true, childList: true, subtree: true, characterData: true });
|
|
30
|
+
|
|
31
|
+
this.vModel && this.setIframeBody(this.vModel);
|
|
32
|
+
// this.sourceEditor.value && this.setIframeBody(this.sourceEditor.value);// 有内容
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.sourceEditor.oninput = (ev: Event) => {
|
|
36
|
+
if (this.isShowCode && this.sourceEditor.value) {
|
|
37
|
+
this.setIframeBody(this.sourceEditor.value);
|
|
38
|
+
this.$emit('on-change', this.sourceEditor.value)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// this.uploadImgMgr = this.$refs.uploadLayer;
|
|
43
|
+
},
|
|
44
|
+
methods: {
|
|
45
|
+
/**
|
|
46
|
+
* 输入 HTML 内容
|
|
47
|
+
*
|
|
48
|
+
* @param html
|
|
49
|
+
*/
|
|
50
|
+
setIframeBody(html: string): void {
|
|
51
|
+
if (this.iframeDoc && this.iframeDoc.body)
|
|
52
|
+
this.iframeDoc.body.innerHTML = html;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 获取内容的 HTML
|
|
57
|
+
*
|
|
58
|
+
* @param cleanWord 是否清理冗余标签
|
|
59
|
+
* @param encode 是否 URL 编码
|
|
60
|
+
*/
|
|
61
|
+
getValue(cleanWord: boolean, encode: boolean): string {
|
|
62
|
+
let result: string = this.iframeDoc.body.innerHTML;
|
|
63
|
+
|
|
64
|
+
if (cleanWord)
|
|
65
|
+
result = cleanPaste(result);
|
|
66
|
+
|
|
67
|
+
if (encode)
|
|
68
|
+
result = encodeURIComponent(result);
|
|
69
|
+
|
|
70
|
+
return result;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
createLink(): void {
|
|
74
|
+
let result: string = prompt("请输入 URL 地址");
|
|
75
|
+
if (result)
|
|
76
|
+
this.format("createLink", result);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
insertImage(): void {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
if (window.isCreate)
|
|
82
|
+
alert('请保存记录后再上传图片。');
|
|
83
|
+
else {
|
|
84
|
+
this.uploadImgMgr.show((json: any) => {
|
|
85
|
+
if (json && json.isOk)
|
|
86
|
+
this.format("insertImage", json.fullUrl);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 清理冗余 HTML
|
|
93
|
+
*/
|
|
94
|
+
cleanHTML(): void {
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
this.setIframeBody(HtmlSanitizer.SanitizeHtml(this.iframeDoc.body.innerHTML));
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
saveRemoteImage2Local(): void {
|
|
100
|
+
saveRemoteImage2Local.call(this);
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 当工具条点击的时候触发
|
|
105
|
+
*
|
|
106
|
+
* @param ev
|
|
107
|
+
*/
|
|
108
|
+
onCmdClk(ev: Event): void {
|
|
109
|
+
let el: HTMLElement = <HTMLElement>ev.target,
|
|
110
|
+
clsName = <string>el.className.split(' ').shift();
|
|
111
|
+
|
|
112
|
+
this.format(clsName);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 通过 document.execCommand() 来操纵可编辑内容区域的元素
|
|
117
|
+
*
|
|
118
|
+
* @param type 命令的名称
|
|
119
|
+
* @param para 一些命令(例如 insertImage)需要额外的参数(insertImage 需要提供插入 image 的 url),默认为 null
|
|
120
|
+
*/
|
|
121
|
+
format(type: string, para?: string): void {
|
|
122
|
+
if (para)
|
|
123
|
+
this.iframeDoc.execCommand(type, false, para);
|
|
124
|
+
else
|
|
125
|
+
this.iframeDoc.execCommand(type, false);
|
|
126
|
+
|
|
127
|
+
// (<Window>this.iframeEl.contentWindow).focus();
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 选择字号大小
|
|
132
|
+
*
|
|
133
|
+
* @param ev
|
|
134
|
+
*/
|
|
135
|
+
onFontsizeChoserClk(ev: Event): void {
|
|
136
|
+
let el: HTMLElement = <HTMLElement>ev.target,
|
|
137
|
+
els = (<HTMLElement>ev.currentTarget).children;
|
|
138
|
+
|
|
139
|
+
let i: number, j: number;
|
|
140
|
+
for (i = 0, j = els.length; i < j; i++)
|
|
141
|
+
if (el == els[i])
|
|
142
|
+
break;
|
|
143
|
+
|
|
144
|
+
this.format('fontsize', i + "");
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 选择字体
|
|
149
|
+
*
|
|
150
|
+
* @param ev
|
|
151
|
+
*/
|
|
152
|
+
onFontfamilyChoserClk(ev: Event): void {
|
|
153
|
+
let el: HTMLElement = <HTMLElement>ev.target;
|
|
154
|
+
this.format('fontname', el.innerHTML);
|
|
155
|
+
|
|
156
|
+
/* 如何解决点击之后马上隐藏面板?由于 js(单击事件) 没有控制 CSS 的 :hover 伪类的方法,故所以必须使用以下技巧:*/
|
|
157
|
+
let menuPanel: HTMLElement = <HTMLElement>el.parentNode;
|
|
158
|
+
menuPanel.style.display = 'none';
|
|
159
|
+
setTimeout(() => menuPanel.style.display = '', 300);
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 创建颜色选择器
|
|
164
|
+
*/
|
|
165
|
+
createColorPickerHTML(): string {
|
|
166
|
+
let cl: string[] = ['00', '33', '66', '99', 'CC', 'FF'],
|
|
167
|
+
b: string, d: string, e: string, f: string,
|
|
168
|
+
h: string[] = ['<div class="colorhead"><span class="colortitle">颜色选择</span></div><div class="colorbody"><table cellspaci="0" cellpadding="0"><tr>'];
|
|
169
|
+
|
|
170
|
+
// 创建 body [6 x 6的色盘]
|
|
171
|
+
for (let i = 0; i < 6; ++i) {
|
|
172
|
+
h.push('<td><table class="colorpanel" cellspacing="0" cellpadding="0">');
|
|
173
|
+
|
|
174
|
+
for (let j = 0, a = cl[i]; j < 6; ++j) {
|
|
175
|
+
h.push('<tr>');
|
|
176
|
+
|
|
177
|
+
for (let k = 0, c = cl[j]; k < 6; ++k) {
|
|
178
|
+
b = cl[k];
|
|
179
|
+
e = (k == 5 && i != 2 && i != 5) ? ';border-right:none;' : '';
|
|
180
|
+
f = (j == 5 && i < 3) ? ';border-bottom:none' : '';
|
|
181
|
+
d = '#' + a + b + c;
|
|
182
|
+
// T = document.all ? ' ' : '';
|
|
183
|
+
h.push('<td unselectable="on" style="background-color: ' + d + e + f + '" title="' + d + '"></td>');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
h.push('</tr>');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
h.push('</table></td>');
|
|
190
|
+
|
|
191
|
+
if (cl[i] == '66')
|
|
192
|
+
h.push('</tr><tr>');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
h.push('</tr></table></div>');
|
|
196
|
+
|
|
197
|
+
return h.join('');
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
watch: {
|
|
202
|
+
vModel(newHtml: string, oldHtml: string): void {
|
|
203
|
+
// if (!html)
|
|
204
|
+
// html = '';
|
|
205
|
+
if (!oldHtml) // 当没有值的时候输入,就是在初始化的时候(第一次)
|
|
206
|
+
this.setIframeBody(newHtml);
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* 切換 HTML 編輯 or 可視化編輯
|
|
211
|
+
*
|
|
212
|
+
* @param n
|
|
213
|
+
*/
|
|
214
|
+
isShowCode(n: boolean): void {
|
|
215
|
+
if (n) {
|
|
216
|
+
this.iframeEl.classList.add('hide');
|
|
217
|
+
this.sourceEditor.classList.add('show');
|
|
218
|
+
grayImg.call(this, true);
|
|
219
|
+
} else {
|
|
220
|
+
this.iframeEl.classList.remove('hide');
|
|
221
|
+
this.sourceEditor.classList.remove('show');
|
|
222
|
+
grayImg.call(this, false);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* 粘贴图片
|
|
230
|
+
*
|
|
231
|
+
* @param this
|
|
232
|
+
* @param ev
|
|
233
|
+
*/
|
|
234
|
+
function onImagePaste(ev: ClipboardEvent): void {
|
|
235
|
+
if (!this.uploadImageActionUrl) {
|
|
236
|
+
alert('未提供图片上传地址');
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
let items: DataTransferItemList | null = ev.clipboardData && ev.clipboardData.items,
|
|
241
|
+
file: File | null = null; // file 就是剪切板中的图片文件
|
|
242
|
+
|
|
243
|
+
if (items && items.length) {// 检索剪切板 items
|
|
244
|
+
for (let i = 0; i < items.length; i++) {
|
|
245
|
+
const item: DataTransferItem = items[i];
|
|
246
|
+
|
|
247
|
+
if (item.type.indexOf('image') !== -1) {
|
|
248
|
+
// @ts-ignore
|
|
249
|
+
if (window.isCreate) { // 有图片
|
|
250
|
+
alert('请保存记录后再上传图片。');
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
file = item.getAsFile();
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (file) {
|
|
261
|
+
// ev.preventDefault();
|
|
262
|
+
// img.changeBlobImageQuality(file, (newBlob: Blob): void => {
|
|
263
|
+
// // 复用上传的方法
|
|
264
|
+
// Vue.options.components["aj-xhr-upload"].extendOptions.methods.doUpload.call({
|
|
265
|
+
// action: this.uploadImageActionUrl,
|
|
266
|
+
// progress: 0,
|
|
267
|
+
// uploadOk_callback(j: ImgUploadRepsonseResult) {
|
|
268
|
+
// if (j.isOk)
|
|
269
|
+
// this.format("insertImage", this.ajResources.imgPerfix + j.imgUrl);
|
|
270
|
+
// },
|
|
271
|
+
// $blob: newBlob,
|
|
272
|
+
// $fileName: 'foo.jpg' // 文件名不重要,反正上传到云空间会重命名
|
|
273
|
+
// });
|
|
274
|
+
// });
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 一键存图
|
|
280
|
+
*
|
|
281
|
+
* @param this
|
|
282
|
+
*/
|
|
283
|
+
function saveRemoteImage2Local(): void {
|
|
284
|
+
const arr: NodeListOf<HTMLImageElement> = this.iframeDoc.querySelectorAll('img'),
|
|
285
|
+
remotePicArr: HTMLImageElement[] = new Array<HTMLImageElement>(),
|
|
286
|
+
srcs: string[] = [];
|
|
287
|
+
|
|
288
|
+
for (let i = 0, j = arr.length; i < j; i++) {
|
|
289
|
+
const imgEl: HTMLImageElement = arr[i],
|
|
290
|
+
src: string = <string>imgEl.getAttribute('src');
|
|
291
|
+
|
|
292
|
+
if (/^http/.test(src)) {
|
|
293
|
+
remotePicArr.push(imgEl);
|
|
294
|
+
srcs.push(src);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (srcs.length) {
|
|
299
|
+
// xhr.post('../downAllPics/', (json: any) => {
|
|
300
|
+
// const _arr: string[] = json.pics;
|
|
301
|
+
|
|
302
|
+
// for (let i = 0, j = _arr.length; i < j; i++)
|
|
303
|
+
// remotePicArr[i].src = "images/" + _arr[i]; // 改变 DOM 的旧图片地址为新的
|
|
304
|
+
|
|
305
|
+
// alert('所有图片下载完成。');
|
|
306
|
+
// }, { pics: srcs.join('|') });
|
|
307
|
+
} else
|
|
308
|
+
alert('未发现有远程图片');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 使图标变灰色
|
|
313
|
+
*
|
|
314
|
+
* @param this
|
|
315
|
+
* @param isGray
|
|
316
|
+
*/
|
|
317
|
+
function grayImg(isGray: boolean): void {
|
|
318
|
+
this.$el.querySelectorAll('.toolbar i').forEach((item: HTMLElement) => {
|
|
319
|
+
if (item.className.indexOf('switchMode') != -1) // 这个按钮永远可按,不受影响
|
|
320
|
+
return;
|
|
321
|
+
item.style.color = isGray ? 'lightgray' : '';
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Remove additional MS Word content
|
|
327
|
+
* MSWordHtmlCleaners.js https://gist.github.com/ronanguilloux/2915995
|
|
328
|
+
*
|
|
329
|
+
* @param html
|
|
330
|
+
*/
|
|
331
|
+
function cleanPaste(html: string): string {
|
|
332
|
+
html = html.replace(/<(\/)*(\\?xml:|meta|link|span|font|del|ins|st1:|[ovwxp]:)((.|\s)*?)>/gi, ''); // Unwanted tags
|
|
333
|
+
html = html.replace(/(class|style|type|start)=("(.*?)"|(\w*))/gi, ''); // Unwanted sttributes
|
|
334
|
+
html = html.replace(/<style(.*?)style>/gi, ''); // Style tags
|
|
335
|
+
html = html.replace(/<script(.*?)script>/gi, ''); // Script tags
|
|
336
|
+
html = html.replace(/<!--(.*?)-->/gi, ''); // HTML comments
|
|
337
|
+
|
|
338
|
+
return html;
|
|
337
339
|
}
|