Files
PC-Light-Forum/component/item-bottom/item-bottom.js
DESKTOP-RQ919RC\Pc 671732d277 feat: 更新组件样式和功能,优化路由链接和用户体验
refactor: 重构组件模板,统一使用相对路径和内部路由

style: 调整CSS样式,修复布局和间距问题

fix: 修复投票和offer组件链接错误问题

chore: 添加新图片资源并更新相关引用路径

perf: 移除调试日志,优化页面加载性能

docs: 更新组件注释和文档说明

test: 更新测试用例以适配新功能

ci: 调整构建配置以支持新资源文件

build: 更新依赖项以兼容新功能
2025-11-03 19:20:55 +08:00

124 lines
6.4 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.

// my-component.js
// 引入全局 Vue 对象(因在 HTML 中通过 script 引入Vue 已挂载到 window
const { defineComponent, ref, inject } = Vue;
import { like } from "../like/like.js";
// 定义组件(直接使用模板)
export const itemBottom = defineComponent({
name: "item-bottom",
props: {
itemdata: {
type: Object,
default: () => {},
},
},
setup(props) {
let item = ref({ ...props.itemdata });
let isLogin = inject("isLogin");
let userInfoWin = inject("userInfoWin");
let realname = inject("realname");
let goLogin = inject("goLogin");
let openAttest = inject("openAttest");
let isLikeGif = ref(false);
let cancelOperate = inject("cancelOperate");
const likeClick = () => {
if (realname.value == 0 && userInfoWin.value?.uin > 0) {
openAttest();
return;
}
if (!isLogin.value) {
goLogin();
return;
}
const token = item.value.token || "";
if (["offer", "offer_summary", "interviewexperience"].includes(item.value["type"]) && item.value["is_like"]) {
creationAlertBox("error", "不可取消点赞");
return;
}
ajax(`/v2/api/forum/postTopicLike`, {
token,
})
.then((res) => {
if (res.code != 200) {
creationAlertBox("error", res.message);
return;
}
let data = res.data;
creationAlertBox("success", res.message);
item.value["is_like"] = data.status;
item.value["likes"] = data.likes;
if (data.status) {
isLikeGif.value = true;
setTimeout(() => (isLikeGif.value = false), 2000);
}
if (data.status == 0) cancelOperate("like", token);
// wx.hideLoading();
})
.catch(() => {});
};
const collectClick = () => {
if (!isLogin.value) {
goLogin();
return;
}
const token = item.value.token || "";
ajax(`https://api.gter.net/v2/api/forum/postTopicCollect`, {
token,
})
.then((res) => {
if (res.code != 200) {
creationAlertBox("error", res.message);
return;
}
const data = res.data || {};
item.value["is_collect"] = data.status;
item.value["collections"] = data.collections;
creationAlertBox("success", res.message);
// 调用父组件的方法
if (data.status == 0) cancelOperate("collection", token);
})
.catch((err) => {
if (err?.code == 401) goLogin();
});
};
const copyLinkClick = () => {
copyForumUid(`http://14.22.79.19:9551/?tpl=forum/details&uniqid=${item.value.uniqid}`);
};
let QRcode = ref("");
const showQRcode = () => {
if (QRcode.value) return
ajaxget(`/v2/api/forum/getQrcode?token=${item.value.token}`).then((res) => {
if (res.code != 200) return;
const data = res.data || {};
QRcode.value = data.url || "";
});
};
return { QRcode, showQRcode, copyLinkClick, collectClick, item, likeClick, isLogin, isLikeGif };
},
components: {
like,
},
template: `<div class="comment flexacenter" v-if="item?.commentreviews && !Array.isArray(item?.commentreviews)"> <img class="icon" :src="item?.commentreviews?.avatar" /> <div class="text one-line-display">{{ item?.commentreviews?.content || "[图]" }}</div></div><template v-if="item.comment_list?.length != 0"> <div class="comment flexacenter" style="margin-bottom: 15px" v-for="(item, index) in item.comment_list" :key="index"> <img class="icon" :src="item.avatar" /> <div class="text one-line-display">{{ item.content || "[图]" }}</div> </div></template><div class="bottom flexacenter"> <div class="bottom-item like flexacenter" @click="likeClick()" v-if="item?.type != 'tenement'"> <img v-if="item.is_like" class="icon" src="/img/like-red-icon.png" /> <img v-else class="icon" src="/img/like-icon.png" /> <div class="text">{{ item.likes || "赞" }}</div> </div> <div class="bottom-item flexacenter" @click="collectClick()"> <img v-if="item.is_collect" class="icon" src="/img/collect-golden.svg" /> <img v-else class="icon" src="/img/collect-gray.png" /> <div class="text">{{ item.collections || "收藏" }}</div> </div> <a class="bottom-item flexacenter" v-if="item?.type != 'tenement'" :href="'/details/' + item.uniqid" target="_blank"> <img class="icon" src="/img/discuss-icon.png" /> <div class="text">{{ item.comments || "讨论" }}</div> </a> <a class="bottom-item flexacenter" v-if="item?.type != 'tenement'" :href="'/details/' + item.uniqid" target="_blank"> <img class="icon" src="/img/bi-copper-icon.png" /> <div class="text">{{ item.coins || "投币" }}</div> </a> <div class="bottom-item share flexacenter"> <img class="icon" src="/img/share-gray.png" /> <div class="text">转发</div> <div class="share-box flexcenter"> <div class="share-item flexcenter" @click="copyLinkClick()"> <img class="share-icon" src="/img/copy-black-icon.png" /> <div class="text">复制链接</div> </div> <!-- 鼠标移入 加载二维码 --> <div class="share-item wenxin flexcenter" @mouseenter="showQRcode"> <img class="share-icon" src="/img/weixin-icon.png" /> <div class="text">微信转发</div> <div v-if="QRcode" class="QRcode-box flexcenter"> <img class="QRcode" :src="QRcode" /> <div class="text">微信扫码</div> </div> </div> </div> </div></div><like v-if="isLikeGif"></like>`,
});