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, }; }; onMounted(() => { checkWConfig(); }); 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 { item }; }, template: `
`, });