Procházet zdrojové kódy

小火箭返回顶部功能

dxz1228 před 2 roky
rodič
revize
906d317917
2 změnil soubory, kde provedl 63 přidání a 4 odebrání
  1. 16 0
      .hbuilderx/launch.json
  2. 47 4
      src/pages/store/nearby/index.vue

+ 16 - 0
.hbuilderx/launch.json

@@ -0,0 +1,16 @@
1
+{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
2
+  // launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
3
+    "version": "0.0",
4
+    "configurations": [{
5
+     	"default" : 
6
+     	{
7
+     		"launchtype" : "local"
8
+     	},
9
+     	"mp-weixin" : 
10
+     	{
11
+     		"launchtype" : "local"
12
+     	},
13
+     	"type" : "uniCloud"
14
+     }
15
+    ]
16
+}

+ 47 - 4
src/pages/store/nearby/index.vue

@@ -3,7 +3,6 @@ import {getMerchantCategory, getSelectMerchant, getSelectMerchantSort} from "~/a
3
 import type {StoreResult} from "~/apis/model/storeModel";
3
 import type {StoreResult} from "~/apis/model/storeModel";
4
 import {StoreParams} from "~/apis/model/storeModel";
4
 import {StoreParams} from "~/apis/model/storeModel";
5
 import CXBEmpty from "~/components/CXBEmpty/CXBEmpty.vue";
5
 import CXBEmpty from "~/components/CXBEmpty/CXBEmpty.vue";
6
-import CXBBackTop from "~/components/CXBBackTop/CXBBackTop.vue";
7
 import {USER_LATITUDE, USER_LONGITUDE} from "~/constants";
6
 import {USER_LATITUDE, USER_LONGITUDE} from "~/constants";
8
 import {getProductShare} from "~/apis/common";
7
 import {getProductShare} from "~/apis/common";
9
 import {useUserStore} from "~/stores/userStore";
8
 import {useUserStore} from "~/stores/userStore";
@@ -49,6 +48,9 @@ const state = reactive({
49
   menuDefaultValue: 1
48
   menuDefaultValue: 1
50
   // merchantPageInfo: {}
49
   // merchantPageInfo: {}
51
 })
50
 })
51
+//返回顶部标识
52
+let flag=ref(false)
53
+
52
 const searchValue = ref('')
54
 const searchValue = ref('')
53
 
55
 
54
 const {windowHeight} = uni.getSystemInfoSync()
56
 const {windowHeight} = uni.getSystemInfoSync()
@@ -207,6 +209,11 @@ const onRefresherRefresh = e => {
207
   loadSelectMerchant('reload')
209
   loadSelectMerchant('reload')
208
 };
210
 };
209
 
211
 
212
+//小火箭滚动事件
213
+const onscroll =e=>{
214
+	state.scrollTop=e.detail.scrollTop
215
+}
216
+
210
 function handleScrollToLower() {
217
 function handleScrollToLower() {
211
   state.status = 'loading';
218
   state.status = 'loading';
212
   state.currentPage += 1;
219
   state.currentPage += 1;
@@ -218,6 +225,24 @@ function handleScrollToLower() {
218
   }
225
   }
219
 }
226
 }
220
 
227
 
228
+//返回顶部事件
229
+const scrollToTop = function () {
230
+  console.log('返回顶部');
231
+	state.scrollTop=0
232
+
233
+}
234
+//监视
235
+watch(()=>state.scrollTop,()=>{
236
+  if(state.scrollTop as number > 400){
237
+    flag.value = true
238
+  }
239
+  if(state.scrollTop as number < 400){
240
+    flag.value = false
241
+  }
242
+})
243
+
244
+
245
+
221
 </script>
246
 </script>
222
 <template>
247
 <template>
223
   <!--  <nut-category :category="state.merchantCategory" @change="change">-->
248
   <!--  <nut-category :category="state.merchantCategory" @change="change">-->
@@ -242,6 +267,7 @@ function handleScrollToLower() {
242
     <!-- 左侧 一级分类 -->
267
     <!-- 左侧 一级分类 -->
243
     <div class="w-1/4">
268
     <div class="w-1/4">
244
       <scroll-view
269
       <scroll-view
270
+		  ref="ToTop"
245
           :scroll-y="true"
271
           :scroll-y="true"
246
           :style="{ height: `${state.scrollHeight}px` }"
272
           :style="{ height: `${state.scrollHeight}px` }"
247
           class="w-full h-full bg-[#f8f8f8]"
273
           class="w-full h-full bg-[#f8f8f8]"
@@ -285,11 +311,14 @@ function handleScrollToLower() {
285
           </nut-menu-item>
311
           </nut-menu-item>
286
         </nut-menu>
312
         </nut-menu>
287
       </div>
313
       </div>
288
-      <CXBBackTop/>
314
+		<!-- 返回顶部 -->
315
+	  <div v-show="flag" class="back-top">
316
+	    <img @click="scrollToTop" class="back-TopImg" src="../../static/icon/返回顶部@2x.png" alt="">
317
+	  </div>
289
       <scroll-view
318
       <scroll-view
290
           :scroll-y="true"
319
           :scroll-y="true"
291
           :style="{ height: `${state.scrollHeight -60}px` }"
320
           :style="{ height: `${state.scrollHeight -60}px` }"
292
-          scroll-with-animation
321
+		  :scroll-top="state.scrollTop"
293
           class="flex flex-1  flex-col   p-3 gap-3 mt-10"
322
           class="flex flex-1  flex-col   p-3 gap-3 mt-10"
294
           :refresher-enabled="true"
323
           :refresher-enabled="true"
295
           refresher-background="#f5f5f5"
324
           refresher-background="#f5f5f5"
@@ -301,7 +330,7 @@ function handleScrollToLower() {
301
           @refresherAbort="onRefresherAbort"
330
           @refresherAbort="onRefresherAbort"
302
           @refresherrefresh="onRefresherRefresh"
331
           @refresherrefresh="onRefresherRefresh"
303
           v-if="state.merchantList && state.merchantList.length > 0"
332
           v-if="state.merchantList && state.merchantList.length > 0"
304
-
333
+		  @scroll="onscroll"
305
       >
334
       >
306
         <div
335
         <div
307
             v-for="(item, index) in state.merchantList" :key="index"
336
             v-for="(item, index) in state.merchantList" :key="index"
@@ -362,6 +391,20 @@ page {
362
   --nut-menu-bar-box-shadow: none;
391
   --nut-menu-bar-box-shadow: none;
363
   --nut-menu-item-active-text-color: #FE0032;
392
   --nut-menu-item-active-text-color: #FE0032;
364
 
393
 
394
+	.back-top{
395
+	  width: 40px;
396
+	  height: 40px;
397
+	  position: fixed;
398
+	  border-radius: 50%;
399
+	  z-index: 999;
400
+	  right: 15px;
401
+	  bottom: 60px;
402
+	}
403
+	.back-TopImg{
404
+	  width: 40px;
405
+	  height: 40px;
406
+	  border-radius: 50%;
407
+	}
365
   .nut-menu {
408
   .nut-menu {
366
     background: none !important;
409
     background: none !important;
367
   }
410
   }