Files
PC-Light-Forum/js/index.js
DESKTOP-RQ919RC\Pc aea14650ff feat(bi组件): 添加解锁内容和币不足弹窗功能
- 在bi组件中新增解锁内容和币不足的弹窗样式及逻辑
- 添加根据用户币数量显示不同弹窗的功能
- 优化投币逻辑,支持解锁内容场景
- 修复学校链接显示条件判断
- 调整CSS样式增加底部间距
2025-11-13 19:20:10 +08:00

310 lines
11 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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";
import { latestList } from "../component/latest-list/latest-list.js";
const appIndex = createApp({
setup() {
onMounted(() => getUserInfoWin());
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([
{
comments: 24,
created_at: "2025-04-14 16:08:52",
description: "''",
status: 0,
title: "25年4月美国无预警大量撤销留学生签证撤销原因是哪些我们的一些相关建议",
topicid: 253942,
uniqid: "uDqLzLTbK4Of",
},
{
comments: 24,
created_at: "2025-04-14 16:08:52",
description: "''",
status: 0,
title: "25年4月美国无预警大量撤销留学生签证撤销原因是哪些我们的一些相关建议",
topicid: 253942,
uniqid: "uDqLzLTbK4Of",
},
{
comments: 24,
created_at: "2025-04-14 16:08:52",
description: "''",
status: 0,
title: "25年4月美国无预警大量撤销留学生签证撤销原因是哪些我们的一些相关建议",
topicid: 253942,
uniqid: "uDqLzLTbK4Of",
},
{
comments: 24,
created_at: "2025-04-14 16:08:52",
description: "''",
status: 0,
title: "25年4月美国无预警大量撤销留学生签证撤销原因是哪些我们的一些相关建议",
topicid: 253942,
uniqid: "uDqLzLTbK4Of",
},
{
comments: 24,
created_at: "2025-04-14 16:08:52",
description: "''",
status: 0,
title: "25年4月美国无预警大量撤销留学生签证撤销原因是哪些我们的一些相关建议",
topicid: 253942,
uniqid: "uDqLzLTbK4Of",
},
]);
onMounted(() => {
offerListScrolling();
getSectionList();
getList();
window.addEventListener("scroll", handleScroll);
getTalkingRecommend();
getTopicHandpicked();
getTopicLatest();
setTimeout(() => {
BiComponent.initComponent('unlock');
}, 1000);
});
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"] || [];
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 = "";
}
});
offer.value = data.offer;
vote.value = data.vote;
interviewexperience.value = data.interviewexperience;
});
};
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();
sidebarHeight.value = -(sidebarRef.value.offsetHeight - window.innerHeight);
};
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: "申请群",
img: "https://o.x-php.com/Zvt57TuJSUvkyhw-xG7Y2l-c-5kpcnzqqsgFptxhcq_cQnrlJKN1WgxCBq_D-81qNDQyOQ~~",
},
{
title: "申请求助",
subtitle: "寄托院校君",
img: "https://u.gter.net/assistantwxqrcode.png",
},
{
title: "香港租房",
subtitle: "交流群",
img: "https://o.x-php.com/Zvt57TuJSUvkyhw-xG7Y2l-c-5kpcnzqqsgFptxhcq_cQnrlJKN1WgxCBq_D-81qNDQyOQ~~",
},
{
title: "香港租房顾问",
subtitle: "寄托方同学",
img: "https://o.x-php.com/Zvt57TuJSUvkyhw-xG7Y2l-d_JkpcHnqqsgFptxhcq_cQnrlcaF2WQQQBq_D-81qNDQyOQ~~",
},
];
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;
});
};
const clickbtn = () => {
BiComponent.initComponent();
};
const sidebarRef = ref(null);
let sidebarHeight = ref(0);
return { sidebarRef, sidebarHeight, clickbtn, interviewexperience, vote, offer, topicHandpickedList, list, sectionList, popList, custom_2AdvRef, ongoingbj, pastList, offerMouseover, offerMouseout, offerlist, offerListRef };
},
});
appIndex.component("headTop", headTop);
appIndex.component("itemForum", itemForum);
appIndex.component("latestList", latestList);
appIndex.mount("#appIndex");