no message
This commit is contained in:
109
js/search.js
109
js/search.js
@@ -1,40 +1,43 @@
|
||||
const { createApp, ref, onMounted, nextTick, onUnmounted, computed, watch, provide } = Vue;
|
||||
import { itemForum } from "../component/item-forum/item-forum.js";
|
||||
import { itemOffer } from "../component/item-offer/item-offer.js";
|
||||
import { itemSummary } from "../component/item-summary/item-summary.js";
|
||||
import { itemVote } from "../component/item-vote/item-vote.js";
|
||||
import { itemMj } from "../component/item-mj/item-mj.js";
|
||||
import { itemTenement } from "../component/item-tenement/item-tenement.js";
|
||||
import { headTop } from "../component/head-top/head-top.js";
|
||||
import { hotTag } from "../component/hot-tag/hot-tag.js";
|
||||
import { hotSearch } from "../component/hot-search/hot-search.js";
|
||||
import { slideshowBox } from "../component/slideshow-box/slideshow-box.js";
|
||||
import { latestList } from "../component/latest-list/latest-list.js";
|
||||
import { itemForum } from "/component/item-forum/item-forum.js";
|
||||
import { itemOffer } from "/component/item-offer/item-offer.js";
|
||||
import { itemSummary } from "/component/item-summary/item-summary.js";
|
||||
import { itemVote } from "/component/item-vote/item-vote.js";
|
||||
import { itemMj } from "/component/item-mj/item-mj.js";
|
||||
import { itemTenement } from "/component/item-tenement/item-tenement.js";
|
||||
import { headTop } from "/component/head-top/head-top.js";
|
||||
import { hotTag } from "/component/hot-tag/hot-tag.js";
|
||||
import { hotSearch } from "/component/hot-search/hot-search.js";
|
||||
import { slideshowBox } from "/component/slideshow-box/slideshow-box.js";
|
||||
import { latestList } from "/component/latest-list/latest-list.js";
|
||||
import { loadBox } from "/component/load-box/load-box.js";
|
||||
|
||||
const appSearch = createApp({
|
||||
setup() {
|
||||
let kwValue = ref(null);
|
||||
let typeValue = ref(null);
|
||||
let kw = ref("");
|
||||
onMounted(() => {
|
||||
const params = getUrlParams();
|
||||
kw.value = params.kw || "";
|
||||
// const params = getUrlParams();
|
||||
// kw.value = params.kw || "";
|
||||
// const urlObj = new URL(location.href);
|
||||
// const pathParts = urlObj.pathname.split("/").filter((part) => part);
|
||||
// kw.value = decodeURIComponent(pathParts.pop());
|
||||
kw.value = kwValue.value.innerText;
|
||||
const tab = typeValue.value.innerText;
|
||||
if (tab) tabValue.value = tab;
|
||||
|
||||
page.value = 1;
|
||||
getList();
|
||||
|
||||
getUserInfoWin();
|
||||
setTimeout(() => (permissions.value = window["permissions"] || ["comment.edit", "comment.delete", "offercollege.hide", "offersummary.hide", "mj.hide", "topic:manager", "topic:hide"]), 1000);
|
||||
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
});
|
||||
|
||||
let isLogin = ref(true);
|
||||
let realname = ref(1); // 是否已经实名
|
||||
let userInfoWin = ref({
|
||||
authority: ["comment.edit", "comment.delete", "offercollege.hide", "offersummary.hide", "mj.hide", "topic:manager", "topic:hide"],
|
||||
avatar: "https://nas.gter.net:9008/avatar/97K4EWIMLrsbGTWXslC2WFVSEKWOikN42jDKLNjtax7HL4xtfMOJSdU9oWFhY2E~/middle?random=1761733169",
|
||||
groupid: 3,
|
||||
nickname: "肖荣豪",
|
||||
realname: 1,
|
||||
token: "01346a38444d71aaadb3adad52b52c39",
|
||||
uid: 500144,
|
||||
uin: 4238049,
|
||||
});
|
||||
let isLogin = ref(false);
|
||||
let realname = ref(0); // 是否已经实名
|
||||
let userInfoWin = ref({});
|
||||
|
||||
let permissions = ref([]);
|
||||
|
||||
@@ -84,6 +87,8 @@ const appSearch = createApp({
|
||||
tabValue.value = type;
|
||||
pagination.value = [];
|
||||
|
||||
updateUrlParams({ type: type == "all" ? null : type });
|
||||
|
||||
getList();
|
||||
};
|
||||
|
||||
@@ -110,19 +115,18 @@ const appSearch = createApp({
|
||||
});
|
||||
};
|
||||
|
||||
let loading = false;
|
||||
let loading = ref(false);
|
||||
let page = ref(0);
|
||||
let maxPage = ref(0);
|
||||
let count = ref(0);
|
||||
let list = ref([]);
|
||||
let pagination = ref([]);
|
||||
const getList = () => {
|
||||
if (loading || page.value == null) return;
|
||||
loading = true;
|
||||
if (loading.value || page.value == null) return;
|
||||
loading.value = true;
|
||||
const limit = 20;
|
||||
ajaxGet(`/v2/api/forum/topicLists?type=${tabValue.value == "all" ? "" : tabValue.value}&page=${page.value}&limit=${limit}&keyword=${kw.value}`)
|
||||
.then((res) => {
|
||||
// wx.hideLoading();
|
||||
if (res.code != 200) {
|
||||
creationAlertBox("error", res.message);
|
||||
return;
|
||||
@@ -130,19 +134,19 @@ const appSearch = createApp({
|
||||
|
||||
let data = res.data;
|
||||
list.value = data.data;
|
||||
// page.value = data.count > limit * data.page ? page.value : null;
|
||||
if (data.count <= limit * data.page) page.value = null
|
||||
|
||||
if (list.value.length == 0) page.value = null;
|
||||
|
||||
count.value = data.count;
|
||||
loading = false;
|
||||
loading.value = false;
|
||||
maxPage.value = Math.ceil(count.value / limit);
|
||||
pagination.value = calculatePagination(page.value, maxPage.value);
|
||||
|
||||
updateUrlLastPath(kw.value);
|
||||
})
|
||||
.catch((err) => {
|
||||
// wx.hideLoading();
|
||||
err = err.data;
|
||||
if (err.code == 401) goLogin();
|
||||
loading = false;
|
||||
loading.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -190,17 +194,20 @@ const appSearch = createApp({
|
||||
if (value == "...") return;
|
||||
if (value == page.value) return;
|
||||
page.value = value;
|
||||
list.value = [];
|
||||
getList();
|
||||
};
|
||||
|
||||
const prevPage = () => {
|
||||
page.value -= 1;
|
||||
list.value = [];
|
||||
pagination.value = [];
|
||||
getList();
|
||||
};
|
||||
|
||||
const nextPage = () => {
|
||||
page.value += 1;
|
||||
list.value = [];
|
||||
pagination.value = [];
|
||||
getList();
|
||||
};
|
||||
@@ -218,7 +225,34 @@ const appSearch = createApp({
|
||||
getList();
|
||||
};
|
||||
|
||||
return { startSearch, kw, maxPage, prevPage, nextPage, tabValue, cutTab, tabList, count, list, page, pagination, cutPage };
|
||||
const sidebarFixed = ref(false);
|
||||
const matterFixed = ref(false);
|
||||
|
||||
const handleScroll = () => {
|
||||
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
const clientHeight = window.innerHeight;
|
||||
|
||||
const sideHeight = sidebarRef.value.offsetHeight;
|
||||
const matterTop = matterRef.value.offsetTop;
|
||||
const matterHeight = matterContentRef.value.offsetHeight;
|
||||
|
||||
console.log("sideHeight", sideHeight);
|
||||
console.log("matterHeight", matterHeight);
|
||||
if (sideHeight < matterHeight) {
|
||||
// 侧边栏滚动固定
|
||||
if (scrollTop >= matterTop + sideHeight - clientHeight) sidebarFixed.value = true;
|
||||
else sidebarFixed.value = false;
|
||||
} else {
|
||||
if (scrollTop >= matterTop + matterHeight - clientHeight) matterFixed.value = true;
|
||||
else matterFixed.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const matterRef = ref(null);
|
||||
const sidebarRef = ref(null);
|
||||
const matterContentRef = ref(null);
|
||||
|
||||
return { matterFixed, matterContentRef, sidebarFixed, matterRef, sidebarRef, loading, typeValue, kwValue, startSearch, kw, maxPage, prevPage, nextPage, tabValue, cutTab, tabList, count, list, page, pagination, cutPage };
|
||||
},
|
||||
});
|
||||
appSearch.component("item-forum", itemForum);
|
||||
@@ -232,4 +266,5 @@ appSearch.component("hot-tag", hotTag);
|
||||
appSearch.component("hot-search", hotSearch);
|
||||
appSearch.component("slideshow-box", slideshowBox);
|
||||
appSearch.component("latest-list", latestList);
|
||||
appSearch.component("load-box", loadBox);
|
||||
appSearch.mount("#search");
|
||||
|
||||
Reference in New Issue
Block a user