@ajaxjs/ui 1.1.8 → 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/dist/index.d.ts +0 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/util/utils.d.ts +7 -0
- package/dist/util/utils.js +35 -1
- package/dist/util/utils.js.map +1 -1
- 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,104 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- 拖拉缩放效果 -->
|
|
3
|
+
<div class="resize-box">
|
|
4
|
+
<div class="rRightDown" @mousedown="start($event, rightDown)"> </div>
|
|
5
|
+
<div class="rLeftDown" @mousedown="start($event, leftDown)"> </div>
|
|
6
|
+
<div class="rRightUp" @mousedown="start($event, rightUp)"> </div>
|
|
7
|
+
<div class="rLeftUp" @mousedown="start($event, leftUp)"> </div>
|
|
8
|
+
<div class="rRight" @mousedown="start($event, right)"> </div>
|
|
9
|
+
<div class="rLeft" @mousedown="start($event, left)"> </div>
|
|
10
|
+
<div class="rDown" @mousedown="start($event, down)"></div>
|
|
11
|
+
<div class="rUp" @mousedown="start($event, up)"> </div>
|
|
12
|
+
</div>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script lang="ts" src="./Resize.ts"></script>
|
|
16
|
+
|
|
17
|
+
<style lang="less" scoped>
|
|
18
|
+
.rRightDown,
|
|
19
|
+
.rLeftDown,
|
|
20
|
+
.rLeftUp,
|
|
21
|
+
.rRightUp,
|
|
22
|
+
.rRight,
|
|
23
|
+
.rLeft,
|
|
24
|
+
.rUp,
|
|
25
|
+
.rDown {
|
|
26
|
+
position: absolute;
|
|
27
|
+
background: #c00;
|
|
28
|
+
width: 7px;
|
|
29
|
+
height: 7px;
|
|
30
|
+
z-index: 5;
|
|
31
|
+
font-size: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.rLeftDown, .rRightUp {
|
|
35
|
+
cursor: ne-resize;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.rRightDown, .rLeftUp {
|
|
39
|
+
cursor: nw-resize;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.rRight, .rLeft {
|
|
43
|
+
cursor: e-resize;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.rUp, .rDown {
|
|
47
|
+
cursor: n-resize;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.rLeftDown {
|
|
51
|
+
left: -4px;
|
|
52
|
+
bottom: -4px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.rRightUp {
|
|
56
|
+
right: -4px;
|
|
57
|
+
top: -4px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.rRightDown {
|
|
61
|
+
right: -4px;
|
|
62
|
+
bottom: -4px;
|
|
63
|
+
background-color: 0f;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.rLeftUp {
|
|
67
|
+
left: -4px;
|
|
68
|
+
top: -4px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.rRight {
|
|
72
|
+
right: -4px;
|
|
73
|
+
top: 50%;
|
|
74
|
+
margin-top: -4px;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.rLeft {
|
|
78
|
+
left: -4px;
|
|
79
|
+
top: 50%;
|
|
80
|
+
margin-top: -4px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.rUp {
|
|
84
|
+
top: -4px;
|
|
85
|
+
left: 50%;
|
|
86
|
+
margin-left: -4px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.rDown {
|
|
90
|
+
bottom: -4px;
|
|
91
|
+
left: 50%;
|
|
92
|
+
margin-left: -4px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.resize-box {
|
|
96
|
+
border: 1px solid gray;
|
|
97
|
+
width: 100px;
|
|
98
|
+
height: 60px;
|
|
99
|
+
top: 150px;
|
|
100
|
+
left: 550px;
|
|
101
|
+
background: #fff;
|
|
102
|
+
position: absolute;
|
|
103
|
+
}
|
|
104
|
+
</style>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<form action="." method="GET" class="dateRange" @submit="valid">
|
|
3
|
+
<aj-form-calendar-input
|
|
4
|
+
:date-only="true"
|
|
5
|
+
:position-fixed="true"
|
|
6
|
+
placeholder="起始时间"
|
|
7
|
+
field-name="startDate"
|
|
8
|
+
></aj-form-calendar-input>
|
|
9
|
+
-
|
|
10
|
+
<aj-form-calendar-input
|
|
11
|
+
:date-only="true"
|
|
12
|
+
:position-fixed="true"
|
|
13
|
+
placeholder="截至时间"
|
|
14
|
+
field-name="endDate"
|
|
15
|
+
></aj-form-calendar-input>
|
|
16
|
+
<button class="aj-btn">按时间筛选</button>
|
|
17
|
+
</form>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
/**
|
|
22
|
+
* 起始时间、截止时间的范围选择
|
|
23
|
+
*/
|
|
24
|
+
export default {
|
|
25
|
+
props: {
|
|
26
|
+
isAjax: { type: Boolean, default: true }, // 是否 AJAX 模式
|
|
27
|
+
},
|
|
28
|
+
methods: {
|
|
29
|
+
valid(this: Vue, ev: Event): void {
|
|
30
|
+
let start = (<HTMLInputElement>(
|
|
31
|
+
this.$el.querySelector("input[name=startDate]")
|
|
32
|
+
)).value,
|
|
33
|
+
end = (<HTMLInputElement>this.$el.querySelector("input[name=endDate]"))
|
|
34
|
+
.value;
|
|
35
|
+
|
|
36
|
+
if (!start || !end) {
|
|
37
|
+
alert("输入数据不能为空");
|
|
38
|
+
ev.preventDefault();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (new Date(start) > new Date(end)) {
|
|
43
|
+
alert("起始日期不能晚于结束日期");
|
|
44
|
+
ev.preventDefault();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//@ts-ignore
|
|
49
|
+
if (this.isAjax) {
|
|
50
|
+
ev.preventDefault();
|
|
51
|
+
let grid: any = this.$parent.$parent;
|
|
52
|
+
|
|
53
|
+
Object.assign(grid.$refs.pager.extraParam, {
|
|
54
|
+
startDate: start,
|
|
55
|
+
endDate: end,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
grid.reload();
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
</script>
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// 日历选择器
|
|
2
|
+
.aj-form-calendar {
|
|
3
|
+
font-family : Verdana;
|
|
4
|
+
font-size : .8rem;
|
|
5
|
+
background-color : white;
|
|
6
|
+
border : 1px solid lightgray;
|
|
7
|
+
border-radius : 5px;
|
|
8
|
+
box-shadow : 0 5px 10px rgba(0, 0, 0, 0.2);
|
|
9
|
+
text-align : center;
|
|
10
|
+
width : 320px;
|
|
11
|
+
-webkit-user-select: none;
|
|
12
|
+
-moz-user-select : none;
|
|
13
|
+
user-select : none;
|
|
14
|
+
padding : 10px;
|
|
15
|
+
line-height : 1.5em;
|
|
16
|
+
|
|
17
|
+
a {
|
|
18
|
+
color: #1e5494;
|
|
19
|
+
text-decoration: none;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.selectYearMonth {
|
|
23
|
+
float: right;
|
|
24
|
+
width: 100px;
|
|
25
|
+
|
|
26
|
+
div {
|
|
27
|
+
display: inline-block;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.showCurrentYearMonth {
|
|
32
|
+
text-align: left;
|
|
33
|
+
color : lightgray;
|
|
34
|
+
font-size : 1.6rem;
|
|
35
|
+
padding : 5% 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
table {
|
|
39
|
+
width : 100%;
|
|
40
|
+
border : 0;
|
|
41
|
+
border-spacing : 0;
|
|
42
|
+
border-collapse: collapse;
|
|
43
|
+
|
|
44
|
+
thead {
|
|
45
|
+
tr {
|
|
46
|
+
color : #acacac;
|
|
47
|
+
border-bottom: 1px solid lightgray;
|
|
48
|
+
margin-bottom: 15px;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
td {
|
|
53
|
+
font-size : .8rem;
|
|
54
|
+
padding : .4rem;
|
|
55
|
+
letter-spacing : 1px;
|
|
56
|
+
border : 0;
|
|
57
|
+
background-color: white;
|
|
58
|
+
text-align : center;
|
|
59
|
+
|
|
60
|
+
&.day {
|
|
61
|
+
cursor : pointer;
|
|
62
|
+
transition: background-color 190ms ease-in-out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&.onToday {
|
|
66
|
+
font-weight: bold;
|
|
67
|
+
color : #C60;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&.onSelect {
|
|
71
|
+
font-weight: bold;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&.day:hover {
|
|
75
|
+
color : darken(#e0ecf9, 50%);
|
|
76
|
+
background-color: #e9e9e9;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.idCalendarPre,
|
|
82
|
+
.idCalendarNext {
|
|
83
|
+
cursor : pointer;
|
|
84
|
+
font-size : 1.2rem;
|
|
85
|
+
text-align : center;
|
|
86
|
+
border-radius: 3px;
|
|
87
|
+
padding : 2px 5px;
|
|
88
|
+
|
|
89
|
+
&:hover {
|
|
90
|
+
background-color: #e9e9e9;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.idCalendarPre {
|
|
95
|
+
float: left;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.idCalendarNext {
|
|
99
|
+
float: right;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.btns {
|
|
103
|
+
position: absolute;
|
|
104
|
+
left : 15px;
|
|
105
|
+
bottom : 5px;
|
|
106
|
+
|
|
107
|
+
input[type=button] {
|
|
108
|
+
font-size: .8rem;
|
|
109
|
+
padding : 2px 4px;
|
|
110
|
+
margin : 1px;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
.showTime{
|
|
114
|
+
margin-top: 5%;
|
|
115
|
+
select {
|
|
116
|
+
min-width:50px;
|
|
117
|
+
text-align: center;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 日历 悬浮出现
|
|
123
|
+
.aj-form-calendar-input {
|
|
124
|
+
position: relative;
|
|
125
|
+
width : 125px;
|
|
126
|
+
line-height: 19px;
|
|
127
|
+
|
|
128
|
+
&.show-time {
|
|
129
|
+
width: 170px;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
display: inline-block;
|
|
133
|
+
|
|
134
|
+
input[type=text] {
|
|
135
|
+
// .aj-input-base();
|
|
136
|
+
max-width: 100% ! important;
|
|
137
|
+
width : 100% ! important;
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.icon {
|
|
142
|
+
position : absolute;
|
|
143
|
+
width : 17px;
|
|
144
|
+
height : 16px;
|
|
145
|
+
right : 5px;
|
|
146
|
+
top : 6px;
|
|
147
|
+
opacity : .6;
|
|
148
|
+
cursor : pointer;
|
|
149
|
+
// .menu {
|
|
150
|
+
// color: #000;
|
|
151
|
+
// position: absolute;
|
|
152
|
+
// margin-left: 2px;
|
|
153
|
+
// margin-top: 8px;
|
|
154
|
+
// width: 17px;
|
|
155
|
+
// height: 1px;
|
|
156
|
+
// background-color: currentColor;
|
|
157
|
+
// &:before {
|
|
158
|
+
// content: '';
|
|
159
|
+
// position: absolute;
|
|
160
|
+
// top: -5px;
|
|
161
|
+
// left: 0;
|
|
162
|
+
// width: 17px;
|
|
163
|
+
// height: 1px;
|
|
164
|
+
// background-color: currentColor;
|
|
165
|
+
// }
|
|
166
|
+
//
|
|
167
|
+
// &:after {
|
|
168
|
+
// content: '';
|
|
169
|
+
// position: absolute;
|
|
170
|
+
// top: 5px;
|
|
171
|
+
// left: 0;
|
|
172
|
+
// width: 17px;
|
|
173
|
+
// height: 1px;
|
|
174
|
+
// background-color: currentColor;
|
|
175
|
+
// }
|
|
176
|
+
// }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.aj-form-calendar {
|
|
180
|
+
z-index : 999999999;
|
|
181
|
+
display : none;
|
|
182
|
+
position: absolute;
|
|
183
|
+
|
|
184
|
+
&.positionFixed {
|
|
185
|
+
// 若父元素 overflow:hidden,则 position: absolute 不能完整显示,故 fixed
|
|
186
|
+
position: fixed;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
right: -3px;
|
|
190
|
+
top : 25px;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
&:hover .aj-form-calendar,
|
|
194
|
+
.aj-form-calendar:hover {
|
|
195
|
+
display: block;
|
|
196
|
+
|
|
197
|
+
.icon {
|
|
198
|
+
opacity: .5;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
&:hover .icon {
|
|
203
|
+
opacity: 1;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.selectYearMonth select {
|
|
207
|
+
min-width: 65px;
|
|
208
|
+
outline: none;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日期选择器
|
|
3
|
+
*/
|
|
4
|
+
export default {
|
|
5
|
+
props: {
|
|
6
|
+
showTime: Boolean // 是否显示时间,即“时分秒”
|
|
7
|
+
},
|
|
8
|
+
data() {
|
|
9
|
+
let date: Date = new Date;
|
|
10
|
+
return {
|
|
11
|
+
date: date,
|
|
12
|
+
year: date.getFullYear(),
|
|
13
|
+
month: date.getMonth() + 1,
|
|
14
|
+
day: 1
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
mounted(): void {
|
|
18
|
+
this.$options.watch.date.call(this);
|
|
19
|
+
},
|
|
20
|
+
watch: {
|
|
21
|
+
date(): void {
|
|
22
|
+
this.year = this.date.getFullYear();
|
|
23
|
+
this.month = this.date.getMonth() + 1;
|
|
24
|
+
this.render();
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
methods: {
|
|
28
|
+
/**
|
|
29
|
+
* 画日历
|
|
30
|
+
*/
|
|
31
|
+
render(): void {
|
|
32
|
+
let arr: number[] = this.getDateArr(),// 用来保存日期列表
|
|
33
|
+
frag: DocumentFragment = document.createDocumentFragment();// 插入日期
|
|
34
|
+
|
|
35
|
+
while (arr.length) {
|
|
36
|
+
let row: HTMLTableRowElement = document.createElement("tr"); // 每个星期插入一个 tr
|
|
37
|
+
|
|
38
|
+
for (let i = 1; i <= 7; i++) { // 每个星期有7天
|
|
39
|
+
let cell: HTMLTableCellElement = document.createElement("td");
|
|
40
|
+
|
|
41
|
+
if (arr.length) {
|
|
42
|
+
let d: number = arr.shift();
|
|
43
|
+
|
|
44
|
+
if (d) {
|
|
45
|
+
let text: string = this.year + '-' + this.month + '-' + d;
|
|
46
|
+
cell.title = text; // 保存日期在 title 属性
|
|
47
|
+
cell.className = 'day day_' + text;
|
|
48
|
+
cell.innerHTML = d + "";
|
|
49
|
+
|
|
50
|
+
let on: Date = new Date(this.year, this.month - 1, d);
|
|
51
|
+
|
|
52
|
+
// 判断是否今日
|
|
53
|
+
if (isSameDay(on, this.date)) {
|
|
54
|
+
cell.classList.add('onToday');
|
|
55
|
+
// this.onToday && this.onToday(cell);// 点击 今天 时候触发的事件
|
|
56
|
+
}
|
|
57
|
+
// 判断是否选择日期
|
|
58
|
+
// this.selectDay && this.onSelectDay && this.isSameDay(on, this.selectDay) && this.onSelectDay(cell);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
row.appendChild(cell);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
frag.appendChild(row);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 先清空内容再插入
|
|
69
|
+
let tbody = <HTMLElement>this.$el.querySelector("table tbody");
|
|
70
|
+
tbody.innerHTML = '';
|
|
71
|
+
tbody.appendChild(frag);
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 获取指定的日期
|
|
76
|
+
*
|
|
77
|
+
* @param dateType
|
|
78
|
+
* @param month
|
|
79
|
+
*/
|
|
80
|
+
getDate(dateType: 'preMonth' | 'nextMonth' | 'setMonth' | 'preYear' | 'nextYear', month: number): void {
|
|
81
|
+
let nowYear: number = this.date.getFullYear(),
|
|
82
|
+
nowMonth: number = this.date.getMonth() + 1; // 当前日期
|
|
83
|
+
|
|
84
|
+
switch (dateType) {
|
|
85
|
+
case 'preMonth':// 上一月
|
|
86
|
+
this.date = new Date(nowYear, nowMonth - 2, 1);
|
|
87
|
+
break;
|
|
88
|
+
case 'nextMonth':// 下一月
|
|
89
|
+
this.date = new Date(nowYear, nowMonth, 1);
|
|
90
|
+
break;
|
|
91
|
+
case 'setMonth':// 指定月份
|
|
92
|
+
this.date = new Date(nowYear, month - 1, 1);
|
|
93
|
+
break;
|
|
94
|
+
case 'preYear':// 上一年
|
|
95
|
+
this.date = new Date(nowYear - 1, nowMonth - 1, 1);
|
|
96
|
+
break;
|
|
97
|
+
case 'nextYear':// 下一年
|
|
98
|
+
this.date = new Date(nowYear + 1, nowMonth - 1, 1);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
*
|
|
106
|
+
* @param querySelectoreven
|
|
107
|
+
*/
|
|
108
|
+
setMonth(ev: Event): void {
|
|
109
|
+
let el: HTMLSelectElement = <HTMLSelectElement>ev.target;
|
|
110
|
+
this.getDate('setMonth', Number(el.selectedOptions[0].value));
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 获取空白的非上月天数 + 当月天数
|
|
115
|
+
*
|
|
116
|
+
* @param this
|
|
117
|
+
*/
|
|
118
|
+
getDateArr(): number[] {
|
|
119
|
+
let arr: number[] = [];
|
|
120
|
+
|
|
121
|
+
// 算出这个月1号距离前面的星期天有多少天
|
|
122
|
+
for (let i = 1, firstDay: number = new Date(this.year, this.month - 1, 1).getDay(); i <= firstDay; i++)
|
|
123
|
+
arr.push(0);
|
|
124
|
+
|
|
125
|
+
// 这个月有多少天。用上个月然后设置日子参数为 0,就可以得到本月有多天
|
|
126
|
+
for (let i = 1, monthDay: number = new Date(this.year, this.month, 0).getDate(); i <= monthDay; i++)
|
|
127
|
+
arr.push(i);
|
|
128
|
+
|
|
129
|
+
return arr;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 获取日期
|
|
134
|
+
*
|
|
135
|
+
* @param event
|
|
136
|
+
*/
|
|
137
|
+
pickDay(ev: Event): string {
|
|
138
|
+
let el: HTMLElement = <HTMLElement>ev.target,
|
|
139
|
+
date: string = el.title;
|
|
140
|
+
this.$emit('pickdate', date);
|
|
141
|
+
|
|
142
|
+
return date;
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
*
|
|
147
|
+
* @param event
|
|
148
|
+
*/
|
|
149
|
+
pickupTime(event: Event): void {
|
|
150
|
+
let hour: HTMLSelectElement = <HTMLSelectElement>this.$el.querySelector('.hour'),
|
|
151
|
+
minute: HTMLSelectElement = <HTMLSelectElement>this.$el.querySelector('.minute'),
|
|
152
|
+
time = hour.selectedOptions[0].value + ':' + minute.selectedOptions[0].value;
|
|
153
|
+
|
|
154
|
+
this.$emit('pick-time', time);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 判断两个日期是否同一日
|
|
161
|
+
*
|
|
162
|
+
* @param d1
|
|
163
|
+
* @param d2
|
|
164
|
+
*/
|
|
165
|
+
function isSameDay(d1: Date, d2: Date): boolean {
|
|
166
|
+
return (d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth() && d1.getDate() == d2.getDate());
|
|
167
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="aj-form-calendar">
|
|
3
|
+
<div class="selectYearMonth">
|
|
4
|
+
<a href="###" @click="getDate('preYear')" class="preYear" title="上一年"> « <!-- < --></a>
|
|
5
|
+
<select @change="setMonth" v-model="month">
|
|
6
|
+
<option value="1">一月</option>
|
|
7
|
+
<option value="2">二月</option>
|
|
8
|
+
<option value="3">三月</option>
|
|
9
|
+
<option value="4">四月</option>
|
|
10
|
+
<option value="5">五月</option>
|
|
11
|
+
<option value="6">六月</option>
|
|
12
|
+
<option value="7">七月</option>
|
|
13
|
+
<option value="8">八月</option>
|
|
14
|
+
<option value="9">九月</option>
|
|
15
|
+
<option value="10">十月</option>
|
|
16
|
+
<option value="11">十一月</option>
|
|
17
|
+
<option value="12">十二月</option>
|
|
18
|
+
</select>
|
|
19
|
+
<a href="###" @click="getDate('nextYear')" class="nextYear" title="下一年"> »<!-- > --> </a>
|
|
20
|
+
</div>
|
|
21
|
+
<div class="showCurrentYearMonth">
|
|
22
|
+
<span class="showYear">{{year}}</span>/<span class="showMonth">{{month}}</span>
|
|
23
|
+
</div>
|
|
24
|
+
<table>
|
|
25
|
+
<thead>
|
|
26
|
+
<tr>
|
|
27
|
+
<td>日</td>
|
|
28
|
+
<td>一</td>
|
|
29
|
+
<td>二</td>
|
|
30
|
+
<td>三</td>
|
|
31
|
+
<td>四</td>
|
|
32
|
+
<td>五</td>
|
|
33
|
+
<td>六</td>
|
|
34
|
+
</tr>
|
|
35
|
+
</thead>
|
|
36
|
+
<tbody @click="pickDay"></tbody>
|
|
37
|
+
</table>
|
|
38
|
+
<div v-if="showTime" class="showTime">
|
|
39
|
+
时 <select class="hour aj-select">
|
|
40
|
+
<option v-for="n in 24" :key="n">{{n}}</option>
|
|
41
|
+
</select>
|
|
42
|
+
分 <select class="minute aj-select">
|
|
43
|
+
<option v-for="n in 61" :key="n">{{n - 1}}</option>
|
|
44
|
+
</select>
|
|
45
|
+
<a href="#" @click="pickupTime">选择时间</a>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</template>
|
|
49
|
+
|
|
50
|
+
<script lang="ts" src="./Calendar.ts"></script>
|
|
51
|
+
|
|
52
|
+
<style lang="less" scoped src="./Calendar.less"></style>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="aj-form-calendar-input" :class="{'show-time': showTime}" @mouseover="onMouseOver">
|
|
3
|
+
<div class="icon fa fa-calendar"></div>
|
|
4
|
+
<input :placeholder="placeholder" size="12" :name="fieldName" :value="date + (dateOnly ? '' : ' ' + time)" type="text" autocomplete="off" />
|
|
5
|
+
<aj-form-calendar ref="calendar" :show-time="showTime" @pick-date="recEvent" @pick-time="recTimeEvent">
|
|
6
|
+
</aj-form-calendar>
|
|
7
|
+
</div>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
/**
|
|
12
|
+
* 帶有 input 輸入框的
|
|
13
|
+
*/
|
|
14
|
+
export default {
|
|
15
|
+
data() {
|
|
16
|
+
return {
|
|
17
|
+
date: this.fieldValue,
|
|
18
|
+
time: "",
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
props: {
|
|
22
|
+
fieldName: { type: String, required: true }, // 表单 name,字段名
|
|
23
|
+
fieldValue: { type: String, required: false, default: "" },
|
|
24
|
+
dateOnly: { type: Boolean, required: false, default: true }, // 是否只处理日期,不考虑时间
|
|
25
|
+
showTime: { type: Boolean, required: false, default: false },
|
|
26
|
+
positionFixed: Boolean, // 是否采用固定定位
|
|
27
|
+
placeholder: { type: String, default: "请输入日期" }, // 提示文字
|
|
28
|
+
},
|
|
29
|
+
watch: {
|
|
30
|
+
fieldValue( n: string): void {
|
|
31
|
+
this.date = n;
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
mounted(): void {
|
|
35
|
+
if (this.positionFixed) {
|
|
36
|
+
let el: HTMLElement = <HTMLElement>this.$el.$(".aj-form-calendar");
|
|
37
|
+
el.classList.add("positionFixed");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 2012-07-08
|
|
41
|
+
// firefox中解析 new Date('2012/12-23') 不兼容,提示invalid date 无效的日期
|
|
42
|
+
// Chrome下可以直接将其格式化成日期格式,且时分秒默认为零
|
|
43
|
+
// var arr = date.split('-'), now = new Date(arr[0], arr[1] - 1, arr[2],
|
|
44
|
+
// " ", "", " ");
|
|
45
|
+
if (this.fieldValue) {
|
|
46
|
+
let arr: string = this.fieldValue.split(" ")[0],
|
|
47
|
+
_arr = arr.split("-");
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
this.$refs.calendar.date = new Date(arr[0],arr[1] - 1, arr[2]," ", "", " ");
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
methods: {
|
|
53
|
+
recTimeEvent(time: string): void {
|
|
54
|
+
this.time = time;
|
|
55
|
+
},
|
|
56
|
+
recEvent(date: string): void {
|
|
57
|
+
this.date = date.trim();
|
|
58
|
+
},
|
|
59
|
+
onMouseOver(ev: Event): void {
|
|
60
|
+
if (this.positionFixed) {
|
|
61
|
+
let el: HTMLElement = <HTMLElement>ev.currentTarget,
|
|
62
|
+
b: DOMRect = el.getBoundingClientRect(),
|
|
63
|
+
c: HTMLElement = <HTMLElement>this.$el.$(".aj-form-calendar");
|
|
64
|
+
|
|
65
|
+
c.style.top = b.top + el.clientHeight - 0 + "px";
|
|
66
|
+
c.style.left = b.left - 0 + 0 + "px";
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
</script>
|