未验证 提交 9db4d91b 编写于 作者: L luoying_ace 提交者: Gitee

update zh-cn/application-dev/reference/arkui-ts/ts-methods-datepicker-dialog.md.

Signed-off-by: Nluoying_ace <luoying19@huawei.com>
上级 b3be3f04
# 日期滑动选择器弹窗 # 日期滑动选择器弹窗
根据指定范围的Date创建可以选择日期的滑动选择器,展示在弹窗上。 提供可以在一定范围内选择日期的滑动选择器,展示在弹窗上。
> **说明:** > **说明:**
>
> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## DatePickerDialog.show ## DatePickerDialog.show
show(options?: DatePickerDialogOptions) show(options?: DatePickerDialogOptions)
...@@ -17,83 +14,70 @@ show(options?: DatePickerDialogOptions) ...@@ -17,83 +14,70 @@ show(options?: DatePickerDialogOptions)
定义日期滑动选择器弹窗并弹出。 定义日期滑动选择器弹窗并弹出。
- DatePickerDialogOptions参数说明 - DatePickerDialogOptions参数说明
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| start | Date | 否 | Date('1970-1-1') | 指定选择器的起始日期。 | | start | Date | 否 | Date('1970-1-1') | 设置选择器的起始日期。 |
| end | Date | 否 | Date('2100-12-31') | 指定选择器的结束日期。 | | end | Date | 否 | Date('2100-12-31') | 设置选择器的结束日期。 |
| selected | Date | 否 | 当前系统日期 | 设置选中项的日期。 | | selected | Date | 否 | 当前系统日期 | 设置当前选中的日期。 |
| lunar | boolean | 否 | false | 日期是否显示农历。 | | lunar | boolean | 否 | false | 日期是否显示为农历。 |确定
| onAccept | (value: [DatePickerResult](ts-basic-components-datepicker.md#DatePickerResult对象说明)) => void | 否 | - | 点击弹窗中确定按钮时触发。 | | onAccept | (value: [DatePickerResult](ts-basic-components-datepicker.md#DatePickerResult对象说明)) => void | 否 | - | 点击弹窗中的“确定”按钮时触发该回调。 |
| onCancel | () => void | 否 | - | 点击弹窗中取消按钮时触发。 | | onCancel | () => void | 否 | - | 点击弹窗中的“取消”按钮时触发该回调。 |
| onChange | (value: [DatePickerResult](ts-basic-components-datepicker.md#DatePickerResult对象说明)) => void | 否 | - | 滑动选择器,当前选择项改变时触发。 | | onChange | (value: [DatePickerResult](ts-basic-components-datepicker.md#DatePickerResult对象说明)) => void | 否 | - | 滑动弹窗中的滑动选择器使当前选中项改变时触发该回调。 |
## 示例 ## 示例
### 日期滑动选择器(显示农历)示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct DatePickerDialogExample01 { struct DatePickerDialogExample {
@State isLunar: boolean = true selectedDate: Date = new Date("2010-1-1")
selectedDate: Date = new Date("2000-1-1")
build() { build() {
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, Column() {
justifyContent: FlexAlign.Center }) { Button("DatePickerDialog")
Button("DatePickerDialog").onClick(() => { .margin(20)
DatePickerDialog.show({ .onClick(() => {
start: new Date("2000-1-1"), DatePickerDialog.show({
end: new Date("2005-1-1"), start: new Date("2000-1-1"),
selected: this.selectedDate, end: new Date("2100-12-31"),
lunar: this.isLunar, selected: this.selectedDate,
onAccept: (value: DatePickerResult) => { onAccept: (value: DatePickerResult) => {
this.selectedDate.setFullYear(value.year, value.month, value.day) // 通过Date的setFullYear方法设置按下确定按钮时的日期,这样当弹窗再次弹出时显示选中的是上一次确定的日期
console.info("DatePickerDialog:onAccept()" + JSON.stringify(value)) this.selectedDate.setFullYear(value.year, value.month, value.day)
}, console.info("DatePickerDialog:onAccept()" + JSON.stringify(value))
onCancel: () => { },
console.info("DatePickerDialog:onCancel()") onCancel: () => {
}, console.info("DatePickerDialog:onCancel()")
onChange: (value: DatePickerResult) => { },
console.info("DatePickerDialog:onChange()" + JSON.stringify(value)) onChange: (value: DatePickerResult) => {
} console.info("DatePickerDialog:onChange()" + JSON.stringify(value))
}
})
}) })
})
}
}
}
```
### 日期滑动选择器(不显示农历)示例
```ts
// xxx.ets
@Entry
@Component
struct DatePickerDialogExample02 {
@State isLunar: boolean = false
selectedDate: Date = new Date("2000-1-1")
build() { Button("Lunar DatePickerDialog")
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, .margin(20)
justifyContent: FlexAlign.Center }) { .onClick(() => {
Button("DatePickerDialog").onClick(() => { DatePickerDialog.show({
DatePickerDialog.show({ start: new Date("2000-1-1"),
start: new Date("2000-1-1"), end: new Date("2100-12-31"),
end: new Date("2005-1-1"), selected: this.selectedDate,
selected: this.selectedDate, lunar: true,
lunar: this.isLunar, onAccept: (value: DatePickerResult) => {
onAccept: (value: DatePickerResult) => { this.selectedDate.setFullYear(value.year, value.month, value.day)
this.selectedDate.setFullYear(value.year, value.month, value.day) console.info("DatePickerDialog:onAccept()" + JSON.stringify(value))
console.info("DatePickerDialog:onAccept()" + JSON.stringify(value)) },
}, onCancel: () => {
onCancel: () => { console.info("DatePickerDialog:onCancel()")
console.info("DatePickerDialog:onCancel()") },
}, onChange: (value: DatePickerResult) => {
onChange: (value: DatePickerResult) => { console.info("DatePickerDialog:onChange()" + JSON.stringify(value))
console.info("DatePickerDialog:onChange()" + JSON.stringify(value)) }
} })
}) })
}) }.width('100%')
}
} }
} }
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册