refactor(components): 重构多个组件并优化公共样式

重构了item-head、item-bottom、item-offer、item-summary和item-tenement组件,优化了props传递和数据处理逻辑
将公共头部和导航样式提取到public.css中,避免重复代码
修复了item-tenement组件中图片显示和数据处理的问题
更新了item-bottom组件的点赞和收藏逻辑,增加错误提示
优化了item-head组件的用户信息显示逻辑
调整了多个组件的样式细节,包括间距、图标大小等
This commit is contained in:
DESKTOP-RQ919RC\Pc
2025-10-30 19:09:38 +08:00
parent 28c890cf94
commit d4244fc783
38 changed files with 2092 additions and 4485 deletions

View File

@@ -11,14 +11,11 @@ import { like } from "../component/like/like.js";
const appSectionIndex = createApp({
setup() {
let signInAlreadyState = ref(false);
let permissions = ref([]);
onMounted(() => {
getUserInfoWin();
setTimeout(() => (permissions.value = window["permissions"] || []), 1000);
setTimeout(() => (permissions.value = window["permissions"] || ["comment.edit", "comment.delete", "offercollege.hide", "offersummary.hide", "mj.hide", "topic:manager", "topic:hide"]), 1000);
});
let isLogin = ref(true);
@@ -34,6 +31,8 @@ const appSectionIndex = createApp({
uin: 4238049,
});
let permissions = ref([]);
const getUserInfoWin = () => {
const checkUser = () => {
const user = window.userInfoWin;
@@ -42,6 +41,7 @@ const appSectionIndex = createApp({
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);
};
@@ -307,10 +307,11 @@ const appSectionIndex = createApp({
data.data.forEach((element, index) => {
element.timestamp = strtimeago(element.created_at, 4);
element["picture"] = [];
element["isReplyBoxShow"] = 0;
if (element.child.length > 0) {
element.child.forEach((el) => {
el["picture"] = [];
el.timestamp = strtimeago(element.created_at, 4);
el["isReplyBoxShow"] = 0;
});
@@ -328,9 +329,6 @@ const appSectionIndex = createApp({
commentList.value = commentList.value.concat(data.data);
commentTotalCount.value = data.count;
console.log("commentTotalCount.value", commentTotalCount.value);
commentPage.value = data.count > commentList.value.length ? commentPage.value + 1 : 0;
})
.finally(() => {
@@ -338,7 +336,7 @@ const appSectionIndex = createApp({
});
};
let picture = ref({});
let picture = ref([]);
const openUserInfo = (index, i) => {
if (i != undefined && commentList.value[index].child[i].user["uin"] > 0) commentList.value[index].child[i]["avatarState"] = true;
@@ -428,14 +426,497 @@ const appSectionIndex = createApp({
creationAlertBox("success", res.message || "操作成功");
// if (status) this.$parent.openLikeGif();
if (data["status"]) {
isLikeGif.value = true;
setTimeout(() => (isLikeGif.value = false), 2000);
}
});
};
let emojiState = ref(false);
let emojiMaskState = ref(false);
let inputTextarea = ref("");
// 打开 Emoji
const openEmoji = (index, i) => {
if (!isLogin.value) {
goLogin();
return;
}
if (i != undefined) commentList.value[index].child[i]["emojiState"] = true;
else if (index != undefined) commentList.value[index]["emojiState"] = true;
else {
closeEmoji();
closeAnswerCommentsChild();
emojiState.value = true;
}
emojiMaskState.value = true;
};
// 关闭 Emoji
const closeEmoji = (index, i) => {
commentList.value.forEach((ele) => {
ele["emojiState"] = false;
if (ele["child"] && ele["child"].length != 0) {
ele["child"].forEach((el) => {
el["emojiState"] = false;
});
}
});
emojiState.value = false;
emojiMaskState.value = false;
editEmojiState.value = false;
};
const TAHomePage = (uin) => goHomePage(uin);
const sendMessage = (uin) => goSendMessage(uin);
return { closeAnswerCommentsChild, openAnswerCommentsChild, dialogSrc, handleAnswerText, sendMessage, TAHomePage, operateAnswerCommentsLike, closeUserInfo, openUserInfo, permissions, commentList, commentPage, commentTotalCount, picture, userInfoWin, relatedList, relatedTime, coinNubmer, coinList, coinAmount, coinSubmit, strategy, mybalance, coinsState, openCoinBox, closeCoinBox, isLikeGif, likeClick, collectClick, islike, iscollect, recentlyList, medal, count, sectionn, tags, signInAlreadyState, authorInfo, info, timestamp, updatedTime };
let emojiData = ref(["😀", "😁", "😆", "😅", "😂", "😉", "😍", "🥰", "😘", "🤥", "😪", "😵‍💫", "🤓", "🥺", "😋", "😜", "🤪", "😎", "🤩", "🥳", "😔", "🙁", "😭", "😡", "😳", "🤗", "🤔", "🤭", "🤫", "😯", "😵", "🙄", "🥴", "🤢", "🤑", "🤠", "👌", "✌️", "🤟", "🤘", "🤙", "👍", "👎", "✊", "👏", "🤝", "🙏", "💪", "❎️", "✳️", "✴️", "❇️", "#️⃣", "*️⃣", "1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣", "🔟", "🆗", "🈶", "🉐", "🉑", "🌹", "🥀", "🌸", "🌺", "🌷", "🌲", "☘️", "🍀", "🍁", "🌙", "⭐", "🌍", "☀️", "⭐️", "🌟", "☁️", "🌈", "☂️", "❄️", "☃️", "☄️", "🔥", "💧", "🍎", "🍐", "🍊", "🍉", "🍓", "🍑", "🍔", "🍟", "🍕", "🥪", "🍜", "🍡", "🍨", "🍦", "🎂", "🍰", "🍭", "🍿", "🍩", "🧃", "🍹", "🍒", "🥝", "🥒", "🥦", "🥨", "🌭", "🥘", "🍱", "🍢", "🥮", "🍩", "🍪", "🧁", "🍵", "🍶", "🍻", "🥂", "🧋", "🎉", "🎁", "🧧", "🎃", "🎄", "🧨", "✨️", "🎈", "🎊", "🎋", "🎍", "🎀", "🎖️", "🏆️", "🏅", "💌", "📬", "🚗", "🚕", "🚲", "🛵", "🚀", "🚁", "⛵", "🚢", "🔮", "🧸", "🀄️"]);
const handleEditFile = () => {
editEmojiState.value = false;
judgeLogin();
};
// 选择 Emoji
const selectEmoji = (key, index, i) => {
closeEmoji();
if (i != undefined) {
if (!commentList.value[index]["child"][i]["commentInput"]) commentList.value[index]["child"][i]["commentInput"] = "";
commentList.value[index]["child"][i]["commentInput"] += key;
} else if (index != undefined) {
if (!commentList.value[index]["commentInput"]) commentList.value[index]["commentInput"] = "";
commentList.value[index]["commentInput"] += key;
} else inputTextarea.value += key;
};
const judgeLogin = () => {
if (!isLogin.value) goLogin();
};
const maxPicture = 10;
const handleFileUpload = (event, index, i) => {
closeEmoji();
const file = event.target.files[0]; // 获取选择的文件
if (!file) return;
if (file.size > maxSize) {
creationAlertBox("error", "文件大小不能超过 20MB");
return;
}
let target = [];
if (editCommentState.value) target = editPicture.value;
else {
if (i != undefined) target = commentList.value[index].child[i]["picture"];
else if (index != undefined) target = commentList.value[index]["picture"];
else target = picture.value;
}
if (target.length >= maxPicture) {
creationAlertBox("error", `最多只能上传 ${maxPicture} 张图片`);
return;
}
console.log("现有图片", target);
const reader = new FileReader();
reader.onload = (e) => {
const base64 = e.target.result;
uploadImg(file).then((res) => {
const obj = {
aid: res.aid || "",
url: res.url || "",
};
target.push(obj);
if (editCommentState.value) editPicture.value = target;
else {
if (i != undefined) commentList.value[index].child[i]["picture"] = target;
else if (index != undefined) commentList.value[index]["picture"] = target;
else picture.value = target;
}
creationAlertBox("success", "上传成功");
});
};
reader.readAsDataURL(file);
};
let uploadConfig = null;
const maxSize = 20 * 1024 * 1024; // 20MB
// 上传图片 获取图片url
const uploadImg = (file) => {
return new Promise((resolve, reject) => {
const upload = () => {
let config = uploadConfig;
const formData = new FormData();
formData.append(config.requestName, file); // 文件数据
formData.append("name", file.name); // 文件名
formData.append("type", "image"); // 文件名
formData.append("data", config.params.data); // 文件名
ajax(config.url, formData).then((res) => {
if (res.code != 200) {
creationAlertBox("error", "上传失败");
return;
}
let data = res.data;
resolve(data);
});
};
if (uploadConfig) upload();
else getUploadConfig().then(() => upload());
});
};
const getUploadConfig = () => {
return new Promise((resolve, reject) => {
ajax("https://api.gter.net/v1/config/upload?type=comment").then((res) => {
let data = res.data;
uploadConfig = data;
resolve();
});
});
};
// 删除上传的图片
const closeFileUpload = (aid, index, i) => {
let target = [];
if (i != undefined) target = [...commentList.value[index].child[i]["picture"]];
else if (index != undefined) target = [...commentList.value[index]["picture"]];
else target = [...picture.value];
let sub = target.findIndex((item) => item.aid == aid);
if (sub != -1) target.splice(sub, 1);
if (i != undefined) commentList.value[index].child[i]["picture"] = target;
else if (index != undefined) commentList.value[index]["picture"] = target;
else picture.value = target;
};
const closePictureUpload = (index) => picture.value.splice(index, 1);
// 提交回答-评论
const submitAnswerComments = (index, i) => {
if (realname.value == 0 && userInfoWin.value?.uin > 0) {
openAttest();
return;
}
if (!isLogin.value) {
goLogin();
return;
}
let content = "";
let parentid = null;
// let token = this.token;
let image = [];
if (i != null) {
content = commentList.value[index]["child"][i]["commentInput"];
parentid = commentList.value[index]["child"][i]["id"];
image = [...commentList.value[index]["child"][i]["picture"]];
} else if (index != null) {
content = commentList.value[index]["commentInput"];
parentid = commentList.value[index]["id"];
image = [...commentList.value[index]["picture"]];
} else {
content = inputTextarea.value;
image = [...picture.value];
}
// this.detailLoading = true;
const attachments = {
images: image,
};
ajax("/v2/api/forum/postComment", {
content,
token,
attachments,
replyid: parentid,
})
.then((res) => {
if (res.code != 200) {
creationAlertBox("error", res.message || "操作成功");
return;
}
let data = res.data;
const timestamp = strtimeago(new Date());
if (i != null) {
let targetData = {
id: data["commentid"],
content,
isauthor: 1,
islike: 0,
likenum: 0,
reply: {
nickname: commentList.value[index]["child"][i]["nickname"],
},
...data,
attachments,
picture: [],
timestamp,
};
commentList.value[index]["child"].push(targetData);
commentList.value[index]["childnum"]++;
} else if (index != null) {
let targetData = {
id: data["commentid"],
content,
isauthor: 1,
islike: 0,
likenum: 0,
reply: [],
...data,
attachments,
picture: [],
timestamp,
};
commentList.value[index]["child"].unshift(targetData);
commentList.value[index]["childnum"]++;
} else {
let targetData = {
id: data["commentid"],
content,
isauthor: 1,
islike: 0,
likenum: 0,
...data,
child: [],
attachments,
picture: [],
timestamp,
};
commentList.value.unshift(targetData);
inputTextarea.value = "";
picture.value = [];
}
commentTotalCount.value = data.count || 0;
// if (!inputTextarea.value) {
// const textarea = this.$refs["input-textarea"]
// textarea.style.height = "80px"
// }
closeAnswerCommentsChild();
creationAlertBox("success", res.message || "操作成功");
})
.finally(() => {
// this.detailLoading = false;
});
};
let editCommentState = ref(false);
let editToken = ref("");
let editPicture = ref([]);
let editInput = ref("");
let editEmojiState = ref(false);
const openEdit = (token, index, i) => {
const list = JSON.parse(JSON.stringify(commentList.value));
let target = {};
if (i != null) target = list[index]["child"][i];
else target = list[index];
console.log("target", target);
editToken.value = target.token || "";
editInput.value = target.content || "";
editPicture.value = target.attachments?.images || [];
console.log("editCommentState", editPicture.value);
editCommentState.value = true;
};
const closeEdit = () => {
editPicture.value = {};
editToken.value = "";
editInput.value = "";
editCommentState.value = false;
};
// 打开 Emoji
const openEditEmoji = (index, i) => {
if (!isLogin.value) {
goLogin();
return;
}
editEmojiState.value = true;
};
const closeEditEmoji = () => {
editEmojiState.value = false;
};
const selectEditEmoji = (key) => {
closeEmoji();
editInput.value += key;
};
const postEditComment = () => {
if (!isLogin.value) {
goLogin();
return;
}
const image = editPicture.value;
const attachments = {
images: image,
};
ajax("/v2/api/forum/postCommentEdit", {
content: editInput.value,
token: editToken.value,
attachments,
}).then((res) => {
if (res.code != 200) {
creationAlertBox("error", res.message || "操作失败");
return;
}
commentList.value.forEach((element) => {
if (element.token == editToken.value) {
element["content"] = editInput.value;
element["attachments"] = attachments;
}
element.child &&
element.child.forEach((ele) => {
if (ele.token == editToken.value) {
ele["content"] = editInput.value;
ele["attachments"] = attachments;
}
});
});
editPicture.value = [];
editToken.value = "";
editCommentState.value = false;
editEmojiState.value = false;
creationAlertBox("success", res.message || "操作成功");
});
};
const closeEditFileUpload = (aid) => {
let target = [...editPicture.value];
let sub = target.findIndex((item) => item.aid == aid);
if (sub != -1) target.splice(sub, 1);
editPicture.value = target;
};
const handleInputPaste = (event, index, ii) => {
const items = event.clipboardData.items; // 获取粘贴的内容
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.type.startsWith("image/")) {
event.preventDefault();
const file = item.getAsFile(); // 获取文件
if (file.size > maxSize) {
creationAlertBox("error", "文件大小不能超过 20MB");
return;
}
let target = [];
if (editCommentState.value) target = editPicture.value;
else {
if (ii != undefined) target = commentList.value[index].child[ii]["picture"];
else if (index != undefined) target = commentList.value[index]["picture"];
else target = picture.value;
}
if (target.length >= maxPicture) {
creationAlertBox("error", `最多只能上传 ${maxPicture} 张图片`);
return;
}
const reader = new FileReader();
reader.onload = (e) => {
const base64 = e.target.result;
uploadImg(file).then((res) => {
const obj = {
aid: res.aid || "",
url: res.url || "",
};
target.push(obj);
if (editCommentState.value) editPicture.value = target;
else {
if (ii != undefined) commentList.value[index].child[ii]["picture"] = target;
else if (index != undefined) commentList.value[index]["picture"] = target;
else picture.value = target;
}
creationAlertBox("success", "上传成功");
});
};
reader.readAsDataURL(file);
}
}
};
// 自动输入框增高
const autoResize = (e) => {
e.target.style.height = "auto"; // 重置高度
e.target.style.height = `${e.target.scrollHeight}px`; // 设置为内容高度
};
let commemtDelete = {};
// 点击删除
const commentDelete = (token, index, i) => {
const post = () => {
ajax("/v2/api/forum/deleteComment", {
token,
}).then((res) => {
if (res.code != 200) {
creationAlertBox("error", res.message);
return;
}
if (i >= 0) {
commentList.value[index].child.splice(i, 1);
commentList.value[index].childnum -= 1;
} else {
commentList.value.splice(index, 1);
}
commentTotalCount.value -= 1;
creationAlertBox("success", res.message || "操作成功");
});
};
const isConfirmed = confirm(`确定要删除讨论吗?`);
if (isConfirmed) post();
};
const openDiscuss = () => {
let dom = document.querySelector(".answer-discuss");
if (!dom) return;
const rect = dom.getBoundingClientRect();
const scrollPosition = window.pageYOffset + rect.top - 50;
window.scrollTo({
top: scrollPosition,
behavior: "smooth",
});
};
return { openDiscuss, commentDelete, handleInputPaste, autoResize, editCommentState, selectEditEmoji, closeEditEmoji, openEditEmoji, closeEdit, openEdit, closeEditFileUpload, postEditComment, submitAnswerComments, closePictureUpload, closeFileUpload, picture, editToken, editPicture, editInput, editEmojiState, handleFileUpload, inputTextarea, judgeLogin, handleEditFile, selectEmoji, emojiData, emojiMaskState, emojiState, closeEmoji, openEmoji, closeAnswerCommentsChild, openAnswerCommentsChild, dialogSrc, handleAnswerText, sendMessage, TAHomePage, operateAnswerCommentsLike, closeUserInfo, openUserInfo, permissions, commentList, commentPage, commentTotalCount, picture, userInfoWin, relatedList, relatedTime, coinNubmer, coinList, coinAmount, coinSubmit, strategy, mybalance, coinsState, openCoinBox, closeCoinBox, isLikeGif, likeClick, collectClick, islike, iscollect, recentlyList, medal, count, sectionn, tags, authorInfo, info, timestamp, updatedTime };
},
});

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -25,7 +25,8 @@ const ajax = (url, data) => {
resolve(data);
})
.catch((err) => {
if (err.response.status == 401)
reject();
if (err.response?.status == 401)
showWindow("login", "https://passport.gter.net/login/ajax", "get", -1, {
cover: true,
});
@@ -336,3 +337,48 @@ const goSendMessage = (uin) => {
}
redirectToExternalWebsite(`https://bbs.gter.net/home.php?mod=space&showmsg=1&uid=${uin}`);
};
const lang = {
money: { 1: "3000以下", 2: "3000-4000", 3: "4000-5000", 4: "5000-6500", 5: "6500-8000", 6: "8000-10000", 7: "10000-20000", 8: "20000-30000", 9: "30000-40000", 10: "40000-50000", 11: "50000以上" },
leaseterm: { 1: "长租", 2: "短租" },
intermediary: { 1: "中介", 2: "非中介", 3: "房东", 4: "有房招室友", 5: "其他", 6: "求房源" },
property: { 1: "唐楼", 2: "洋楼", 3: "酒店式公寓", 4: "村屋", 5: "其他", 6: "学生公寓", 7: "house", 8: "屋苑", 9: "酒店" },
elevator: { 1: "有电梯", 2: "无电梯", "-1": "不限" },
sunshinearea: { 1: "阳台", 2: "天台", "-1": "无" },
floor: { 1: "低层", 2: "中层", 3: "高层", 4: "地下", 5: "不要一楼", 6: "不要顶层" },
tenementtype: { 1: "合租", 2: "整租", 1.5: "独卫套房", 1.1: "房间", 1.2: "床位", 1.3: "客厅", 1.4: "其他", 2.1: "studio", 2.2: "一房", 2.3: "两房", 2.4: "三房", 2.5: "四房以上" },
gender: { 1: "女性", 2: "男性", 3: "男女皆可" },
location: { 1: "港岛", 2: "九龙", 3: "新界", 1.1: "上环/中环/金钟", 1.2: "湾仔/铜锣湾", 1.3: "天后/炮台山", 1.4: "北角/则鱼涌", 1.5: "太古/西湾河", 1.6: "筲箕湾/柴湾", 1.7: "西营盘/坚尼地城/石塘咀", 1.8: "薄扶林", 1.9: "赤柱/香港仔", 1.11: "半山/山顶", 1.12: "南区", 2.1: "九龙站/奥运/南昌", 2.2: "尖沙咀/佐敦", 2.3: "长沙湾/深水埗/荔枝角", 2.4: "美孚/荔景", 2.5: "红磡/黄埔", 2.6: "土瓜湾/何文田", 2.7: "九龙城/启德", 2.8: "石夹尾/九龙塘", 2.9: "乐富/黄大仙", 2.11: "钻石山/彩虹", 2.12: "牛头角/九龙湾/观塘", 2.13: "蓝田/油塘", 2.14: "调景岭", 2.15: "油麻地/旺角/太子", 3.1: "葵芳/葵兴", 3.2: "荃湾", 3.3: "将军澳/坑口/宝琳", 3.4: "大埔仔/西贡", 3.5: "康城", 3.6: "大围/沙田", 3.7: "马鞍山", 3.8: "大埔/火炭/太和", 3.9: "粉岭/上水", 3.11: "赤泥坪/大埔尾/樟树滩", 3.12: "元朗/天水围/屯门", 3.13: "青衣", 3.14: "东涌/马湾/愉景湾", 3.15: "长洲" },
apartmentschool: [
{ id: 1, name: "港大", sid: 309 },
{ id: 2, name: "城大", sid: 311 },
{ id: 3, name: "理工", sid: 312 },
{ id: 4, name: "浸会", sid: 313 },
{ id: 5, name: "中大", sid: 308 },
{ id: 6, name: "教大", sid: 453 },
{ id: 7, name: "科大", sid: 310 },
{ id: 8, name: "岭大", sid: 314 },
{ id: 9, name: "都大", sid: 315 },
],
rentalduration: { 1: "1个月", 2: "2个月", 3: "3个月", 4: "4个月", 5: "5个月", 6: "6个月", 7: "7个月", 8: "8个月", 9: "9个月", 10: "10个月", 11: "11个月", 12: "1年", 13: "1年1个月", 14: "1年2个月", 15: "1年3个月", 16: "1年4个月", 17: "1年5个月", 18: "1年6个月", 24: "2年", 36: "3年" },
};
let copyUid = (text) => {
if (navigator.clipboard)
copyUid = () => {
navigator.clipboard.writeText(text);
creationAlertBox("success", "复制成功");
};
else {
copyUid = () => {
var tempInput = document.createElement("input");
tempInput.value = text;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand("copy");
document.body.removeChild(tempInput);
creationAlertBox("success", "复制成功");
};
}
copyUid();
};

View File

@@ -23,6 +23,8 @@ const watchList = {
"../component/latest-list/latest-list.txt": "../component/latest-list/latest-list.js",
// 监听 slideshow-box.txt同步到 slideshow-box.js
"../component/slideshow-box/slideshow-box.txt": "../component/slideshow-box/slideshow-box.js",
// 监听 head-top.txt同步到 head-top.js
"../component/head-top/head-top.txt": "../component/head-top/head-top.js",
// 可添加更多文件(格式:'txt路径': 'js路径'
// './component/other/other.txt': './component/other/other.js',

23
js/search.js Normal file
View File

@@ -0,0 +1,23 @@
const { createApp, ref, onMounted, nextTick, onUnmounted, computed, watch, provide } = Vue;
import { itemForum } from "../component/item-forum/item-forum.js";
const appSearch = createApp({
setup() {
onMounted(() => {
const params = getUrlParams();
const id = params.section || "";
if (id) {
section.value = id;
init();
}
section.value = id;
// init();
});
return {};
},
});
appSearch.component("item-forum", itemForum);
appSearch.mount("#sectionIndex");

View File

@@ -3,7 +3,6 @@ import { itemForum } from "../component/item-forum/item-forum.js";
const appSectionIndex = createApp({
setup() {
let signInAlreadyState = ref(false);
onMounted(() => {
const params = getUrlParams();
const id = params.section || "";
@@ -199,7 +198,7 @@ const appSectionIndex = createApp({
updateUrlParams({ section: uniqid });
};
return { changeSection, signInAlreadyState, sectionList, section, info, handpickList, tagsList, list, count };
return { changeSection, sectionList, section, info, handpickList, tagsList, list, count };
},
});
appSectionIndex.component("item-forum", itemForum);