doc.md 4.7 KB
Newer Older
灰灰 已提交
1
# Calendar 组件
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203

### 介绍

日历,可平铺/弹窗展示

### 安装

```javascript
import { createApp } from 'vue';
import { Calendar } from '@nutui/nutui';

const app = createApp();
app.use(Calendar);
```

## 代码演示

### 基础用法

```html
<nut-cell
  :showIcon="true"
  title="选择单个日期"
  :desc="date ? `${date} ${dateWeek}` : '请选择'"
  @click="openSwitch('isVisible')"
>
</nut-cell>
<nut-calendar
  :is-visible="isVisible"
  :default-value="date"
  @close="closeSwitch('isVisible')"
  @choose="setChooseValue"
  :start-date="`2019-10-11`"
  :end-date="`2022-11-11`"
>
</nut-calendar>
```

```javascript
setup() {
    const state: TestCalendarState = reactive({
      isVisible: false,
      date: '',
      dateWeek: ''
    });
    const openSwitch = param => {
      state[`${param}`] = true;
    };
    const closeSwitch = param => {
      state[`${param}`] = false;
    };
    const setChooseValue = param => {
      state.date = param[3];
      state.dateWeek = param[4];
    };
    return {
      ...toRefs(state),
      openSwitch,
      closeSwitch,
      setChooseValue
    };
  }
```

### 区间选择

```html
<nut-cell
  :showIcon="true"
  title="选择日期区间"
  :desc="date ? `${date[0]}至${date[1]}` : '请选择'"
  @click="openSwitch('isVisible')"
>
</nut-cell>
<nut-calendar
  :is-visible="isVisible"
  :default-value="date"
  type="range"
  :start-date="`2019-12-22`"
  :end-date="`2021-01-08`"
  @close="closeSwitch('isVisible')"
  @choose="setChooseValue"
>
</nut-calendar>
```

```javascript
setup() {
    const state: TestCalendarState = reactive({
      date: ['2019-12-23', '2019-12-26'],
      isVisible2: true
    });
    const openSwitch = param => {
      state[`${param}`] = true;
    };
    const closeSwitch = param => {
      state[`${param}`] = false;
    };
    const setChooseValue= param => {
      state.date = [...[param[0][3], param[1][3]]];
    };
    return {
      ...toRefs(state),
      openSwitch,
      closeSwitch,
      setChooseValue,
    };
  }
```

### 自定义日历-自动回填

```html
<nut-cell
  :showIcon="true"
  title="选择日期"
  :desc="date ? date : '请选择'"
  @click="openSwitch('isVisible')"
>
</nut-cell>
<nut-calendar
  :is-visible="isVisible"
  @close="closeSwitch('isVisible')"
  @choose="setChooseValue"
  :start-date="null"
  :end-date="null"
  :is-auto-back-fill="true"
>
</nut-calendar>
```

```javascript
setup() {
    const state: TestCalendarState = reactive({
      date: '',
      isVisible: false
    });
    const openSwitch = param => {
      state[`${param}`] = true;
    };
    const closeSwitch = param => {
      state[`${param}`] = false;
    };
     const setChooseValue = param => {
      state.date= param[3];
    };
    return {
      ...toRefs(state),
      setChooseValue
    };
  }
```

### 平铺展示

```html
<div class="test-calendar-wrapper">
  <nut-calendar
    :poppable="false"
    :is-auto-back-fill="true"
    :default-value="date"
    @choose="setChooseValue"
  >
  </nut-calendar
></div>
```

```javascript
setup() {
    const state: TestCalendarState = reactive({
      date: '2020-07-08'
    });
    const setChooseValue = param => {
      state.date = param[3];
    };
    return {
      ...toRefs(state),
      setChooseValue
    };
  }
```

### 基础用法

```html

```

```javascript
```

## API

### Props

| 字段              | 说明                                              | 类型           | 默认值          |
| ----------------- | ------------------------------------------------- | -------------- | --------------- |
| type              | 类型,日期选择'one',区间选择'range'              | String         | 'one'           |
| is-visible        | 是否可见                                          | Boolean        | false           |
| poppable          | 是否弹窗状态展示                                  | Boolean        | true            |
| is-auto-back-fill | 自动回填                                          | Boolean        | false           |
| title             | 显示标题                                          | String         | ‘日期选择’      |
S
suzigang 已提交
204
| default-value     | 默认值,日期选择 String 格式,区间选择 Array 格式 | String 、 Array | null            |
205 206 207 208 209 210
| start-date        | 开始日期, 如果不限制开始日期传 null              | String         | 今天            |
| end-date          | 结束日期,如果不限制结束日期传 null               | String         | 距离今天 365 天 |

### Events

| 事件名 | 说明 | 回调参数 |
S
suzigang 已提交
211
| ----------------- | --------------------- | -------------- |
212 213
| choose | 选择之后或是点击确认按钮触发 | 日期数组(包含年月日和星期)
| close | 关闭时触发 | -