|
@@ -1,97 +0,0 @@
|
1
|
|
-
|
2
|
|
-import React, { useEffect, useMemo, useRef, useState } from 'react'
|
3
|
|
-import Taro from '@tarojs/taro';
|
4
|
|
-import { ScrollView, View, Image, Text } from '@tarojs/components';
|
5
|
|
-import deleteIcon from '@/assets/icons/landlord/delete.png';
|
6
|
|
-import './style.less'
|
7
|
|
-
|
8
|
|
-export default (props) => {
|
9
|
|
- const { className, action, del, onDelete } = props;
|
10
|
|
-
|
11
|
|
- const contextRef = useRef()
|
12
|
|
- const contentHeightRef = useRef(0)
|
13
|
|
- const [actStyle, setActStyle]= useState()
|
14
|
|
-
|
15
|
|
- const uqClass = useMemo(() => `f-${Math.random().toString(36).substring(2)}`, [])
|
16
|
|
- const classes = [className, 'slideview-wrapper', uqClass].filter(Boolean).join(' ');
|
17
|
|
-
|
18
|
|
- const handleScrollLeft = () => {
|
19
|
|
- if (contextRef.current) {
|
20
|
|
- contextRef.current.scrollIntoView('.slideview-content')
|
21
|
|
- }
|
22
|
|
- }
|
23
|
|
-
|
24
|
|
- const handleScrollRight = () => {
|
25
|
|
- if (contextRef.current) {
|
26
|
|
- contextRef.current.scrollIntoView('.slideview-actions')
|
27
|
|
- }
|
28
|
|
- }
|
29
|
|
-
|
30
|
|
- const handleDelete = (e) => {
|
31
|
|
- if (onDelete) {
|
32
|
|
- onDelete(e)
|
33
|
|
- }
|
34
|
|
- }
|
35
|
|
-
|
36
|
|
- useEffect(() => {
|
37
|
|
- Taro.nextTick(() => {
|
38
|
|
- Taro.createSelectorQuery()
|
39
|
|
- .select(`.${uqClass}`)
|
40
|
|
- .node()
|
41
|
|
- .exec((res) => {
|
42
|
|
- contextRef.current = res[0].node;
|
43
|
|
- })
|
44
|
|
- })
|
45
|
|
- }, [])
|
46
|
|
-
|
47
|
|
- useEffect(() => {
|
48
|
|
- Taro.nextTick(() => {
|
49
|
|
- // 不清楚为什么, 此处获取高度一直不准确
|
50
|
|
- const t = setTimeout(() => {
|
51
|
|
- Taro.createSelectorQuery()
|
52
|
|
- .select(`.${uqClass}`)
|
53
|
|
- .boundingClientRect()
|
54
|
|
- .exec((res) => {
|
55
|
|
- if (res && res[0]) {
|
56
|
|
- const { height } = res[0]
|
57
|
|
- if (height && height !== contentHeightRef.current) {
|
58
|
|
- setActStyle({
|
59
|
|
- height: `${height}px`,
|
60
|
|
- })
|
61
|
|
- contentHeightRef.current = height
|
62
|
|
- }
|
63
|
|
- }
|
64
|
|
- })
|
65
|
|
- clearTimeout(t)
|
66
|
|
- }, 500)
|
67
|
|
- })
|
68
|
|
- })
|
69
|
|
-
|
70
|
|
- return (
|
71
|
|
- <ScrollView
|
72
|
|
- className={classes}
|
73
|
|
- upperThreshold={20}
|
74
|
|
- lowerThreshold={20}
|
75
|
|
- scrollX
|
76
|
|
- scrollWithAnimation
|
77
|
|
- enhanced
|
78
|
|
- onScrollToUpper={handleScrollLeft}
|
79
|
|
- onScrollToLower={handleScrollRight}
|
80
|
|
- >
|
81
|
|
- <View className='slideview-content'>{props.children}</View>
|
82
|
|
- <View className='slideview-actions' style={actStyle}>
|
83
|
|
- <View className='slideview-action'>
|
84
|
|
- {
|
85
|
|
- del && (
|
86
|
|
- <View className='slideview-action_delete' onClick={handleDelete}>
|
87
|
|
- <Image src={deleteIcon} />
|
88
|
|
- <View>删除</View>
|
89
|
|
- </View>
|
90
|
|
- )
|
91
|
|
- }
|
92
|
|
- {action}
|
93
|
|
- </View>
|
94
|
|
- </View>
|
95
|
|
- </ScrollView>
|
96
|
|
- )
|
97
|
|
-}
|