Browse Source

搜索优化

viczhq 3 days ago
parent
commit
9f206da706

+ 18 - 5
src/pages/indexSub/searchList/index.jsx

@@ -1,6 +1,7 @@
1
 import { Component } from "react";
1
 import { Component } from "react";
2
 import Taro from "@tarojs/taro";
2
 import Taro from "@tarojs/taro";
3
 import { View } from "@tarojs/components";
3
 import { View } from "@tarojs/components";
4
+import { AtIcon } from "taro-ui";
4
 import "./index.less";
5
 import "./index.less";
5
 import ProductList from "../../../components/index/ProductList";
6
 import ProductList from "../../../components/index/ProductList";
6
 import { getSearchProductList } from "../../../service";
7
 import { getSearchProductList } from "../../../service";
@@ -11,6 +12,7 @@ export default class Index extends Component {
11
     totalPages: 1,
12
     totalPages: 1,
12
     loading: false,
13
     loading: false,
13
     keyword: "",
14
     keyword: "",
15
+    isHasData: true,
14
   };
16
   };
15
   componentDidMount() {
17
   componentDidMount() {
16
     const { keyword }  = Taro.getCurrentInstance().router.params||"";
18
     const { keyword }  = Taro.getCurrentInstance().router.params||"";
@@ -35,7 +37,11 @@ export default class Index extends Component {
35
         : [...prevState.productList, ...res.goods_list],
37
         : [...prevState.productList, ...res.goods_list],
36
       totalPages: res.total_pages,
38
       totalPages: res.total_pages,
37
       loading: false,
39
       loading: false,
38
-    }));
40
+    }),()=>{
41
+      this.setState({
42
+        isHasData: res.goods_list.length > 0,
43
+      });
44
+    });
39
   };
45
   };
40
   // 页面上拉触底
46
   // 页面上拉触底
41
   onReachBottom = () => {
47
   onReachBottom = () => {
@@ -51,10 +57,17 @@ export default class Index extends Component {
51
     return (
57
     return (
52
       <View className="index">
58
       <View className="index">
53
         {/* 搜索列表 */}
59
         {/* 搜索列表 */}
54
-        <ProductList
55
-          productList={this.state.productList}
56
-          loading={this.state.loading}
57
-        ></ProductList>
60
+        {this.state.isHasData ? (
61
+          <ProductList
62
+            productList={this.state.productList}
63
+            loading={this.state.loading}
64
+          ></ProductList>
65
+        ) : (
66
+          <View className="no-data">
67
+            <AtIcon value="search" size="30" color="#999"></AtIcon>
68
+            <View className="no-data-text">暂无数据</View>
69
+          </View>
70
+        )}
58
       </View>
71
       </View>
59
     );
72
     );
60
   }
73
   }

+ 9 - 1
src/pages/indexSub/searchList/index.less

@@ -3,4 +3,12 @@
3
     background-color: #f9f9f9;
3
     background-color: #f9f9f9;
4
     padding-top: 20px;
4
     padding-top: 20px;
5
     box-sizing: border-box;
5
     box-sizing: border-box;
6
-}
6
+    .no-data{
7
+        display: flex;
8
+        flex-direction: column;
9
+        align-items: center;
10
+        justify-content: center;
11
+        height: 100vh;
12
+        color: #999;
13
+    }
14
+}