@ajaxjs/util 1.0.9 → 1.1.0
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/LICENSE +201 -0
- package/README.md +11 -20
- package/dist/index.d.ts +34 -6
- package/dist/index.js +45 -8
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +1 -0
- package/dist/main.js +16 -0
- package/dist/main.js.map +1 -0
- package/dist/router/index.d.ts +3 -0
- package/dist/router/index.js +44 -0
- package/dist/router/index.js.map +1 -0
- 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/utils.d.ts +51 -0
- package/dist/util/utils.js +174 -0
- package/dist/util/utils.js.map +1 -0
- package/dist/{xhr-config.js.map → util/xhr-config.js.map} +1 -1
- package/dist/{xhr.d.ts → util/xhr.d.ts} +16 -1
- package/dist/{xhr.js → util/xhr.js} +84 -36
- package/dist/util/xhr.js.map +1 -0
- package/dist/widget/AccordionMenu.vue +140 -0
- package/dist/widget/AdjustFontSize.vue +65 -0
- package/dist/widget/Article.vue +59 -0
- 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/widget/Expander.vue +65 -0
- package/dist/widget/FileUploader/FileUploader.d.ts +70 -0
- package/dist/widget/FileUploader/FileUploader.js +139 -0
- package/dist/widget/FileUploader/FileUploader.js.map +1 -0
- package/dist/widget/FileUploader/FileUploader.less +68 -0
- package/dist/widget/FileUploader/FileUploader.ts +156 -0
- package/dist/widget/FileUploader/FileUploader.vue +43 -0
- package/dist/widget/HtmlEditor/HtmlEditor.d.ts +70 -0
- package/dist/widget/HtmlEditor/HtmlEditor.js +287 -0
- package/dist/widget/HtmlEditor/HtmlEditor.js.map +1 -0
- package/dist/widget/HtmlEditor/HtmlEditor.less +345 -0
- package/dist/widget/HtmlEditor/HtmlEditor.ts +339 -0
- package/dist/widget/HtmlEditor/HtmlEditor.vue +70 -0
- package/dist/widget/HtmlEditor/html-editor-HtmlSanitizer.js +103 -0
- package/dist/widget/ImageEnlarger.vue +105 -0
- package/dist/widget/OpacityBanner.vue +125 -0
- package/dist/widget/ProcessLine.vue +133 -0
- 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 +210 -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 +70 -0
- package/dist/widget/form/validator.js +220 -0
- package/dist/widget/form/validator.js.map +1 -0
- package/dist/widget/form/validator.ts +289 -0
- package/dist/widget/play-ground/sku.vue +93 -0
- package/package.json +31 -15
- package/dist/base.d.ts +0 -42
- package/dist/base.js +0 -133
- package/dist/base.js.map +0 -1
- package/dist/entity.d.ts +0 -26
- package/dist/entity.js +0 -2
- package/dist/entity.js.map +0 -1
- package/dist/xhr.js.map +0 -1
- package/src/base.ts +0 -145
- package/src/entity.ts +0 -31
- package/src/index.ts +0 -13
- package/src/xhr-config.ts +0 -25
- package/src/xhr.ts +0 -233
- package/tsconfig.json +0 -73
- /package/dist/{xhr-config.d.ts → util/xhr-config.d.ts} +0 -0
- /package/dist/{xhr-config.js → util/xhr-config.js} +0 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
.aj-form-html-editor {
|
|
2
|
+
ul.toolbar {
|
|
3
|
+
border : 1px solid #C5C5C5;
|
|
4
|
+
border-radius : 4px 4px 0 0;
|
|
5
|
+
border-bottom : 0;
|
|
6
|
+
background-color: #E8E7E4;
|
|
7
|
+
width : 100%;
|
|
8
|
+
min-height : 30px;
|
|
9
|
+
margin : 0;
|
|
10
|
+
box-sizing : border-box;
|
|
11
|
+
padding : 3px 4px;
|
|
12
|
+
|
|
13
|
+
&>li {
|
|
14
|
+
list-style: none;
|
|
15
|
+
float : left;
|
|
16
|
+
cursor : pointer;
|
|
17
|
+
|
|
18
|
+
&>i {
|
|
19
|
+
border : 1px solid transparent;
|
|
20
|
+
min-width : 25px;
|
|
21
|
+
height : 20px;
|
|
22
|
+
line-height: 20px;
|
|
23
|
+
text-align : center;
|
|
24
|
+
display : block;
|
|
25
|
+
|
|
26
|
+
&.text-icon{
|
|
27
|
+
font-family:Times New Roman;font-weight: bold;font-style: normal;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&.fontAwesome{
|
|
31
|
+
padding-top: 2px;
|
|
32
|
+
font : normal normal normal 18px/1 FontAwesome;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&:hover {
|
|
36
|
+
border-right-color : #aaa;
|
|
37
|
+
border-bottom-color: #aaa;
|
|
38
|
+
border-top-color : #fff;
|
|
39
|
+
border-left-color : #fff;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&:active {
|
|
43
|
+
border-right-color : #f3f8fc;
|
|
44
|
+
border-bottom-color: #f3f8fc;
|
|
45
|
+
border-top-color : #ccc;
|
|
46
|
+
border-left-color : #ccc;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
ul li {
|
|
51
|
+
padding: 3px;
|
|
52
|
+
cursor : pointer;
|
|
53
|
+
|
|
54
|
+
&:hover {
|
|
55
|
+
background-color: lightgray;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.cleanHTML {
|
|
60
|
+
background-size: 16px 16px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.noBg {
|
|
64
|
+
background-image: none;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.editorBody {
|
|
70
|
+
iframe,
|
|
71
|
+
textarea {
|
|
72
|
+
border : 1px solid #C5C5C5;
|
|
73
|
+
border-radius : 0 0 4px 4px;
|
|
74
|
+
border-top-width: 0;
|
|
75
|
+
box-sizing : border-box;
|
|
76
|
+
background-color: white;
|
|
77
|
+
min-height : 300px;
|
|
78
|
+
width : 100%;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
iframe.hide{
|
|
82
|
+
display: none;
|
|
83
|
+
}
|
|
84
|
+
textarea {
|
|
85
|
+
resize: none;
|
|
86
|
+
display: none;
|
|
87
|
+
&.show{
|
|
88
|
+
display: block;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.colorPicker {
|
|
94
|
+
width : 210px;
|
|
95
|
+
border : 1px solid #D3D3D3;
|
|
96
|
+
position: absolute;
|
|
97
|
+
|
|
98
|
+
table {
|
|
99
|
+
border-collapse: collapse;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.colorhead {
|
|
103
|
+
height : 23px;
|
|
104
|
+
line-height: 23px;
|
|
105
|
+
font-weight: bold;
|
|
106
|
+
width : 100%;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.colortitle {
|
|
110
|
+
margin-left: 6px;
|
|
111
|
+
font-size : 12px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.colorpanel td {
|
|
115
|
+
border : 1px solid #000;
|
|
116
|
+
height : 10px;
|
|
117
|
+
width : 10px;
|
|
118
|
+
overflow : hidden;
|
|
119
|
+
font-size: 1px;
|
|
120
|
+
cursor : pointer;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 字体演示
|
|
125
|
+
.fontfamilyChoser,
|
|
126
|
+
.fontsizeChoser {
|
|
127
|
+
a {
|
|
128
|
+
padding-right : 2px;
|
|
129
|
+
display : block;
|
|
130
|
+
padding-left : 2px;
|
|
131
|
+
padding-bottom : 2px;
|
|
132
|
+
color : #000;
|
|
133
|
+
line-height : 120%;
|
|
134
|
+
padding-top : 2px;
|
|
135
|
+
text-decoration: none;
|
|
136
|
+
|
|
137
|
+
&:hover {
|
|
138
|
+
background: #e5e5e5
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 登录面板 和忘记密码
|
|
144
|
+
.dorpdown {
|
|
145
|
+
position: relative;
|
|
146
|
+
|
|
147
|
+
&:hover .fontfamilyChoser,
|
|
148
|
+
.fontfamilyChoser:hover,
|
|
149
|
+
&:hover .fontsizeChoser,
|
|
150
|
+
.fontsizeChoser:hover,
|
|
151
|
+
&:hover .colorPicker,
|
|
152
|
+
.colorPicker:hover {
|
|
153
|
+
display: block;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
&>div {
|
|
157
|
+
display : none;
|
|
158
|
+
position : absolute;
|
|
159
|
+
top : 22px;
|
|
160
|
+
left : 0;
|
|
161
|
+
background-color: #f5f5f5;
|
|
162
|
+
border : 1px solid lightgray;
|
|
163
|
+
border-top : 0;
|
|
164
|
+
padding : 5px;
|
|
165
|
+
width : 230px;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.fontsizeChoser {
|
|
169
|
+
top : inherit;
|
|
170
|
+
right: 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}.aj-form-html-editor {
|
|
174
|
+
ul.toolbar {
|
|
175
|
+
border : 1px solid #C5C5C5;
|
|
176
|
+
border-radius : 4px 4px 0 0;
|
|
177
|
+
border-bottom : 0;
|
|
178
|
+
background-color: #E8E7E4;
|
|
179
|
+
width : 100%;
|
|
180
|
+
min-height : 30px;
|
|
181
|
+
margin : 0;
|
|
182
|
+
box-sizing : border-box;
|
|
183
|
+
padding : 3px 4px;
|
|
184
|
+
|
|
185
|
+
&>li {
|
|
186
|
+
list-style: none;
|
|
187
|
+
float : left;
|
|
188
|
+
cursor : pointer;
|
|
189
|
+
|
|
190
|
+
&>i {
|
|
191
|
+
border : 1px solid transparent;
|
|
192
|
+
min-width : 25px;
|
|
193
|
+
height : 20px;
|
|
194
|
+
line-height: 20px;
|
|
195
|
+
text-align : center;
|
|
196
|
+
display : block;
|
|
197
|
+
|
|
198
|
+
&.text-icon{
|
|
199
|
+
font-family:Times New Roman;font-weight: bold;font-style: normal;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
&.fontAwesome{
|
|
203
|
+
padding-top: 2px;
|
|
204
|
+
font : normal normal normal 18px/1 FontAwesome;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
&:hover {
|
|
208
|
+
border-right-color : #aaa;
|
|
209
|
+
border-bottom-color: #aaa;
|
|
210
|
+
border-top-color : #fff;
|
|
211
|
+
border-left-color : #fff;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
&:active {
|
|
215
|
+
border-right-color : #f3f8fc;
|
|
216
|
+
border-bottom-color: #f3f8fc;
|
|
217
|
+
border-top-color : #ccc;
|
|
218
|
+
border-left-color : #ccc;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
ul li {
|
|
223
|
+
padding: 3px;
|
|
224
|
+
cursor : pointer;
|
|
225
|
+
|
|
226
|
+
&:hover {
|
|
227
|
+
background-color: lightgray;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.cleanHTML {
|
|
232
|
+
background-size: 16px 16px;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.noBg {
|
|
236
|
+
background-image: none;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.editorBody {
|
|
242
|
+
iframe,
|
|
243
|
+
textarea {
|
|
244
|
+
border : 1px solid #C5C5C5;
|
|
245
|
+
border-radius : 0 0 4px 4px;
|
|
246
|
+
border-top-width: 0;
|
|
247
|
+
box-sizing : border-box;
|
|
248
|
+
background-color: white;
|
|
249
|
+
min-height : 300px;
|
|
250
|
+
width : 100%;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
iframe.hide{
|
|
254
|
+
display: none;
|
|
255
|
+
}
|
|
256
|
+
textarea {
|
|
257
|
+
resize: none;
|
|
258
|
+
display: none;
|
|
259
|
+
&.show{
|
|
260
|
+
display: block;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
.colorPicker {
|
|
266
|
+
width : 210px;
|
|
267
|
+
border : 1px solid #D3D3D3;
|
|
268
|
+
position: absolute;
|
|
269
|
+
|
|
270
|
+
table {
|
|
271
|
+
border-collapse: collapse;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.colorhead {
|
|
275
|
+
height : 23px;
|
|
276
|
+
line-height: 23px;
|
|
277
|
+
font-weight: bold;
|
|
278
|
+
width : 100%;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.colortitle {
|
|
282
|
+
margin-left: 6px;
|
|
283
|
+
font-size : 12px;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.colorpanel td {
|
|
287
|
+
border : 1px solid #000;
|
|
288
|
+
height : 10px;
|
|
289
|
+
width : 10px;
|
|
290
|
+
overflow : hidden;
|
|
291
|
+
font-size: 1px;
|
|
292
|
+
cursor : pointer;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// 字体演示
|
|
297
|
+
.fontfamilyChoser,
|
|
298
|
+
.fontsizeChoser {
|
|
299
|
+
a {
|
|
300
|
+
padding-right : 2px;
|
|
301
|
+
display : block;
|
|
302
|
+
padding-left : 2px;
|
|
303
|
+
padding-bottom : 2px;
|
|
304
|
+
color : #000;
|
|
305
|
+
line-height : 120%;
|
|
306
|
+
padding-top : 2px;
|
|
307
|
+
text-decoration: none;
|
|
308
|
+
|
|
309
|
+
&:hover {
|
|
310
|
+
background: #e5e5e5
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// 登录面板 和忘记密码
|
|
316
|
+
.dorpdown {
|
|
317
|
+
position: relative;
|
|
318
|
+
|
|
319
|
+
&:hover .fontfamilyChoser,
|
|
320
|
+
.fontfamilyChoser:hover,
|
|
321
|
+
&:hover .fontsizeChoser,
|
|
322
|
+
.fontsizeChoser:hover,
|
|
323
|
+
&:hover .colorPicker,
|
|
324
|
+
.colorPicker:hover {
|
|
325
|
+
display: block;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
&>div {
|
|
329
|
+
display : none;
|
|
330
|
+
position : absolute;
|
|
331
|
+
top : 22px;
|
|
332
|
+
left : 0;
|
|
333
|
+
background-color: #f5f5f5;
|
|
334
|
+
border : 1px solid lightgray;
|
|
335
|
+
border-top : 0;
|
|
336
|
+
padding : 5px;
|
|
337
|
+
width : 230px;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.fontsizeChoser {
|
|
341
|
+
top : inherit;
|
|
342
|
+
right: 0;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
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;
|
|
339
|
+
}
|