Files
PC-Light-Forum/component/item-project/item-project.js
DESKTOP-RQ919RC\Pc 6ce06b133a refactor(components): 重构图片资源引用方式,使用动态路径
将静态图片路径改为从valueUrl动态获取,统一管理图片资源路径
添加新的SVG图标资源
修复BI组件401未授权时的登录跳转逻辑
优化签到组件图片资源路径
2025-12-08 19:09:04 +08:00

97 lines
4.6 KiB
JavaScript

const { defineComponent, ref, onMounted } = Vue;
export const itemProject = defineComponent({
name: "item-project",
props: {
itemdata: {
type: Object,
default: () => ({}),
},
},
setup(props) {
const formatNumberWithSpaces = (number) => {
if (Number(number) != number) return;
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};
const judgmentClass = (name) => {
const redtag = redtagArr.value || ["26Fall", "26Spring"];
let classname = "";
if (redtag.includes(name)) classname = "gray semester";
else {
// 判断 字符串 是以 25/26/27... + Fall/Spring/Summer
const regex = /^(2[0-9]|3\d)(Fall|Spring|Summer)$/;
classname = regex.test(name) ? "gray" : "";
}
return {
name,
class: classname,
};
};
let valueUrl = ref("");
onMounted(() => {
checkWConfig();
const valueA = document.querySelector(".valueA");
valueUrl.value = valueA.innerText;
});
let redtagArr = ref([]);
const checkWConfig = () => {
const wConfig = JSON.parse(localStorage.getItem("wConfig")) || {};
if (wConfig.time) {
const time = new Date(wConfig.time);
const now = new Date();
if (now - time > 24 * 60 * 60 * 1000) {
getWConfig();
monitorGetRedTag();
} else {
const config = wConfig.config || {};
redtagArr.value = config.redtag || [];
}
} else {
getWConfig();
monitorGetRedTag();
}
};
const monitorGetRedTag = () => {
let timer = setInterval(() => {
const wConfig = JSON.parse(localStorage.getItem("wConfig")) || {};
if (wConfig.time) {
const config = wConfig.config || {};
redtagArr.value = config.redtag;
clearInterval(timer);
}
}, 1000);
};
const getWConfig = () => {
if (window.wConfigloading) return;
window.wConfigloading = true;
ajaxGet("/v2/api/config/website").then((res) => {
if (res.code == 200) {
let data = res["data"] || {};
const config = data.config || {};
redtagArr.value = config.redtag;
data.time = new Date().toISOString();
localStorage.setItem("wConfig", JSON.stringify(data));
}
window.wConfigloading = false;
});
};
let item = ref({ ...props.itemdata });
item.value["tuition_fee_text"] = formatNumberWithSpaces(item.value.tuition_fee || "");
item.value["url"] = "https://program.gter.net/details/" + item.value.uniqid;
return { valueUrl, item };
},
template: `<div class="item-box item-project"> <div class="tag flexflex"> <img class="tag-item icon" v-if="item.admissionsproject" :src="valueUrl + '/img/admissions-icon.png'" /> <a class="tag-item blue" href="https://program.gter.net/" target="_blank">港校项目库</a> <div class="tag-item" :class="item.class" v-for="(tag, index) in item.tags" :key="index">{{ tag.name || tag }} </div> </div> <a class="school flexacenter" :href="item.url" target="_blank"> <img class="icon" v-if="item.schoollogo" :src="item.schoollogo" /> <span class="flex1">{{ item.schoolname }}</span> </a> <a class="name flexacenter" :href="item.url" target="_blank">{{ item.name_zh || item.program_zh }}</a> <a class="en flexacenter" :href="item.url" target="_blank">{{ item.name_en || item.program_en }}</a> <a class="introduce flexacenter" :href="item.url" target="_blank"> <span>{{ item.department }}</span> <div class="flexacenter" v-if="item.rank"> <div class="line" v-if="item.department">|</div> 专业排名 <div class="q">{{ item.rank }}</div> </div> <div class="flexacenter" v-if="item.tuition_fee"> <div class="line" v-if="item.department || item.rank">|</div> 学费HK$ <div class="q">{{ item.tuition_fee_text }}</div> </div> </a> <a class="word flexacenter one-line-display" v-if="item.distinctive" :href="item.url" target="_blank">{{ item.distinctive }}</a></div>`,
});