|
@@ -6,6 +6,9 @@ import { ToolsHelper } from '../ToolsHelper'
|
|
export struct DatePickerView {
|
|
export struct DatePickerView {
|
|
@Prop option: DateDialogOptions | undefined = undefined
|
|
@Prop option: DateDialogOptions | undefined = undefined
|
|
@Prop dialogTag: string | undefined = undefined
|
|
@Prop dialogTag: string | undefined = undefined
|
|
|
|
+ @State showYear: boolean = false
|
|
|
|
+ @State showMonth: boolean = false
|
|
|
|
+ @State showDay: boolean = false
|
|
//年份相关
|
|
//年份相关
|
|
@State startYear: number = 1970
|
|
@State startYear: number = 1970
|
|
@State endYear: number = 1970
|
|
@State endYear: number = 1970
|
|
@@ -26,7 +29,14 @@ export struct DatePickerView {
|
|
if (!this.option?.type) {
|
|
if (!this.option?.type) {
|
|
this.option!.type = 'YYYY-MM-DD'
|
|
this.option!.type = 'YYYY-MM-DD'
|
|
}
|
|
}
|
|
- if (this.option!.type.indexOf('YYYY') > -1) {
|
|
|
|
|
|
+ this.checkYear()
|
|
|
|
+ this.checkMonth()
|
|
|
|
+ this.checkDays()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ checkYear() {
|
|
|
|
+ this.showYear = this.option!.type!.indexOf('YYYY') > -1
|
|
|
|
+ if (this.showYear) {
|
|
if (this.option?.startDate) {
|
|
if (this.option?.startDate) {
|
|
this.startYear = Number.parseInt(this.option.startDate?.split('-')[0])
|
|
this.startYear = Number.parseInt(this.option.startDate?.split('-')[0])
|
|
}
|
|
}
|
|
@@ -46,12 +56,11 @@ export struct DatePickerView {
|
|
this.currentYear = this.years.indexOf(new Date().getFullYear().toString())
|
|
this.currentYear = this.years.indexOf(new Date().getFullYear().toString())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- this.checkMonth()
|
|
|
|
- this.checkDays()
|
|
|
|
}
|
|
}
|
|
|
|
|
|
checkMonth() {
|
|
checkMonth() {
|
|
- if (this.option!.type!.indexOf('MM') > -1) {
|
|
|
|
|
|
+ this.showMonth = this.option!.type!.indexOf('MM') > -1
|
|
|
|
+ if (this.showMonth) {
|
|
if (this.option?.startDate) {
|
|
if (this.option?.startDate) {
|
|
this.startMonth = Number.parseInt(this.option.startDate?.split('-')[1])
|
|
this.startMonth = Number.parseInt(this.option.startDate?.split('-')[1])
|
|
}
|
|
}
|
|
@@ -80,7 +89,8 @@ export struct DatePickerView {
|
|
}
|
|
}
|
|
|
|
|
|
checkDays() {
|
|
checkDays() {
|
|
- if (this.option!.type!.indexOf('DD') > -1) {
|
|
|
|
|
|
+ this.showDay = this.option!.type!.indexOf('DD') > -1
|
|
|
|
+ if (this.showDay) {
|
|
if (this.option?.startDate) {
|
|
if (this.option?.startDate) {
|
|
this.startDay = Number.parseInt(this.option.startDate?.split('-')[2])
|
|
this.startDay = Number.parseInt(this.option.startDate?.split('-')[2])
|
|
}
|
|
}
|
|
@@ -135,15 +145,21 @@ export struct DatePickerView {
|
|
.padding(15)
|
|
.padding(15)
|
|
|
|
|
|
Row() {
|
|
Row() {
|
|
- TextPicker({ range: this.years, selected: $$this.currentYear })
|
|
|
|
- .onChange((value: string | string[], index: number | number[]) => {
|
|
|
|
- this.checkDays()
|
|
|
|
- }).canLoop(false)
|
|
|
|
- TextPicker({ range: this.months, selected: $$this.currentMonth })
|
|
|
|
- .onChange((value: string | string[], index: number | number[]) => {
|
|
|
|
- this.checkDays()
|
|
|
|
- }).canLoop(false)
|
|
|
|
- TextPicker({ range: this.days, selected: $$this.currentDay })
|
|
|
|
|
|
+ if (this.startYear) {
|
|
|
|
+ TextPicker({ range: this.years, selected: $$this.currentYear })
|
|
|
|
+ .onChange((value: string | string[], index: number | number[]) => {
|
|
|
|
+ this.checkDays()
|
|
|
|
+ }).canLoop(false)
|
|
|
|
+ }
|
|
|
|
+ if (this.startMonth) {
|
|
|
|
+ TextPicker({ range: this.months, selected: $$this.currentMonth })
|
|
|
|
+ .onChange((value: string | string[], index: number | number[]) => {
|
|
|
|
+ this.checkDays()
|
|
|
|
+ }).canLoop(false)
|
|
|
|
+ }
|
|
|
|
+ if (this.startDay) {
|
|
|
|
+ TextPicker({ range: this.days, selected: $$this.currentDay })
|
|
|
|
+ }
|
|
|
|
|
|
}.width('100%').justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Center)
|
|
}.width('100%').justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Center)
|
|
}
|
|
}
|