Files
PC-Light-Forum/component/item-bottom/item-bottom.js
DESKTOP-RQ919RC\Pc 003b5992a5 refactor(components): 使用defineAsyncComponent优化异步组件加载
fix(public.js): 添加getScriptParameter函数并处理请求参数
style(index.html): 移除多余空行和注释
perf(bi.js): 移除冗余ajax方法并优化请求参数处理
docs(sign-in.txt): 调整样式和响应式布局
2025-12-05 19:07:33 +08:00

152 lines
8.0 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, defineAsyncComponent } = Vue;
const like = defineAsyncComponent(() => import(withVer("../like/like.js")).then(m => m.like));
// 定义组件(直接使用模板)
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(`/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(`${location.origin}/details/${item.value.uniqid}`);
};
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 || {};
QRcode.value = data.url || "";
});
};
let isright = ref(false);
const share = () => {
const token = item.value.token || "";
ajax(`/v2/api/forum/postTopicShare`, { token });
if (!shareBoxRef.value) return;
// 1. 获取元素相对于可视窗口的位置信息
const rect = shareBoxRef.value.getBoundingClientRect();
// 2. 获取可视窗口宽度(不包含滚动条,更准确)
const clientWidth = document.documentElement.clientWidth;
// 3. 计算距离:可视窗口宽度 - 元素右边缘到左边缘的距离
const distance = clientWidth - rect.right;
console.log("distance", distance);
if (distance < 140) isright.value = true;
else isright.value = false;
};
const shareBoxRef = ref(null);
return { isright, shareBoxRef, share, QRcode, showQRcode, copyLinkClick, collectClick, item, likeClick, isLogin, isLikeGif };
},
components: {
like,
},
template: `<a class="comment flexacenter" v-if="item?.commentreviews && !Array.isArray(item?.commentreviews)" :href="item.url" target="_blank"> <img class="icon" :src="item?.commentreviews?.avatar" /> <div class="text one-line-display">{{ item?.commentreviews?.content || "[图]" }}</div></a><template v-if="item.comment_list?.length != 0"> <a class="comment flexacenter" style="margin-bottom: 15px" v-for="(item, index) in item.comment_list" :key="index" :href="item.url" target="_blank"> <img class="icon" :src="item.avatar" /> <div class="text one-line-display">{{ item.content || "[图]" }}</div> </a></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" @mouseenter="share"> <img class="icon" src="/img/share-gray.png" style="width: 19px; height: 19px;" /> <div class="text">{{ item.shares || '转发'}}</div> <div class="share-box flexcenter" ref="shareBoxRef"> <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 class="QRcode-box flexcenter" :class="{'right': isright}"> <img v-if="QRcode" class="QRcode" :src="QRcode" /> <div v-else class="QRcode flexcenter"> <img class="load" src="/img/load-icon.svg" /> </div> <div class="text">微信扫码</div> </div> </div> </div> </div></div><like v-if="isLikeGif"></like>`,
});