searchWeb1.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. },
  7. onLoad: function () {
  8. wx.hideShareMenu();
  9. var that = this;
  10. that.setData({
  11. Containnerheight: main.getWindowHeight(),
  12. IsShowNull: false,
  13. });
  14. },
  15. onShow:function(){
  16. if (wx.getStorageSync("SearchNull")){
  17. this.setData({
  18. IsShowNull:true,
  19. })
  20. wx.removeStorageSync("SearchNull");
  21. }
  22. },
  23. onKeyInput: function (e) {
  24. var search = e.detail.value;
  25. var that = this;
  26. that.setData({
  27. SearchInfo: search,
  28. });
  29. },
  30. onSearch: function (e) {
  31. if (this.data.SearchInfo && this.data.SearchInfo.length>0){
  32. var search = this.data.SearchInfo;
  33. var arr=wx.getStorageSync("SearchWord");
  34. if (!arr)
  35. arr=[];
  36. var obj = {};
  37. obj.Key = search;
  38. for(var i=0;i<arr.length;i++){
  39. if (arr[i].Key == search){
  40. obj.Key = arr[i].Key;
  41. obj.Value = arr[i].Value;
  42. arr.splice(i,1);
  43. break;
  44. }
  45. }
  46. arr.unshift(obj);
  47. wx.setStorageSync("SearchWord", arr);
  48. wx.navigateTo({
  49. url: './searchWeb2?back=3&search=' + search+'&type=0',
  50. })
  51. }
  52. else{
  53. wx.showToast({
  54. title: '请输搜索内容',
  55. })
  56. }
  57. },
  58. onSearchHistory: function (e) {
  59. var search = e.currentTarget.dataset.search;
  60. var arr = wx.getStorageSync("SearchWord");
  61. if (!arr)
  62. arr = [];
  63. var obj = {};
  64. obj.Key = search;
  65. var b=false,type=0;
  66. for (var i = 0; i < arr.length; i++) {
  67. if (arr[i].Key == search) {
  68. obj.Key = arr[i].Key;
  69. obj.Value = arr[i].Value;
  70. arr.splice(i, 1);
  71. b=true;
  72. type=1
  73. break;
  74. }
  75. }
  76. if (b){
  77. arr.unshift(obj);
  78. wx.setStorageSync("SearchWord", arr);
  79. }
  80. wx.navigateTo({
  81. url: './searchWeb2?back=2&search=' + search + '&type='+type,
  82. });
  83. },
  84. close: function (e) {
  85. wx.navigateBack({
  86. delta: 1,
  87. });
  88. },
  89. onShareAppMessage: function () {
  90. return {
  91. title: app.globalData.ShareTitle,
  92. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  93. imageUrl: app.globalData.ShareImage,
  94. }
  95. },
  96. })