searchCard.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. IsNull:false,
  7. Searching:true,
  8. SearchList:[],
  9. InfoArr:["拼音","默写","书写","组词","诗词","译文","发音","释义","反义词","近义词","部首","作者","翻译","例句"],
  10. },
  11. onLoad: function () {
  12. var that = this;
  13. that.setData({
  14. Containnerheight: main.getWindowHeight(),
  15. IsShowNull: false,
  16. Searching:true,
  17. });
  18. common.getStorageValue(that, "SearchTextList", [], function () {});
  19. },
  20. onShow:function(){
  21. this.setData({
  22. Focus: true,
  23. });
  24. },
  25. onKeyInput: function (e) {
  26. var search = e.detail.value;
  27. var that = this;
  28. that.setData({
  29. SearchInfo: search,
  30. });
  31. },
  32. onFocus: function (e) {
  33. var that = this;
  34. that.setData({
  35. Searching:true,
  36. IsNull:false,
  37. });
  38. },
  39. onSearch: function (e) {
  40. if (e.currentTarget.dataset.search){
  41. this.data.SearchInfo = e.currentTarget.dataset.search;
  42. this.setData({
  43. SearchInfo:this.data.SearchInfo,
  44. });
  45. }
  46. if (this.data.SearchInfo && this.data.SearchInfo.length > 0) {
  47. var search = this.data.SearchInfo;
  48. var that = this;
  49. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  50. if (search)
  51. url += "&Key=" + search;
  52. var timeoutGetData=0;
  53. wx.showLoading({
  54. title: '请稍后...',
  55. });
  56. main.getData(url, function (data) {
  57. wx.hideLoading();
  58. clearTimeout(timeoutGetData);
  59. if (data) {
  60. if (data.List.length==0){
  61. that.setData({
  62. IsNull:true,
  63. });
  64. that.getSearchData();
  65. }
  66. else{
  67. app.globalData.CardList= data.List;
  68. wx.navigateTo({
  69. url: './mainlist?search=' + search+'&Count='+data.Count,
  70. });
  71. }
  72. }
  73. });
  74. timeoutGetData=setTimeout(function(){
  75. wx.hideLoading();
  76. },10000);
  77. setTimeout(function () {
  78. var arr = that.data.SearchTextList;
  79. for (var i = 0; i < arr.length; i++) {
  80. if (arr[i] == search) {
  81. arr.splice(i, 1);
  82. break;
  83. }
  84. }
  85. arr.unshift(search);
  86. while (arr.length > 10) {
  87. arr.pop();
  88. }
  89. wx.setStorageSync("SearchTextList", arr);
  90. that.setData({
  91. SearchTextList: arr,
  92. });
  93. }, 2000);
  94. }
  95. else {
  96. wx.showToast({
  97. title: '请输搜索内容',
  98. })
  99. }
  100. },
  101. getSearchData:function(){
  102. var that=this;
  103. var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
  104. url += "&Word=" + that.data.SearchInfo;
  105. main.getData(url, function (data) {
  106. if (data) {
  107. var len = 26;
  108. var list = [];
  109. if (!data.List){
  110. list=[];
  111. var obj={};
  112. obj.Value = data;
  113. if (data.CHN){
  114. obj.Key=data.CHN.HanZi;
  115. obj.Content=data.CHN.PinYin[0].explain;
  116. if (obj.Key.length==1)
  117. obj.TypeName="Z";
  118. else
  119. obj.TypeName="C";
  120. obj.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+obj.Key;
  121. }
  122. else if (data.ENG){
  123. obj.Key=data.ENG.Word;
  124. obj.TypeName="D";
  125. obj.Remark=data.ENG.Soundmark.Eng;
  126. obj.Content=data.ENG.Paraphrase[0].ParaphraseList;
  127. obj.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+obj.Key;
  128. }
  129. if (data.CHN && data.CHN.PinYin && data.CHN.PinYin.length>0){
  130. obj.Remark=data.CHN.PinYin[0].pinyin;
  131. }
  132. if (obj.Content && obj.Content.length > len)
  133. obj.Content = obj.Content.substr(0, len) + "...";
  134. list.push(obj);
  135. }
  136. else {
  137. list=data.List;
  138. for (var i = 0; i < list.length; i++) {
  139. var item = list[i];
  140. if (item.TypeName=="字词"){
  141. if (item.Key.length==1)
  142. item.TypeName="Z";
  143. else
  144. item.TypeName="C";
  145. }
  146. else if (item.TypeName=="诗词"){
  147. item.TypeName="S";
  148. item.Remark=item.Author+" ["+item.Dynasty+"]";
  149. }
  150. else if (item.TypeName=="翻译"){
  151. item.TypeName="D";
  152. }
  153. if (item.Type=="shici")
  154. item.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+item.Key+"&Author="+item.Author+"&SearchType="+item.Type+"&Url="+item.Url;
  155. else
  156. item.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+item.Key;
  157. if (item.Content && item.Content.length > len)
  158. item.Content = item.Content.substr(0, len) + "...";
  159. }
  160. }
  161. that.setData({
  162. SearchList:list,
  163. Searching:false,
  164. });
  165. }
  166. else{
  167. that.setData({
  168. Searching:false,
  169. SearchList:[],
  170. });
  171. }
  172. });
  173. },
  174. goto: function (e) {
  175. var url = e.currentTarget.dataset.url;
  176. var url2 = e.currentTarget.dataset.url2;
  177. if (url2){
  178. url+=url2;
  179. if (url2.indexOf("&Url=")>0){
  180. var url3=url2.substr(url2.indexOf("&Url=")+5);
  181. app.globalData.TempStr=url3;
  182. url+=url.substr(0,url2.indexOf("&Url="));
  183. }
  184. }
  185. wx.navigateTo({
  186. url: url,
  187. });
  188. },
  189. clearInput:function(){
  190. this.setData({
  191. SearchInfo:"",
  192. IsNull:false,
  193. SearchList:[],
  194. });
  195. },
  196. close: function (e) {
  197. wx.navigateBack({
  198. delta: 1,
  199. });
  200. },
  201. deleteItem: function (e) {
  202. var that = this;
  203. that.setData({
  204. SearchTextList: [],
  205. });
  206. wx.removeStorageSync("SearchTextList");
  207. },
  208. onShareAppMessage: function () {
  209. return {
  210. title: app.globalData.ShareTitle,
  211. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  212. imageUrl: app.globalData.ShareImage,
  213. }
  214. },
  215. })