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

95 lines
5.6 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, defineAsyncComponent } = Vue;
const itemBottom = defineAsyncComponent(() => import(withVer("../item-bottom/item-bottom.js")).then((m) => m.itemBottom));
const itemHead = defineAsyncComponent(() => import(withVer("../item-head/item-head.js")).then((m) => m.itemHead));
// 定义组件(直接使用模板)
export const itemTenement = defineComponent({
name: "item-tenement",
props: {
itemdata: {
type: Object,
default: () => {},
},
page: {
type: String,
default: "",
},
},
setup(props) {
const handleHousing = (ele) => {
const langs = lang;
console.log("langs", langs);
if (ele["distance"]) ele["distance"] = Math.round(ele["distance"] * 10) / 10;
// 这个是将 详情键 替换语言包里的值
let list = ["tenementtype", "rentalduration", "intermediary", "property", "elevator", "sunshinearea", "gender"];
// let list = ["rentalduration", "intermediary", "property", "elevator", "sunshinearea", "gender"];
if (Array.isArray(ele["floor"])) list.push("floor"); // 判断 楼层是否需要 替换值, 因为在求房源里是多个值
let differentNames = {
// 需要替换的 键名
intermediary: "intermediary_text",
};
list.forEach((element) => {
if (ele[element] == -1) {
} else if (ele[element] == 0) ele[differentNames[element] ? differentNames[element] : element] = "不限";
// 当 值为 [0] 时为不限
else ele[differentNames[element] ? differentNames[element] : element] = langs[element][ele[element]];
});
let tabArr = ["gptype", "tenementtype", "elevator", "sunshinearea", "gender"];
let tabList = [];
tabArr.forEach((el) => {
if (ele[el] && ele[el] != -1) tabList.push(ele[el]);
});
ele["tabList"] = tabList;
let location = langs.location; // 遍历替换区域的值 所有房源
if (ele.intermediary == 6) {
if (Array.isArray(ele.rent)) ele.rent = `${ele.rent[0]} ~ ${ele.rent[1]}`;
if (Array.isArray(ele["location"])) {
let arr = [];
ele["location"].forEach((element) => {
arr.push(`${location[Math.trunc(element)]} > ${location[element]}`);
});
ele["location"] = arr;
}
} else {
let pendingData = ele["location"];
ele["location"] = `${location[Math.trunc(pendingData)]} > ${location[pendingData]}`;
}
return ele;
};
let item = ref({ ...props.itemdata });
// console.log("item", item.value);
item.value = handleHousing(item.value);
item.value["url"] = "https://fang.gter.net/detail?id=" + item.value.uniqid;
let sectionn = ref([]);
let tags = ref([]);
if (item.value.type == "tenement") {
const tabList = item.value?.tabList || [];
sectionn.value = ["香港租房", tabList[0]];
tags.value = tabList.slice(1) || [];
}
if (item.value.images?.length > 4) item.value.images = item.value.images.slice(0, 4);
let valueUrl = ref("");
const valueA = document.querySelector(".valueA");
valueUrl.value = valueA.innerText;
return { valueUrl, sectionn, tags, item };
},
components: {
itemBottom,
itemHead,
},
template: `<div class="item-box item-tenement"> <item-head :itemdata="item" :page="page"></item-head> <div class="label flexflex" v-if="sectionn?.length || tags?.length"> <img class="item icon" v-if="item.isintermediary == 1" style="width: 94px; cursor: auto;" :src="valueUrl + '/img/intermediary-icon.png'" /> <img class="item icon" v-if="item.verified == 1" style="width: 94px; cursor: auto;" :src="valueUrl + '/img/attestation-icon.png'" /> <div class="item blue" v-for="(item, index) in sectionn" :key="item" style="cursor: auto;">{{ item }}</div> <div class="item" v-for="(item, index) in tags" :key="item" style="cursor: auto;">{{ item }}</div> </div> <a class="title" :href="item.url" target="_blank">{{ item.subject }}</a> <a class="site-box flexacenter" :href="item.url" target="_blank"> <template v-if="item.intermediary == 6"> <div class="site-item flexacenter" v-for="(item, index) in item.location" :key="index"> <img class="site-icon" :src="valueUrl + '/img/orientation.png'"> {{ item }} </div> </template> <div v-else class="site-item flexacenter"> <img class="site-icon" :src="valueUrl + '/img/orientation.png'"> {{ item.location || '' }} </div> </a> <a class="price-section flexacenter" :href="item.url" target="_blank"> <div class="unit">HK$</div> <div class="price">{{ item.rent }}</div> <span class="text">/月</span> <div class="rentalduration">[ 租期{{ item.rentalduration }} ]</div> </a> <a class="picture flexacenter" :href="item.url" target="_blank" v-if="item.images?.length != 0"> <img class="picture-item" v-for="(item, index) in item.images" :key="index" :src="item" alt=""> </a> <item-bottom :itemdata="item" :page="page"></item-bottom></div>`,
});