bhd-components 0.7.21 → 0.7.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,8 +11,35 @@ var TeacherList = function(props) {
11
11
  var _useState = _sliced_to_array(useState(""), 2), keyWordProblem = _useState[0], setKeyWordProblem = _useState[1]; //搜索内容
12
12
  var _useState1 = _sliced_to_array(useState(1), 2), showLoadingState = _useState1[0], setShowLoadingState = _useState1[1]; //1,初始状态,2、无数据 ,3、不显示图片
13
13
  var _useState2 = _sliced_to_array(useState([]), 2), totalData = _useState2[0], setTotalData = _useState2[1]; //总数据
14
- var _useState3 = _sliced_to_array(useState([]), 2), teacher_list = _useState3[0], setTeacher_list = _useState3[1]; //老师列表,有头像
14
+ // const [teacher_list, setTeacher_list] = useState([]); //老师列表,有头像
15
+ var teacher_list = useRef([]); //老师列表,有头像
15
16
  var timer = useRef(null); //文本框输入时
17
+ var page = useRef(1);
18
+ var loading = useRef(true);
19
+ var sliderRef = useRef(null);
20
+ useEffect(function() {
21
+ var handleScroll = function(e) {
22
+ // 处理滚轮事件的逻辑
23
+ var container = document.getElementById("teacher_list");
24
+ var scrollTop = container.scrollTop;
25
+ var clientHeight = container.clientHeight;
26
+ var scrollHeight = container.scrollHeight;
27
+ if (scrollTop + clientHeight + 60 >= scrollHeight && loading.current) {
28
+ loading.current = false;
29
+ // console.log('加载下一页');
30
+ page.current = page.current + 1;
31
+ getList(keyWordProblem);
32
+ }
33
+ };
34
+ // 添加滚轮事件监听器
35
+ sliderRef.current.addEventListener("wheel", handleScroll);
36
+ // 清除滚轮事件监听器
37
+ return function() {
38
+ sliderRef.current.removeEventListener("wheel", handleScroll);
39
+ };
40
+ }, [
41
+ keyWordProblem
42
+ ]);
16
43
  useEffect(function() {
17
44
  getList("");
18
45
  return function() {
@@ -20,17 +47,32 @@ var TeacherList = function(props) {
20
47
  };
21
48
  }, []);
22
49
  var getList = function(val) {
50
+ if (page.current == 1) {
51
+ setTotalData([]);
52
+ }
23
53
  http.get("".concat(urllocation, "/chat-service/public/v1.0/teachers"), {
24
54
  params: {
25
- name: val
55
+ name: val,
56
+ page: page.current,
57
+ maxPageSize: 20
26
58
  }
27
59
  }).then(function(res) {
28
60
  console.log(res);
29
- var data = res.data;
30
- if (data.total > 0) {
61
+ if (res.data.total > 0) {
62
+ loading.current = true;
31
63
  setShowLoadingState(3);
32
- setTotalData(res.data.teachers);
64
+ var data = new Map();
65
+ setTotalData(function(totalData) {
66
+ return totalData.concat(res.data.teachers).filter(function(a) {
67
+ return !data.has(a.uid) && data.set(a.uid, 1);
68
+ });
69
+ });
33
70
  getUserName(res.data.teachers);
71
+ } else {
72
+ loading.current = false;
73
+ if (page.current == 1) {
74
+ setShowLoadingState(2);
75
+ }
34
76
  }
35
77
  });
36
78
  };
@@ -39,7 +81,7 @@ var TeacherList = function(props) {
39
81
  var list = dataList;
40
82
  var ids = [];
41
83
  list = list.map(function(item) {
42
- if (!item.headImg && teacher_list.filter(function(v) {
84
+ if (!item.headImg && teacher_list.current.filter(function(v) {
43
85
  return v.uid == item.uid;
44
86
  }).length <= 0) {
45
87
  ids.push(item.uid);
@@ -58,16 +100,27 @@ var TeacherList = function(props) {
58
100
  if (name.length > 0) {
59
101
  return _object_spread({}, item, name[0]);
60
102
  } else {
61
- return item;
103
+ var nameList1 = teacher_list.current;
104
+ var name1 = nameList1.filter(function(v) {
105
+ return v.uid == item.uid;
106
+ });
107
+ if (name1.length > 0) {
108
+ return _object_spread({}, item, name1[0]);
109
+ } else {
110
+ return item;
111
+ }
62
112
  }
63
113
  });
64
- setTeacher_list(list);
114
+ var data = new Map();
115
+ teacher_list.current = teacher_list.current.concat(list).filter(function(a) {
116
+ return !data.has(a.uid) && data.set(a.uid, 1);
117
+ });
65
118
  return list;
66
119
  });
67
120
  }
68
121
  });
69
122
  } else {
70
- var nameList = teacher_list;
123
+ var nameList = teacher_list.current;
71
124
  setTotalData(function(list1) {
72
125
  var list = list1;
73
126
  list = list.map(function(item) {
@@ -80,7 +133,6 @@ var TeacherList = function(props) {
80
133
  return item;
81
134
  }
82
135
  });
83
- setTeacher_list(list);
84
136
  return list;
85
137
  });
86
138
  }
@@ -131,13 +183,9 @@ var TeacherList = function(props) {
131
183
  setKeyWordProblem(val);
132
184
  clearTimeout(timer.current);
133
185
  timer.current = setTimeout(function() {
134
- if (val != "") {
135
- setTotalData([]);
136
- getList(val);
137
- } else {
138
- setShowLoadingState(1);
139
- setTotalData([]);
140
- }
186
+ page.current = 1;
187
+ setTotalData([]);
188
+ getList(val);
141
189
  }, 1000);
142
190
  }
143
191
  }),
@@ -154,7 +202,7 @@ var TeacherList = function(props) {
154
202
  }),
155
203
  /*#__PURE__*/ _jsxs("div", {
156
204
  className: styles.main_list,
157
- id: "history_list",
205
+ id: "teacher_list",
158
206
  children: [
159
207
  showLoadingState == 1 && /*#__PURE__*/ _jsxs("div", {
160
208
  className: styles.no_data,
@@ -174,12 +222,13 @@ var TeacherList = function(props) {
174
222
  src: "/new_yun/images/aiService/no_data.png"
175
223
  }),
176
224
  /*#__PURE__*/ _jsx("p", {
177
- children: "暂无记录"
225
+ children: "未搜索到老师"
178
226
  })
179
227
  ]
180
228
  }),
181
229
  /*#__PURE__*/ _jsx("div", {
182
230
  className: styles.list_item,
231
+ ref: sliderRef,
183
232
  children: totalData.map(function(item) {
184
233
  var span = item.name.replaceAll(new RegExp(keyWordProblem, "ig"), function(i) {
185
234
  return "<span class=".concat(styles.sign, ">").concat(i, "</span>");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bhd-components",
3
- "version": "0.7.21",
3
+ "version": "0.7.22",
4
4
  "description": "组件功能描述",
5
5
  "files": [
6
6
  "esm",