| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- const WORD_LENGTH=18;
- Page({
- data: {
- IsStart: false,
- Searching: false,
- SearchList: [],
- SearchInfo: "",
- },
- onLoad: function () {
- var that = this;
- that.setData({
- Containnerheight: main.getWindowHeight(),
- });
- },
- onShow: function () {
- var that = this;
- common.getStorageValue(that, "SearchTextList", [], function () {});
- common.getStorageValue(that, "SearchWord3", [], function () {
- var list = that.data.SearchWord3;
- for (var i = 0; i < list.length; i++) {
- var item = list[i];
- if (item.Type == "shici") {
- item.TypeName = "S";
- item.Remark = item.Author + " " + item.Dynasty;
- } else if (item.Type == "eng") {
- item.TypeName = "D";
- } else {
- if (item.Key.length == 1)
- item.TypeName = "Z";
- else
- item.TypeName = "C";
- }
- if (item.Content && item.Content.length > WORD_LENGTH)
- item.Content = item.Content.substr(0, WORD_LENGTH) + "...";
- }
- that.setData({
- SearchWord3: list,
- });
- });
- },
- goto: function (e) {
- var url = e.currentTarget.dataset.url;
- wx.navigateTo({
- url: './' + url,
- })
- },
- onKeyInput: function (e) {
- var search = e.detail.value;
- var that = this;
- that.setData({
- SearchInfo: search,
- });
- },
- onSearchHistory: function (e) {
- var index = Number(e.currentTarget.dataset.index);
- var obj = {};
- if (e.currentTarget.dataset.type == "SearchWord3")
- obj = this.data.SearchWord3[index];
- else
- obj = this.data.SearchList[index];
- main.updateSearchList(obj);
- app.globalData.TempSearchBackNumber = 2;
- app.globalData.CardList2=[];
- wx.navigateTo({
- url: './addInfomationDetail',
- });
- },
- searchResult: function (e) {
- var that = this;
- var search = that.data.SearchInfo;
- if (e.currentTarget.dataset.search) {
- search = e.currentTarget.dataset.search;
- that.setData({
- SearchInfo:search,
- });
- }
- var searchtype=e.currentTarget.dataset.searchtype;
- var author=e.currentTarget.dataset.author;
- var shiciurl=e.currentTarget.dataset.shiciurl;
- main.searchInfomation(search,searchtype,author,shiciurl,function(list,obj){
-
- if (obj){
- main.updateSearchList(obj,function(){
- wx.navigateTo({
- url: './addInfomationDetail',
- });
- });
- }
- else{
- wx.setNavigationBarTitle({
- title: "搜索结果"
- });
- that.setData({
- SearchList: list,
- IsStart: true,
- });
- that.getCardList();
- 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);
-
- while (arr.length > 10) {
- arr.pop();
- }
-
- wx.setStorageSync("SearchTextList", arr);
- that.setData({
- SearchTextList: arr,
- });
- }, 2000);
- }
-
- });
- // wx.showLoading({
- // title: '查询中',
- // });
- // var timeout=setTimeout(function () {
- // wx.hideLoading();
- // }, 5000);
- // var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
- // url += "&Word=" + search;
- // if (e.currentTarget.dataset.searchtype)
- // url += "&SearchType=" + e.currentTarget.dataset.searchtype;
- // if (e.currentTarget.dataset.author)
- // url += "&Author=" + e.currentTarget.dataset.author;
- // if (e.currentTarget.dataset.shiciurl)
- // url += "&ShiciUrl=" + e.currentTarget.dataset.shiciurl;
- // main.getData(url, function (data) {
- // wx.hideLoading();
- // clearTimeout(timeout);
- // wx.setNavigationBarTitle({
- // title: "搜索结果"
- // });
- // if (data) {
- // //console.log(data);
- // if (data.List) {
- // var len = WORD_LENGTH;
- // var list = data.List;
- // for (var i = 0; i < list.length; i++) {
- // var item = list[i];
- // if (item.TypeName == "字词") {
- // if (item.Key.length == 1)
- // item.TypeName = "Z";
- // else
- // item.TypeName = "C";
- // } else if (item.TypeName == "诗词") {
- // item.TypeName = "S";
- // item.Remark = item.Author + " " + item.Dynasty;
- // } else if (item.TypeName == "翻译") {
- // item.TypeName = "D";
- // }
- // if (item.Content && item.Content.length > len)
- // item.Content = item.Content.substr(0, len) + "...";
- // }
- // that.setData({
- // SearchList: list,
- // IsStart: true,
- // });
- // } else if (data.CHN || data.ENG) {
- // 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, WORD_LENGTH);
- // obj.ShiciUrl = e.currentTarget.dataset.shiciurl;
- // } else if (data.CHN) {
- // obj.Type = "zici";
- // if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].pinyin)
- // obj.Remark = data.CHN.PinYin[0].pinyin;
- // if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].explain) {
- // obj.Content = data.CHN.PinYin[0].explain.substr(0, WORD_LENGTH);
- // obj.Content = obj.Content.replace("<p>", "");
- // obj.Content = obj.Content.replace("</p>", "");
- // if (obj.Content.length >= WORD_LENGTH)
- // obj.Content += "..."
- // }
- // }
- // if (data.ENG && !data.CHN) {
- // obj.Type = "eng";
- // obj.TypeName = "D";
- // if (data.ENG.Soundmark && data.ENG.Soundmark.Eng)
- // obj.Remark = data.ENG.Soundmark.Eng;
- // if (data.ENG.Paraphrase.length > 0) {
- // if (common.checkIsArray(data.ENG.Paraphrase) && data.ENG.Paraphrase[0].ParaphraseList)
- // obj.Content = data.ENG.Paraphrase[0].ParaphraseList.join("; ").substr(0, WORD_LENGTH);
- // else
- // obj.Content = data.ENG.Paraphrase.substr(0, WORD_LENGTH) + "...";
- // }
- // }
- // main.updateSearchList(obj);
- // app.globalData.TempSearchBackNumber = 2;
- // //app.globalData.CardList=[];
- // app.globalData.CardList2=[];
- // wx.navigateTo({
- // url: './addInfomationDetail',
- // });
- // }
- // else{
- // that.setData({
- // SearchList: [],
- // IsStart: true,
- // });
- // }
- // } else {
- // that.setData({
- // SearchList: [],
- // IsStart: true,
- // });
- // }
-
- // });
- },
- getCardList: function () {
- var that = this;
- var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
- url += "&Key=" + that.data.SearchInfo;
- that.setData({
- Searching: true,
- });
- main.getData(url, function (data) {
- that.setData({
- Searching: false,
- });
- if (data) {
- if (data.List.length > 0) {
- var list=data.List;
- for (var i = 0; i < list.length; i++) {
- var item = list[i];
- item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].Content);
- if (item.Content[1].ContentStr.length > WORD_LENGTH)
- item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].ContentStr.substr(0, WORD_LENGTH)) + "...";
-
- item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].Content);
- if (item.Content[2].ContentStr.length > WORD_LENGTH)
- item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].ContentStr.substr(0, WORD_LENGTH)) + "...";
-
- var imageUrl = getImage(item.Content[1].Content);
- if (imageUrl.length == 0 && item.Content[2].Content)
- imageUrl = getImage(item.Content[2].Content);
- if (imageUrl.length == 0 && item.Content[3].Content)
- imageUrl = getImage(item.Content[3].Content);
-
- if (imageUrl.length > 0) {
- item.ImageUrlTemp = main.getTempImage(imageUrl);
- item.ImageUrlServer = imageUrl;
- }
- }
- that.setData({
- SearchCardList:list,
- });
- app.globalData.CardList2=list;
- }
- else{
- that.setData({
- SearchCardList:[],
- });
- }
- }
- });
- function getImage(str) {
- var result = "";
- if (str.indexOf("[图") >= 0) {
- result = str.substring(str.indexOf("[图") + 3, str.indexOf("[/图]"));
- result = result.substring(result.indexOf("]") + 1);
- }
- //console.log(result);
- return result;
- }
- },
- clearInput: function () {
- this.setData({
- IsStart: false,
- Searching: false,
- SearchInfo: "",
- Focus:true,
- });
- },
- close: function (e) {
- wx.navigateBack({
- delta: 1,
- });
- },
- deleteItem: function (e) {
- var that = this;
- that.setData({
- SearchTextList: [],
- });
- wx.removeStorageSync("SearchTextList");
- },
- deleteItem2: function (e) {
- var that = this;
- var index = e.currentTarget.dataset.index;
- that.data.SearchWord3.splice(index, 1);
- that.setData({
- SearchWord3: that.data.SearchWord3,
- });
- wx.setStorageSync("SearchWord3", that.data.SearchWord3);
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- });
|