李志伟 3 년 전
부모
커밋
294ac2d9df

+ 62
- 0
src/pages/details/components/ImageList/index.jsx 파일 보기

@@ -0,0 +1,62 @@
1
+import Taro from "@tarojs/taro";
2
+import { Image, Swiper, SwiperItem, View, Text } from "@tarojs/components";
3
+import { useState} from "react";
4
+import { compressImage } from '@/utils'
5
+import './style.less'
6
+
7
+//详情页面上面的滑动图集
8
+export default (props) => {
9
+  const { imglist } = props
10
+  const [swiperHeight, setSwiperHeight] = useState()
11
+  const [swiperImgHeightList, setSwiperImgHeightList] = useState([])
12
+  const [swiperImgWidthList, setSwiperImgWidthList] = useState([])
13
+  const handleImageOnLoad = (e, inx) => {
14
+    const { detail } = e;
15
+    const { height, width } = detail || {}
16
+    if (height) {
17
+      const heightList = swiperImgHeightList.slice()
18
+      heightList[inx] = height
19
+      setSwiperImgHeightList(heightList)
20
+      const widthList = swiperImgWidthList.slice()
21
+      widthList[inx] = width
22
+      setSwiperImgWidthList(widthList)
23
+      if (!swiperHeight && inx === 0) {
24
+        let { screenWidth } = Taro.getSystemInfoSync()
25
+        let nowHeight = (screenWidth - 30) * height / width
26
+        setSwiperHeight(`${nowHeight}px`)
27
+      }
28
+    }
29
+  }
30
+
31
+  const [index, setIndex] = useState(0);
32
+  const handchange = (e) => {
33
+    const inx = e.detail.current
34
+    setIndex(inx);
35
+    const height = swiperImgHeightList[inx]
36
+    const width = swiperImgWidthList[inx]
37
+    let { screenWidth } = Taro.getSystemInfoSync()
38
+    let nowHeight = (screenWidth - 30) * height / width
39
+    setSwiperHeight(nowHeight ? `${nowHeight}px` : 'auto')
40
+  };
41
+  return (
42
+    <View className='huadong'>
43
+      <Swiper
44
+        circular
45
+        className='swiper'
46
+        onChange={handchange}
47
+        style={{ height: swiperHeight }}
48
+      >
49
+        {imglist.map((item, inx) => (
50
+          <SwiperItem key={inx}>
51
+            <Image src={compressImage(item.url)} mode='widthFix' className='storeImage' onLoad={(e) => handleImageOnLoad(e, inx)} />
52
+          </SwiperItem>
53
+        ))}
54
+      </Swiper>
55
+      <View className='tpPage'>
56
+        <Text>
57
+          {index + 1}/{imglist.length}
58
+        </Text>
59
+      </View>
60
+    </View>
61
+  )
62
+}

+ 27
- 0
src/pages/details/components/ImageList/style.less 파일 보기

@@ -0,0 +1,27 @@
1
+.huadong{    
2
+  position: relative;
3
+  .swiper {
4
+    transition: all 0.3s linear;
5
+    .storeImage {
6
+      border-radius: 22px;
7
+      width: 100%;
8
+      height: 100%;
9
+    }
10
+  }
11
+  .tpPage {
12
+    position: absolute;
13
+    right: 20px;
14
+    bottom: 20px;
15
+    background: #000000;
16
+    border-radius: 16px;
17
+    font-size: 24px;
18
+    color: #ffffff;
19
+    padding: 0 7px;
20
+    opacity: 0.4;
21
+    line-height: 32px;
22
+    padding: 7px 8px 8px 7px;
23
+    text {
24
+      opacity: 0.64;
25
+    }
26
+  }  
27
+}

+ 7
- 32
src/pages/details/foodDetails/foodDetails.jsx 파일 보기

@@ -8,8 +8,7 @@ import {
8 8
 } from "@/services/home";
9 9
 import { getVerifyTargetList } from "@/services/payOrder";
10 10
 import { useState, useEffect, useRef } from "react";
11
-import { Button, Swiper, SwiperItem, View, Ad } from "@tarojs/components";
12
-import { compressImage } from '@/utils'
11
+import { Button,View, Ad } from "@tarojs/components";
13 12
 import Star from "@/components/Star/Star.jsx";
14 13
 import NoData from '@/components/NoData'
15 14
 import Cards from "@/components/foodCards/foodCards.jsx";
@@ -28,15 +27,14 @@ import weibaozan from "@/assets/icons/housemantj/unLike.png";
28 27
 import useSave from "@/utils/hooks/useSave";
29 28
 import useLike from "@/utils/hooks/useLike";
30 29
 import Extend from "../components/Extend/extend";
30
+import ImageList from "../components/ImageList";
31 31
 import logo from "./laba.png";
32
-
33 32
 import "./foodDetails.less";
34 33
 
35 34
 export default withLayout((props) => {
36 35
   const { router, person, location } = props;
37 36
   const { id, subOrderId, scene } = props.router.params;
38 37
 
39
-
40 38
   useEffect(() => {
41 39
     if (id && (scene || subOrderId)) {
42 40
       getVerifyTargetList({
@@ -60,10 +58,6 @@ export default withLayout((props) => {
60 58
   const [spackage, setPackage] = useState([]);
61 59
   //banner图集数组
62 60
   const [imglist, setimglist] = useState([]);
63
-  const [index, setIndex] = useState(0);
64
-  const handchange = (e) => {
65
-    setIndex(e.detail.current);
66
-  };
67 61
 
68 62
   const [isSaved, toggleSave] = useSave(detail.isSaved, "shop", id);
69 63
   const [isLike, toggleLike] = useLike(detail.isLike, "shop", id);
@@ -143,7 +137,6 @@ export default withLayout((props) => {
143 137
   const [isScroll, setScroll] = useState(true)
144 138
   return (
145 139
     <view className='page-index'>
146
-
147 140
       {
148 141
         guidance === 'shareOn' ? <view className='index-navbar'>
149 142
           <add-tipsFood logo={logo} custom duration={-1} />
@@ -153,31 +146,13 @@ export default withLayout((props) => {
153 146
             <CustomNav title='十公里' />
154 147
           </view>
155 148
       }
156
-
157 149
       <SpinBox loading={loading} className='index-container' style={{ padding: '0 30rpx', background: '#F8F8F8' }}>
158 150
         <scroll-view
159 151
           scrollY={isScroll}
160 152
           style={{ height: '100%' }}
161 153
         >
162 154
           <view className='storeDetails'>
163
-            <View className='huadong'>
164
-              <Swiper
165
-                circular
166
-                className='swiper'
167
-                onChange={handchange}
168
-              >
169
-                {imglist.map((item, inx) => (
170
-                  <SwiperItem key={inx}>
171
-                    <image src={compressImage(item.url)} mode='aspectFit' className='storeImage' />
172
-                  </SwiperItem>
173
-                ))}
174
-              </Swiper>
175
-              <view className='tpPage'>
176
-                <text>
177
-                  {index + 1}/{imglist.length}
178
-                </text>
179
-              </view>
180
-            </View>
155
+            <ImageList imglist={imglist} />
181 156
             <view className='storeJs'>
182 157
               <view style={{ overflow: "hidden" }}>
183 158
                 <view className='storeName'>{detail.shopName}</view>
@@ -254,10 +229,10 @@ export default withLayout((props) => {
254 229
                     <image src={titlezs} />
255 230
                     <text>本店指南</text>
256 231
                   </view>
257
-                  <View style={{background:'#FFF'}}>
258
-                  {(extend || []).map((item) => (
259
-                    <Extend key={item.extId} item={item} />
260
-                  ))}
232
+                  <View style={{ background: '#FFF' }}>
233
+                    {(extend || []).map((item) => (
234
+                      <Extend key={item.extId} item={item} />
235
+                    ))}
261 236
                   </View>
262 237
                 </view>
263 238
                 <view

+ 1
- 28
src/pages/details/foodDetails/foodDetails.less 파일 보기

@@ -1,34 +1,7 @@
1 1
 .storeDetails {
2 2
   background-color: #fff;
3 3
   border-radius: 12px;
4
-  margin-bottom: 20px;
5
-  .huadong{    
6
-    position: relative;
7
-    .swiper {
8
-      height: calc((100vw - 60px) * 0.6);
9
-      .storeImage {
10
-        border-radius: 22px;
11
-        width: 100%;
12
-        height: 100%;
13
-      }
14
-    }
15
-    .tpPage {
16
-      position: absolute;
17
-      right: 20px;
18
-      bottom: 20px;
19
-      background: #000000;
20
-      border-radius: 16px;
21
-      font-size: 24px;
22
-      color: #ffffff;
23
-      padding: 0 7px;
24
-      opacity: 0.4;
25
-      line-height: 32px;
26
-      padding: 7px 8px 8px 7px;
27
-      text {
28
-        opacity: 0.64;
29
-      }
30
-    }  
31
-  }
4
+  margin-bottom: 20px;  
32 5
   .storeJs {
33 6
     padding: 20px;
34 7
     .storeName {

+ 3
- 25
src/pages/details/mjDetails/sceneryDetails.jsx 파일 보기

@@ -3,7 +3,6 @@ import ax from '@/assets/icons/housemantj/onlove.png'
3 3
 import dw from '@/assets/icons/housemantj/loc-o.png'
4 4
 import titlejd from '@/assets/icons/housemantj/goodTourist.png'
5 5
 import titlems from '@/assets/icons/housemantj/goodFood.png'
6
-import { compressImage } from '@/utils'
7 6
 import share from '@/assets/icons/housemantj/touristShare.png'
8 7
 import good from '@/assets/icons/housemantj/touristGood.png'
9 8
 import baozan from '@/assets/icons/housemantj/bgood.png'
@@ -14,12 +13,13 @@ import SpinBox from "@/components/Spin/SpinBox";
14 13
 import TabIcon from '@/components/HorTabbar/TabIcon'
15 14
 import { useState, useEffect } from 'react'
16 15
 import { getTouristDetail, getExtendContent, getRecommendList } from '@/services/home'
17
-import { Swiper, SwiperItem, Button, View, Ad } from '@tarojs/components';
16
+import { Button, View, Ad } from '@tarojs/components';
18 17
 import useSave from "@/utils/hooks/useSave"
19 18
 import useLike from "@/utils/hooks/useLike"
20 19
 import Cards from '@/components/foodCards/foodCards.jsx'
21 20
 import Taro, { useShareAppMessage } from '@tarojs/taro'
22 21
 import Extend from '../components/Extend/extend'
22
+import ImageList from "../components/ImageList";
23 23
 import logo from "../foodDetails/laba.png";
24 24
 
25 25
 import './sceneryDetails.less'
@@ -34,10 +34,6 @@ export default withLayout((props) => {
34 34
 
35 35
   //banner图集数组
36 36
   const [imglist, setimglist] = useState([])
37
-  const [index, setIndex] = useState(0)
38
-  const handchange = (e) => {
39
-    setIndex(e.detail.current)
40
-  }
41 37
 
42 38
   //本店指南
43 39
   const [extend, setExtend] = useState([])
@@ -114,25 +110,7 @@ export default withLayout((props) => {
114 110
       <SpinBox loading={loading} className='index-container' style={{ padding: '0 30rpx', background: '#F8F8F8' }}>
115 111
         <scroll-view scrollY style={{ height: '100%' }}>
116 112
           <view className='storeDetails'>
117
-            <View className='huadong'>
118
-              <Swiper
119
-                className='swiper'
120
-                circular
121
-                onChange={handchange}
122
-              >
123
-                {
124
-                  imglist.map((item) => (
125
-                    <SwiperItem>
126
-                      <image src={compressImage(item.url)} mode='aspectFit' className='storeImage' />
127
-                    </SwiperItem>
128
-                  ))}
129
-              </Swiper>
130
-              <view className='tpPage'>
131
-                <text>
132
-                  {index + 1}/{imglist.length}
133
-                </text>
134
-              </view>
135
-            </View>
113
+            <ImageList imglist={imglist} />
136 114
 
137 115
             <view className='storeJs'>
138 116
               <view className='introduce'>

+ 1
- 28
src/pages/details/mjDetails/sceneryDetails.less 파일 보기

@@ -1,34 +1,7 @@
1 1
 .storeDetails {
2 2
   background-color: #fff;
3 3
   border-radius: 12px;
4
-  margin-bottom: 20px;
5
-  .huadong{    
6
-    position: relative;
7
-    .swiper {
8
-      height: calc((100vw - 60px) * 0.6);
9
-      .storeImage {
10
-        border-radius: 22px;
11
-        width: 100%;
12
-        height: 100%;
13
-      }
14
-    }
15
-    .tpPage {
16
-      position: absolute;
17
-      right: 20px;
18
-      bottom: 20px;
19
-      background: #000000;
20
-      border-radius: 16px;
21
-      font-size: 24px;
22
-      color: #ffffff;
23
-      padding: 0 7px;
24
-      opacity: 0.4;
25
-      line-height: 32px;
26
-      padding: 7px 8px 8px 7px;
27
-      text {
28
-        opacity: 0.64;
29
-      }
30
-    }  
31
-  }
4
+  margin-bottom: 20px;  
32 5
   .storeJs {
33 6
     padding: 22px;
34 7
     .introduce {