import common from '../../utils/util'; import main from '../../utils/main'; const app = getApp(); Page({ data: { ListOther: [{ Key: '愛', Type: 'zici', TypeName: '字词' }, { Key: '饕餮', Type: 'zici', TypeName: '字词' }, { Key: '鸿鹄之志', Type: 'zici', TypeName: '字词' }, { Key: '咏鹅', Type: 'shici', Author: '骆宾王', Dynasty: '唐', TypeName: '诗词' }, { Key: '天净沙·秋思', Type: 'shici', Author: '马致远', Dynasty: '元', TypeName: '诗词' }, { Key: 'success', Type: 'zici', TypeName: '字词' },{ Key: 'Study hard and make progress every day.', Type: 'eng', TypeName: '翻译' }, ] }, onLoad: function () { wx.hideShareMenu(); var that = this; that.setData({ Containnerheight: main.getWindowHeight(), IsStart: true, }); common.getStorageValue(that, "SearchTextList", [], function () { }); }, onKeyInput: function (e) { var search = e.detail.value; var that = this; that.setData({ SearchInfo: search, }); }, onBindfocus:function(){ this.setData({ IsStart:true, List:[], }); wx.setNavigationBarTitle({ title: "搜索中" }); }, onSearch: function (e) { var that = this; if (e.currentTarget.dataset.search) this.data.SearchInfo = e.currentTarget.dataset.search; if (this.data.SearchInfo && this.data.SearchInfo.length > 0) { var search = this.data.SearchInfo; that.searchResult(search); setTimeout(function(){ var arr = that.data.SearchTextList; for (var i = 0; i < arr.length; i++) { if (arr[i] == search) { arr.splice(i, 1); break; } } arr.unshift(search); wx.setStorageSync("SearchTextList", arr); that.setData({ SearchTextList: arr, }); },2000); } else { wx.showToast({ title: '请输搜索内容', }) } }, onSearchHistory: function (e) { var index = e.currentTarget.dataset.index; var listtype = e.currentTarget.dataset.type; var list = this.data.List; if (listtype=="null") list=this.data.ListOther; var obj={}; for(var i=0;i len) item.Content = item.Content.substr(0, len) + "..."; } that.setData({ List: list, IsStart: false, }); } else { var obj = {}; obj.Key=search; obj.Value = data; if (data.CHN && data.CHN.Author) obj.Author = data.CHN.Author; if (data.CHN && data.CHN.Dynasty) obj.Dynasty = data.CHN.Dynasty; if (data.CHN && data.CHN.PeomContent) { obj.Type = "shici"; obj.TypeName = "诗词"; obj.Content = data.CHN.PeomContent.join("").substr(0, 26); } else if (data.CHN){ obj.Type = "zici"; } if (data.ENG && !data.CHN) { obj.Type = "eng"; obj.TypeName ="翻译"; } main.updateSearchList(obj); wx.navigateTo({ url: './searchWeb2', }); } } else { that.setData({ List: [], IsStart: false, }); } }); }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID, imageUrl: app.globalData.ShareImage, } }, })