| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- 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<list.length;i++){
- if (index==i){
- obj=list[i];
- break;
- }
- }
- this.searchResult(obj.Key,obj.Type,obj.Author);
-
- },
- close: function (e) {
- wx.navigateBack({
- delta: 1,
- });
- },
- deleteItem: function (e) {
- var that = this;
- var index = e.currentTarget.dataset.id;
- that.data.SearchTextList.splice(index, 1);
- that.setData({
- SearchTextList: that.data.SearchTextList,
- });
- wx.setStorageSync("SearchTextList", that.data.SearchTextList);
- },
- searchResult: function (search, searchType, author) {
- wx.showLoading({
- title: '查询中',
- });
- var that = this;
- var url = 'GetMiaoguoAISearch?UserID=' + app.globalData.userInfo.UserID;
- url += "&Word=" + search;
- if (searchType)
- url += "&SearchType=" + searchType;
- if (author)
- url += "&Author=" + author;
- main.getData(url, function (data) {
- wx.hideLoading();
- wx.setNavigationBarTitle({
- title: "搜索结果"
- });
- searchType = "";
- author = "";
- if (data) {
- //console.log(data);
- if (data.List) {
- var len = 26;
- var list = data.List;
- for (var i = 0; i < list.length; i++) {
- var item = list[i];
- if (item.Content && item.Content.length > 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,
- }
- },
- })
|