Skip to content

Elevator 电梯楼层

介绍

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

基础用法

html
<template>
  <nut-elevator :index-list="dataList" :height="260" @click-item="clickItem" @click-index="clickIndex"></nut-elevator>
</template>
<script lang="ts">
  import { reactive, toRefs } from 'vue';
  export default {
    setup() {
      const state = reactive({
        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
              }
            ]
          }
        ]
      });

      const clickItem = (key: string, item: any) => {
        console.log(key, JSON.stringify(item));
      };

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

      return { ...toRefs(state), clickItem, clickIndex };
    }
  };
</script>

自定义索引

html
<template>
  <nut-elevator :index-list="dataList2" :height="220" :acceptKey="acceptKey" @click-item="clickItem" @click-index="clickIndex"></nut-elevator>
</template>
<script lang="ts">
  import { reactive, toRefs } from 'vue';
  export default {
    setup() {
      const state = reactive({
        acceptKey: 'num',
        dataList2: [
          {
            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);
      };

      return { ...toRefs(state), clickItem, clickIndex };
    }
  };
</script>

索引吸顶

html
<template>
  <nut-elevator :index-list="dataList3" :is-sticky="true" :height="220"  @click-item="clickItem" @click-index="clickIndex"></nut-elevator>
</template>
<script lang="ts">
  import { reactive, toRefs } from 'vue';
  export default {
    setup() {
      const state = reactive({
        dataList3: [
          {
            title: 'A',
            list: [
              {
                name: '安徽',
                id: 1
              }
            ]
          },
          {
            title: 'B',
            list: [
              {
                name: '北京',
                id: 2
              }
            ]
          },
          {
            title: 'C',
            list: [
              {
                name: '重庆',
                id: 3
              }
            ]
          },
          {
            title: 'F',
            list: [
              {
                name: '福建',
                id: 4
              }
            ]
          },
          {
            title: 'G',
            list: [
              {
                name: '广西',
                id: 5
              },
              {
                name: '广东',
                id: 6
              },
              {
                name: '甘肃',
                id: 7
              },
              {
                name: '贵州',
                id: 8
              }
            ]
          },
          {
            title: 'H',
            list: [
              {
                name: '湖南',
                id: 9
              },
              {
                name: '湖北',
                id: 10
              },
              {
                name: '海南',
                id: 11
              },
              {
                name: '河北',
                id: 12
              },
              {
                name: '河南',
                id: 13
              },
              {
                name: '黑龙江',
                id: 14
              }
            ]
          },
          {
            title: 'J',
            list: [
              {
                name: '吉林',
                id: 15
              },
              {
                name: '江苏',
                id: 16
              },
              {
                name: '江西',
                id: 17
              }
            ]
          },
          {
            title: 'L',
            list: [
              {
                name: '辽宁',
                id: 18
              }
            ]
          }
        ]
      });

      const clickItem = (key: string, item: any) => {
        console.log(key, JSON.stringify(item));
      };

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

      return { ...toRefs(state), clickItem, clickIndex };
    }
  };
</script>

自定义内容

html
<template>
  <nut-elevator :index-list="dataList" :height="260" @click-item="clickItem" @click-index="clickIndex">
      <template v-slot:default="slotProps">
        <nut-icon name="jd" width="12px"></nut-icon>
        <span :style="{marginLeft: '15px'}">{{ slotProps.item.name }}</span>
      </template>
  </nut-elevator>
</template>
<script lang="ts">
  import { reactive, toRefs } from 'vue';
  export default {
    setup() {
      const state = reactive({
        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
              }
            ]
          }
        ]
      });

      const clickItem = (key: string, item: any) => {
        console.log(key, JSON.stringify(item));
      };

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

      return { ...toRefs(state), clickItem, clickIndex };
    }
  };
</script>

API

Props

参数说明类型默认值
height电梯区域的高度number | string200px
accept-key索引 keystringtitle
index-list索引列表Array( item 需包含 idname 属性, name 支持传入 html 结构)[{id: 0, name: ''}]
is-sticky索引是否吸顶booleanfalse
space-height右侧锚点的上下间距number23
title-height左侧索引的高度number35

Slots

名称说明
default自定义左侧索引下每条数据的内容

Events

事件名说明回调参数
click-item点击内容key: string, item: { id: 0, name: '' }
click-index点击索引key: string
change索引改变index: number

Methods

方法名说明参数
scrollTo滚动到对应索引的位置index:number

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值
--nut-elevator-list-item-highcolorvar(--nut-primary-color)
--nut-elevator-list-item-font-size12px
--nut-elevator-list-item-font-color#333333
--nut-elevator-list-item-name-padding0 20px
--nut-elevator-list-item-name-height30px
--nut-elevator-list-item-name-line-height30px
--nut-elevator-list-item-code-font-size14px
--nut-elevator-list-item-code-font-color#1a1a1a
--nut-elevator-list-item-code-font-weight500
--nut-elevator-list-item-code-padding0 20px
--nut-elevator-list-item-code-height35px
--nut-elevator-list-item-code-line-height35px
--nut-elevator-list-item-code-after-width100%
--nut-elevator-list-item-code-after-height1px
--nut-elevator-list-item-code-after-bg-color#f5f5f5
--nut-elevator-list-item-code-current-box-shadow0 3px 3px 1px rgba(240, 240, 240, 1)
--nut-elevator-list-item-code-current-bg-color#fff
--nut-elevator-list-item-code-current-border-radius50%
--nut-elevator-list-item-code-current-width45px
--nut-elevator-list-item-code-current-height45px
--nut-elevator-list-item-code-current-line-height45px
--nut-elevator-list-item-code-current-positionabsolute
--nut-elevator-list-item-code-current-right60px
--nut-elevator-list-item-code-current-top50%
--nut-elevator-list-item-code-current-transformtranslateY(-50%)
--nut-elevator-list-item-code-current-text-aligncenter
--nut-elevator-list-item-bars-positionabsolute
--nut-elevator-list-item-bars-right8px
--nut-elevator-list-item-bars-top50%
--nut-elevator-list-item-bars-transformtranslateY(-50%)
--nut-elevator-list-item-bars-padding15px 0
--nut-elevator-list-item-bars-background-color#eeeff2
--nut-elevator-list-item-bars-border-radius6px
--nut-elevator-list-item-bars-text-aligncenter
--nut-elevator-list-item-bars-z-index1
--nut-elevator-list-item-bars-inner-item-padding3px
--nut-elevator-list-item-bars-inner-item-font-size10px
--nut-elevator-list-fixed-colorvar(--nut-primary-color)
--nut-elevator-list-fixed-bg-colorvar(--nut-white)
--nut-elevator-list-fixed-box-shadow0 0 10px #eee
--nut-elevator-list-item-bars-inner-item-active-colorvar(--nut-primary-color)

MIT Licensed