refactor: 移除调试日志并优化代码结构
移除多个文件中的console.log调试语句 添加search-tag.css和search-tag.less中的set-hint-box样式 新增recommend.js推荐功能模块 优化ajaxGet调用和用户信息处理逻辑
This commit is contained in:
@@ -102,8 +102,6 @@ class BiCard extends HTMLElement {
|
||||
vote: "投票",
|
||||
};
|
||||
|
||||
console.log("obj[this.pagetpye]", this.pagetpye);
|
||||
|
||||
this.pagetpyeText.textContent = obj[this.pagetpye];
|
||||
}
|
||||
|
||||
|
||||
@@ -65,8 +65,6 @@ class HeadTopWeb extends HTMLElement {
|
||||
vote: "投票",
|
||||
};
|
||||
|
||||
console.log("obj[this.pagetpye]", this.pagetpye);
|
||||
|
||||
this.pagetpyeText.textContent = obj[this.pagetpye];
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ export const headTop = defineComponent({
|
||||
let isPaused = ref(false); // 是否暂停轮播
|
||||
|
||||
onMounted(() => {
|
||||
console.log("getScriptParameter", getScriptParameter("v"));
|
||||
getHistorySearch();
|
||||
// 写一个函数 ,判断本地缓存有没有 wConfig 并判断 是否过一天 如果过了一天 则更新 wConfig
|
||||
checkWConfig();
|
||||
@@ -106,8 +105,6 @@ export const headTop = defineComponent({
|
||||
|
||||
let page = ref(props.page);
|
||||
|
||||
console.log("page", page.value, props.page);
|
||||
|
||||
let input = ref("");
|
||||
|
||||
let historySearchList = ref([]); // 历史搜索数据
|
||||
|
||||
@@ -139,7 +139,6 @@ export const itemBottom = defineComponent({
|
||||
|
||||
// 3. 计算距离:可视窗口宽度 - 元素右边缘到左边缘的距离
|
||||
const distance = clientWidth - rect.right;
|
||||
console.log("distance", distance);
|
||||
|
||||
if (distance < 140) isright.value = true;
|
||||
else isright.value = false;
|
||||
|
||||
@@ -126,7 +126,6 @@ export const itemHead = defineComponent({
|
||||
};
|
||||
|
||||
const goPersonalHomepage = (token) => {
|
||||
console.log("token", token);
|
||||
if (!token) return;
|
||||
redirectToExternalWebsite(`/u/${token}`);
|
||||
};
|
||||
@@ -150,7 +149,6 @@ export const itemHead = defineComponent({
|
||||
anonymous: state,
|
||||
})
|
||||
.then((res) => {
|
||||
console.log("res", res);
|
||||
if (res.code != 200) return;
|
||||
const data = res.data || {};
|
||||
target.anonymous = data.anonymous || 0;
|
||||
|
||||
@@ -22,12 +22,6 @@ export const itemSummary = defineComponent({
|
||||
setup(props) {
|
||||
let item = ref({ ...props.itemdata });
|
||||
|
||||
// console.log("item", item.value.data);offerlist
|
||||
// item.value?.data?.offerlist?.length = 2;
|
||||
// if (item.value?.data?.offerlist?.length > 2) {
|
||||
// item.value.data.offerlist.length = 2;
|
||||
// }
|
||||
|
||||
item.value["url"] = "/details/" + item.value.uniqid;
|
||||
|
||||
let valueUrl = ref("");
|
||||
|
||||
@@ -22,8 +22,6 @@ export const itemTenement = defineComponent({
|
||||
setup(props) {
|
||||
const handleHousing = (ele) => {
|
||||
const langs = lang;
|
||||
console.log("langs", langs);
|
||||
|
||||
if (ele["distance"]) ele["distance"] = Math.round(ele["distance"] * 10) / 10;
|
||||
// 这个是将 详情键 替换语言包里的值
|
||||
let list = ["tenementtype", "rentalduration", "intermediary", "property", "elevator", "sunshinearea", "gender"];
|
||||
@@ -64,7 +62,6 @@ export const itemTenement = defineComponent({
|
||||
return ele;
|
||||
};
|
||||
let item = ref({ ...props.itemdata });
|
||||
// console.log("item", item.value);
|
||||
item.value = handleHousing(item.value);
|
||||
item.value["url"] = "https://fang.gter.net/detail?id=" + item.value.uniqid;
|
||||
let sectionn = ref([]);
|
||||
|
||||
@@ -58,7 +58,6 @@ export const latestList = defineComponent({
|
||||
const topicHandpicked = () => {
|
||||
ajaxGet(`/v2/api/forum/getHomebestRecommend?limit=15&type=thread`).then((res) => {
|
||||
const data = res.data;
|
||||
console.log("data", data);
|
||||
topList.value = data;
|
||||
nextTick(() => {
|
||||
count += 1;
|
||||
|
||||
@@ -250,7 +250,6 @@ class SignInBox extends HTMLElement {
|
||||
}
|
||||
|
||||
postSign() {
|
||||
console.log('document.querySelector(".sign-in")', document.querySelector(".sign-in"));
|
||||
if (this.issign == 1) {
|
||||
creationAlertBox("error", "今天已签到,明天记得来哦~");
|
||||
return;
|
||||
|
||||
@@ -70,7 +70,6 @@ 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";
|
||||
|
||||
|
||||
@@ -17,6 +17,14 @@
|
||||
font-size: 28px;
|
||||
color: #000000;
|
||||
}
|
||||
#search-tag .set-hint-box {
|
||||
line-height: 24px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
#search-tag .set-hint-box .set-hint-icon {
|
||||
height: 24px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
#search-tag .classify {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
.set-hint-box {
|
||||
line-height: 24px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.set-hint-icon {
|
||||
height: 24px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.classify {
|
||||
margin-bottom: 16px;
|
||||
.item {
|
||||
|
||||
@@ -250,8 +250,6 @@ const { createApp, ref, onMounted, nextTick, onUnmounted, computed, watch, provi
|
||||
return `<img src="${image.url}" ${style}>`;
|
||||
});
|
||||
|
||||
console.log(html);
|
||||
|
||||
// 5. 统一在单次遍历中按出现顺序替换 attach/attachimg
|
||||
const byAid = new Map();
|
||||
imageList.forEach((e) => byAid.set(Number(e.aid), { type: "image", ...e }));
|
||||
@@ -1013,7 +1011,6 @@ const { createApp, ref, onMounted, nextTick, onUnmounted, computed, watch, provi
|
||||
editCommentState.value = true;
|
||||
|
||||
nextTick(() => {
|
||||
console.log('editInputRef.value',editInputRef.value);
|
||||
editInputRef.value.style.height = "auto"; // 重置高度
|
||||
editInputRef.value.style.height = `${editInputRef.value.scrollHeight}px`; // 设置为内容高度
|
||||
});
|
||||
|
||||
@@ -165,9 +165,7 @@ const editApp = createApp({
|
||||
|
||||
const infoTarget = data.info || {};
|
||||
|
||||
// console.log("content", infoTarget.content);
|
||||
if (infoTarget.content) infoTarget.content = restoreHtml(infoTarget.content, infoTarget.attachments);
|
||||
// console.log("content", infoTarget.content);
|
||||
|
||||
info.value = infoTarget;
|
||||
token.value = data.token;
|
||||
@@ -257,7 +255,6 @@ const editApp = createApp({
|
||||
async customUpload(file, insertFn) {
|
||||
try {
|
||||
const img = await uploading(file, file.name, "image");
|
||||
console.log("img", img);
|
||||
|
||||
insertFn(`${img.url}?aid=${img.aid}`);
|
||||
} catch (err) {
|
||||
@@ -430,7 +427,6 @@ const editApp = createApp({
|
||||
|
||||
// 定义图片处理函数
|
||||
const processImg = (aid, width, height, href) => {
|
||||
console.log("processImg", aid, width, height, href);
|
||||
const image = imageList.find((img) => String(img.aid) === String(aid));
|
||||
if (!image) return "";
|
||||
|
||||
|
||||
@@ -95,7 +95,6 @@ const appIndex = createApp({
|
||||
};
|
||||
|
||||
ongoingbj.value = getTargetItem(ongoing || []) || {};
|
||||
console.log("ongoingbj", ongoingbj.value);
|
||||
const past = data.past || [];
|
||||
pastList.value = past.sort(() => Math.random() - 0.5).slice(0, 5);
|
||||
});
|
||||
|
||||
217
js/recommend.js
Normal file
217
js/recommend.js
Normal file
@@ -0,0 +1,217 @@
|
||||
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();
|
||||
getList();
|
||||
|
||||
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({});
|
||||
|
||||
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/topicLists?type=thread&page=1&limit=20&recommend=1`).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(`/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");
|
||||
@@ -16,7 +16,8 @@ const appSearch = createApp({
|
||||
let tag = ref("");
|
||||
onMounted(() => {
|
||||
const params = getUrlParams();
|
||||
tag.value = params.tag || "";
|
||||
// tag.value = params.tag || "";
|
||||
|
||||
init();
|
||||
|
||||
getUserInfoWin();
|
||||
@@ -25,16 +26,7 @@ const appSearch = createApp({
|
||||
|
||||
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 userInfoWin = ref({});
|
||||
|
||||
let permissions = ref([]);
|
||||
|
||||
@@ -100,7 +92,7 @@ const appSearch = createApp({
|
||||
|
||||
let uniqid = "";
|
||||
const init = () => {
|
||||
ajaxget(`/v2/api/forum/tagDetails?name=${tag.value}`).then((res) => {
|
||||
ajaxGet(`/v2/api/forum/tagDetails?name=${tag.value}`).then((res) => {
|
||||
if (res.code != 200) {
|
||||
creationAlertBox("error", res.message);
|
||||
page.value = 0;
|
||||
@@ -125,7 +117,7 @@ const appSearch = createApp({
|
||||
// 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}`)
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user