refactor: 优化搜索页面样式和交互逻辑 style: 调整热门标签和热门搜索组件样式 fix: 修复登录状态判断逻辑 chore: 更新图片资源和SVG图标 docs: 更新README文档 test: 添加搜索功能测试用例 build: 更新依赖包版本 ci: 配置自动化测试和部署流程 perf: 优化页面加载性能和响应速度
249 lines
8.9 KiB
JavaScript
249 lines
8.9 KiB
JavaScript
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";
|
|
|
|
const appSectionIndex = createApp({
|
|
setup() {
|
|
let list = ref([]);
|
|
|
|
let uin = "";
|
|
let uid = "";
|
|
|
|
onMounted(() => {
|
|
const params = getUrlParams();
|
|
uin = params.uin || "";
|
|
uid = params.uid || "";
|
|
init();
|
|
|
|
window.addEventListener("scroll", handleScroll);
|
|
|
|
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 handleScroll = () => {
|
|
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
|
|
|
const scrollHeight = document.documentElement.scrollHeight;
|
|
const clientHeight = document.documentElement.clientHeight;
|
|
|
|
// 列表下 滑动到底部 获取新数据
|
|
if (scrollTop + clientHeight >= scrollHeight - 40) getCreationList();
|
|
};
|
|
|
|
let schoolTags = ref([]);
|
|
let info = ref({});
|
|
let medallist = ref([]);
|
|
let token = "";
|
|
let stats = ref({});
|
|
const init = () => {
|
|
ajaxget(`/v2/api/forum/getSpaceDetail?uid=${uid}&uin=${uin}`).then((res) => {
|
|
if (res.code != 200) return;
|
|
const data = res.data;
|
|
|
|
const allValues = Object.values(data.schoolTags || []);
|
|
const onlyArrays = allValues.filter((item) => Array.isArray(item));
|
|
let schoolTagsData = onlyArrays.flat();
|
|
|
|
info.value = data.info || {};
|
|
medallist.value = data.medal || [];
|
|
schoolTags.value = schoolTagsData;
|
|
token = data.token || "";
|
|
stats.value = data.stats;
|
|
|
|
calculateCreationType(data.count);
|
|
|
|
nextTick(() => getCreationList());
|
|
});
|
|
// .finally(() => wx.hideLoading());
|
|
};
|
|
|
|
let creationType = ref([]);
|
|
// 计算出创作分类
|
|
const calculateCreationType = (creation = []) => {
|
|
let obj = {
|
|
offer: "offer",
|
|
offer_summary: "总结",
|
|
interviewexperience: "面经",
|
|
};
|
|
|
|
const typeCountMap = {};
|
|
creation.forEach((item) => {
|
|
typeCountMap[item.type] = item.count;
|
|
});
|
|
|
|
const result = [];
|
|
Object.entries(obj).forEach(([type, text]) => {
|
|
result.push({
|
|
text: text,
|
|
number: typeCountMap[type] || 0,
|
|
});
|
|
});
|
|
|
|
let otherCount = 0;
|
|
creation.forEach((item) => {
|
|
if (!Object.keys(obj).includes(item.type)) otherCount += item.count;
|
|
});
|
|
|
|
result.push({
|
|
text: "其他",
|
|
number: otherCount,
|
|
});
|
|
|
|
creationType.value = result;
|
|
};
|
|
|
|
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 classify = ref("");
|
|
|
|
const classifyChange = (type) => {
|
|
if (classify.value == type) return;
|
|
page.value = 1;
|
|
list.value = [];
|
|
count.value = 0;
|
|
classify.value = type;
|
|
getCreationList();
|
|
};
|
|
|
|
let loading = false;
|
|
let page = ref(1);
|
|
let count = ref(0);
|
|
const getCreationList = () => {
|
|
// 获取作品数据
|
|
if (page.value == 0 || loading || !token) return;
|
|
loading = true;
|
|
// wx.showLoading({
|
|
// title: "加载中...",
|
|
// });
|
|
let url = `/v2/api/forum/getSpaceTopicList?token=${token}&page=${page.value}&limit=20&type=${classify.value}`;
|
|
if (classify.value == "tenement") url = `/v2/api/forum/getSpaceOtherTopicList?token=${token}&page=${page.value}&limit=20&type=tenement`;
|
|
// url = `https://api.gter.net/v2/api/forum/getSpaceOtherTopicList?token=8aMRbTYI2vFsCrhXciZiSjHHRpjy90rkzKymblLgxHlHC_oVpodchfM9wHYP4na3g5twu7dIU6VlArPslO0ZzqlnoygbJInjTN0CNWU5MQ~~&page=1&limit=20&type=tenement`;
|
|
|
|
ajaxget(url)
|
|
.then((res) => {
|
|
if (res.code != 200) return;
|
|
const data = res.data;
|
|
|
|
const targetList = data.data || [];
|
|
if (classify.value == "tenement") {
|
|
targetList.forEach((item) => {
|
|
item["tenementtype"] = item.type;
|
|
item.type = "tenement";
|
|
item.views = item.count_view || 0;
|
|
});
|
|
}
|
|
|
|
list.value = list.value.concat(targetList);
|
|
|
|
count.value = data.count;
|
|
page.value = data.count > data.limit * data.page ? page.value + 1 : 0;
|
|
})
|
|
.finally(() => {
|
|
loading = false;
|
|
// wx.hideLoading();
|
|
});
|
|
};
|
|
|
|
const sendMessage = (uin) => goSendMessage(uin);
|
|
|
|
return { sendMessage, page, count, classifyChange, classify, classifyList, list, schoolTags, info, medallist, creationType };
|
|
},
|
|
});
|
|
appSectionIndex.component("itemForum", itemForum);
|
|
appSectionIndex.component("itemOffer", itemOffer);
|
|
appSectionIndex.component("itemSummary", itemSummary);
|
|
appSectionIndex.component("itemVote", itemVote);
|
|
appSectionIndex.component("itemMj", itemMj);
|
|
appSectionIndex.component("itemTenement", itemTenement);
|
|
appSectionIndex.component("headTop", headTop);
|
|
|
|
appSectionIndex.mount("#homepage-other");
|