// e:\project\dy_video_all\初晴剧场\pages\search\search.ts import { httpRequest } from "../../utils/httpReques"; Page({ data: { searchValue: '', historySearchList: [], searchList: [], searchFlag: false }, onLoad: function (options) { }, onShow() { const historySearchList = tt.getStorageSync('historySearchList') || []; console.log(historySearchList, "historySearchList") this.setData({ historySearchList }) }, handelSearchInput(ev: any) { const val = ev.detail.value; this.setData({ searchValue: val, }) }, handelKeyword() { const searchValue = this.data.searchValue; const historySearchList: any = this.data.historySearchList; if (!searchValue) { tt.showToast({ title: '搜索剧名不能为空', icon: 'none', }); return; } tt.showLoading({ title: '加载中...', }); httpRequest('/sididtidlaunchsite', 'POST', { tid: searchValue }).then((res: any) => { if (res.status == 1) { if (res.data.pageurl) { tt.hideLoading({}); tt.navigateTo({ url: `/pages/videoDetail/videoDetail?${res.data.pageurl}`, }); } else { if (historySearchList.length >= 10) { historySearchList.pop(); historySearchList.unshift(searchValue); } else { historySearchList.unshift(searchValue) } httpRequest('/find', 'POST', { keyword: searchValue }).then((reults: any) => { tt.hideLoading({}); if (reults.status == 1 && Array.isArray(reults.data)) { tt.setStorageSync('historySearchList', historySearchList) this.setData({ historySearchList: historySearchList, searchList: reults.data, searchFlag: true }) } }) } } }) }, handelHistoryItem(ev: any) { console.log(ev, "jjjjjjjjjjjjjj") const item = ev.currentTarget.dataset.item; this.setData({ searchValue: item, }) this.handelKeyword() }, cleanHistory() { tt.setStorageSync('historySearchList', []); this.setData({ historySearchList: [] }) tt.showToast({ title: '清空搜索历史成功', }); }, toPathVideo(ev: any) { const sid = ev.currentTarget.dataset.sid; tt.navigateTo({ url: `/pages/videoDetail/videoDetail?sid=${sid}`, }); }, })