合同小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.0 KiB

1 week ago
  1. ## Calendar 日历
  2. > **组件名:uni-calendar**
  3. > 代码块: `uCalendar`
  4. 日历组件
  5. > **注意事项**
  6. > 为了避免错误使用,给大家带来不好的开发体验,请在使用组件前仔细阅读下面的注意事项,可以帮你避免一些错误。
  7. > - 本组件农历转换使用的js是 [@1900-2100区间内的公历、农历互转](https://github.com/jjonline/calendar.js)
  8. > - 仅支持自定义组件模式
  9. > - `date`属性传入的应该是一个 String ,如: 2019-06-27 ,而不是 new Date()
  10. > - 通过 `insert` 属性来确定当前的事件是 @change 还是 @confirm 。理应合并为一个事件,但是为了区分模式,现使用两个事件,这里需要注意
  11. > - 弹窗模式下无法阻止后面的元素滚动,如有需要阻止,请在弹窗弹出后,手动设置滚动元素为不可滚动
  12. ### 安装方式
  13. 本组件符合[easycom](https://uniapp.dcloud.io/collocation/pages?id=easycom)规范,`HBuilderX 2.5.5`起,只需将本组件导入项目,在页面`template`中即可直接使用,无需在页面中`import`和注册`components`。
  14. 如需通过`npm`方式使用`uni-ui`组件,另见文档:[https://ext.dcloud.net.cn/plugin?id=55](https://ext.dcloud.net.cn/plugin?id=55)
  15. ### 基本用法
  16. 在 ``template`` 中使用组件
  17. ```html
  18. <view>
  19. <uni-calendar
  20. :insert="true"
  21. :lunar="true"
  22. :start-date="'2019-3-2'"
  23. :end-date="'2019-5-20'"
  24. @change="change"
  25. />
  26. </view>
  27. ```
  28. ### 通过方法打开日历
  29. 需要设置 `insert``false`
  30. ```html
  31. <view>
  32. <uni-calendar
  33. ref="calendar"
  34. :insert="false"
  35. @confirm="confirm"
  36. />
  37. <button @click="open">打开日历</button>
  38. </view>
  39. ```
  40. ```javascript
  41. export default {
  42. data() {
  43. return {};
  44. },
  45. methods: {
  46. open(){
  47. this.$refs.calendar.open();
  48. },
  49. confirm(e) {
  50. console.log(e);
  51. }
  52. }
  53. };
  54. ```
  55. ## API
  56. ### Calendar Props
  57. | 属性名 | 类型 | 默认值| 说明 |
  58. | - | - | - | - |
  59. | date | String |- | 自定义当前时间,默认为今天 |
  60. | lunar | Boolean | false | 显示农历 |
  61. | startDate | String |- | 日期选择范围-开始日期 |
  62. | endDate | String |- | 日期选择范围-结束日期 |
  63. | range | Boolean | false | 范围选择 |
  64. | insert | Boolean | false | 插入模式,可选值,ture:插入模式;false:弹窗模式;默认为插入模式 |
  65. |clearDate |Boolean |true |弹窗模式是否清空上次选择内容 |
  66. | selected | Array |- | 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}] |
  67. |showMonth | Boolean | true | 是否显示月份为背景 |
  68. ### Calendar Events
  69. | 事件名 | 说明 |返回值|
  70. | - | - | - |
  71. | open | 弹出日历组件,`insert :false` 时生效|- |
  72. ## 组件示例
  73. 点击查看:[https://hellouniapp.dcloud.net.cn/pages/extUI/calendar/calendar](https://hellouniapp.dcloud.net.cn/pages/extUI/calendar/calendar)