doc.md 3.7 KB
Newer Older
宋宋 已提交
1 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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
# Elevator 组件

### 介绍

用于列表快速定位以及索引的显示

### 安装

## 代码演示

### 基础用法

```tsx
const dataList = [
  {
    title: 'A',
    list: [
      {
        name: '安徽',
        id: 1,
      },
    ],
  },
  {
    title: 'B',
    list: [
      {
        name: '北京',
        id: 2,
      },
    ],
  },
  {
    title: 'G',
    list: [
      {
        name: '广西',
        id: 3,
      },
      {
        name: '广东',
        id: 4,
      },
    ],
  },
  {
    title: 'H',
    list: [
      {
        name: '湖南',
        id: 5,
      },
      {
        name: '湖北',
        id: 6,
      },
      ,
      {
        name: '琥珀',
        id: 7,
      },
    ],
  },
]
const clickItem = (key: string, item: any) => {
  console.log(key, JSON.stringify(item))
}

const clickIndex = (key: string) => {
  console.log(key)
}
```

```tsx
<Elevator
  indexList={dataList}
  height="260"
  clickItem={(key: string, item: any) => clickItem(key, item)}
  clickIndex={(key: string) => clickIndex(key)}
></Elevator>
```

### 自定义索引

## API

```tsx
const dataList = [
  {
    num: '',
    list: [
      {
        name: '北京',
        id: 1,
      },
      {
        name: '上海',
        id: 2,
      },
      {
        name: '深圳',
        id: 3,
      },
      {
        name: '广州',
        id: 4,
      },
      {
        name: '杭州',
        id: 5,
      },
    ],
  },
  {
    num: '',
    list: [
      {
        name: '成都',
        id: 6,
      },
      {
        name: '西安',
        id: 7,
      },
      {
        name: '天津',
        id: 8,
      },
      {
        name: '武汉',
        id: 9,
      },
      {
        name: '长沙',
        id: 10,
      },
      {
        name: '重庆',
        id: 11,
      },
      {
        name: '苏州',
        id: 12,
      },
      {
        name: '南京',
        id: 13,
      },
    ],
  },
  {
    num: '',
    list: [
      {
        name: '西宁',
        id: 14,
      },
      {
        name: '兰州',
        id: 15,
      },
      {
        name: '石家庄',
        id: 16,
      },
      {
        name: '秦皇岛',
        id: 17,
      },
      {
        name: '大连',
        id: 18,
      },
      {
        name: '哈尔滨',
        id: 19,
      },
      {
        name: '长春',
        id: 20,
      },
      {
        name: '太原',
        id: 21,
      },
    ],
  },
]
const clickItem = (key: string, item: any) => {
  console.log(key, JSON.stringify(item))
}

const clickIndex = (key: string) => {
  console.log(key)
}
```

```tsx
<Elevator
  indexList={dataList2}
  height="220"
  acceptKey="num"
  clickItem={(key: string, item: any) => clickItem(key, item)}
  clickIndex={(key: string) => clickIndex(key)}
></Elevator>
```

### Props

| 字段      | 说明           | 类型                                                        | 默认值                |
| --------- | -------------- | ----------------------------------------------------------- | --------------------- |
| height    | 电梯区域的高度 | Number、String                                              | `200px`               |
| acceptKey | 索引 key 值    | String                                                      | `title`               |
| indexList | 索引列表       | Array(item 需包含 id、name 属性, name 支持传入 html 结构) | `[{id: 0, name: ''}]` |

### Event

| 名称       | 说明     | 回调参数                               |
| ---------- | -------- | -------------------------------------- |
| clickItem  | 点击内容 | key: string, item: { id: 0, name: '' } |
| clickIndex | 点击索引 | key: string                            |