张延森 3 yıl önce
ebeveyn
işleme
efa080ef5f

+ 97
- 0
src/components/SlideView/index.jsx Dosyayı Görüntüle

@@ -0,0 +1,97 @@
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
+}

+ 46
- 0
src/components/SlideView/style.less Dosyayı Görüntüle

@@ -0,0 +1,46 @@
1
+.slideview-wrapper {
2
+  box-sizing: border-box;
3
+  white-space: nowrap;
4
+
5
+  .slideview-content {
6
+    min-width: 100%;
7
+    display: inline-block;
8
+    vertical-align: middle;
9
+  }
10
+
11
+  .slideview-actions {
12
+    display: inline-block;
13
+    vertical-align: middle;
14
+    margin: 0 20px;
15
+    background: #FFFFFF;
16
+    box-shadow: 0px 8px 38px 0px rgba(0, 0, 0, 0.12);
17
+    border-radius: 12px;
18
+
19
+    .slideview-action {
20
+      height: 100%;
21
+      display: flex;
22
+      align-items: center;
23
+      justify-content: center;
24
+      
25
+      &_delete {
26
+        display: block;
27
+        flex: none;
28
+        height: 74px;
29
+        width: 67px;
30
+        text-align: center;
31
+        padding: 10px;
32
+        font-size: 24px;
33
+        font-weight: bold;
34
+        color: #FF3434;
35
+
36
+        & > image {
37
+          width: 28px;
38
+          height: 30px;
39
+          display: block;
40
+          margin: 0 auto 20px;
41
+        }
42
+      }
43
+    }
44
+
45
+  }
46
+}

+ 5
- 4
src/hotel/pages/components/Extend/index.jsx Dosyayı Görüntüle

@@ -4,6 +4,7 @@ import del from '@/assets/icons/landlord/delete.png'
4 4
 import Popup from '@/components/Popup'
5 5
 import { View, Text, Image, Textarea, Label, Button } from '@tarojs/components';
6 6
 import { update, deleteExtend } from '@/services/landlord'
7
+import SlideView from '@/components/SlideView';
7 8
 import './style.less'
8 9
 
9 10
 export default (props) => {
@@ -91,16 +92,16 @@ export default (props) => {
91 92
       {
92 93
         item.contentType == 'image' ?
93 94
           <View>
94
-            <mp-slideview buttons={detele} icon onbuttontap={handelDelete}>
95
+            <SlideView del onDelete={handelDelete}>
95 96
               <Image src={eimg} mode='widthFix' style={{ width: '100%', display: 'block' }} onClick={handerChange} />
96
-            </mp-slideview>
97
+            </SlideView>
97 98
           </View>
98 99
           :
99 100
           item.contentType == 'text' ?
100 101
             <View>
101
-              <mp-slideview buttons={detele} icon onbuttontap={handelDelete2}>
102
+              <SlideView del onDelete={handelDelete2}>
102 103
                 <View className='storezn' onClick={showText}>{content}</View>
103
-              </mp-slideview>
104
+              </SlideView>
104 105
             </View>
105 106
             : null
106 107
       }

+ 13
- 13
src/hotel/pages/components/Extend/style.less Dosyayı Görüntüle

@@ -49,19 +49,19 @@
49 49
     margin-bottom: 60px;
50 50
     text-align: justify;
51 51
   }
52
-  .weui-slideview__btn__wrp{
53
-    background: #FFFFFF;
54
-    box-shadow: 0px 8px 38px 0px rgba(0, 0, 0, 0.12);
55
-    border-radius: 12px;
56
-    margin: 5px 5px 5px 20px;
57
-    height: 97%;
58
-    width: 67px;
59
-  }
60
-  .weui-slideview__btn{
61
-    width: 44px;
62
-    height: 44px;
63
-    line-height: 44px;
64
-  }
52
+  // .weui-slideview__btn__wrp{
53
+  //   background: #FFFFFF;
54
+  //   box-shadow: 0px 8px 38px 0px rgba(0, 0, 0, 0.12);
55
+  //   border-radius: 12px;
56
+  //   margin: 5px 5px 5px 20px;
57
+  //   height: 97%;
58
+  //   width: 67px;
59
+  // }
60
+  // .weui-slideview__btn{
61
+  //   width: 44px;
62
+  //   height: 44px;
63
+  //   line-height: 44px;
64
+  // }
65 65
   Textarea{
66 66
     height: 300px;
67 67
     width: 100%;

+ 5
- 4
src/hotel/pages/landlord/addRoom/addRoom.jsx Dosyayı Görüntüle

@@ -214,16 +214,17 @@ export default withLayout((props) => {
214 214
               </mp-cell>
215 215
             </mp-cells>
216 216
             {roomId ? <>
217
-              <mp-cells title='其他指引'>
217
+              <view>
218
+                <view className='weui-cells__title'>其他指引</view>
218 219
                 {
219 220
                   extend == '' ? null :
220
-                    <mp-cell >
221
+                    <view>
221 222
                       {extend.map((item) => (
222 223
                         <Extend key={item.extId} item={item} setReset={setReset} />
223 224
                       ))}
224
-                    </mp-cell>
225
+                    </view>
225 226
                 }
226
-              </mp-cells>
227
+              </view>
227 228
             </> : null
228 229
             }
229 230
           </mp-form>