addInfomation.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. const WORD_LENGTH=18;
  5. Page({
  6. data: {
  7. IsStart: false,
  8. Searching: false,
  9. SearchList: [],
  10. SearchInfo: "",
  11. },
  12. onLoad: function () {
  13. var that = this;
  14. that.setData({
  15. Containnerheight: main.getWindowHeight(),
  16. });
  17. },
  18. onShow: function () {
  19. var that = this;
  20. common.getStorageValue(that, "SearchTextList", [], function () {});
  21. common.getStorageValue(that, "SearchWord3", [], function () {
  22. var list = that.data.SearchWord3;
  23. for (var i = 0; i < list.length; i++) {
  24. var item = list[i];
  25. if (item.Type == "shici") {
  26. item.TypeName = "S";
  27. item.Remark = item.Author + " " + item.Dynasty;
  28. } else if (item.Type == "eng") {
  29. item.TypeName = "D";
  30. } else {
  31. if (item.Key.length == 1)
  32. item.TypeName = "Z";
  33. else
  34. item.TypeName = "C";
  35. }
  36. if (item.Content && item.Content.length > WORD_LENGTH)
  37. item.Content = item.Content.substr(0, WORD_LENGTH) + "...";
  38. }
  39. that.setData({
  40. SearchWord3: list,
  41. });
  42. });
  43. },
  44. goto: function (e) {
  45. var url = e.currentTarget.dataset.url;
  46. wx.navigateTo({
  47. url: './' + url,
  48. })
  49. },
  50. onKeyInput: function (e) {
  51. var search = e.detail.value;
  52. var that = this;
  53. that.setData({
  54. SearchInfo: search,
  55. });
  56. },
  57. onSearchHistory: function (e) {
  58. var index = Number(e.currentTarget.dataset.index);
  59. var obj = {};
  60. if (e.currentTarget.dataset.type == "SearchWord3")
  61. obj = this.data.SearchWord3[index];
  62. else
  63. obj = this.data.SearchList[index];
  64. main.updateSearchList(obj);
  65. app.globalData.TempSearchBackNumber = 2;
  66. app.globalData.CardList2=[];
  67. wx.navigateTo({
  68. url: './addInfomationDetail',
  69. });
  70. },
  71. searchResult: function (e) {
  72. var that = this;
  73. var search = that.data.SearchInfo;
  74. if (e.currentTarget.dataset.search) {
  75. search = e.currentTarget.dataset.search;
  76. that.setData({
  77. SearchInfo:search,
  78. });
  79. }
  80. var searchtype=e.currentTarget.dataset.searchtype;
  81. var author=e.currentTarget.dataset.author;
  82. var shiciurl=e.currentTarget.dataset.shiciurl;
  83. main.searchInfomation(search,searchtype,author,shiciurl,function(list,obj){
  84. if (obj){
  85. main.updateSearchList(obj,function(){
  86. wx.navigateTo({
  87. url: './addInfomationDetail',
  88. });
  89. });
  90. }
  91. else{
  92. wx.setNavigationBarTitle({
  93. title: "搜索结果"
  94. });
  95. that.setData({
  96. SearchList: list,
  97. IsStart: true,
  98. });
  99. that.getCardList();
  100. setTimeout(function () {
  101. var arr = that.data.SearchTextList;
  102. for (var i = 0; i < arr.length; i++) {
  103. if (arr[i] == search) {
  104. arr.splice(i, 1);
  105. break;
  106. }
  107. }
  108. arr.unshift(search);
  109. while (arr.length > 10) {
  110. arr.pop();
  111. }
  112. wx.setStorageSync("SearchTextList", arr);
  113. that.setData({
  114. SearchTextList: arr,
  115. });
  116. }, 2000);
  117. }
  118. });
  119. // wx.showLoading({
  120. // title: '查询中',
  121. // });
  122. // var timeout=setTimeout(function () {
  123. // wx.hideLoading();
  124. // }, 5000);
  125. // var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
  126. // url += "&Word=" + search;
  127. // if (e.currentTarget.dataset.searchtype)
  128. // url += "&SearchType=" + e.currentTarget.dataset.searchtype;
  129. // if (e.currentTarget.dataset.author)
  130. // url += "&Author=" + e.currentTarget.dataset.author;
  131. // if (e.currentTarget.dataset.shiciurl)
  132. // url += "&ShiciUrl=" + e.currentTarget.dataset.shiciurl;
  133. // main.getData(url, function (data) {
  134. // wx.hideLoading();
  135. // clearTimeout(timeout);
  136. // wx.setNavigationBarTitle({
  137. // title: "搜索结果"
  138. // });
  139. // if (data) {
  140. // //console.log(data);
  141. // if (data.List) {
  142. // var len = WORD_LENGTH;
  143. // var list = data.List;
  144. // for (var i = 0; i < list.length; i++) {
  145. // var item = list[i];
  146. // if (item.TypeName == "字词") {
  147. // if (item.Key.length == 1)
  148. // item.TypeName = "Z";
  149. // else
  150. // item.TypeName = "C";
  151. // } else if (item.TypeName == "诗词") {
  152. // item.TypeName = "S";
  153. // item.Remark = item.Author + " " + item.Dynasty;
  154. // } else if (item.TypeName == "翻译") {
  155. // item.TypeName = "D";
  156. // }
  157. // if (item.Content && item.Content.length > len)
  158. // item.Content = item.Content.substr(0, len) + "...";
  159. // }
  160. // that.setData({
  161. // SearchList: list,
  162. // IsStart: true,
  163. // });
  164. // } else if (data.CHN || data.ENG) {
  165. // var obj = {};
  166. // obj.Key = search;
  167. // obj.Value = data;
  168. // if (data.CHN && data.CHN.Author)
  169. // obj.Author = data.CHN.Author;
  170. // if (data.CHN && data.CHN.Dynasty)
  171. // obj.Dynasty = data.CHN.Dynasty;
  172. // if (data.CHN && data.CHN.PeomContent) {
  173. // obj.Type = "shici";
  174. // obj.TypeName = "诗词";
  175. // obj.Content = data.CHN.PeomContent.join("").substr(0, WORD_LENGTH);
  176. // obj.ShiciUrl = e.currentTarget.dataset.shiciurl;
  177. // } else if (data.CHN) {
  178. // obj.Type = "zici";
  179. // if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].pinyin)
  180. // obj.Remark = data.CHN.PinYin[0].pinyin;
  181. // if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].explain) {
  182. // obj.Content = data.CHN.PinYin[0].explain.substr(0, WORD_LENGTH);
  183. // obj.Content = obj.Content.replace("<p>", "");
  184. // obj.Content = obj.Content.replace("</p>", "");
  185. // if (obj.Content.length >= WORD_LENGTH)
  186. // obj.Content += "..."
  187. // }
  188. // }
  189. // if (data.ENG && !data.CHN) {
  190. // obj.Type = "eng";
  191. // obj.TypeName = "D";
  192. // if (data.ENG.Soundmark && data.ENG.Soundmark.Eng)
  193. // obj.Remark = data.ENG.Soundmark.Eng;
  194. // if (data.ENG.Paraphrase.length > 0) {
  195. // if (common.checkIsArray(data.ENG.Paraphrase) && data.ENG.Paraphrase[0].ParaphraseList)
  196. // obj.Content = data.ENG.Paraphrase[0].ParaphraseList.join("; ").substr(0, WORD_LENGTH);
  197. // else
  198. // obj.Content = data.ENG.Paraphrase.substr(0, WORD_LENGTH) + "...";
  199. // }
  200. // }
  201. // main.updateSearchList(obj);
  202. // app.globalData.TempSearchBackNumber = 2;
  203. // //app.globalData.CardList=[];
  204. // app.globalData.CardList2=[];
  205. // wx.navigateTo({
  206. // url: './addInfomationDetail',
  207. // });
  208. // }
  209. // else{
  210. // that.setData({
  211. // SearchList: [],
  212. // IsStart: true,
  213. // });
  214. // }
  215. // } else {
  216. // that.setData({
  217. // SearchList: [],
  218. // IsStart: true,
  219. // });
  220. // }
  221. // });
  222. },
  223. getCardList: function () {
  224. var that = this;
  225. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  226. url += "&Key=" + that.data.SearchInfo;
  227. that.setData({
  228. Searching: true,
  229. });
  230. main.getData(url, function (data) {
  231. that.setData({
  232. Searching: false,
  233. });
  234. if (data) {
  235. if (data.List.length > 0) {
  236. var list=data.List;
  237. for (var i = 0; i < list.length; i++) {
  238. var item = list[i];
  239. item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].Content);
  240. if (item.Content[1].ContentStr.length > WORD_LENGTH)
  241. item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].ContentStr.substr(0, WORD_LENGTH)) + "...";
  242. item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].Content);
  243. if (item.Content[2].ContentStr.length > WORD_LENGTH)
  244. item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].ContentStr.substr(0, WORD_LENGTH)) + "...";
  245. var imageUrl = getImage(item.Content[1].Content);
  246. if (imageUrl.length == 0 && item.Content[2].Content)
  247. imageUrl = getImage(item.Content[2].Content);
  248. if (imageUrl.length == 0 && item.Content[3].Content)
  249. imageUrl = getImage(item.Content[3].Content);
  250. if (imageUrl.length > 0) {
  251. item.ImageUrlTemp = main.getTempImage(imageUrl);
  252. item.ImageUrlServer = imageUrl;
  253. }
  254. }
  255. that.setData({
  256. SearchCardList:list,
  257. });
  258. app.globalData.CardList2=list;
  259. }
  260. else{
  261. that.setData({
  262. SearchCardList:[],
  263. });
  264. }
  265. }
  266. });
  267. function getImage(str) {
  268. var result = "";
  269. if (str.indexOf("[图") >= 0) {
  270. result = str.substring(str.indexOf("[图") + 3, str.indexOf("[/图]"));
  271. result = result.substring(result.indexOf("]") + 1);
  272. }
  273. //console.log(result);
  274. return result;
  275. }
  276. },
  277. clearInput: function () {
  278. this.setData({
  279. IsStart: false,
  280. Searching: false,
  281. SearchInfo: "",
  282. Focus:true,
  283. });
  284. },
  285. close: function (e) {
  286. wx.navigateBack({
  287. delta: 1,
  288. });
  289. },
  290. deleteItem: function (e) {
  291. var that = this;
  292. that.setData({
  293. SearchTextList: [],
  294. });
  295. wx.removeStorageSync("SearchTextList");
  296. },
  297. deleteItem2: function (e) {
  298. var that = this;
  299. var index = e.currentTarget.dataset.index;
  300. that.data.SearchWord3.splice(index, 1);
  301. that.setData({
  302. SearchWord3: that.data.SearchWord3,
  303. });
  304. wx.setStorageSync("SearchWord3", that.data.SearchWord3);
  305. },
  306. onShareAppMessage: function () {
  307. return {
  308. title: app.globalData.ShareTitle,
  309. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  310. imageUrl: app.globalData.ShareImage,
  311. }
  312. },
  313. });