106 lines
2.3 KiB
JavaScript
106 lines
2.3 KiB
JavaScript
// index.js
|
|
import { sididtidlaunchsite, find } from "@/api/home";
|
|
import { PlayerManager } from "@/utils/playerManager";
|
|
Page({
|
|
data: {
|
|
value: "",
|
|
historyList: [],
|
|
list: [],
|
|
isSearch: false,
|
|
},
|
|
onLoad() {
|
|
console.log(wx.getStorageSync("historyList"));
|
|
this.setData({
|
|
historyList: wx.getStorageSync("historyList") || [],
|
|
});
|
|
},
|
|
clearHistory() {
|
|
const _this = this;
|
|
wx.showModal({
|
|
title: "提示",
|
|
content: "你确定要删除历史记录吗",
|
|
success(res) {
|
|
if (res.confirm) {
|
|
_this.setData({
|
|
historyList: [],
|
|
});
|
|
wx.setStorageSync("historyList", []);
|
|
} else if (res.cancel) {
|
|
console.log("用户点击取消");
|
|
}
|
|
},
|
|
});
|
|
},
|
|
onChange(e) {
|
|
this.setData({
|
|
value: e.detail,
|
|
});
|
|
},
|
|
onSearch() {
|
|
const keyword = this.data.value;
|
|
console.log(this.data.value);
|
|
if (keyword.trim()) {
|
|
this.navigator(keyword);
|
|
} else {
|
|
this.setData({
|
|
list: [],
|
|
});
|
|
// wx.showToast({
|
|
// title: "搜索内容不能为空",
|
|
// icon: "none",
|
|
// });
|
|
}
|
|
},
|
|
onClear() {
|
|
this.setData({
|
|
list: [],
|
|
});
|
|
},
|
|
search(event) {
|
|
const item = event.currentTarget.dataset.item;
|
|
this.setData({
|
|
value: item,
|
|
});
|
|
this.navigator(item);
|
|
},
|
|
navigator(item) {
|
|
const index = this.data.historyList.indexOf(item);
|
|
this.keyword = item;
|
|
this.status = 2;
|
|
wx.hideKeyboard();
|
|
sididtidlaunchsite({ tid: this.keyword }).then((result) => {
|
|
const historyList = this.data.historyList;
|
|
if (index !== -1) {
|
|
historyList.splice(index, 1);
|
|
historyList.unshift(item);
|
|
} else {
|
|
historyList.unshift(item);
|
|
}
|
|
wx.setStorageSync("historyList", historyList);
|
|
wx.hideKeyboard();
|
|
this.setData({
|
|
historyList,
|
|
isSearch: true,
|
|
});
|
|
const findParams = {
|
|
data: {},
|
|
};
|
|
find({ keyword: this.keyword }).then((res) => {
|
|
this.setData({
|
|
list: res || [],
|
|
});
|
|
});
|
|
});
|
|
},
|
|
|
|
openDetail(event) {
|
|
const data = event.currentTarget.dataset.item;
|
|
if (data.wx_drama_id) {
|
|
PlayerManager.navigateToPlayer({
|
|
srcAppid: "wx2ab73633e3b9fcbf",
|
|
dramaId: data.wx_drama_id,
|
|
});
|
|
}
|
|
},
|
|
});
|