张延森 пре 3 година
родитељ
комит
128e0f45aa

+ 1
- 1
config/prod.js Прегледај датотеку

@@ -3,7 +3,7 @@ module.exports = {
3 3
     NODE_ENV: '"production"'
4 4
   },
5 5
   defineConstants: {
6
-    HOST: '"https://sgl-v2-test.njyunzhi.com"',
6
+    HOST: '"https://sgl-v2.njyunzhi.com"',
7 7
     OSS: '"yz-shigongli.oss-accelerate.aliyuncs.com"',
8 8
   },
9 9
   mini: {},

+ 1
- 1
project.config.json Прегледај датотеку

@@ -2,7 +2,7 @@
2 2
   "miniprogramRoot": "./dist",
3 3
   "projectname": "miniapp",
4 4
   "description": "十公里",
5
-  "appid": "wx835627a9b9b3932a",
5
+  "appid": "wx06a7372d48d56843",
6 6
   "setting": {
7 7
     "urlCheck": true,
8 8
     "es6": false,

+ 5
- 3
src/components/List/index.jsx Прегледај датотеку

@@ -1,4 +1,4 @@
1
-import React, { useEffect, useRef, useState, useImperativeHandle } from 'react';
1
+import React, { useEffect, useRef, useState, useImperativeHandle, useMemo } from 'react';
2 2
 import SpinBox from "@/components/Spin/SpinBox";
3 3
 
4 4
 import { ScrollView } from '@tarojs/components';
@@ -24,6 +24,8 @@ export default React.forwardRef((props, ref) => {
24 24
   const pageRef = useRef({ current: 1 })
25 25
   const [hasMore, setHasMore] = useState(false)
26 26
 
27
+  const uqCls = useMemo(() => `f-${Math.random().toString(36).substring(2)}`, [])
28
+
27 29
   // 滚动
28 30
   const handleScrollToLower = (e) => {
29 31
     if (!loading && hasMore) {
@@ -78,7 +80,7 @@ export default React.forwardRef((props, ref) => {
78 80
 
79 81
   useEffect(() => {
80 82
     Taro.nextTick(() => {
81
-      Taro.createSelectorQuery().select('.list-view').node(function (res) {
83
+      Taro.createSelectorQuery().select(`.${uqCls}`).node(function (res) {
82 84
         contextRef.current = res.node
83 85
       }).exec()
84 86
     })
@@ -98,7 +100,7 @@ export default React.forwardRef((props, ref) => {
98 100
         enhanced
99 101
         onScrollToLower={handleScrollToLower}
100 102
         {...leftProps}
101
-        className={`${className} list-view`}
103
+        className={`${className} ${uqCls} list-view`}
102 104
       >
103 105
         {!render
104 106
           ? props.children

+ 50
- 35
src/components/MasonryLayout/index.jsx Прегледај датотеку

@@ -23,57 +23,72 @@ export default (props) => {
23 23
   const { list, rfTimes: refresh } = listData
24 24
 
25 25
   // 用来绘制页面的数据
26
-  const renderListRef = useRef([])
26
+  // const renderListRef = useRef([])
27 27
 
28 28
   const lastList = usePrevious(list)
29
-  const lastRf = usePrevious(refresh)
29
+  // const lastRf = usePrevious(refresh)
30 30
 
31 31
 
32 32
   // 记录左右2栏的数据及高度
33
-  const leftHeight = useRef(0)
34
-  const rightHeight = useRef(0)
35
-  const [leftList, appendLeft, setLeftList] = useColumn()
36
-  const [rightList, appendRight, setRightList] = useColumn()
33
+  // const leftHeight = useRef(0)
34
+  // const rightHeight = useRef(0)
35
+  // const [leftList, appendLeft, setLeftList] = useColumn()
36
+  // const [rightList, appendRight, setRightList] = useColumn()
37
+  const [leftList, setLeftList] = useState([])
38
+  const [rightList, setRightList] = useState([])
37 39
   
38 40
   // 渲染逻辑
39
-  const forceRender = useRenderFunc(renderListRef, leftHeight, rightHeight, appendLeft, appendRight)
41
+  // const forceRender = useRenderFunc(renderListRef, leftHeight, rightHeight, appendLeft, appendRight)
40 42
 
41 43
   // 每个元素渲染完成, 会拿到当前栏的高度
42 44
   const handleRenderFinish = (direct) => (height) => {
43
-    if (direct === 'left') {
44
-      leftHeight.current = height
45
-    } else {
46
-      rightHeight.current = height
47
-    }
48
-
49
-    //
50
-    forceRender.current()
45
+    // if (direct === 'left') {
46
+    //   leftHeight.current = height
47
+    // } else {
48
+    //   rightHeight.current = height
49
+    // }
50
+
51
+    // //
52
+    // forceRender.current()
51 53
   }
52 54
   
53
-  console.debug('------leftHeight------->', leftHeight.current)
54
-  console.debug('------rightHeight------->', rightHeight.current)
55
-  console.debug('------renderListRef------->', renderListRef.current)
56
-  console.debug('------list------->', list)
55
+  // console.debug('------leftHeight------->', leftHeight.current)
56
+  // console.debug('------rightHeight------->', rightHeight.current)
57
+  // console.debug('------renderListRef------->', renderListRef.current)
58
+  // console.debug('------list------->', list)
57 59
 
58 60
   useEffect(() => {
59 61
     if (lastList && lastList === list) return;
60 62
 
61
-    // 新数据源 = 首次进入 或者 切换数据源
62
-    const isNew = (!lastList?.length && list.length) || (lastRf !== refresh)
63
-
64
-    if (!isNew) {
65
-      // 非新数据源, list 变更那就说明是执行了上拉加载      
66
-      // 于是, 只继续绘制变更的那部分
67
-      renderListRef.current = list.slice(lastList.length)
68
-    } else {
69
-      leftHeight.current = 0
70
-      rightHeight.current = 0
71
-      setLeftList([])
72
-      setRightList([])
73
-      renderListRef.current = list ? list.slice() : []
74
-    }
75
-
76
-    forceRender.current()
63
+    // // 新数据源 = 首次进入 或者 切换数据源
64
+    // const isNew = (!lastList?.length && list.length) || (lastRf !== refresh)
65
+
66
+    // if (!isNew) {
67
+    //   // 非新数据源, list 变更那就说明是执行了上拉加载      
68
+    //   // 于是, 只继续绘制变更的那部分
69
+    //   renderListRef.current = list.slice(lastList.length)
70
+    // } else {
71
+    //   leftHeight.current = 0
72
+    //   rightHeight.current = 0
73
+    //   setLeftList([])
74
+    //   setRightList([])
75
+    //   renderListRef.current = list ? list.slice() : []
76
+    // }
77
+
78
+    // forceRender.current()
79
+
80
+    const lst1 = []
81
+    const lst2 = []
82
+    list.map((item, index) => {
83
+      if (index % 2 === 0) {
84
+        lst1.push(item)
85
+      } else {
86
+        lst2.push(item)
87
+      }
88
+    })
89
+
90
+    setLeftList(lst1)
91
+    setRightList(lst2)
77 92
   }, [lastList, list])
78 93
 
79 94
   return (

+ 11
- 6
src/pages/index/tabs/Recommend.jsx Прегледај датотеку

@@ -26,7 +26,6 @@ export default (props) => {
26 26
   // 获取资源表信息
27 27
   // const [alllist, setAllList] = useState([])
28 28
   const [listData, setListData] = useState({ list: [], rfTimes: 0 })
29
-  const { isSaved } = listData
30 29
 
31 30
 
32 31
   //分类标签
@@ -41,16 +40,22 @@ export default (props) => {
41 40
       ...queryParams,
42 41
       typeId: tab
43 42
     })
44
-
45
-    //如果context有的话代表他滚动了   那么切换tab页就置顶
46
-    if (listRef.current?.context) {
47
-      listRef.current.context.scrollTo({ top: 0 })
48
-    }
49 43
   }
50 44
 
51 45
   const handleDataChange = (value, e) => {
52 46
     if (e.paramsChanged) {
53 47
       rfTimes.current += 1
48
+      
49
+      //如果context有的话代表他滚动了   那么切换tab页就置顶
50
+      if (listRef.current?.context) {
51
+        Taro.nextTick(() => {
52
+          const t = setTimeout(() => {
53
+            console.log('------------>', listRef.current.context.scrollTo)
54
+            listRef.current.context.scrollTo({ top: 0 })
55
+            clearTimeout(t)
56
+          }, 500)
57
+        })
58
+      }
54 59
     }
55 60
 
56 61
     setListData({ list: value, rfTimes: rfTimes.current })

+ 11
- 1
src/utils/preFetchData.js Прегледај датотеку

@@ -25,7 +25,17 @@ export default () => {
25 25
           },
26 26
           fail(err) {
27 27
             console.error(err)
28
-            reject(err)
28
+            // reject(err)
29
+            Taro.showToast({
30
+              title: '获取定位失败',
31
+              icon: 'none',
32
+            })
33
+
34
+            // 默认新街口
35
+            const location = '116.367742,39.940667';
36
+            resolve({
37
+              location,
38
+            })
29 39
           }
30 40
         })
31 41
       }