jiuyiUniapp/jiuyi2/unpackage/dist/dev/mp-weixin/pages/index/search.js

282 lines
8.4 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const common_js_util = require("../../common/js/util.js");
const api_index = require("../../api/index.js");
if (!Array) {
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
_easycom_uni_icons2();
}
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
if (!Math) {
(statusBar + _easycom_uni_icons)();
}
const statusBar = () => "../../components/header/statusBar.js";
const _sfc_main = {
__name: "search",
setup(__props) {
const searchState = common_vendor.ref(false);
const searchLog = common_vendor.reactive([]);
const hotVideoList = common_vendor.reactive([]);
const tabList = common_vendor.reactive([
{
name: "视频",
getList: () => getVideoList(),
getMoreList: () => getMoreVideoList(),
refreshList: () => refreshVideoList()
},
{
name: "用户",
getList: () => getFriendList(),
getMoreList: () => getMoreFriendList(),
refreshList: () => refreshFriendList()
}
]);
const tabIndex = common_vendor.ref(0);
const keyword = common_vendor.ref("");
const videoList = common_vendor.reactive({
data: [],
pageNum: 1,
pageSize: 10,
total: 0
});
const userList = common_vendor.reactive({
data: [],
pageNum: 1,
pageSize: 10,
total: 0
});
common_vendor.onLoad(() => {
getSearchLog();
getHotVideo();
});
common_vendor.onReachBottom(() => {
if (searchState.value)
tabList[tabIndex.value].getMoreList();
});
common_vendor.onPullDownRefresh(() => {
if (!searchState.value) {
common_vendor.index.stopPullDownRefresh();
return;
}
tabList[tabIndex.value].refreshList();
});
function getSearchLog() {
api_index.api.video.videoSearchLog().then((rs) => {
if (rs.code == 200) {
searchLog.push(...rs.data);
return;
}
common_js_util.util.alert({
content: rs.msg,
showCancel: false
});
});
}
function getHotVideo() {
api_index.api.video.hotVideos().then((rs) => {
if (rs.code == 200) {
hotVideoList.push(...rs.data);
return;
}
common_js_util.util.alert({
contuent: rs.msg,
showCancel: false
});
});
}
function handleTabIndex(index) {
if (tabIndex.value === index)
return;
tabIndex.value = index;
tabList[tabIndex.value].refreshList();
}
function handleUser(item) {
common_vendor.index.navigateTo({
url: common_js_util.util.setUrl("/pages/index/videoHome", {
userId: item.userId
})
});
}
function handleSearch() {
if (!keyword.value) {
searchState.value = false;
return;
} else
searchState.value = true;
tabList[tabIndex.value].getList();
}
function refreshVideoList() {
videoList.pageNum = 1;
videoList.total = 0;
getVideoList();
}
function getMoreVideoList() {
if (videoList.data.length >= videoList.total)
return;
videoList.pageNum++;
getVideoList();
}
function getVideoList() {
api_index.api.video.videoSearch({
query: {
// 搜索
search: keyword.value,
pageNum: videoList.pageNum,
pageSize: videoList.pageSize
}
}).then((rs) => {
if (rs.code == 200) {
if (videoList.pageNum)
videoList.data.length = 0;
videoList.data.push(...rs.rows.map((item) => {
item.format_videoUrl = common_js_util.util.format_url(item.videoUrl, "video");
item.format_header = common_js_util.util.format_url(item.header, "img");
item.format_imageUrl = common_js_util.util.format_url(item.imageUrl, "img");
return item;
}));
videoList.total = rs.total;
console.log("videoList", videoList.data);
return;
}
common_js_util.util.alert({
content: rs.msg,
showCancel: false
});
}).finally(() => {
common_vendor.index.stopPullDownRefresh();
});
}
function refreshFriendList() {
userList.pageNum = 1;
userList.total = 0;
getFriendList();
}
function getMoreFriendList() {
if (userList.data.length >= userList.total)
return;
userList.pageNum++;
getFriendList();
}
function getFriendList() {
api_index.api.video.searchFriendByName({
path: [keyword.value],
query: {
pageNum: userList.pageNum,
pageSize: userList.pageSize
}
}).then((rs) => {
console.log(rs);
if (rs.code == 200) {
if (userList.pageNum)
userList.data.length = 0;
userList.data.push(...rs.rows.map((item) => {
item.format_userPortrait = common_js_util.util.format_url(item.userPortrait, "img");
return item;
}));
userList.total = rs.total;
return;
}
common_js_util.util.alert({
content: rs.msg,
showCancel: false
});
}).finally(() => {
common_vendor.index.stopPullDownRefresh();
});
}
function handleItemSearch(item, key) {
keyword.value = item[key];
handleSearch();
}
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.p({
type: "left",
size: "48rpx",
color: "#333"
}),
b: common_vendor.p({
type: "search",
size: "32rpx",
color: "#aaa"
}),
c: keyword.value,
d: common_vendor.o$1(($event) => keyword.value = $event.detail.value),
e: common_vendor.o$1(handleSearch),
f: !searchState.value
}, !searchState.value ? common_vendor.e({
g: common_vendor.f(searchLog, (item, index, i0) => {
return {
a: common_vendor.t(item.search),
b: index,
c: common_vendor.o$1(($event) => handleItemSearch(item, "search"), index)
};
}),
h: !searchLog[0]
}, !searchLog[0] ? {} : {}, {}, {
j: common_vendor.f(hotVideoList, (item, index, i0) => {
return common_vendor.e({
a: common_vendor.t(index + 1),
b: common_vendor.t(item.title)
}, {}, {
e: common_vendor.t(item.play)
}, {}, {
i: index,
j: common_vendor.o$1(($event) => handleItemSearch(item, "title"), index)
});
})
}) : common_vendor.e({
k: common_vendor.f(tabList, (item, index, i0) => {
return {
a: common_vendor.t(item.name),
b: index,
c: index === tabIndex.value ? 1 : "",
d: common_vendor.o$1(($event) => handleTabIndex(index), index)
};
}),
l: tabIndex.value === 0
}, tabIndex.value === 0 ? {
m: common_vendor.f(videoList.data, (item, index, i0) => {
return common_vendor.e({
a: item.format_header,
b: common_vendor.o$1(($event) => handleUser(item), index),
c: common_vendor.t(item.userName),
d: common_vendor.t(item.createTime),
e: common_vendor.t(item.title),
f: item.format_imageUrl,
g: item.isLike == 0
}, item.isLike == 0 ? {
h: common_assets._imports_2$2
} : {
i: common_assets._imports_3
}, {
j: common_vendor.t(item.likes),
k: common_vendor.t(item.comment),
l: common_vendor.t(item.collect)
}, {}, {}, {
p: index
});
}),
n: common_assets._imports_5,
o: common_assets._imports_8
} : {}, {
p: tabIndex.value === 1
}, tabIndex.value === 1 ? {
q: common_vendor.f(userList.data, (item, index, i0) => {
return common_vendor.e({
a: item.format_userPortrait,
b: common_vendor.t(item.userNickname),
c: common_vendor.t(item.userFans),
d: item.isAttention
}, item.isAttention ? {} : {}, {
e: index,
f: common_vendor.o$1(($event) => handleUser(item), index)
});
})
} : {}));
};
}
};
wx.createPage(_sfc_main);