-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[calendar] 调用接口对日历的某几天进行文案定义 #2319
Comments
👋 @landhuang,感谢给 TDesign 提出了 issue。 |
我来处理下 |
感谢,有人回应就是惊喜!~期待最终效果。 |
有进展了吗, 希望通过接口返回的数据来设置日期的禁用状态 |
Component({
data: {
format: undefined,
},
lifetimes: {
ready() {
setTimeout(() => {
this.setData({
format: (day) => {
const { date } = day;
const year = date.getFullYear();
const month = date.getMonth() + 1;
const curDate = date.getDate();
day.suffix = '¥60';
if (year === 2022) {
if (month === 2) {
const map = {
1: '初一',
2: '初二',
3: '初三',
14: '情人节',
15: '元宵节',
};
if (curDate in map) {
day.prefix = map[curDate];
day.suffix = '¥100';
day.className = 'is-holiday';
}
}
}
return day;
}
})
}, 1000)
}
},
}); 这样呢? |
如图,没有效果,代码如下 Component({
data: {
visible: true,
usePopup: false,
value: new Date(2023, 8, 15).getTime(),
minDate: new Date(2023, 8, 1).getTime(),
maxDate: new Date(2023, 9, 15).getTime(),
format: undefined
},
methods: {
handleCalendar() {
this.setData({ visible: true });
},
handleConfirm(e) {
console.log(e.detail.value);
},
handleButton1() {
console.log('test');
setTimeout(() => {
console.log('test1000');
this.setData({
format: (day) => {
const { date } = day;
const year = date.getFullYear();
const month = date.getMonth() + 1;
const curDate = date.getDate();
day.suffix = '¥60';
if (year === 2023) {
if (month === 9) {
const map = {
1: '初一1',
2: '初二1',
3: '初三1',
14: '情人节1',
15: '元宵节1',
};
if (curDate in map) {
day.prefix = map[curDate];
day.suffix = '¥100';
day.className = 'is-holiday';
}
}
}
return day;
}
})
}, 1000)
},
},
});
|
@LeeJim 加不加setTimeout 都是没有作用的 |
终于试出来了,这个可以成功,供参考。 // pages/demo02/demo02.js
Page({
/**
* 页面的初始数据
*/
data: {
visible: true,
usePopup: false,
style: 'border: 2rpx solid rgba(220,220,220,1);border-radius: 12rpx;',
inputValue: '1',
kDates: []
},
test() {
let kDate= parseInt(this.data.inputValue, 10);
let kDates= this.data.kDates;
kDates.push(kDate);
this.setData({format(day) {
const { date } = day;
const curDate = date.getDate();
if( kDates.includes(curDate)) {
day.suffix = '打卡';
} else {
day.prefix = '中秋节';
day.suffix = '¥100';
day.className = 'is-holiday';
}
return day;
}, kDates: kDates})
},
bindChangeDate(e) {
let val = e.detail.value;
console.log(val);
this.setData({
inputValue: val
})
},
test2() {
console.log(this.data.inputValue);
}
}) <view>
<view>
<t-button theme="primary" size="large" variant="outline" bind:tap="test">打卡</t-button>
<t-input placeholder="日期" style="{{style}}" value="{{inputValue}}" bind:change="bindChangeDate" maxcharacter="{{2}}" clearable />
</view>
<view>
<t-calendar
visible="{{visible}}"
use-popup="{{usePopup}}"
value="{{value}}"
minDate="{{minDate}}"
maxDate="{{maxDate}}"
format="{{format}}"
bind:confirm="handleConfirm"
/>
</view>
</view> |
问题同样, wxml文件 后台js文件
})` data中的format可以正常执行,但是在方法中是要碰运气,但是90%的时候是不能执行的。 |
这个功能解决了什么问题
我觉得这个日历不错,但是比如我想对某几天的日历做标记,比如:8月25日做个上标:纪念日,8月28日做个上标:重要
但是我看例子我没有办法完成这个过程,因为例子中只有在整个初始化过程中就把这些内容通过format定好。我没有办法类似于通过某个按钮之类的,把format调用。
你建议的方案是什么
建议能够提供函数方法之类的,我可以按钮事件调用这个方法,把日历的某几个日期做自定义文案的suffix和prefix
The text was updated successfully, but these errors were encountered: