@ajaxjs/ui 1.1.9 → 1.2.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/package.json +3 -3
- package/src/App.vue +14 -0
- package/src/index.ts +50 -0
- package/src/main.ts +12 -0
- package/src/pages/calendar.vue +33 -0
- package/src/pages/form.vue +68 -0
- package/src/pages/html-editor.vue +44 -0
- package/src/pages/index.vue +150 -0
- package/src/pages/play-ground.vue +14 -0
- package/src/pages/widgets.vue +183 -0
- package/src/router/index.ts +19 -0
- package/src/shims-vue.d.ts +4 -0
- package/src/style/common-functions.less +294 -0
- package/src/style/reset.less +19 -0
- package/src/util/cookies.ts +43 -0
- package/src/util/dom.ts +47 -0
- package/src/util/utils.ts +184 -0
- package/src/util/xhr-config.ts +25 -0
- package/src/util/xhr.ts +296 -0
- package/src/widget/AccordionMenu.vue +140 -0
- package/src/widget/AdjustFontSize.vue +65 -0
- package/src/widget/Article.vue +59 -0
- package/src/widget/EmptyContent.js +4 -0
- package/src/widget/Expander.vue +65 -0
- package/src/widget/FileUploader/FileUploader.less +68 -0
- package/src/widget/FileUploader/FileUploader.ts +156 -0
- package/src/widget/FileUploader/FileUploader.vue +43 -0
- package/src/widget/HtmlEditor/HtmlEditor.less +345 -0
- package/src/widget/HtmlEditor/HtmlEditor.ts +339 -0
- package/src/widget/HtmlEditor/HtmlEditor.vue +70 -0
- package/src/widget/HtmlEditor/html-editor-HtmlSanitizer.js +103 -0
- package/src/widget/ImageEnlarger.vue +105 -0
- package/src/widget/OpacityBanner.vue +125 -0
- package/src/widget/ProcessLine.vue +133 -0
- package/src/widget/Resize.ts +152 -0
- package/src/widget/Resize.vue +104 -0
- package/src/widget/TreeSelector.vue +4 -0
- package/src/widget/calendar/BetweenDate.vue +63 -0
- package/src/widget/calendar/Calendar.less +210 -0
- package/src/widget/calendar/Calendar.ts +167 -0
- package/src/widget/calendar/Calendar.vue +52 -0
- package/src/widget/calendar/CalendarInput.vue +71 -0
- package/src/widget/form/validator.ts +289 -0
- package/src/widget/play-ground/sku.vue +93 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--admin-main-color: #1e6bb8;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.aj-center-title () {
|
|
6
|
+
text-align : center;
|
|
7
|
+
font-size : 1.3rem;
|
|
8
|
+
font-weight : bold;
|
|
9
|
+
letter-spacing: 5px;
|
|
10
|
+
padding : 20px 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.aj-text-function() {
|
|
14
|
+
color : #333;
|
|
15
|
+
line-height : 160%;
|
|
16
|
+
margin : 15px 0;
|
|
17
|
+
font-size : .95rem;
|
|
18
|
+
letter-spacing: 1px;
|
|
19
|
+
text-align : justify;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.centerBody (@defaultWidth: 1300px) {
|
|
23
|
+
max-width: @defaultWidth;
|
|
24
|
+
margin : 0 auto;
|
|
25
|
+
width : 100%;
|
|
26
|
+
height : 100%;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.transition (@t) {
|
|
30
|
+
-webkit-transition: @t;
|
|
31
|
+
-moz-transition : @t;
|
|
32
|
+
-ms-transition : @t;
|
|
33
|
+
-o-transition : @t;
|
|
34
|
+
transition : @t;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.transition_withTransform (@t) {
|
|
38
|
+
-webkit-transition: -webkit-transform @t;
|
|
39
|
+
-moz-transition : -moz-transform @t;
|
|
40
|
+
-ms-transition : -moz-transform @t;
|
|
41
|
+
-o-transition : -o-transform @t;
|
|
42
|
+
transition : transform @t;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.transform (@t) {
|
|
46
|
+
-webkit-transform: @t;
|
|
47
|
+
-moz-transform : @t;
|
|
48
|
+
-ms-transform : @t;
|
|
49
|
+
-o-transform : @t;
|
|
50
|
+
-transform : @t;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.heightFx () {
|
|
54
|
+
.transition (300ms height ease-out);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.widthFx () {
|
|
58
|
+
.transition (200ms width ease-out);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.leftFx () {
|
|
62
|
+
.transition (200ms left linear);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 解决使用CSS动画时闪烁的问题
|
|
66
|
+
// http://ued.taobao.com/blog/2012/01/chrome%E6%B8%B2%E6%9F%93transition%E6%97%B6%E9%A1%B5%E9%9D%A2%E9%97%AA%E5%8A%A8bug/
|
|
67
|
+
.fixTransitionFlash () {
|
|
68
|
+
backface-visibility : hidden;
|
|
69
|
+
-webkit-backface-visibility: hidden;
|
|
70
|
+
-moz-backface-visibility : hidden;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 解决高度塌陷的问题 – 清除浮动 或叫 闭合浮动
|
|
74
|
+
// http://www.iyunlu.com/view/css-xhtml/55.html
|
|
75
|
+
// http://www.zhangxinxu.com/wordpress/2010/01/css-float%E6%B5%AE%E5%8A%A8%E7%9A%84%E6%B7%B1%E5%85%A5%E7%A0%94%E7%A9%B6%E3%80%81%E8%AF%A6%E8%A7%A3%E5%8F%8A%E6%8B%93%E5%B1%95%E4%BA%8C/
|
|
76
|
+
// 强制换行
|
|
77
|
+
.forceBreak () {
|
|
78
|
+
word-wrap : break-word;
|
|
79
|
+
word-break: break-all;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.giveHeight () {
|
|
83
|
+
overflow: hidden;
|
|
84
|
+
zoom : 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 透明度
|
|
88
|
+
.imgOpacityShow (@time: 300ms) {
|
|
89
|
+
.transition (opacity @time ease-in);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 旋转角度
|
|
93
|
+
.rotate (@ro: 30deg) {
|
|
94
|
+
.transform (rotate(@ro));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 渐变
|
|
98
|
+
.gradient (@direction , @startColor , @endColor) {
|
|
99
|
+
background-image: -webkit-linear-gradient(@direction, @startColor, @endColor);
|
|
100
|
+
background-image: -moz-linear-gradient(@direction, @startColor, @endColor);
|
|
101
|
+
background-image: -ms-linear-gradient(@direction, @startColor, @endColor);
|
|
102
|
+
background-image: -o-linear-gradient(@direction, @startColor, @endColor);
|
|
103
|
+
background-image: linear-gradient(@direction, @startColor, @endColor);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 渐变
|
|
107
|
+
.gradient (@direction , @startColor , @midColor , @endColor) {
|
|
108
|
+
background-image: -webkit-linear-gradient(@direction, @startColor, @midColor, @endColor);
|
|
109
|
+
background-image: -moz-linear-gradient(@direction, @startColor, @midColor, @endColor);
|
|
110
|
+
background-image: -ms-linear-gradient(@direction, @startColor, @midColor, @endColor);
|
|
111
|
+
background-image: -o-linear-gradient(@direction, @startColor, @midColor, @endColor);
|
|
112
|
+
background-image: linear-gradient(@direction, @startColor, @midColor, @endColor);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.fadeIn (@duration) {
|
|
116
|
+
animation : fade-in;
|
|
117
|
+
animation-duration: @duration;
|
|
118
|
+
-webkit-animation : fade-in @duration;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.fadeOut (@duration) {
|
|
122
|
+
animation : fade-out-hide;
|
|
123
|
+
animation-duration: @duration;
|
|
124
|
+
-webkit-animation : fade-out-hide @duration;
|
|
125
|
+
}
|
|
126
|
+
.aj-text-title {
|
|
127
|
+
letter-spacing: 2px;
|
|
128
|
+
margin: 10px;
|
|
129
|
+
}
|
|
130
|
+
.aj-text-function() {
|
|
131
|
+
color : #333;
|
|
132
|
+
line-height : 160%;
|
|
133
|
+
margin : 15px 0;
|
|
134
|
+
font-size : .95rem;
|
|
135
|
+
letter-spacing: 1px;
|
|
136
|
+
text-align : justify;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 快速制作1px 表格边框,为需要设置的 table 元素加上 border 的class即可
|
|
140
|
+
.aj-table {
|
|
141
|
+
border : 1px lightgray solid;
|
|
142
|
+
border-collapse: collapse;
|
|
143
|
+
border-spacing : 0;
|
|
144
|
+
|
|
145
|
+
th {
|
|
146
|
+
background-color: #efefef;
|
|
147
|
+
letter-spacing : 3px;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
td,
|
|
151
|
+
th {
|
|
152
|
+
border : 1px lightgray solid;
|
|
153
|
+
line-height: 160%;
|
|
154
|
+
height : 120%;
|
|
155
|
+
padding : 6px;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
tr {
|
|
159
|
+
.transition (background-color 400ms ease-out);
|
|
160
|
+
|
|
161
|
+
&:nth-child(odd) {
|
|
162
|
+
background: #f5f5f5;
|
|
163
|
+
box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
&:hover {
|
|
167
|
+
background-color: #fbf8e9;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.aj-form-table {
|
|
174
|
+
border-collapse: collapse;
|
|
175
|
+
border-spacing : 0;
|
|
176
|
+
|
|
177
|
+
th {
|
|
178
|
+
background-color: #efefef;
|
|
179
|
+
letter-spacing : 3px;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
td,
|
|
183
|
+
th {
|
|
184
|
+
line-height: 160%;
|
|
185
|
+
height : 120%;
|
|
186
|
+
padding : 10px 15px;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
tr {
|
|
190
|
+
.transition (background-color 400ms ease-out);
|
|
191
|
+
|
|
192
|
+
&:nth-child(odd) {
|
|
193
|
+
background: #f5f5f5;
|
|
194
|
+
box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
&:hover {
|
|
198
|
+
background-color: #fbf8e9;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.aj-btn-base() {
|
|
204
|
+
min-height : 26px;
|
|
205
|
+
font-size : .8rem;
|
|
206
|
+
//line-height: 100%;
|
|
207
|
+
padding : .3em 2.3em;
|
|
208
|
+
margin : 10px auto;
|
|
209
|
+
color : #333;
|
|
210
|
+
letter-spacing : .3em;
|
|
211
|
+
border-radius : 4px;
|
|
212
|
+
border : 1px solid #ccc;
|
|
213
|
+
border-bottom-color: #B4B4B4;
|
|
214
|
+
box-shadow : 0 1px 3px rgba(0, 0, 0, 0.12);
|
|
215
|
+
text-shadow : 0 1px 0 rgba(255, 255, 255, 0.8);
|
|
216
|
+
background-color : lightgray;
|
|
217
|
+
background-repeat : repeat-x;
|
|
218
|
+
transition : background-image 0.5s linear 1s;
|
|
219
|
+
cursor : pointer;
|
|
220
|
+
outline : 0;
|
|
221
|
+
.gradient (to bottom, rgba(255, 255, 255, 1) 0%, rgba(239, 239, 239, 1) 60%, rgba(225, 223, 226, 1) 100%);
|
|
222
|
+
|
|
223
|
+
img {
|
|
224
|
+
vertical-align: middle;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
&:hover {
|
|
228
|
+
color : black;
|
|
229
|
+
border-color: lighten(black, 65%);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
&:active {
|
|
233
|
+
box-shadow : inset 0 3px 5px rgba(0, 0, 0, .2);
|
|
234
|
+
border-color: lighten(black, 55%);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
&:focus {
|
|
238
|
+
border-color: lighten(black, 60%);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
&:hover {
|
|
242
|
+
background-position: 0px -10px;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.aj-btnsHolder {
|
|
247
|
+
text-align: center;
|
|
248
|
+
padding : 2% 0;
|
|
249
|
+
|
|
250
|
+
button {
|
|
251
|
+
margin-right: 3% !important;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.aj-input-base() {
|
|
256
|
+
min-height : 25px;
|
|
257
|
+
font-size : .9rem;
|
|
258
|
+
border : 1px solid #abadb3;
|
|
259
|
+
// border-radius : 3px;
|
|
260
|
+
box-sizing : border-box;
|
|
261
|
+
background-color: white;
|
|
262
|
+
transition : border-color ease-in-out 200ms;
|
|
263
|
+
outline : 0;
|
|
264
|
+
padding : 2px;
|
|
265
|
+
vertical-align : middle;
|
|
266
|
+
color : #333;
|
|
267
|
+
// letter-spacing : 1px;
|
|
268
|
+
|
|
269
|
+
&:hover,
|
|
270
|
+
&:focus {
|
|
271
|
+
// box-shadow : 1px 2px 3px #e5e5e5 inset;
|
|
272
|
+
border-color: lighten(black, 45);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
form.aj-form {
|
|
277
|
+
input[type=text], .form input[type=password], .form textarea{
|
|
278
|
+
.aj-input-base();
|
|
279
|
+
}
|
|
280
|
+
button {
|
|
281
|
+
.aj-btn-base();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
select {
|
|
285
|
+
color: gray;
|
|
286
|
+
height: 25px;
|
|
287
|
+
border: 1px solid gray;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
select:hover {
|
|
291
|
+
border-color: black;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* AJAXJS Base CSS */
|
|
2
|
+
body,dl,dt,dd,ul,li,pre,form,fieldset,input,p,blockquote,th,td,h1,h2,h3,h4,h5{margin:0;padding:0;}
|
|
3
|
+
h1,h2,h3,h4,h5{font-weight: normal;}img{border:0;}ul li{list-style-type:none}.hide{display:none}
|
|
4
|
+
body {-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing: grayscale;
|
|
5
|
+
font-family: "Lantinghei SC", "Open Sans", Arial, "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", "STHeiti", "WenQuanYi Micro Hei", SimSun, sans-serif;}
|
|
6
|
+
|
|
7
|
+
/* a{text-decoration:none;color:#666;transition:color .4s ease-in-out;}
|
|
8
|
+
a:hover{color:#000;}
|
|
9
|
+
button{border:none;outline:0;cursor:pointer;letter-spacing:2px;text-align:center;-webkit-user-select:none;-moz-user-select:none;user-select:none}
|
|
10
|
+
input[type=password],input[type=text],select,textarea{outline:0;-moz-appearance:none;} */
|
|
11
|
+
|
|
12
|
+
/* 手机端浏览器所显示的网页 CSS */
|
|
13
|
+
@media screen and (max-width:480px) {
|
|
14
|
+
* {
|
|
15
|
+
-webkit-tap-highlight-color: transparent; /* 很多 Android 浏览器的 a 链接有边框,这里取消它 */
|
|
16
|
+
-webkit-touch-callout: none; /* 在 iOS 浏览器里面,假如用户长按 a 标签,都会出现默认的弹出菜单事件 */
|
|
17
|
+
/* -webkit-user-select:none; */
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取某个 Cookie
|
|
3
|
+
*
|
|
4
|
+
* @param name 键名称
|
|
5
|
+
* @returns 值
|
|
6
|
+
*/
|
|
7
|
+
export function getCookie(name: string): string | null {
|
|
8
|
+
let arr: RegExpMatchArray, reg: RegExp = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
|
|
9
|
+
|
|
10
|
+
if (arr = document.cookie.match(reg))
|
|
11
|
+
return unescape(arr[2]);
|
|
12
|
+
else
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 设置某个 Cookie
|
|
18
|
+
*
|
|
19
|
+
* @param name 键名称
|
|
20
|
+
* @param value 值
|
|
21
|
+
*/
|
|
22
|
+
export function setCookie(name: string, value: string): void {
|
|
23
|
+
let days: number = 2, exp: Date = new Date();
|
|
24
|
+
exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 清空 Cookie
|
|
31
|
+
*/
|
|
32
|
+
export function delCookie(): void {
|
|
33
|
+
let keys = document.cookie.match(/[^ =;]+(?==)/g);
|
|
34
|
+
|
|
35
|
+
if (keys) {
|
|
36
|
+
let date: string = new Date(0).toUTCString();
|
|
37
|
+
for (let i = keys.length; i--;) {
|
|
38
|
+
document.cookie = keys[i] + '=0;path=/;expires=' + date; // 清除当前域名下的,例如:m.ratingdog.cn
|
|
39
|
+
document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + date; // 清除当前域名下的,例如 .m.ratingdog.cn
|
|
40
|
+
document.cookie = keys[i] + '=0;path=/;domain=' + location.host + ';expires=' + date; // 清除一级域名下的或指定的,例如 .ratingdog.cn
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/util/dom.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 向父级元素递归搜索
|
|
3
|
+
*
|
|
4
|
+
* @param _el 当前所在元素
|
|
5
|
+
* @param tagName 目标标签名称
|
|
6
|
+
* @param className 目标元素样式类
|
|
7
|
+
* @returns 目标元素,找不到为 null
|
|
8
|
+
*/
|
|
9
|
+
export function up(_el: Element, tagName: string, className: string): Element | null {
|
|
10
|
+
if (tagName && className)
|
|
11
|
+
throw '只能任选一种参数,不能同时传';
|
|
12
|
+
|
|
13
|
+
let el: Element = _el.parentNode as Element;
|
|
14
|
+
tagName = tagName && tagName.toUpperCase();
|
|
15
|
+
|
|
16
|
+
while (el) {
|
|
17
|
+
if (tagName && el.tagName == tagName)
|
|
18
|
+
return el;
|
|
19
|
+
|
|
20
|
+
if (className && el.className && ~el.className.indexOf(className))
|
|
21
|
+
return el;
|
|
22
|
+
|
|
23
|
+
el = <Element>el.parentNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 加载脚本
|
|
31
|
+
*
|
|
32
|
+
* @param url 脚本地址
|
|
33
|
+
* @param id 脚本元素 id,可选的
|
|
34
|
+
* @param cb 回调函数,可选的
|
|
35
|
+
*/
|
|
36
|
+
export function loadScript(url: string, id?: string, cb?: (ev: Event) => any): void {
|
|
37
|
+
let script: HTMLScriptElement = document.createElement("script");
|
|
38
|
+
script.src = url;
|
|
39
|
+
|
|
40
|
+
if (cb)
|
|
41
|
+
script.onload = cb;
|
|
42
|
+
|
|
43
|
+
if (id)
|
|
44
|
+
script.id = id;
|
|
45
|
+
|
|
46
|
+
document.getElementsByTagName("head")[0].appendChild(script);
|
|
47
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用工具类
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const env = process.env.NODE_ENV;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 是否调试模式中
|
|
9
|
+
*
|
|
10
|
+
* 打包成组件之后不能用
|
|
11
|
+
*
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export function isDebug(): boolean {
|
|
15
|
+
return env === 'development';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isDev(): boolean {
|
|
19
|
+
let currentHostname: string = window.location.hostname;
|
|
20
|
+
|
|
21
|
+
// 判断主机名是否是内网地址
|
|
22
|
+
return (currentHostname.startsWith('192.168.') || currentHostname.startsWith('10.') || currentHostname === 'localhost');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 日期格式化。详见博客文章:http://blog.csdn.net/zhangxin09/archive/2011/01/01/6111294.aspx
|
|
27
|
+
* e.g: new Date().format("yyyy-MM-dd hh:mm:ss")
|
|
28
|
+
*
|
|
29
|
+
* @param {String} format
|
|
30
|
+
* @return {String}
|
|
31
|
+
*/
|
|
32
|
+
export function dateFormat(this: Date, format: string): string {
|
|
33
|
+
let $1, o: any = {
|
|
34
|
+
"M+": this.getMonth() + 1, // 月份,从0开始算
|
|
35
|
+
"d+": this.getDate(), // 日期
|
|
36
|
+
"h+": this.getHours(), // 小时
|
|
37
|
+
"m+": this.getMinutes(), // 分钟
|
|
38
|
+
"s+": this.getSeconds(), // 秒钟
|
|
39
|
+
// 季度 quarter
|
|
40
|
+
"q+": Math.floor((this.getMonth() + 3) / 3),
|
|
41
|
+
"S": this.getMilliseconds() // 千秒
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (/(y+)/.test(format)) {
|
|
45
|
+
$1 = RegExp.$1, format = format.replace($1, String(this.getFullYear()).substr(4 - $1));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let key: string, value: string;
|
|
49
|
+
for (key in o) { // 如果没有指定该参数,则子字符串将延续到 stringvar 的最后。
|
|
50
|
+
if (new RegExp("(" + key + ")").test(format)) {
|
|
51
|
+
$1 = RegExp.$1,
|
|
52
|
+
value = String(o[key]),
|
|
53
|
+
value = $1.length == 1 ? value : ("00" + value).substr(value.length),
|
|
54
|
+
format = format.replace($1, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return format;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 日期格式化
|
|
63
|
+
* @author meizz
|
|
64
|
+
* @param date 日期,必须为 Date 类型
|
|
65
|
+
* @param fmt 格式模板
|
|
66
|
+
* @returns 格式化后的字符串
|
|
67
|
+
*/
|
|
68
|
+
export function dateFormat2(date: Date, fmt: string): string {
|
|
69
|
+
let o: { [key: string]: number } = {
|
|
70
|
+
"M+": date.getMonth() + 1, // 月份
|
|
71
|
+
"d+": date.getDate(), // 日
|
|
72
|
+
"h+": date.getHours(), // 小时
|
|
73
|
+
"m+": date.getMinutes(), // 分
|
|
74
|
+
"s+": date.getSeconds(), // 秒
|
|
75
|
+
"q+": Math.floor((date.getMonth() + 3) / 3),// 季度
|
|
76
|
+
"S": date.getMilliseconds() // 毫秒
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
if (/(y+)/.test(fmt))
|
|
80
|
+
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
81
|
+
|
|
82
|
+
for (var k in o)
|
|
83
|
+
if (new RegExp("(" + k + ")").test(fmt)) {
|
|
84
|
+
let obj = (RegExp.$1.length == 1) ? o[k] : ("00" + o[k]).substr(("" + o[k]).length);
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
fmt = fmt.replace(RegExp.$1, obj);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return fmt;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 并行和串行任务
|
|
94
|
+
*
|
|
95
|
+
* @author https://segmentfault.com/a/1190000013265925
|
|
96
|
+
* @param arr
|
|
97
|
+
* @param finnaly
|
|
98
|
+
*/
|
|
99
|
+
export function parallel(arr: [], _finally: Function) {
|
|
100
|
+
let fn: Function, index: number = 0;
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
let statusArr = Array(arr.length).fill().map(() => ({ isActive: false, data: null }));
|
|
103
|
+
|
|
104
|
+
let isFinished = function () {
|
|
105
|
+
return statusArr.every((item: any) => item.isActive === true);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let resolve = function (index: number): Function {
|
|
109
|
+
return function (data: any) {
|
|
110
|
+
statusArr[index].data = data;
|
|
111
|
+
statusArr[index].isActive = true;
|
|
112
|
+
let isFinish = isFinished();
|
|
113
|
+
|
|
114
|
+
if (isFinish) {
|
|
115
|
+
let datas = statusArr.map((item: any) => item.data);
|
|
116
|
+
|
|
117
|
+
_finally(datas);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
while ((fn = arr.shift())) {
|
|
124
|
+
fn(resolve(index));// 给 resolve 函数追加参数,可以使用 bind 函数实现,这里使用了柯里化
|
|
125
|
+
index++;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 函数节流
|
|
131
|
+
*
|
|
132
|
+
* @author https://www.cnblogs.com/moqiutao/p/6875955.html
|
|
133
|
+
* @param fn
|
|
134
|
+
* @param delay
|
|
135
|
+
* @param mustRunDelay
|
|
136
|
+
*/
|
|
137
|
+
export function throttle(fn: Function, delay: number, mustRunDelay: number): Function {
|
|
138
|
+
var timer: number, t_start: number;
|
|
139
|
+
|
|
140
|
+
return function () {
|
|
141
|
+
var t_curr = +new Date();
|
|
142
|
+
window.clearTimeout(timer);
|
|
143
|
+
|
|
144
|
+
if (!t_start)
|
|
145
|
+
t_start = t_curr;
|
|
146
|
+
|
|
147
|
+
if (t_curr - t_start >= mustRunDelay) {
|
|
148
|
+
// @ts-ignore
|
|
149
|
+
fn.apply(this, arguments);
|
|
150
|
+
t_start = t_curr;
|
|
151
|
+
} else {
|
|
152
|
+
var args = arguments;
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
timer = window.setTimeout(() => fn.apply(this, args), delay);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 复制文字到剪切板
|
|
161
|
+
*
|
|
162
|
+
* @param {*} text
|
|
163
|
+
*/
|
|
164
|
+
export function copyToClipboard(text) {
|
|
165
|
+
if (navigator.clipboard) {
|
|
166
|
+
// clipboard api 复制
|
|
167
|
+
navigator.clipboard.writeText(text);
|
|
168
|
+
} else {
|
|
169
|
+
let textarea = document.createElement('textarea');
|
|
170
|
+
document.body.appendChild(textarea);
|
|
171
|
+
// 隐藏此输入框
|
|
172
|
+
textarea.style.position = 'fixed';
|
|
173
|
+
textarea.style.clip = 'rect(0 0 0 0)';
|
|
174
|
+
textarea.style.top = '10px';
|
|
175
|
+
// 赋值
|
|
176
|
+
textarea.value = text;
|
|
177
|
+
// 选中
|
|
178
|
+
textarea.select();
|
|
179
|
+
// 复制
|
|
180
|
+
document.execCommand('copy', true);
|
|
181
|
+
// 移除输入框
|
|
182
|
+
document.body.removeChild(textarea);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XHR 请求配置
|
|
3
|
+
*/
|
|
4
|
+
export interface XhrConfig {
|
|
5
|
+
/**
|
|
6
|
+
* 请求头里面的 Content-Type 字段
|
|
7
|
+
*/
|
|
8
|
+
contentType?: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* XHR 响应结果的类型
|
|
12
|
+
*/
|
|
13
|
+
parseContentType?: 'text' | 'xml' | 'json';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 超时时间,单位是毫秒
|
|
17
|
+
* 设为 0 适合不控制超时
|
|
18
|
+
*/
|
|
19
|
+
timeout?: number;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 是否跨域
|
|
23
|
+
*/
|
|
24
|
+
withCredentials?: boolean;
|
|
25
|
+
}
|