Skip to content

Commit faef33d

Browse files
committed
update: uni-th 支持 date 日期筛选范围
1 parent d4ad497 commit faef33d

File tree

5 files changed

+100
-11
lines changed

5 files changed

+100
-11
lines changed

docs/components/table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ selection-change | 开启多选时,当选择项发生变化时会触发该事
109109
|:-: |:-: |:-: | :-: |:-:|
110110
|width |String | - |- | 单元格宽度|
111111
|align |String | left |left/center/right | 表头对齐方式|
112-
|filter-type |String | |search/select/range | 筛选类型,search关键字搜索,select类别选择|
112+
|filter-type |String | |search/select/range/date | 筛选类型,search关键字搜索,select类别选择|
113113
|filter-data |Array | || 筛选数据|
114114
|sortable |Boolean| false |- | 是否启用排序|
115115

uni_modules/uni-table/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 1.0.7(2021-07-08)
2+
- 新增 uni-th 支持 date 日期筛选范围
13
## 1.0.6(2021-07-05)
24
- 新增 uni-th 支持 range 筛选范围
35
## 1.0.5(2021-06-28)

uni_modules/uni-table/components/uni-th/filter-dropdown.vue

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<template>
22
<view class="uni-filter-dropdown">
33
<view class="dropdown-btn" @click="onDropdown">
4-
<view class="icon-select" :class="{active: canReset}"
5-
v-if="filterType == 'select' || filterType == 'range'"></view>
6-
<view class="icon-search" :class="{active: canReset}" v-if="filterType == 'search'">
4+
<view class="icon-select" :class="{active: canReset}" v-if="isSelect || isRange"></view>
5+
<view class="icon-search" :class="{active: canReset}" v-if="isSearch">
76
<view class="icon-search-0"></view>
87
<view class="icon-search-1"></view>
98
</view>
9+
<view class="icon-calendar" :class="{active: canReset}" v-if="isDate">
10+
<view class="icon-calendar-0"></view>
11+
<view class="icon-calendar-1"></view>
12+
</view>
1013
</view>
1114
<view class="uni-dropdown-cover" v-if="isOpened" @click="handleClose"></view>
1215
<view class="dropdown-popup dropdown-popup-right" v-if="isOpened" @click.stop>
@@ -47,6 +50,11 @@
4750
<view class="flex-f btn btn-submit" @click="handleRangeSubmit">{{resource.submit}}</view>
4851
</view>
4952
<!-- date -->
53+
<view v-if="isDate">
54+
<uni-datetime-picker ref="datetimepicker" :value="dateRange" type="datetimerange" return-type="timestamp" @change="datetimechange" @maskClick="timepickerclose">
55+
<view></view>
56+
</uni-datetime-picker>
57+
</view>
5058
</view>
5159
</view>
5260
</template>
@@ -60,14 +68,16 @@
6068
"submit": "确定",
6169
"filter": "筛选",
6270
"gt": "大于等于",
63-
"lt": "小于等于"
71+
"lt": "小于等于",
72+
"date": "日期范围"
6473
}
6574
6675
const DropdownType = {
6776
Select: "select",
6877
Search: "search",
6978
Range: "range",
70-
Date: "date"
79+
Date: "date",
80+
Timestamp: "timestamp"
7181
}
7282
7383
export default {
@@ -114,6 +124,9 @@
114124
if (this.isRange) {
115125
return (this.gtValue.length > 0 && this.ltValue.length > 0)
116126
}
127+
if (this.isDate) {
128+
return this.dateSelect.length > 0
129+
}
117130
return false
118131
},
119132
isSelect() {
@@ -126,7 +139,7 @@
126139
return this.filterType === DropdownType.Range
127140
},
128141
isDate() {
129-
return this.filterType === DropdownType.Date
142+
return (this.filterType === DropdownType.Date || this.filterType === DropdownType.Timestamp)
130143
}
131144
},
132145
watch: {
@@ -146,7 +159,9 @@
146159
filterValue: '',
147160
checkedValues: [],
148161
gtValue: '',
149-
ltValue: ''
162+
ltValue: '',
163+
dateRange: [],
164+
dateSelect: []
150165
};
151166
},
152167
created() {
@@ -164,13 +179,26 @@
164179
},
165180
openPopup() {
166181
this.isOpened = true
182+
if (this.isDate) {
183+
this.$nextTick(() => {
184+
if (!this.dateRange.length) {
185+
this.resetDate()
186+
}
187+
this.$refs.datetimepicker.show()
188+
})
189+
}
167190
},
168191
closePopup() {
169192
this.isOpened = false
170193
},
171194
handleClose(e) {
172195
this.closePopup()
173196
},
197+
resetDate() {
198+
let date = new Date()
199+
let dateText = date.toISOString().split('T')[0]
200+
this.dateRange = [dateText + ' 0:00:00', dateText + ' 23:59:59']
201+
},
174202
onDropdown(e) {
175203
this.openPopup()
176204
},
@@ -192,6 +220,18 @@
192220
}
193221
this.checkedValues = checkvalues
194222
},
223+
datetimechange(e) {
224+
this.closePopup()
225+
this.dateRange = e
226+
this.dateSelect = e
227+
this.$emit('change', {
228+
filterType: this.filterType,
229+
filter: e
230+
})
231+
},
232+
timepickerclose(e) {
233+
this.closePopup()
234+
},
195235
handleSelectSubmit() {
196236
this.closePopup()
197237
this.$emit('change', {
@@ -309,6 +349,53 @@
309349
background-color: #1890ff;
310350
}
311351
352+
.icon-calendar {
353+
color: #ddd;
354+
width: 14px;
355+
height: 16px;
356+
}
357+
358+
.icon-calendar-0 {
359+
height: 4px;
360+
margin-top: 3px;
361+
margin-bottom: 1px;
362+
background-color: #ddd;
363+
border-radius: 2px 2px 1px 1px;
364+
position: relative;
365+
}
366+
.icon-calendar-0:before, .icon-calendar-0:after {
367+
content: '';
368+
position: absolute;
369+
top: -3px;
370+
width: 4px;
371+
height: 3px;
372+
border-radius: 1px;
373+
background-color: #ddd;
374+
}
375+
.icon-calendar-0:before {
376+
left: 2px;
377+
}
378+
.icon-calendar-0:after {
379+
right: 2px;
380+
}
381+
382+
.icon-calendar-1 {
383+
height: 9px;
384+
background-color: #ddd;
385+
border-radius: 1px 1px 2px 2px;
386+
}
387+
388+
.icon-calendar.active {
389+
color: #1890ff;
390+
}
391+
392+
.icon-calendar.active .icon-calendar-0,
393+
.icon-calendar.active .icon-calendar-1,
394+
.icon-calendar.active .icon-calendar-0:before,
395+
.icon-calendar.active .icon-calendar-0:after {
396+
background-color: #1890ff;
397+
}
398+
312399
.uni-filter-dropdown {
313400
position: relative;
314401
font-weight: normal;

uni_modules/uni-table/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "uni-table",
33
"displayName": "uni-table 表格",
4-
"version": "1.0.6",
4+
"version": "1.0.7",
55
"description": "用于展示多条结构类似的数据",
66
"keywords": [
77
"uni-ui",
@@ -40,7 +40,7 @@
4040
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui"
4141
},
4242
"uni_modules": {
43-
"dependencies": [],
43+
"dependencies": ["uni-datetime-picker"],
4444
"encrypt": [],
4545
"platforms": {
4646
"cloud": {

uni_modules/uni-table/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ selection-change | 开启多选时,当选择项发生变化时会触发该事
107107
|:-: |:-: |:-: | :-: |:-:|
108108
|width |String | - |- | 单元格宽度|
109109
|align |String | left |left/center/right | 表头对齐方式|
110-
|filter-type |String | |search/select/range | 筛选类型,search关键字搜索,select类别选择|
110+
|filter-type |String | |search/select/range/date | 筛选类型,search关键字搜索,select类别选择|
111111
|filter-data |Array | || 筛选数据|
112112
|sortable |Boolean| false |- | 是否启用排序|
113113

0 commit comments

Comments
 (0)