// my-component.js // 引入全局 Vue 对象(因在 HTML 中通过 script 引入,Vue 已挂载到 window) const { defineComponent, ref, onMounted, nextTick } = Vue; // 定义组件(直接使用模板) export const slideshowBox = defineComponent({ name: "slideshowBox", props: { itemdata: { type: Object, default: () => {}, }, }, setup(props) { let item = ref({ ...props.itemdata }); onMounted(() => getTopicLatest()); let tabPitch = ref(""); // thread offer vote interviewexperience let latestList = 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 = ""; } }); latestList.value = data; nextTick(() => { tabItem(tabArr[Math.floor(Math.random() * tabArr.length)]); }); }); }; const tabArr = ["offer", "vote", "interviewexperience"]; // const tabArr = ["thread", "offer", "vote", "interviewexperience"]; const tabItem = (key) => { if (key == tabPitch.value) return; const boxbox = document.querySelector(`.box-box`); boxbox.classList.add(`box-${key}`); let index = tabArr.indexOf(key); // 修改 tab 状态的 if (tabPitch.value) { let oldNode = boxbox.querySelector(`.slideshow-box .tab-item.${tabPitch.value}`); oldNode.classList.toggle("pitch"); boxbox.classList.remove(`box-${tabPitch.value}`); } let targetTabNode = boxbox.querySelector(`.slideshow-box .tab-item.${key}`); targetTabNode.classList.toggle("pitch"); let targetHeight = targetTabNode.offsetHeight; // 修改全局背景状态的 let targetContentNode = boxbox.querySelector(`.slideshow-content .${key}-side-box`); let targetContentHeight = targetContentNode.offsetHeight; console.log("targetContentHeight", targetContentHeight); boxbox.style.height = targetContentHeight + 66 + "px"; let slideshowContent = boxbox.querySelector(".slideshow-content"); slideshowContent.scrollTo({ left: 272 * index, behavior: "smooth", }); tabPitch.value = key; }; const handleCheckAttest = (e) => { if (realname.value === 0 && userInfoWin.value?.uin > 0) { openAttest(); e.preventDefault(); // 阻止默认跳转(即使 href 为链接,也强制拦截) } }; return { handleCheckAttest, tabItem, tabPitch, tabPitch, latestList }; }, template: `