Skip to content

Commit 0eb64b1

Browse files
committed
update: uni-ui calendar tags 对象改为数组,头条小程序不支持循环对象。
1 parent 30d4f71 commit 0eb64b1

2 files changed

Lines changed: 40 additions & 50 deletions

File tree

‎components/uni-calendar/uni-calendar.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@
615615
}
616616
},
617617
getQueryDom(index) {
618-
let dom = uni.createSelectorQuery().selectAll(`.${this.elClass}`);
618+
let dom = uni.createSelectorQuery().in(this).selectAll(`.${this.elClass}`);
619619
dom.boundingClientRect(rect => {}).exec(e => {
620620
if (!e[0][index]) {
621621
setTimeout(() => this.getQueryDom(1), 50);

‎pages/extUI/calendar/calendar.vue‎

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,16 @@
1111
<button class="calendar-button" type="button" @click="open">打开日历</button>
1212
<text v-if="timeData.lunar" class="calendar-title">已选日期</text>
1313
<view v-if="timeData.lunar" class="calendar-info">
14-
<view>当前选择时间 : {{timeData.fulldate}}</view>
15-
<view v-if="tags['lunar'].checked">农历日期 : {{timeData.year +
16-
'年' +
17-
timeData.month +
18-
'月' +
19-
timeData.date +
20-
'日 (' +
21-
timeData.lunar.astro +
22-
')'}}</view>
23-
<view v-if="tags['lunar'].checked"> {{
24-
timeData.lunar.gzYear +
25-
'年' +
26-
timeData.lunar.gzMonth +
27-
'月' +
28-
timeData.lunar.gzDay +
29-
'日 (' +
30-
timeData.lunar.Animal +
31-
'年)'
32-
}}
33-
{{ timeData.lunar.IMonthCn + timeData.lunar.IDayCn }}
34-
{{ timeData.lunar.isTerm ? timeData.lunar.Term : '' }}</view>
14+
<view>当前选择时间 : {{ timeData.fulldate }}</view>
15+
<view v-if="tags[0].checked">农历日期 : {{ timeData.year + '年' + timeData.month + '月' + timeData.date + '日 (' + timeData.lunar.astro + ')' }}</view>
16+
<view v-if="tags[0].checked">
17+
{{ timeData.lunar.gzYear + '年' + timeData.lunar.gzMonth + '月' + timeData.lunar.gzDay + '日 (' + timeData.lunar.Animal + '年)' }}
18+
{{ timeData.lunar.IMonthCn + timeData.lunar.IDayCn }} {{ timeData.lunar.isTerm ? timeData.lunar.Term : '' }}
19+
</view>
3520
</view>
3621
<view v-if="show" class="calendar-mask" @click="closeMask">
3722
<view class="calendar-box" @click.stop="">
38-
<uni-calendar :lunar="tags['lunar'].checked" :fixedHeihgt="tags['fixedHeihgt'].checked" :slide="slide" :disableBefore="tags['disableBefore'].checked" :start-date="startDate" :end-date="endDate" :date="date" @change="change" @to-click="toClick" />
23+
<uni-calendar :lunar="tags[0].checked" :fixedHeihgt="tags[1].checked" :slide="slide" :disableBefore="tags[6].checked" :start-date="startDate" :end-date="endDate" :date="date" @change="change" @to-click="toClick" />
3924
<view class="calendar-button-groups">
4025
<button class="calendar-button-confirm" @click="closeMask">取消</button>
4126
<button class="calendar-button-confirm" @click="confirm">确认</button>
@@ -52,7 +37,6 @@
5237
components: {
5338
uniCalendar
5439
},
55-
5640
data() {
5741
/**
5842
* 时间计算
@@ -68,52 +52,58 @@
6852
let d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate(); // 获取当前几号,不足10补0
6953
return y + '-' + m + '-' + d;
7054
}
71-
let tags = {
72-
lunar: {
55+
let tags = [{
56+
id: 0,
7357
name: '农历',
7458
checked: false,
7559
attr: 'lunar'
7660
},
77-
fixedHeihgt: {
61+
{
62+
id: 1,
7863
name: '固定高度',
7964
checked: false,
8065
attr: 'fixedHeihgt'
8166
},
82-
vertical: {
67+
{
68+
id: 2,
8369
name: '垂直滚动',
8470
checked: false,
8571
attr: 'vertical'
8672
},
87-
horizontal: {
73+
{
74+
id: 3,
8875
name: '水平滚动',
8976
checked: false,
9077
attr: 'horizontal'
9178
},
92-
startDate: {
79+
{
80+
id: 4,
9381
name: '开始日期(' + getDate(new Date(), -1) + ')',
9482
checked: false,
9583
value: getDate(new Date(), -1),
9684
attr: 'startDate'
9785
},
98-
endDate: {
86+
{
87+
id: 5,
9988
name: '结束日期(' + getDate(new Date(), 2) + ')',
10089
value: getDate(new Date(), 2),
10190
checked: false,
10291
attr: 'endDate'
10392
},
104-
disableBefore: {
93+
{
94+
id: 6,
10595
name: '禁用今天之前的日期',
10696
checked: false,
10797
attr: 'disableBefore'
10898
},
109-
date: {
99+
{
100+
id: 7,
110101
name: '自定义当前日期(' + getDate(new Date(), 1) + ')',
111102
value: getDate(new Date(), 1),
112103
checked: false,
113104
attr: 'date'
114105
}
115-
};
116-
106+
];
117107
118108
return {
119109
show: false,
@@ -133,39 +123,40 @@
133123
toggle(index, item) {
134124
this.tags[index].checked = !item.checked;
135125
// item.checked = !item.checked;
136-
if (index === 'horizontal') {
137-
this.tags['vertical'].checked = false;
126+
console.log(index)
127+
if (index === 2) {
128+
this.tags[3].checked = false;
138129
}
139-
if (index === 'vertical') {
140-
this.tags['horizontal'].checked = false;
130+
if (index === 3) {
131+
this.tags[2].checked = false;
141132
}
142133
// this.attribute[item.attr] = !item.checked;
143134
},
144135
open() {
145-
if (this.tags['horizontal'].checked) {
136+
if (this.tags[3].checked) {
146137
this.slide = 'horizontal';
147-
} else if (this.tags['vertical'].checked) {
138+
} else if (this.tags[2].checked) {
148139
this.slide = 'vertical';
149140
} else {
150141
this.slide = 'none';
151142
}
152-
if (this.tags['startDate'].checked) {
153-
this.startDate = this.tags['startDate'].value;
143+
if (this.tags[4].checked) {
144+
this.startDate = this.tags[4].value;
154145
} else {
155146
this.startDate = '';
156147
}
157-
if (this.tags['endDate'].checked) {
158-
this.endDate = this.tags['endDate'].value;
148+
if (this.tags[5].checked) {
149+
this.endDate = this.tags[5].value;
159150
} else {
160151
this.endDate = '';
161152
}
162-
if (this.tags['date'].checked) {
163-
this.date = this.tags['date'].value;
153+
if (this.tags[7].checked) {
154+
this.date = this.tags[7].value;
164155
} else {
165156
this.date = '';
166157
}
167158
this.show = true;
168-
console.log(this.date)
159+
console.log(this.date);
169160
},
170161
change(e) {
171162
console.log('change 返回:', e.fulldate);
@@ -249,7 +240,7 @@
249240
250241
.calendar-tags-item {
251242
padding: 10upx 20upx;
252-
border: 1px rgba(0, 0, 0, .2) solid;
243+
border: 1px rgba(0, 0, 0, 0.2) solid;
253244
color: #333;
254245
border-radius: 10upx;
255246
text-align: center;
@@ -263,7 +254,6 @@
263254
264255
.checked .calendar-tags-item {
265256
background: rgb(0, 122, 255);
266-
;
267257
color: #fff;
268258
border: 1px rgba(0, 0, 0, 0.1) solid;
269259
}

0 commit comments

Comments
 (0)