searchWeb1.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. ListOther: [{
  7. Key: '愛', Type: 'zici'
  8. }, {
  9. Key: '饕餮', Type: 'zici'
  10. }, {
  11. Key: '鸿鹄之志', Type: 'zici'
  12. }, {
  13. Key: '天净沙·秋思', Type: 'shici'
  14. }, {
  15. Key: 'success', Type: 'zici'
  16. }, {
  17. Key: 'Study hard and make progress every day.', Type: 'eng'
  18. }
  19. ]
  20. },
  21. onLoad: function () {
  22. wx.hideShareMenu();
  23. var that = this;
  24. that.setData({
  25. Containnerheight: main.getWindowHeight(),
  26. IsShowNull: false,
  27. });
  28. app.globalData.SearchResultList = [];
  29. app.globalData.SearchNull = 0;
  30. common.getStorageValue(that, "SearchTextList", [], function () {
  31. });
  32. },
  33. onShow: function () {
  34. if (app.globalData.SearchNull == 1) {
  35. var len = 26;
  36. var list = app.globalData.SearchResultList;
  37. for (var i = 0; i < list.length; i++) {
  38. var item = list[i];
  39. if (item.Content && item.Content.length > len)
  40. item.Content = item.Content.substr(0, len) + "...";
  41. }
  42. this.setData({
  43. List: list,
  44. });
  45. app.globalData.SearchNull = 0;
  46. }
  47. },
  48. onKeyInput: function (e) {
  49. var search = e.detail.value;
  50. var that = this;
  51. that.setData({
  52. SearchInfo: search,
  53. });
  54. },
  55. onSearch: function (e) {
  56. var that = this;
  57. if (e.currentTarget.dataset.search)
  58. this.data.SearchInfo = e.currentTarget.dataset.search;
  59. if (this.data.SearchInfo && this.data.SearchInfo.length > 0) {
  60. var search = this.data.SearchInfo;
  61. that.searchResult(search);
  62. var arr = that.data.SearchTextList;
  63. for (var i = 0; i < arr.length; i++) {
  64. if (arr[i] == search) {
  65. arr.splice(i, 1);
  66. break;
  67. }
  68. }
  69. arr.unshift(search);
  70. wx.setStorageSync("SearchTextList", arr);
  71. that.setData({
  72. SearchTextList: arr,
  73. });
  74. }
  75. else {
  76. wx.showToast({
  77. title: '请输搜索内容',
  78. })
  79. }
  80. },
  81. onSearchSelect: function (e) {
  82. var search = e.currentTarget.dataset.search;
  83. var searchType = e.currentTarget.dataset.searchtype;
  84. var author = e.currentTarget.dataset.author;
  85. wx.navigateTo({
  86. url: './searchWeb2?search=' + search + '&searchType=' + searchType + '&author=' + author,
  87. });
  88. },
  89. close: function (e) {
  90. wx.navigateBack({
  91. delta: 1,
  92. });
  93. },
  94. deleteItem: function (e) {
  95. var that = this;
  96. var index = e.currentTarget.dataset.id;
  97. that.data.SearchTextList.splice(index, 1);
  98. that.setData({
  99. SearchTextList: that.data.SearchTextList,
  100. });
  101. wx.setStorageSync("SearchTextList", that.data.SearchTextList);
  102. },
  103. searchResult: function (search, searchType, author,dynasty,content) {
  104. wx.showLoading({
  105. title: '查询中',
  106. });
  107. var that = this;
  108. var arr = wx.getStorageSync("SearchWord2");
  109. if (!arr)
  110. arr = [];
  111. var obj = {};
  112. obj.Key = search;
  113. if (searchType)
  114. obj.Type = searchType;
  115. else
  116. obj.Type = "zici";
  117. if (author)
  118. obj.Author = author;
  119. if (dynasty)
  120. obj.dynasty = dynasty;
  121. if (content)
  122. obj.Content = content;
  123. var b = false;
  124. for (var i = 0; i < arr.length; i++) {
  125. if (arr[i].Key == search
  126. && arr[i].Type == searchType
  127. && arr[i].Author == author) {
  128. obj.Value = arr[i].Value;
  129. arr.splice(i, 1);
  130. b = true;
  131. break;
  132. }
  133. }
  134. if (b) {
  135. arr.unshift(obj);
  136. wx.setStorageSync("SearchWord2", arr);
  137. app.globalData.SearchItem=obj.Value;
  138. wx.hideLoading();
  139. wx.navigateTo({
  140. url: './searchWeb2?back=3',
  141. });
  142. }
  143. else {
  144. var url = 'GetMiaoguoAISearch?UserID=' + app.globalData.userInfo.UserID;
  145. url += "&Word=" + search;
  146. if (searchType)
  147. url += "&SearchType=" + searchType;
  148. if (author)
  149. url += "&Author=" + author;
  150. main.getData(url, function (data) {
  151. wx.hideLoading();
  152. searchType = "";
  153. author = "";
  154. if (data) {
  155. //console.log(data);
  156. if (data.List) {
  157. app.globalData.SearchResultList = data.List;
  158. app.globalData.SearchNull = 1;
  159. wx.navigateBack({
  160. delta: 1,
  161. });
  162. }
  163. else {
  164. obj.Value = data;
  165. if (data.CHN && data.CHN.Author)
  166. obj.Author = data.CHN.Author;
  167. if (data.CHN && data.CHN.PeomContent)
  168. obj.Type = "shici";
  169. arr.unshift(obj);
  170. if (arr.length > 100) {
  171. arr.pop();
  172. }
  173. wx.setStorageSync("SearchWord2", arr);
  174. that.getListFinished(data);
  175. }
  176. }
  177. else {
  178. app.globalData.SearchNull = 1;
  179. app.globalData.SearchResultList = [];
  180. wx.navigateBack({
  181. delta: 1,
  182. });
  183. }
  184. });
  185. }
  186. },
  187. onShareAppMessage: function () {
  188. return {
  189. title: app.globalData.ShareTitle,
  190. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  191. imageUrl: app.globalData.ShareImage,
  192. }
  193. },
  194. })