| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- Component({
- options: {
- addGlobalClass: true
- },
- properties: {
- iconName: {
- type: String,
- value: "icon-rili1"
- },
- title: {
- type: String,
- },
- onChange: {
- type: Function,
- },
- fields: {
- type: String,
- value: "day", //有效值 year,month,day,表示选择器的粒度
- },
- end: {
- type: [String, Number]
- },
- start: {
- type: [String, Number]
- }
- },
- lifetimes: {
- attached: function () {
- const fields = this.properties.fields;
- let value = new Date();
- if (fields === "year") {
- value = value.getFullYear().toString();
- } else if (fields === "month") {
- const year = value.getFullYear();
- const month = (value.getMonth() + 1).toString().padStart(2, '0');
- value = `${year}-${month}`;
- } else if (fields === "day") {
- value = value.toISOString().split('T')[0];
- }
- this.setData({
- value
- });
- getApp().globalData.Language.getLanguagePackage(this);
- }
- },
- data: {
- value: new Date().toISOString().split('T')[0], // 默认值为今天,格式为 YYYY-MM-DD
- },
- methods: {
- onChange(e) {
- if (e.detail.value == this.data.value) return;
- this.setData({
- value: e.detail.value
- })
- this.triggerEvent("onChange", e.detail.value)
- },
- }
- })
|