Files
PC-Light-Forum/component/item-bottom/item-bottom.js
DESKTOP-RQ919RC\Pc c9e229a5cd fix(bi): 添加投币数量必须大于0的校验
feat(item-bottom): 实现二维码弹窗自适应右侧边界
添加判断逻辑使二维码弹窗在靠近右侧边界时向左弹出

refactor(public.js): 优化ajax请求配置和登录跳转逻辑
统一设置axios默认配置,提取登录跳转函数

style(public.css): 调整QRcode-box.right的定位
修复二维码弹窗靠近右侧时的显示问题

fix(details.js): 修复粗体标记正则匹配多行内容
使用[\s\S]*?匹配可能的多行内容

refactor(index.js): 优化列表加载和滚动逻辑
移除模拟数据,添加加载状态,调整滚动加载阈值

chore: 更新html模板中的唯一标识和广告类名
2025-11-19 19:27:43 +08:00

150 lines
7.5 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(`/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>`,
});