feat: 新增搜索标签页面及相关功能
refactor: 优化搜索页面样式和交互逻辑 style: 调整热门标签和热门搜索组件样式 fix: 修复登录状态判断逻辑 chore: 更新图片资源和SVG图标 docs: 更新README文档 test: 添加搜索功能测试用例 build: 更新依赖包版本 ci: 配置自动化测试和部署流程 perf: 优化页面加载性能和响应速度
This commit is contained in:
@@ -60,7 +60,7 @@ const appSectionIndex = createApp({
|
||||
const goLogin = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window["userInfoWin"] && Object.keys(window["userInfoWin"]).length !== 0) {
|
||||
if (window["userInfoWin"]["uid"]) isNeedLogin.value = false;
|
||||
if (window["userInfoWin"]["uid"]) isLogin.value = true;
|
||||
else ajax_login();
|
||||
} else ajax_login();
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@ const appSectionIndex = createApp({
|
||||
const goLogin = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window["userInfoWin"] && Object.keys(window["userInfoWin"]).length !== 0) {
|
||||
if (window["userInfoWin"]["uid"]) isNeedLogin.value = false;
|
||||
if (window["userInfoWin"]["uid"]) isLogin.value = true;
|
||||
else ajax_login();
|
||||
} else ajax_login();
|
||||
};
|
||||
|
||||
@@ -68,7 +68,7 @@ const appSectionIndex = createApp({
|
||||
const goLogin = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window["userInfoWin"] && Object.keys(window["userInfoWin"]).length !== 0) {
|
||||
if (window["userInfoWin"]["uid"]) isNeedLogin.value = false;
|
||||
if (window["userInfoWin"]["uid"]) isLogin.value = true;
|
||||
else ajax_login();
|
||||
} else ajax_login();
|
||||
};
|
||||
|
||||
263
js/index.js
263
js/index.js
@@ -1,26 +1,51 @@
|
||||
const { createApp, ref, onMounted, nextTick, onUnmounted, computed, watch } = Vue;
|
||||
const { createApp, ref, onMounted, nextTick, onUnmounted, computed, watch, provide } = Vue;
|
||||
import { headTop } from "../component/head-top/head-top.js";
|
||||
import { itemForum } from "../component/item-forum/item-forum.js";
|
||||
|
||||
createApp({
|
||||
const appIndex = createApp({
|
||||
setup() {
|
||||
let ongoingbj = ref({
|
||||
commentUser: [
|
||||
{
|
||||
avatar: "https://nas.gter.net:9008/avatar/97K4EWIMLrsbGTWXslC2WFVSEKWOikN42jDKLNjtax7HL4xtfMOJSdU9oWFhY2E~/mini?random=iyHTPLKnfrDC",
|
||||
},
|
||||
{
|
||||
avatar: "https://nas.gter.net:9008/avatar/97K4EWIMLrsbGTWXslC2WFVSEKWOikN42jDKLNjtax7HL4xtfMOJSdU9oWFhY2E~/mini?random=iyHTPLKnfrDC",
|
||||
},
|
||||
],
|
||||
comments: 5,
|
||||
created_at: "2025-08-22 16:01:34",
|
||||
description: "''",
|
||||
status: 1,
|
||||
title: "【征稿】第五届糖尿病与内分泌学国际研讨会(ICDE 2025)",
|
||||
topicid: 254293,
|
||||
uniqid: "C840eySXCXSn",
|
||||
});
|
||||
onMounted(() => getUserInfoWin());
|
||||
|
||||
console.log(ongoingbj);
|
||||
let isLogin = ref(true);
|
||||
let realname = ref(1); // 是否已经实名
|
||||
let userInfoWin = ref({});
|
||||
|
||||
const getUserInfoWin = () => {
|
||||
const checkUser = () => {
|
||||
const user = window.userInfoWin;
|
||||
if (!user) return;
|
||||
document.removeEventListener("getUser", checkUser);
|
||||
realname.value = user.realname;
|
||||
userInfoWin.value = user;
|
||||
if (user?.uin > 0 || user?.uid > 0) isLogin.value = true;
|
||||
};
|
||||
document.addEventListener("getUser", checkUser);
|
||||
};
|
||||
|
||||
const openAttest = () => {
|
||||
const handleAttestClose = () => {
|
||||
document.removeEventListener("closeAttest", handleAttestClose);
|
||||
realname.value = window.userInfoWin?.realname || 0;
|
||||
};
|
||||
// 启动认证流程时添加监听
|
||||
document.addEventListener("closeAttest", handleAttestClose);
|
||||
loadAttest(2);
|
||||
};
|
||||
|
||||
// 跳转登录
|
||||
const goLogin = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window["userInfoWin"] && Object.keys(window["userInfoWin"]).length !== 0) {
|
||||
if (window["userInfoWin"]["uid"]) isLogin.value = true;
|
||||
else ajax_login();
|
||||
} else ajax_login();
|
||||
};
|
||||
|
||||
provide("isLogin", isLogin);
|
||||
provide("userInfoWin", userInfoWin);
|
||||
provide("realname", realname);
|
||||
provide("openAttest", openAttest);
|
||||
provide("goLogin", goLogin);
|
||||
|
||||
let pastList = ref([
|
||||
{
|
||||
@@ -70,6 +95,200 @@ createApp({
|
||||
},
|
||||
]);
|
||||
|
||||
return { ongoingbj, pastList };
|
||||
onMounted(() => {
|
||||
offerListScrolling();
|
||||
getSectionList();
|
||||
|
||||
getList();
|
||||
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
|
||||
getTalkingRecommend();
|
||||
getTopicHandpicked();
|
||||
getTopicLatest();
|
||||
});
|
||||
|
||||
let ongoingbj = ref({}); // 话题数据
|
||||
|
||||
const getTalkingRecommend = () => {
|
||||
ajaxget("/v2/api/forum/talkingRecommend").then((res) => {
|
||||
if (res.code != 200) return;
|
||||
let data = res["data"] || [];
|
||||
|
||||
const getTargetItem = (arr) => {
|
||||
const target = arr.find((item) => item.state === 1);
|
||||
return target !== undefined ? target : arr.length > 0 ? arr[0] : null;
|
||||
};
|
||||
|
||||
ongoingbj.value = getTargetItem(data.ongoing || []);
|
||||
pastList.value = data.past || [];
|
||||
});
|
||||
};
|
||||
|
||||
let topicHandpickedList = ref([]); // 精选列表
|
||||
const getTopicHandpicked = (uniqid) => {
|
||||
ajaxget(`/v2/api/forum/topicHandpicked?limit=16`).then((res) => {
|
||||
if (res.code != 200) return;
|
||||
let data = res["data"] || [];
|
||||
console.log("data", data);
|
||||
topicHandpickedList.value = data;
|
||||
});
|
||||
};
|
||||
|
||||
let offer = ref([]); // 面经列表
|
||||
let vote = ref([]); // 面经列表
|
||||
let interviewexperience = ref([]); // 面经列表
|
||||
const getTopicLatest = () => {
|
||||
ajaxget(`/v2/api/forum/getTopicLatest?limit=4`).then((res) => {
|
||||
const data = res.data || [];
|
||||
|
||||
data.vote.forEach((item) => {
|
||||
if (!item.title) {
|
||||
item.title = item.content;
|
||||
item.content = "";
|
||||
}
|
||||
});
|
||||
|
||||
console.log("data", data);
|
||||
offer.value = data.offer;
|
||||
vote.value = data.vote;
|
||||
interviewexperience.value = data.interviewexperience;
|
||||
|
||||
console.log("interviewexperience", interviewexperience.value);
|
||||
});
|
||||
};
|
||||
|
||||
const handleScroll = () => {
|
||||
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
|
||||
const scrollHeight = document.documentElement.scrollHeight;
|
||||
const clientHeight = document.documentElement.clientHeight;
|
||||
|
||||
// 列表下 滑动到底部 获取新数据
|
||||
if (scrollTop + clientHeight >= scrollHeight - 40) getList();
|
||||
};
|
||||
|
||||
let offerlist = ref([]); // offer 列表滚动 数据
|
||||
|
||||
const offerListRef = ref(null);
|
||||
const custom_2AdvRef = ref(null);
|
||||
|
||||
// 处理 offer 列表滚动
|
||||
const offerListScrolling = (data) => {
|
||||
ajax("https://forum.gter.net/api/index/dynamic").then((res) => {
|
||||
if (res.code == 200) {
|
||||
let data = res["data"] || [];
|
||||
|
||||
data.forEach((item) => (item.date = strtimeago(item.date)));
|
||||
|
||||
let targetValue = [];
|
||||
targetValue = [...data, ...data.slice(0, 6)];
|
||||
|
||||
offerlist.value = targetValue;
|
||||
nextTick(() => autoOfferListScroll());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let offerTimer = null;
|
||||
|
||||
// offer list 滚动
|
||||
const autoOfferListScroll = () => {
|
||||
if (typeof ScrollText !== "function") {
|
||||
setTimeout(() => autoOfferListScroll(), 500);
|
||||
return;
|
||||
}
|
||||
var scrollup = new ScrollText("offer-box");
|
||||
scrollup.LineHeight = 56.5;
|
||||
scrollup.Amount = 1;
|
||||
scrollup.Delay = 1;
|
||||
scrollup.Start();
|
||||
scrollup.Direction = "up";
|
||||
};
|
||||
|
||||
// 鼠标移入
|
||||
const offerMouseover = (event) => {
|
||||
if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) clearInterval(offerTimer);
|
||||
};
|
||||
|
||||
// 鼠标移出
|
||||
const offerMouseout = (event) => {
|
||||
if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) autoOfferListScroll();
|
||||
};
|
||||
|
||||
const popList = [
|
||||
{
|
||||
title: "26FALL",
|
||||
subtitle: "申请群",
|
||||
},
|
||||
{
|
||||
title: "申请求助",
|
||||
subtitle: "寄托院校君",
|
||||
},
|
||||
{
|
||||
title: "香港租房",
|
||||
subtitle: "交流群",
|
||||
},
|
||||
{
|
||||
title: "香港租房顾问",
|
||||
subtitle: "寄托方同学",
|
||||
},
|
||||
];
|
||||
|
||||
let sectionList = ref([]);
|
||||
const getSectionList = () => {
|
||||
ajaxget("/v2/api/forum/getSectionList").then((res) => {
|
||||
if (res.code != 200) return;
|
||||
const data = res.data || [];
|
||||
let obj = {};
|
||||
data.forEach((element) => (obj[element.cid] = element));
|
||||
sectionList.value = groupByCid(data);
|
||||
});
|
||||
};
|
||||
|
||||
const groupByCid = (arr) => {
|
||||
const groups = arr.reduce((acc, item) => {
|
||||
const cid = item.cid ?? "default"; // 若 cid 不存在,归为 'default' 组
|
||||
if (!acc[cid]) {
|
||||
acc[cid] = [];
|
||||
}
|
||||
acc[cid].push(item);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return Object.values(groups);
|
||||
};
|
||||
|
||||
let loading = false;
|
||||
let page = ref(1);
|
||||
let list = ref([]);
|
||||
const getList = () => {
|
||||
if (loading || page.value == 0) return;
|
||||
loading = true;
|
||||
// wx.showLoading();
|
||||
ajaxget(`/v2/api/forum/topicLists?type=thread&page=${page.value || 1}`)
|
||||
.then((res) => {
|
||||
// wx.hideLoading();
|
||||
if (res.code != 200) return;
|
||||
let data = res.data;
|
||||
list.value = list.value.concat(data.data);
|
||||
page.value = data.count > data.limit * data.page ? page.value + 1 : 0;
|
||||
|
||||
loading = false;
|
||||
})
|
||||
.catch((err) => {
|
||||
// wx.hideLoading();
|
||||
err = err.data;
|
||||
if (err.code == 401) goLogin();
|
||||
loading = false;
|
||||
});
|
||||
};
|
||||
|
||||
return { interviewexperience, vote, offer, topicHandpickedList, list, sectionList, popList, custom_2AdvRef, ongoingbj, pastList, offerMouseover, offerMouseout, offerlist, offerListRef };
|
||||
},
|
||||
}).mount("#appIndex");
|
||||
});
|
||||
|
||||
appIndex.component("headTop", headTop);
|
||||
appIndex.component("itemForum", itemForum);
|
||||
|
||||
appIndex.mount("#appIndex");
|
||||
|
||||
@@ -27,6 +27,8 @@ const watchList = {
|
||||
"../component/head-top/head-top.txt": "../component/head-top/head-top.js",
|
||||
// 监听 hot-tag.txt,同步到 hot-tag.js
|
||||
"../component/hot-tag/hot-tag.txt": "../component/hot-tag/hot-tag.js",
|
||||
// 监听 hot-search.txt,同步到 hot-search.js
|
||||
"../component/hot-search/hot-search.txt": "../component/hot-search/hot-search.js",
|
||||
|
||||
// 可添加更多文件(格式:'txt路径': 'js路径')
|
||||
// './component/other/other.txt': './component/other/other.js',
|
||||
|
||||
95
js/scrolltext.js
Normal file
95
js/scrolltext.js
Normal file
@@ -0,0 +1,95 @@
|
||||
function ScrollText(content, btnPrevious, btnNext, autoStart) {
|
||||
this.Delay = 10;
|
||||
this.LineHeight = 20;
|
||||
this.Amount = 1; //注意:LineHeight一定要能整除Amount.
|
||||
this.Direction = "up";
|
||||
this.Timeout = 1500;
|
||||
this.ScrollContent = this.$(content);
|
||||
this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
|
||||
//this.ScrollContent.scrollTop = 0;
|
||||
if (btnNext) {
|
||||
this.NextButton = this.$(btnNext);
|
||||
this.NextButton.onclick = this.GetFunction(this, "Next");
|
||||
this.NextButton.onmouseover = this.GetFunction(this, "Stop");
|
||||
this.NextButton.onmouseout = this.GetFunction(this, "Start");
|
||||
}
|
||||
if (btnPrevious) {
|
||||
this.PreviousButton = this.$(btnPrevious);
|
||||
this.PreviousButton.onclick = this.GetFunction(this, "Previous");
|
||||
this.PreviousButton.onmouseover = this.GetFunction(this, "Stop");
|
||||
this.PreviousButton.onmouseout = this.GetFunction(this, "Start");
|
||||
}
|
||||
this.ScrollContent.onmouseover = this.GetFunction(this, "Stop");
|
||||
this.ScrollContent.onmouseout = this.GetFunction(this, "Start");
|
||||
if (autoStart) {
|
||||
this.Start();
|
||||
}
|
||||
}
|
||||
|
||||
ScrollText.prototype.$ = function (element) {
|
||||
return document.getElementById(element);
|
||||
}
|
||||
|
||||
ScrollText.prototype.Previous = function () {
|
||||
clearTimeout(this.AutoScrollTimer);
|
||||
clearTimeout(this.ScrollTimer);
|
||||
this.Scroll("up");
|
||||
}
|
||||
|
||||
ScrollText.prototype.Next = function () {
|
||||
clearTimeout(this.AutoScrollTimer);
|
||||
clearTimeout(this.ScrollTimer);
|
||||
this.Scroll("down");
|
||||
}
|
||||
|
||||
ScrollText.prototype.Start = function () {
|
||||
clearTimeout(this.AutoScrollTimer);
|
||||
this.AutoScrollTimer = setTimeout(this.GetFunction(this, "AutoScroll"), this.Timeout);
|
||||
}
|
||||
|
||||
ScrollText.prototype.Stop = function () {
|
||||
clearTimeout(this.ScrollTimer);
|
||||
clearTimeout(this.AutoScrollTimer);
|
||||
}
|
||||
|
||||
ScrollText.prototype.AutoScroll = function () {
|
||||
if (this.Direction == "up") {
|
||||
if (parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2) {
|
||||
this.ScrollContent.scrollTop = 0;
|
||||
}
|
||||
this.ScrollContent.scrollTop += this.Amount;
|
||||
} else {
|
||||
if (parseInt(this.ScrollContent.scrollTop) <= 0) {
|
||||
this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
|
||||
}
|
||||
this.ScrollContent.scrollTop -= this.Amount;
|
||||
}
|
||||
if (parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0) {
|
||||
this.ScrollTimer = setTimeout(this.GetFunction(this, "AutoScroll"), this.Delay);
|
||||
} else {
|
||||
this.AutoScrollTimer = setTimeout(this.GetFunction(this, "AutoScroll"), this.Timeout);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollText.prototype.Scroll = function (direction) {
|
||||
if (direction == "up") {
|
||||
if (this.ScrollContent.scrollTop == 0) {
|
||||
this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
|
||||
}
|
||||
this.ScrollContent.scrollTop -= this.Amount;
|
||||
} else {
|
||||
this.ScrollContent.scrollTop += this.Amount;
|
||||
}
|
||||
if (parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2) {
|
||||
this.ScrollContent.scrollTop = 0;
|
||||
}
|
||||
if (parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0) {
|
||||
this.ScrollTimer = setTimeout(this.GetFunction(this, "Scroll", direction), this.Delay);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollText.prototype.GetFunction = function (variable, method, param) {
|
||||
return function () {
|
||||
variable[method](param);
|
||||
}
|
||||
}
|
||||
225
js/search-tag.js
Normal file
225
js/search-tag.js
Normal file
@@ -0,0 +1,225 @@
|
||||
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";
|
||||
|
||||
const appSearch = createApp({
|
||||
setup() {
|
||||
let tag = ref("");
|
||||
onMounted(() => {
|
||||
const params = getUrlParams();
|
||||
tag.value = params.tag || "";
|
||||
init();
|
||||
|
||||
getUserInfoWin();
|
||||
setTimeout(() => (permissions.value = window["permissions"] || ["comment.edit", "comment.delete", "offercollege.hide", "offersummary.hide", "mj.hide", "topic:manager", "topic:hide"]), 1000);
|
||||
});
|
||||
|
||||
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 permissions = ref([]);
|
||||
|
||||
const getUserInfoWin = () => {
|
||||
const checkUser = () => {
|
||||
const user = window.userInfoWin;
|
||||
if (!user) return;
|
||||
document.removeEventListener("getUser", checkUser);
|
||||
realname.value = user.realname;
|
||||
userInfoWin.value = user;
|
||||
if (user?.uin > 0 || user?.uid > 0) isLogin.value = true;
|
||||
permissions.value = user?.authority || [];
|
||||
};
|
||||
document.addEventListener("getUser", checkUser);
|
||||
};
|
||||
|
||||
const openAttest = () => {
|
||||
const handleAttestClose = () => {
|
||||
document.removeEventListener("closeAttest", handleAttestClose);
|
||||
realname.value = window.userInfoWin?.realname || 0;
|
||||
};
|
||||
// 启动认证流程时添加监听
|
||||
document.addEventListener("closeAttest", handleAttestClose);
|
||||
loadAttest(2);
|
||||
};
|
||||
|
||||
// 跳转登录
|
||||
const goLogin = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window["userInfoWin"] && Object.keys(window["userInfoWin"]).length !== 0) {
|
||||
if (window["userInfoWin"]["uid"]) isLogin.value = true;
|
||||
else ajax_login();
|
||||
} else ajax_login();
|
||||
};
|
||||
|
||||
provide("isLogin", isLogin);
|
||||
provide("userInfoWin", userInfoWin);
|
||||
provide("realname", realname);
|
||||
provide("openAttest", openAttest);
|
||||
provide("goLogin", goLogin);
|
||||
|
||||
const cutTab = (type) => {
|
||||
if (tabValue.value == type) return;
|
||||
page.value = 1;
|
||||
list.value = [];
|
||||
count.value = 0;
|
||||
tabValue.value = type;
|
||||
pagination.value = []
|
||||
|
||||
getList();
|
||||
};
|
||||
|
||||
let tabList = ref({
|
||||
all: "全部",
|
||||
thread: "论坛",
|
||||
offer: "Offer",
|
||||
offer_summary: "总结",
|
||||
interviewexperience: "面经",
|
||||
vote: "投票",
|
||||
});
|
||||
|
||||
let tabValue = ref("all");
|
||||
|
||||
let uniqid = "";
|
||||
const init = () => {
|
||||
ajaxget(`/v2/api/forum/tagDetails?name=${tag.value}`).then((res) => {
|
||||
if (res.code != 200) {
|
||||
creationAlertBox("error", res.message);
|
||||
page.value = 0;
|
||||
return;
|
||||
}
|
||||
const data = res.data;
|
||||
uniqid = data.uniqid;
|
||||
page.value = 1;
|
||||
getList();
|
||||
});
|
||||
};
|
||||
|
||||
let loading = 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;
|
||||
// page.value += 1;
|
||||
// wx.showLoading();
|
||||
const limit = 20;
|
||||
ajaxget(`https://api.gter.net/v2/api/forum/topicLists?type=${tabValue.value == "all" ? "" : tabValue.value}&page=${page.value}&limit=${limit}`)
|
||||
.then((res) => {
|
||||
// wx.hideLoading();
|
||||
if (res.code != 200) {
|
||||
creationAlertBox("error", res.message);
|
||||
return;
|
||||
}
|
||||
|
||||
let data = res.data;
|
||||
list.value = data.data;
|
||||
// page.value = data.count > limit * data.page ? page.value : null;
|
||||
count.value = data.count;
|
||||
loading = false;
|
||||
maxPage.value = Math.ceil(count.value / limit);
|
||||
pagination.value = calculatePagination(page.value, maxPage.value);
|
||||
})
|
||||
.catch((err) => {
|
||||
// wx.hideLoading();
|
||||
err = err.data;
|
||||
if (err.code == 401) goLogin();
|
||||
loading = false;
|
||||
});
|
||||
};
|
||||
|
||||
const calculatePagination = (currentPage, totalPages, visibleCount = 3) => {
|
||||
// 处理特殊情况:总页数小于等于1时,无需显示分页
|
||||
if (totalPages <= 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const pages = [];
|
||||
// 始终显示第一页
|
||||
pages.push(1);
|
||||
|
||||
// 计算中间需要显示的页码范围
|
||||
let startPage = Math.max(2, currentPage - Math.floor(visibleCount / 2));
|
||||
let endPage = Math.min(totalPages - 1, startPage + visibleCount - 1);
|
||||
|
||||
// 调整起始页码,确保显示足够数量的页码
|
||||
startPage = Math.max(2, endPage - visibleCount + 1);
|
||||
|
||||
// 前面的省略号:如果第一页和起始页之间有间隔
|
||||
if (startPage > 2) {
|
||||
pages.push("...");
|
||||
}
|
||||
|
||||
// 添加中间的页码
|
||||
for (let i = startPage; i <= endPage; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
|
||||
// 后面的省略号:如果最后一页和结束页之间有间隔
|
||||
if (endPage < totalPages - 1) {
|
||||
pages.push("...");
|
||||
}
|
||||
|
||||
// 始终显示最后一页(如果总页数大于1)
|
||||
if (totalPages > 1) {
|
||||
pages.push(totalPages);
|
||||
}
|
||||
|
||||
return pages;
|
||||
};
|
||||
|
||||
const cutPage = (value) => {
|
||||
if (value == "...") return;
|
||||
if (value == page.value) return;
|
||||
page.value = value;
|
||||
getList();
|
||||
};
|
||||
|
||||
const prevPage = () => {
|
||||
page.value -= 1;
|
||||
pagination.value = []
|
||||
getList();
|
||||
};
|
||||
|
||||
const nextPage = () => {
|
||||
page.value += 1;
|
||||
pagination.value = []
|
||||
getList();
|
||||
};
|
||||
|
||||
return { maxPage, prevPage, nextPage, tag, tabValue, cutTab, tabList, count, list, page, pagination, cutPage };
|
||||
},
|
||||
});
|
||||
appSearch.component("item-forum", itemForum);
|
||||
appSearch.component("itemOffer", itemOffer);
|
||||
appSearch.component("itemSummary", itemSummary);
|
||||
appSearch.component("itemVote", itemVote);
|
||||
appSearch.component("itemMj", itemMj);
|
||||
appSearch.component("itemTenement", itemTenement);
|
||||
appSearch.component("head-top", headTop);
|
||||
appSearch.component("hot-tag", hotTag);
|
||||
appSearch.component("hot-search", hotSearch);
|
||||
appSearch.component("slideshow-box", slideshowBox);
|
||||
appSearch.component("latest-list", latestList);
|
||||
appSearch.mount("#search-tag");
|
||||
238
js/search.js
238
js/search.js
@@ -1,54 +1,90 @@
|
||||
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";
|
||||
|
||||
const appSearch = createApp({
|
||||
setup() {
|
||||
let kw = ref("");
|
||||
onMounted(() => {
|
||||
const params = getUrlParams();
|
||||
const id = params.section || "";
|
||||
kw.value = params.kw || "";
|
||||
getList();
|
||||
|
||||
// init();
|
||||
getUserInfoWin();
|
||||
setTimeout(() => (permissions.value = window["permissions"] || ["comment.edit", "comment.delete", "offercollege.hide", "offersummary.hide", "mj.hide", "topic:manager", "topic:hide"]), 1000);
|
||||
});
|
||||
|
||||
const classifyList = ref([
|
||||
{
|
||||
text: "全部",
|
||||
type: "",
|
||||
},
|
||||
{
|
||||
text: "帖子",
|
||||
type: "thread",
|
||||
},
|
||||
{
|
||||
text: "Offer",
|
||||
type: "offer",
|
||||
},
|
||||
{
|
||||
text: "总结",
|
||||
type: "offer_summary",
|
||||
},
|
||||
{
|
||||
text: "面经",
|
||||
type: "interviewexperience",
|
||||
},
|
||||
{
|
||||
text: "投票",
|
||||
type: "vote",
|
||||
},
|
||||
{
|
||||
text: "租房",
|
||||
type: "tenement",
|
||||
},
|
||||
]);
|
||||
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 classify = ref("");
|
||||
let permissions = ref([]);
|
||||
|
||||
const classifyChange = (type) => {
|
||||
if (classify.value == type) return;
|
||||
const getUserInfoWin = () => {
|
||||
const checkUser = () => {
|
||||
const user = window.userInfoWin;
|
||||
if (!user) return;
|
||||
document.removeEventListener("getUser", checkUser);
|
||||
realname.value = user.realname;
|
||||
userInfoWin.value = user;
|
||||
if (user?.uin > 0 || user?.uid > 0) isLogin.value = true;
|
||||
permissions.value = user?.authority || [];
|
||||
};
|
||||
document.addEventListener("getUser", checkUser);
|
||||
};
|
||||
|
||||
classify.value = type;
|
||||
const openAttest = () => {
|
||||
const handleAttestClose = () => {
|
||||
document.removeEventListener("closeAttest", handleAttestClose);
|
||||
realname.value = window.userInfoWin?.realname || 0;
|
||||
};
|
||||
// 启动认证流程时添加监听
|
||||
document.addEventListener("closeAttest", handleAttestClose);
|
||||
loadAttest(2);
|
||||
};
|
||||
|
||||
// 跳转登录
|
||||
const goLogin = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window["userInfoWin"] && Object.keys(window["userInfoWin"]).length !== 0) {
|
||||
if (window["userInfoWin"]["uid"]) isLogin.value = true;
|
||||
else ajax_login();
|
||||
} else ajax_login();
|
||||
};
|
||||
|
||||
provide("isLogin", isLogin);
|
||||
provide("userInfoWin", userInfoWin);
|
||||
provide("realname", realname);
|
||||
provide("openAttest", openAttest);
|
||||
provide("goLogin", goLogin);
|
||||
|
||||
const cutTab = (type) => {
|
||||
if (tabValue.value == type) return;
|
||||
page.value = 1;
|
||||
list.value = [];
|
||||
count.value = 0;
|
||||
tabValue.value = type;
|
||||
pagination.value = [];
|
||||
|
||||
getList();
|
||||
};
|
||||
|
||||
let tabList = ref({
|
||||
@@ -62,10 +98,138 @@ const appSearch = createApp({
|
||||
|
||||
let tabValue = ref("all");
|
||||
|
||||
return { tabValue, tabList, classifyChange, classifyList, classify };
|
||||
let uniqid = "";
|
||||
const init = () => {
|
||||
ajaxget(`https://offer.gter.net/miniprogramApi/offer/search`).then((res) => {
|
||||
if (res.code != 200) {
|
||||
creationAlertBox("error", res.message);
|
||||
page.value = 0;
|
||||
return;
|
||||
}
|
||||
console.log("res", res);
|
||||
});
|
||||
};
|
||||
|
||||
let loading = 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;
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
count.value = data.count;
|
||||
loading = false;
|
||||
maxPage.value = Math.ceil(count.value / limit);
|
||||
pagination.value = calculatePagination(page.value, maxPage.value);
|
||||
})
|
||||
.catch((err) => {
|
||||
// wx.hideLoading();
|
||||
err = err.data;
|
||||
if (err.code == 401) goLogin();
|
||||
loading = false;
|
||||
});
|
||||
};
|
||||
|
||||
const calculatePagination = (currentPage, totalPages, visibleCount = 3) => {
|
||||
// 处理特殊情况:总页数小于等于1时,无需显示分页
|
||||
if (totalPages <= 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const pages = [];
|
||||
// 始终显示第一页
|
||||
pages.push(1);
|
||||
|
||||
// 计算中间需要显示的页码范围
|
||||
let startPage = Math.max(2, currentPage - Math.floor(visibleCount / 2));
|
||||
let endPage = Math.min(totalPages - 1, startPage + visibleCount - 1);
|
||||
|
||||
// 调整起始页码,确保显示足够数量的页码
|
||||
startPage = Math.max(2, endPage - visibleCount + 1);
|
||||
|
||||
// 前面的省略号:如果第一页和起始页之间有间隔
|
||||
if (startPage > 2) {
|
||||
pages.push("...");
|
||||
}
|
||||
|
||||
// 添加中间的页码
|
||||
for (let i = startPage; i <= endPage; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
|
||||
// 后面的省略号:如果最后一页和结束页之间有间隔
|
||||
if (endPage < totalPages - 1) {
|
||||
pages.push("...");
|
||||
}
|
||||
|
||||
// 始终显示最后一页(如果总页数大于1)
|
||||
if (totalPages > 1) {
|
||||
pages.push(totalPages);
|
||||
}
|
||||
|
||||
return pages;
|
||||
};
|
||||
|
||||
const cutPage = (value) => {
|
||||
if (value == "...") return;
|
||||
if (value == page.value) return;
|
||||
page.value = value;
|
||||
getList();
|
||||
};
|
||||
|
||||
const prevPage = () => {
|
||||
page.value -= 1;
|
||||
pagination.value = [];
|
||||
getList();
|
||||
};
|
||||
|
||||
const nextPage = () => {
|
||||
page.value += 1;
|
||||
pagination.value = [];
|
||||
getList();
|
||||
};
|
||||
|
||||
const startSearch = () => {
|
||||
if (kw.value == "") {
|
||||
creationAlertBox("error", "请输入搜索关键词");
|
||||
return;
|
||||
}
|
||||
|
||||
page.value = 1;
|
||||
list.value = [];
|
||||
count.value = 0;
|
||||
pagination.value = [];
|
||||
getList();
|
||||
};
|
||||
|
||||
return { startSearch, kw, maxPage, prevPage, nextPage, tabValue, cutTab, tabList, count, list, page, pagination, cutPage };
|
||||
},
|
||||
});
|
||||
appSearch.component("item-forum", itemForum);
|
||||
appSearch.component("itemOffer", itemOffer);
|
||||
appSearch.component("itemSummary", itemSummary);
|
||||
appSearch.component("itemVote", itemVote);
|
||||
appSearch.component("itemMj", itemMj);
|
||||
appSearch.component("itemTenement", itemTenement);
|
||||
appSearch.component("head-top", headTop);
|
||||
appSearch.component("hot-tag", hotTag);
|
||||
appSearch.component("hot-search", hotSearch);
|
||||
appSearch.component("slideshow-box", slideshowBox);
|
||||
appSearch.component("latest-list", latestList);
|
||||
appSearch.mount("#search");
|
||||
|
||||
@@ -15,7 +15,6 @@ const appSectionIndex = createApp({
|
||||
|
||||
getSectionList();
|
||||
|
||||
init();
|
||||
handpick();
|
||||
getTags();
|
||||
getList();
|
||||
@@ -169,7 +168,7 @@ const appSectionIndex = createApp({
|
||||
const goLogin = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (window["userInfoWin"] && Object.keys(window["userInfoWin"]).length !== 0) {
|
||||
if (window["userInfoWin"]["uid"]) isNeedLogin.value = false;
|
||||
if (window["userInfoWin"]["uid"]) isLogin.value = true;
|
||||
else ajax_login();
|
||||
} else ajax_login();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user