Files
PC-Light-Forum/component/item-head/item-head.js
A1300399510 a7d803f633 no message
2025-11-04 01:57:07 +08:00

129 lines
5.9 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, provide, onMounted } = Vue;
import { report } from "../report/report.js";
// 定义组件(直接使用模板)
export const itemHead = defineComponent({
name: "item-head",
props: {
itemdata: {
type: Object,
default: () => {},
},
},
setup(props) {
let sectionn = ref([]);
let tags = ref([]);
let item = ref({ ...props.itemdata });
if (!item.value.hidden) item.value.hidden = 0;
// item.value['best'] = 0
// item.value['recommend'] = 1
let timestamp = ref(strtimeago(item.value.release_at, 4));
if (item.value.type == "tenement") timestamp = timeago(item.value.updatetime, 2);
sectionn.value = item.value.sectionn || [];
const sectionNameSet = new Set(sectionn.value.map((item) => item.name));
tags.value = item.value.tags.filter((tagName) => !sectionNameSet.has(tagName));
// const sectionSet = new Set(sectionn.value);
// tags.value = item.value.tags?.filter((tag) => !sectionSet.has(tag));
let show = ref(false);
const cutShow = () => {
show.value = !show.value; // 修改为切换显示状态
};
let reportState = ref(false);
provide("reportState", reportState);
let ismanager = ref(false); // 添加管理员状态变量
let permissions = ref([]);
onMounted(() => {
setTimeout(() => {
permissions.value = window["permissions"] || [];
// ismanager.value = permissions.value.indexOf("topic:manager") >= 0;
ismanager.value = true;
}, 1000);
});
// 举报
const report = () => {
cutShow();
reportState.value = true;
};
// 隐藏
const hide = () => {
const target = item.value;
managerHide(target.token, target.hidden, target.type).then((value) => {
target.hidden = value;
item.value = target;
cutShow();
});
};
// 推荐
const recommend = () => {
const target = item.value;
managerRecommend(target.token, target.recommend).then((value) => {
target.recommend = value;
item.value = target;
cutShow();
});
};
// 精华
const essence = () => {
const target = item.value;
managerEssence(target.token, target.best).then((value) => {
target.best = value;
item.value = target;
cutShow();
});
};
// let cancelOperate = inject("cancelOperate");
// 删除
const deleteItem = () => {
const target = item.value;
console.log("deleteItem");
// managerDelete(target.token)
// .then(() => {
// cancelOperate("like", token);
// })
// .finally(() => {
// cutShow();
// });
};
// 编辑
const edit = () => {
const target = item.value;
redirectToExternalWebsite(`/publish?uniqid=${target.uniqid}`);
};
const goPersonalHomepage = (uin, uid) => {
if (!uin && !uid) return;
redirectToExternalWebsite(`/space?uin=${uin}&uid=${uid}`);
};
return { edit, deleteItem, goPersonalHomepage, reportState, cutShow, show, item, timestamp, sectionn, tags, ismanager, report, hide, recommend, essence };
},
components: {
report,
},
template: `<div class="item-head flexacenter"> <div class="user-box flexacenter" @click="goPersonalHomepage(item?.user?.uin, item?.user?.uid)"> <img class="avatar" :src="item?.user?.avatar || item.avatar" /> <div class="name">{{ item?.user?.nickname || item.nickname || "匿名用户" }}</div> <img class="group" v-if="info?.group?.image" :src="info?.group?.image" /> </div> <div class="time">{{ timestamp }}</div> <div class="flex1"></div> <div class="view flexacenter"> <img class="icon" src="/img/eye-icon.svg" /> <div class="text">{{ item.views }}</div> </div> <div class="btn flexcenter" @click.stop="cutShow"> <img class="icon" src="/img/dot-dot-dot-gray.png" /> </div> <div v-if="show"> <div class="mask" @click.stop="cutShow"></div> <div class="operate"> <div class="item" @click.stop="report">举报</div> <template v-if="ismanager"> <div class="item" @click.stop="hide">{{ item.hidden == 0 ? "隐藏" : "显示" }}</div> <div class="item" @click.stop="recommend">{{ item.recommend == 1 ? "取消" : "" }}推荐</div> <div class="item" @click.stop="essence">{{ item.best == 1 ? "取消" : "" }}精华</div> </template> <template v-if="item.type == 'thread' && item.ismyself"> <div class="item" @click.stop="edit">编辑</div> <div class="item" @click.stop="deleteItem">删除</div> </template> </div> </div></div><div class="label flexflex" v-if="sectionn?.length || tags?.length || item.recommend == 1 || item.best == 1"> <img class="item icon" v-if="item.recommend == 1 && item.best != 1" src="/img/recommend-icon.png" /> <img class="item icon" v-if="item.best == 1" src="/img/essence-icon.png" /> <a class="item blue" v-for="(item, index) in sectionn" :key="item" :href="'/section/' + item.uniqid" target="_blank">{{ item.name }}</a> <a class="item" v-for="(item, index) in tags" :key="item" :href="'/tag/' + item" target="_blank">{{ item }}</a></div><report v-if="reportState" :itemdata="item"></report>`,
});