| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- Page({
- data: {
- ListOther: [{
- Key: '愛', Type: 'zici'
- }, {
- Key: '饕餮', Type: 'zici'
- }, {
- Key: '鸿鹄之志', Type: 'zici'
- }, {
- Key: '天净沙·秋思', Type: 'shici'
- }, {
- Key: 'success', Type: 'zici'
- }, {
- Key: 'Study hard and make progress every day.', Type: 'eng'
- }
- ]
- },
- onLoad: function () {
- wx.hideShareMenu();
- var that = this;
- that.setData({
- Containnerheight: main.getWindowHeight(),
- IsShowNull: false,
- });
- app.globalData.SearchResultList = [];
- app.globalData.SearchNull = 0;
- common.getStorageValue(that, "SearchTextList", [], function () {
- });
- },
- onShow: function () {
- if (app.globalData.SearchNull == 1) {
- var len = 26;
- var list = app.globalData.SearchResultList;
- 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) + "...";
- }
- this.setData({
- List: list,
- });
- app.globalData.SearchNull = 0;
- }
- },
- onKeyInput: function (e) {
- var search = e.detail.value;
- var that = this;
- that.setData({
- SearchInfo: search,
- });
- },
- 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);
- 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,
- });
- }
- else {
- wx.showToast({
- title: '请输搜索内容',
- })
- }
- },
- onSearchSelect: function (e) {
- var search = e.currentTarget.dataset.search;
- var searchType = e.currentTarget.dataset.searchtype;
- var author = e.currentTarget.dataset.author;
- wx.navigateTo({
- url: './searchWeb2?search=' + search + '&searchType=' + searchType + '&author=' + 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,dynasty,content) {
- wx.showLoading({
- title: '查询中',
- });
- var that = this;
- var arr = wx.getStorageSync("SearchWord2");
- if (!arr)
- arr = [];
- var obj = {};
- obj.Key = search;
- if (searchType)
- obj.Type = searchType;
- else
- obj.Type = "zici";
- if (author)
- obj.Author = author;
- if (dynasty)
- obj.dynasty = dynasty;
- if (content)
- obj.Content = content;
- var b = false;
- for (var i = 0; i < arr.length; i++) {
- if (arr[i].Key == search
- && arr[i].Type == searchType
- && arr[i].Author == author) {
- obj.Value = arr[i].Value;
- arr.splice(i, 1);
- b = true;
- break;
- }
- }
- if (b) {
- arr.unshift(obj);
- wx.setStorageSync("SearchWord2", arr);
- app.globalData.SearchItem=obj.Value;
- wx.hideLoading();
- wx.navigateTo({
- url: './searchWeb2?back=3',
- });
- }
- else {
- 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();
- searchType = "";
- author = "";
- if (data) {
- //console.log(data);
- if (data.List) {
- app.globalData.SearchResultList = data.List;
- app.globalData.SearchNull = 1;
- wx.navigateBack({
- delta: 1,
- });
- }
- else {
- obj.Value = data;
- if (data.CHN && data.CHN.Author)
- obj.Author = data.CHN.Author;
- if (data.CHN && data.CHN.PeomContent)
- obj.Type = "shici";
- arr.unshift(obj);
- if (arr.length > 100) {
- arr.pop();
- }
- wx.setStorageSync("SearchWord2", arr);
- that.getListFinished(data);
- }
- }
- else {
- app.globalData.SearchNull = 1;
- app.globalData.SearchResultList = [];
- wx.navigateBack({
- delta: 1,
- });
- }
- });
- }
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|