Authored by QC-L

更新搜索相关逻辑 review by 黄敬囿

@@ -41,8 +41,8 @@ @@ -41,8 +41,8 @@
41 } 41 }
42 .progress-box { 42 .progress-box {
43 /* position: absolute; */ 43 /* position: absolute; */
44 - width: 220rpx;  
45 - height: 220rpx; 44 + width: 240rpx;
  45 + height: 240rpx;
46 display: flex; 46 display: flex;
47 margin-right: 50rpx; 47 margin-right: 50rpx;
48 /* align-items: center; */ 48 /* align-items: center; */
@@ -53,13 +53,13 @@ @@ -53,13 +53,13 @@
53 53
54 .progress-bg { 54 .progress-bg {
55 position: absolute; 55 position: absolute;
56 - width: 220rpx;  
57 - height: 220rpx; 56 + width: 240rpx;
  57 + height: 240rpx;
58 } 58 }
59 59
60 .progress-canvas { 60 .progress-canvas {
61 - width: 220rpx;  
62 - height: 220rpx; 61 + width: 240rpx;
  62 + height: 240rpx;
63 } 63 }
64 64
65 .progress-text { 65 .progress-text {
@@ -66,28 +66,39 @@ export default class Search extends Component { @@ -66,28 +66,39 @@ export default class Search extends Component {
66 if (e.detail.value === '') { 66 if (e.detail.value === '') {
67 return; 67 return;
68 } 68 }
69 - this.savaLateSearch(e); 69 + this.saveLateSearch(e);
70 router.go('productList', { 70 router.go('productList', {
71 query: e.detail.value 71 query: e.detail.value
72 }); 72 });
73 } 73 }
74 74
75 - savaLateSearch(e) { 75 + saveLateSearch(e) {
76 const latelySearch = this.state.latelySearch; 76 const latelySearch = this.state.latelySearch;
77 if (latelySearch.length >= 10) { 77 if (latelySearch.length >= 10) {
78 latelySearch.pop(); 78 latelySearch.pop();
79 } 79 }
80 - latelySearch.unshift({search_word: e.detail.value});  
81 - try {  
82 - Taro.setStorageSync('latelySearch', latelySearch); 80 + let setList = this.removeSameSearch(latelySearch, e.detail.value);
  81 + setList.unshift({search_word: e.detail.value});
  82 + try {
  83 + Taro.setStorageSync('latelySearch', setList);
83 } catch (error) { 84 } catch (error) {
84 console.log(error); 85 console.log(error);
85 } 86 }
86 - this.setState({  
87 - latelySearch  
88 - }) 87 + // this.setState({
  88 + // latelySearch
  89 + // })
89 } 90 }
90 91
  92 + removeSameSearch(arr, search_word) {
  93 + let hash = [];
  94 + for (var i = 0; i < arr.length; i++) {
  95 + if (arr[i].search_word !== search_word) {
  96 + hash.push(arr[i]);
  97 + }
  98 + }
  99 + return hash;
  100 + }
  101 +
91 onRemoveAllSearch() { 102 onRemoveAllSearch() {
92 try { 103 try {
93 Taro.setStorageSync('latelySearch', []); 104 Taro.setStorageSync('latelySearch', []);
@@ -277,13 +277,24 @@ export default class SearchList extends Component { @@ -277,13 +277,24 @@ export default class SearchList extends Component {
277 if (searchList.length >= 10) { 277 if (searchList.length >= 10) {
278 searchList.pop(); 278 searchList.pop();
279 } 279 }
280 - searchList.unshift({search_word: e.detail.value}); 280 + let setList = this.removeSameSearch(searchList, e.detail.value);
  281 + setList.unshift({ search_word: e.detail.value });
281 try { 282 try {
282 - Taro.setStorageSync('latelySearch', searchList); 283 + Taro.setStorageSync('latelySearch', setList);
283 } catch (error) { 284 } catch (error) {
284 console.log(error); 285 console.log(error);
285 } 286 }
286 } 287 }
  288 +
  289 + removeSameSearch(arr, search_word) {
  290 + let hash = [];
  291 + for (var i = 0; i < arr.length; i++) {
  292 + if (arr[i].search_word !== search_word) {
  293 + hash.push(arr[i]);
  294 + }
  295 + }
  296 + return hash;
  297 + }
287 298
288 goYohoBuyMinApp() { 299 goYohoBuyMinApp() {
289 wx.navigateToMiniProgram({ 300 wx.navigateToMiniProgram({
1 'use strict'; 1 'use strict';
2 -var strictUriEncode = require('strict-uri-encode');  
3 -var objectAssign = require('object-assign'); 2 +var strictUriEncode = require('./strict-uri-encode');
  3 +var objectAssign = require('./object-assign');
4 4
5 function encode(value, opts) { 5 function encode(value, opts) {
6 if (opts.encode) { 6 if (opts.encode) {