|
1 | 1 | import React, {
|
| 2 | + createContext, |
2 | 3 | FunctionComponent,
|
3 |
| - useRef, |
4 | 4 | useEffect,
|
| 5 | + useRef, |
5 | 6 | useState,
|
6 |
| - createContext, |
7 | 7 | } from 'react'
|
8 |
| -import Taro, { nextTick, createSelectorQuery } from '@tarojs/taro' |
| 8 | +import Taro, { createSelectorQuery, nextTick } from '@tarojs/taro' |
9 | 9 |
|
10 | 10 | import { ScrollView } from '@tarojs/components'
|
11 | 11 | import classNames from 'classnames'
|
12 | 12 | import { BasicComponent, ComponentDefaults } from '@/utils/typings'
|
| 13 | +import useUuid from '@/utils/use-uuid' |
13 | 14 |
|
14 | 15 | export const elevatorContext = createContext({} as ElevatorData)
|
15 | 16 |
|
@@ -65,6 +66,7 @@ export const Elevator: FunctionComponent<
|
65 | 66 | ...defaultProps,
|
66 | 67 | ...props,
|
67 | 68 | }
|
| 69 | + const uuid = useUuid() |
68 | 70 | const classPrefix = 'nut-elevator'
|
69 | 71 | const listview = useRef<HTMLDivElement>(null)
|
70 | 72 | const initData = {
|
@@ -106,7 +108,7 @@ export const Elevator: FunctionComponent<
|
106 | 108 | for (let i = 0; i < state.current.listGroup.length; i++) {
|
107 | 109 | const query = createSelectorQuery()
|
108 | 110 | query
|
109 |
| - .selectAll(`.${className} .nut-elevator-item-${i}`) |
| 111 | + .selectAll(`.${classPrefix}-${uuid} .nut-elevator-item-${i}`) |
110 | 112 | .boundingClientRect()
|
111 | 113 | // eslint-disable-next-line no-loop-func
|
112 | 114 | query.exec((res: any) => {
|
@@ -180,7 +182,7 @@ export const Elevator: FunctionComponent<
|
180 | 182 | const setListGroup = () => {
|
181 | 183 | if (listview.current) {
|
182 | 184 | createSelectorQuery()
|
183 |
| - .selectAll(`.${className} .nut-elevator-list-item`) |
| 185 | + .selectAll(`.${classPrefix}-${uuid} .nut-elevator-list-item`) |
184 | 186 | .node((el) => {
|
185 | 187 | state.current.listGroup = [...Object.keys(el)]
|
186 | 188 | calculateHeight()
|
@@ -220,7 +222,11 @@ export const Elevator: FunctionComponent<
|
220 | 222 | }, [listview])
|
221 | 223 |
|
222 | 224 | return (
|
223 |
| - <div className={`${classPrefix} ${className}`} style={style} {...rest}> |
| 225 | + <div |
| 226 | + className={`${classPrefix} ${className} ${classPrefix}-${uuid}`} |
| 227 | + style={style} |
| 228 | + {...rest} |
| 229 | + > |
224 | 230 | <div
|
225 | 231 | className={`${classPrefix}-list`}
|
226 | 232 | style={{ height: Number.isNaN(+height) ? height : `${height}px` }}
|
|
0 commit comments