yangchenggong1_wd

desc:历史搜索 关联用户

@@ -34,6 +34,8 @@ export struct SearchComponent { @@ -34,6 +34,8 @@ export struct SearchComponent {
34 aboutToAppear() { 34 aboutToAppear() {
35 //获取提示滚动 35 //获取提示滚动
36 this.getSearchHint() 36 this.getSearchHint()
  37 + //清除缓存
  38 + SearcherAboutDataModel.searchHistoryData = []
37 //获取搜索历史 39 //获取搜索历史
38 this.getSearchHistoryData() 40 this.getSearchHistoryData()
39 } 41 }
@@ -80,7 +80,7 @@ export struct SearchHotsComponent{ @@ -80,7 +80,7 @@ export struct SearchHotsComponent{
80 .fontWeight('400lpx') 80 .fontWeight('400lpx')
81 .lineHeight('42lpx') 81 .lineHeight('42lpx')
82 }.layoutWeight(1) 82 }.layoutWeight(1)
83 - if(item.mark!=0){ 83 + if(item.mark===1 || item.mark===2){
84 Image(item.mark===1?$r('app.media.search_hots_mark1'):$r('app.media.search_hots_mark2')) 84 Image(item.mark===1?$r('app.media.search_hots_mark1'):$r('app.media.search_hots_mark2'))
85 .width('42lpx') 85 .width('42lpx')
86 .height('31lpx') 86 .height('31lpx')
1 1
2 -import { Logger, SPHelper, UserDataLocal } from 'wdKit'; 2 +import { Logger, SPHelper, StringUtils, UserDataLocal } from 'wdKit';
3 import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork'; 3 import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
4 import { SearchHistoryItem } from '../viewmodel/SearchHistoryItem'; 4 import { SearchHistoryItem } from '../viewmodel/SearchHistoryItem';
5 import { SearchHotContentItem } from '../viewmodel/SearchHotContentItem'; 5 import { SearchHotContentItem } from '../viewmodel/SearchHotContentItem';
@@ -18,7 +18,7 @@ const TAG = "SearcherAboutDataModel" @@ -18,7 +18,7 @@ const TAG = "SearcherAboutDataModel"
18 class SearcherAboutDataModel{ 18 class SearcherAboutDataModel{
19 private static instance: SearcherAboutDataModel; 19 private static instance: SearcherAboutDataModel;
20 public searchHistoryData:SearchHistoryItem[] = [] 20 public searchHistoryData:SearchHistoryItem[] = []
21 - public SEARCH_HISTORY_KEY:string = "SEARCH_HISTORY_KEY" + UserDataLocal.getUserId() 21 + public SEARCH_HISTORY_KEY:string = "SEARCH_HISTORY_KEY"
22 22
23 private constructor() { } 23 private constructor() { }
24 24
@@ -37,7 +37,7 @@ class SearcherAboutDataModel{ @@ -37,7 +37,7 @@ class SearcherAboutDataModel{
37 * 插入搜索记录(单个) 37 * 插入搜索记录(单个)
38 */ 38 */
39 public async putSearchHistoryData(content:string){ 39 public async putSearchHistoryData(content:string){
40 - let history = SPHelper.default.getSync(this.SEARCH_HISTORY_KEY,"[]") as string 40 + let history = SPHelper.default.getSync(this.generationSearchKey(),"[]") as string
41 this.searchHistoryData = JSON.parse(history) 41 this.searchHistoryData = JSON.parse(history)
42 this.searchHistoryData.forEach((element,index) => { 42 this.searchHistoryData.forEach((element,index) => {
43 if (element.searchContent == content) { 43 if (element.searchContent == content) {
@@ -45,14 +45,14 @@ class SearcherAboutDataModel{ @@ -45,14 +45,14 @@ class SearcherAboutDataModel{
45 } 45 }
46 }); 46 });
47 this.searchHistoryData.splice(0,0,new SearchHistoryItem(content)) 47 this.searchHistoryData.splice(0,0,new SearchHistoryItem(content))
48 - await SPHelper.default.saveSync(this.SEARCH_HISTORY_KEY, JSON.stringify(this.searchHistoryData)); 48 + await SPHelper.default.saveSync(this.generationSearchKey(), JSON.stringify(this.searchHistoryData));
49 } 49 }
50 50
51 /** 51 /**
52 * 删除搜索记录(所有) 52 * 删除搜索记录(所有)
53 */ 53 */
54 public async delSearchHistoryData(){ 54 public async delSearchHistoryData(){
55 - SPHelper.default.deleteSync(this.SEARCH_HISTORY_KEY) 55 + SPHelper.default.deleteSync(this.generationSearchKey())
56 this.searchHistoryData = [] 56 this.searchHistoryData = []
57 } 57 }
58 /** 58 /**
@@ -62,11 +62,11 @@ class SearcherAboutDataModel{ @@ -62,11 +62,11 @@ class SearcherAboutDataModel{
62 if(this.searchHistoryData!=null && this.searchHistoryData.length>0){ 62 if(this.searchHistoryData!=null && this.searchHistoryData.length>0){
63 this.searchHistoryData.splice(index,1) 63 this.searchHistoryData.splice(index,1)
64 }else{ 64 }else{
65 - let history = SPHelper.default.getSync(this.SEARCH_HISTORY_KEY,"[]") as string 65 + let history = SPHelper.default.getSync(this.generationSearchKey(),"[]") as string
66 this.searchHistoryData = JSON.parse(history) 66 this.searchHistoryData = JSON.parse(history)
67 this.searchHistoryData.splice(index,1) 67 this.searchHistoryData.splice(index,1)
68 } 68 }
69 - SPHelper.default.saveSync(this.SEARCH_HISTORY_KEY, JSON.stringify(this.searchHistoryData)) 69 + SPHelper.default.saveSync(this.generationSearchKey(), JSON.stringify(this.searchHistoryData))
70 } 70 }
71 71
72 /** 72 /**
@@ -79,7 +79,7 @@ class SearcherAboutDataModel{ @@ -79,7 +79,7 @@ class SearcherAboutDataModel{
79 } 79 }
80 return this.searchHistoryData 80 return this.searchHistoryData
81 } 81 }
82 - let history = SPHelper.default.getSync(this.SEARCH_HISTORY_KEY,"[]") as string 82 + let history = SPHelper.default.getSync(this.generationSearchKey(),"[]") as string
83 83
84 this.searchHistoryData = JSON.parse(history) 84 this.searchHistoryData = JSON.parse(history)
85 if(this.searchHistoryData.length>10){ 85 if(this.searchHistoryData.length>10){
@@ -91,6 +91,15 @@ class SearcherAboutDataModel{ @@ -91,6 +91,15 @@ class SearcherAboutDataModel{
91 return this.searchHistoryData 91 return this.searchHistoryData
92 } 92 }
93 93
  94 + public generationSearchKey():string{
  95 + let userId = UserDataLocal.getUserId()
  96 + if(StringUtils.isEmpty(userId)){
  97 + return this.SEARCH_HISTORY_KEY + "_" + "0000111122223333"
  98 + }else{
  99 + return this.SEARCH_HISTORY_KEY + "_" + userId
  100 + }
  101 + }
  102 +
94 /** 103 /**
95 * 首页 搜索提示滚动内容 104 * 首页 搜索提示滚动内容
96 */ 105 */
1 import { Logger } from 'wdKit/src/main/ets/utils/Logger' 1 import { Logger } from 'wdKit/src/main/ets/utils/Logger'
2 import { LoginModel } from './LoginModel' 2 import { LoginModel } from './LoginModel'
3 import { LoginBean } from './LoginBean' 3 import { LoginBean } from './LoginBean'
4 -import { SPHelper, StringUtils } from 'wdKit' 4 +import { SPHelper, StringUtils, UserDataLocal } from 'wdKit'
5 import { CheckVerifyBean } from './CheckVerifyBean' 5 import { CheckVerifyBean } from './CheckVerifyBean'
6 import cryptoFramework from '@ohos.security.cryptoFramework' 6 import cryptoFramework from '@ohos.security.cryptoFramework'
7 import buffer from '@ohos.buffer' 7 import buffer from '@ohos.buffer'
@@ -157,6 +157,7 @@ export class LoginViewModel { @@ -157,6 +157,7 @@ export class LoginViewModel {
157 SPHelper.default.saveSync(SpConstants.USER_STATUS, '') 157 SPHelper.default.saveSync(SpConstants.USER_STATUS, '')
158 SPHelper.default.saveSync(SpConstants.USER_Type, '') 158 SPHelper.default.saveSync(SpConstants.USER_Type, '')
159 SPHelper.default.saveSync(SpConstants.USER_NAME, '') 159 SPHelper.default.saveSync(SpConstants.USER_NAME, '')
  160 + UserDataLocal.clearUserData()
160 success(data) 161 success(data)
161 }).catch((message: string) => { 162 }).catch((message: string) => {
162 fail(message) 163 fail(message)