From dc871d80c053b47714d252ed508edbb67d7d7003 Mon Sep 17 00:00:00 2001 From: "DESKTOP-RQ919RC\\Pc" <1300399510@qq.com> Date: Fri, 7 Nov 2025 19:42:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0BI=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E5=A4=9A=E4=B8=AA=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E5=92=8C=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor: 重构slideshow-box组件,移除帖子标签 fix: 修复item-bottom组件中QR码加载状态显示问题 style: 调整多个页面的CSS样式,包括字体大小和间距 perf: 优化save.js文件同步逻辑,支持更多模板格式 docs: 更新组件文档和注释 chore: 添加bi组件相关文件并配置监听同步 test: 更新测试用例以适应组件变更 --- component/bi/bi.js | 207 ++++++++++++++++++ component/bi/bi.txt | 252 ++++++++++++++++++++++ component/head-top/head-top.js | 15 +- component/head-top/head-top.txt | 52 +++-- component/item-bottom/item-bottom.js | 3 +- component/item-bottom/item-bottom.txt | 7 +- component/latest-list/latest-list.js | 2 +- component/slideshow-box/slideshow-box.js | 14 +- component/slideshow-box/slideshow-box.txt | 8 +- css/details.css | 38 ++-- css/details.less | 43 ++-- css/edit.css | 2 + css/edit.less | 2 + css/homepage-other.css | 2 +- css/homepage-other.less | 2 +- css/index.css | 14 +- css/index.less | 14 +- css/public.css | 23 +- css/public.less | 27 ++- css/search-tag.css | 8 + css/search-tag.less | 8 + css/search.css | 8 + css/search.less | 8 + css/section.css | 27 ++- css/section.less | 76 ++++--- index.html | 5 + js/index.js | 7 +- js/save.js | 14 +- 28 files changed, 768 insertions(+), 120 deletions(-) create mode 100644 component/bi/bi.js create mode 100644 component/bi/bi.txt diff --git a/component/bi/bi.js b/component/bi/bi.js new file mode 100644 index 0000000..294b0e6 --- /dev/null +++ b/component/bi/bi.js @@ -0,0 +1,207 @@ +// 1. 创建组件模板和样式(内置到 JS 中,无需外部 HTML/Template) +const template = document.createElement("template"); +template.innerHTML = `
该帖子已获得
个寄托币
投币
你当前共有
寄托币 [挣币攻略]
`; + +// 2. 定义组件类 +class BiCard extends HTMLElement { + constructor() { + super(); + + this.coins = 0; + this.token = ""; + this.pagetpye = ""; + + // 创建 Shadow DOM 并挂载模板 + this.attachShadow({ mode: "open" }); + this.shadowRoot.appendChild(template.content.cloneNode(true)); + this.strategyEl = this.shadowRoot.querySelector(".coins-info .strategy"); + this.mybalanceEl = this.shadowRoot.querySelector(".coins-info .sum"); + this.coinsAreaEl = this.shadowRoot.querySelector(".coins-area"); + this.coinsEl = this.shadowRoot.querySelector(".coins-area .coins-head .sum"); + + this.coinSubmitEl = this.shadowRoot.querySelector(".coins-input .coinSubmit"); + this.closeCoinBoxEl = this.shadowRoot.querySelector(".coins-area .closeCoinBox"); + + this.coinSubmitEl.addEventListener("click", () => this.coinSubmit()); + this.closeCoinBoxEl.addEventListener("click", () => this.closeCoinBox()); + + this.input = this.shadowRoot.querySelector(".coins-input .input"); + + this.coinListAreaEl = this.shadowRoot.querySelector(".coins-list-area"); + + this.defaultcoinnum = 0; + // 将实例存储到全局变量中,以便外部调用 + window.biComponent = this; + } + + // 监听的属性列表 + static get observedAttributes() { + return ["coins", "token", "pagetpye"]; + } + + // 属性变化回调 + attributeChangedCallback(attrName, oldVal, newVal) { + this[attrName] = newVal; // 同步属性值到变量 + } + + init() { + this.getCoinConfig(); + if (!this.coinListAreaEl.querySelector(".list")) this.getCoinRankList(); + } + + getCoinConfig() { + this.$ajaxget(`https://api.gter.net/v2/api/forum/getCoinConfig`).then((res) => { + const data = res.data; + const strategy = data.config.strategy.url || 0; + const mybalance = data.mybalance || 0; + const defaultcoinnum = data.defaultcoinnum || 0; + + // 替换策略链接 + this.strategyEl.href = strategy; + this.mybalanceEl.textContent = mybalance; + this.coinsEl.textContent = this.coins; + this.defaultcoinnum = defaultcoinnum; + + this.coinsAreaEl.style.display = "flex"; + }); + } + + getCoinRankList() { + this.$ajaxget(`https://api.gter.net/v2/api/forum/getCoinRankList?token=${this.token}&limit=1000`).then((res) => { + const data = res.data; + this.coinListAreaEl.innerHTML = ""; + const coinNubmer = data.nubmer; + if (coinNubmer == 0) return + const total = `
${coinNubmer}
人参与投币:
`; + + const coinList = data.data; + let list = coinList + .map((item) => { + return `
+
${item.rank}
+ + +
${item.user.nickname || "匿名用户"}
+
+
+ ${item.coins} +
+
+
`; + }) + .join(""); + list = `
${list}
`; + const listHTML = total + list; + this.coinListAreaEl.innerHTML = listHTML; + }); + } + + coinSubmit() { + const num = Number(this.input.value || this.defaultcoinnum) || 0; + this.$ajax(`https://api.gter.net/v2/api/forum/postTopicCoin`, { + token: this.token, + num, + }).then((res) => { + if (res.code == 200) creationAlertBox("success", res.message); + else creationAlertBox("error", res.message); + + if (res.code != 200) return; + let data = res.data; + + this.mybalanceEl.textContent = Number(this.mybalanceEl.textContent) - num || 0; + this.input.value = ""; + const coins = data.coins; + this.coinsEl.textContent = coins || 0; + + if (this.pagetpye == "forum") document.querySelector(".action-bar-item.coins .text").textContent = coins || 0; + + this.getCoinRankList(); + }); + } + + closeCoinBox() { + this.coinsAreaEl.style.display = "none"; + } + + // 静态方法,用于在外部调用组件初始化 + static initComponent() { + if (window.biComponent) { + window.biComponent.init(); + return true; + } + console.warn("bi组件尚未加载或挂载"); + return false; + } + + // 生命周期:组件挂载 + connectedCallback() {} + + // 生命周期:组件卸载 + disconnectedCallback() { + console.log(`用户卡片 ${this.getAttribute("username")} 已卸载`); + } + + $ajax(url) { + var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return new Promise(function (resolve, reject) { + axios + .post(url, data, { + emulateJSON: true, + withCredentials: true, + }) + .then(function (res) { + var data = typeof res.data == "string" ? JSON.parse(res.data) : res.data; + + if (data.code == 401) { + // 需要登录 + showWindow("login", "https://passport.gter.net/login/ajax", "get", -1, { + cover: true, + }); + reject(); + } + resolve(data); + }) + .catch((err) => { + if (err.response.status == 401) + showWindow("login", "https://passport.gter.net/login/ajax", "get", -1, { + cover: true, + }); + }); + }); + } + + $ajaxget(url) { + var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return new Promise(function (resolve, reject) { + axios + .get( + url, + {}, + { + emulateJSON: true, + withCredentials: true, + } + ) + .then(function (res) { + var data = typeof res.data == "string" ? JSON.parse(res.data) : res.data; + if (data.code == 401) { + // 需要登录 + showWindow("login", "https://passport.gter.net/login/ajax", "get", -1, { + cover: true, + }); + reject(); + } + resolve(data); + }) + .catch((error) => { + reject(error); + }); + }); + } +} + +// 3. 注册组件(确保只注册一次) +if (!customElements.get("bi-card")) customElements.define("bi-card", BiCard); + +// 4. 导出组件类,以便在外部直接调用 +window.BiComponent = BiCard; diff --git a/component/bi/bi.txt b/component/bi/bi.txt new file mode 100644 index 0000000..4d1b620 --- /dev/null +++ b/component/bi/bi.txt @@ -0,0 +1,252 @@ + + +
+
+ +
+ +
+ 该帖子已获得 +
+ 个寄托币 +
+
+
+ +
投币
+
+ +
+ + 你当前共有 +
+ 寄托币 + [挣币攻略] +
+ +
+
+
\ No newline at end of file diff --git a/component/head-top/head-top.js b/component/head-top/head-top.js index 61874ab..e5dfe27 100644 --- a/component/head-top/head-top.js +++ b/component/head-top/head-top.js @@ -5,7 +5,12 @@ const { defineComponent, ref, onMounted, nextTick } = Vue; // 定义组件(直接使用模板) export const headTop = defineComponent({ name: "headTop", - props: {}, + props: { + page: { + type: String, + default: "", + }, + }, setup(props) { onMounted(() => {}); @@ -44,8 +49,12 @@ export const headTop = defineComponent({ let pitchState = ref(false); - return { pitchState, state, signIn, input, defaultSearchText, goSearch }; + let page = ref(...props.page); + + // console.log("page", page.value); + + return { page, pitchState, state, signIn, input, defaultSearchText, goSearch }; }, - template: `
签到领寄托币
GO
已签到,明天再来
`, + template: `
`, }); diff --git a/component/head-top/head-top.txt b/component/head-top/head-top.txt index d2496b1..45abe97 100644 --- a/component/head-top/head-top.txt +++ b/component/head-top/head-top.txt @@ -7,22 +7,40 @@ - -
- - - - 签到领寄托币 -
- - GO +
+ + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/component/item-bottom/item-bottom.js b/component/item-bottom/item-bottom.js index 82f8f60..b9903ec 100644 --- a/component/item-bottom/item-bottom.js +++ b/component/item-bottom/item-bottom.js @@ -106,6 +106,7 @@ export const itemBottom = defineComponent({ let QRcode = ref(""); const showQRcode = () => { if (QRcode.value) return + // return ajaxGet(`/v2/api/forum/getQrcode?token=${item.value.token}`).then((res) => { if (res.code != 200) return; const data = res.data || {}; @@ -120,5 +121,5 @@ export const itemBottom = defineComponent({ like, }, - template: `
{{ item?.commentreviews?.content || "[图]" }}
{{ item.collections || "收藏" }}
{{ item.comments || "讨论" }}
{{ item.coins || "投币" }}
`, + template: `
{{ item?.commentreviews?.content || "[图]" }}
{{ item.collections || "收藏" }}
{{ item.comments || "讨论" }}
{{ item.coins || "投币" }}
`, }); diff --git a/component/item-bottom/item-bottom.txt b/component/item-bottom/item-bottom.txt index ed65304..5aa4410 100644 --- a/component/item-bottom/item-bottom.txt +++ b/component/item-bottom/item-bottom.txt @@ -44,8 +44,11 @@
微信转发
-
- +
+ +
+ +
微信扫码
diff --git a/component/latest-list/latest-list.js b/component/latest-list/latest-list.js index 303c070..bd4f52c 100644 --- a/component/latest-list/latest-list.js +++ b/component/latest-list/latest-list.js @@ -53,7 +53,7 @@ export const latestList = defineComponent({ let topList = ref([]); const topicHandpicked = () => { - ajaxGet(`/v2/api/forum/topicLists?simple=1&best=1`).then((res) => { + ajaxGet(`/v2/api/forum/topicLists?simple=1&best=1&limit=15`).then((res) => { const data = res.data; topList.value = data.data; nextTick(() => { diff --git a/component/slideshow-box/slideshow-box.js b/component/slideshow-box/slideshow-box.js index 427bd2d..3b1c0c1 100644 --- a/component/slideshow-box/slideshow-box.js +++ b/component/slideshow-box/slideshow-box.js @@ -17,7 +17,7 @@ export const slideshowBox = defineComponent({ onMounted(() => getTopicLatest()); - let tabPitch = ref("thread"); // thread offer vote interviewexperience + let tabPitch = ref(""); // thread offer vote interviewexperience let latestList = ref({}); const getTopicLatest = () => { @@ -25,8 +25,8 @@ export const slideshowBox = defineComponent({ const data = res.data || []; (data.vote || []).forEach((item) => { if (!item.title) { - item.title = item.content; - item.content = ""; + // item.title = item.content; + // item.content = ""; } }); @@ -38,9 +38,10 @@ export const slideshowBox = defineComponent({ }); }; - const tabArr = ["thread", "offer", "vote", "interviewexperience"]; + const tabArr = ["offer", "vote", "interviewexperience"]; + // const tabArr = ["thread", "offer", "vote", "interviewexperience"]; - const tabItem = (key) => { + const tabItem = (key) => { if (key == tabPitch.value) return; const boxbox = document.querySelector(`.box-box`); @@ -62,6 +63,7 @@ export const slideshowBox = defineComponent({ // 修改全局背景状态的 let targetContentNode = boxbox.querySelector(`.slideshow-content .${key}-side-box`); let targetContentHeight = targetContentNode.offsetHeight; + console.log("targetContentHeight", targetContentHeight); boxbox.style.height = targetContentHeight + 66 + "px"; @@ -78,5 +80,5 @@ export const slideshowBox = defineComponent({ return { tabItem, tabPitch, tabPitch, latestList }; }, - template: `
帖子
Offer
投票
面经
`, + template: `
Offer
投票
面经
`, }); diff --git a/component/slideshow-box/slideshow-box.txt b/component/slideshow-box/slideshow-box.txt index 39d5326..7f8c7c9 100644 --- a/component/slideshow-box/slideshow-box.txt +++ b/component/slideshow-box/slideshow-box.txt @@ -1,7 +1,7 @@
-
帖子
+
Offer
投票
面经
@@ -9,7 +9,7 @@
-