refactor(components): 重构多个组件并优化公共样式
重构了item-head、item-bottom、item-offer、item-summary和item-tenement组件,优化了props传递和数据处理逻辑 将公共头部和导航样式提取到public.css中,避免重复代码 修复了item-tenement组件中图片显示和数据处理的问题 更新了item-bottom组件的点赞和收藏逻辑,增加错误提示 优化了item-head组件的用户信息显示逻辑 调整了多个组件的样式细节,包括间距、图标大小等
This commit is contained in:
@@ -6,7 +6,7 @@ import { itemHead } from "../item-head/item-head.js";
|
||||
|
||||
// 定义组件(直接使用模板)
|
||||
export const itemTenement = defineComponent({
|
||||
name: "item-tenement",
|
||||
name: "item-tenement",
|
||||
props: {
|
||||
itemdata: {
|
||||
type: Object,
|
||||
@@ -15,17 +15,55 @@ export const itemTenement = defineComponent({
|
||||
},
|
||||
|
||||
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 });
|
||||
// item.value.title = "【投41票】" + item.value.title;
|
||||
// res["timestamp"] = util.strtimeago(res.release_at, 4);
|
||||
// const data = res.data;
|
||||
// const option = data.option || [];
|
||||
// res["isvote"] = option.some((item) => item.selected == 1);
|
||||
// const time = util.handleDeadline(data.deadline);
|
||||
// res["time"] = time;
|
||||
// this.setData({
|
||||
// item: res,
|
||||
// });
|
||||
// console.log("item", item.value);
|
||||
item.value = handleHousing(item.value);
|
||||
|
||||
console.log("item.value", item.value);
|
||||
|
||||
return { item };
|
||||
},
|
||||
|
||||
@@ -34,5 +72,5 @@ export const itemTenement = defineComponent({
|
||||
itemHead,
|
||||
},
|
||||
|
||||
template: `<div class="item-box item-tenement"> <item-head :itemdata="item"></item-head> <div class="title">三房找一位室友合租,家具设备齐全</div> <div class="site-box flexacenter"> <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="https://app.gter.net/image/miniApp/offer/room.png"> {{ item }} </div> </template> <div v-else class="site-item flexacenter"> <img class="site-icon" src="https://app.gter.net/image/miniApp/offer/orientation.png"> {{ item.location || '九龙 > 尖沙咀/佐敦' }} </div> </div> <div class="price-section flexacenter"> <div class="unit">HK$</div> <div class="price">{{ item.rent }}</div> <span class="text">/月</span> <div class="rentalduration">[ 租期{{ item.rentalduration }} ]</div> </div> <div class="picture flexacenter"> <img class="picture-item" v-for="(item, index) in 15" :key="index" src="https://axure-file.lanhuapp.com/md5__34fc6e5f5fef1d31bbd4604d33be77cc.svg" alt=""> </div> <item-bottom :itemdata="item"></item-bottom></div>`,
|
||||
template: `<div class="item-box item-tenement"> <item-head :itemdata="item"></item-head> <div class="title">三房找一位室友合租,家具设备齐全</div> <div class="site-box flexacenter"> <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="https://app.gter.net/image/miniApp/offer/room.png"> {{ item }} </div> </template> <div v-else class="site-item flexacenter"> <img class="site-icon" src="https://app.gter.net/image/miniApp/offer/orientation.png"> {{ item.location || '九龙 > 尖沙咀/佐敦' }} </div> </div> <div class="price-section flexacenter"> <div class="unit">HK$</div> <div class="price">{{ item.rent }}</div> <span class="text">/月</span> <div class="rentalduration">[ 租期{{ item.rentalduration }} ]</div> </div> <div class="picture flexacenter" v-if="item.images?.length != 0"> <img class="picture-item" v-for="(item, index) in item.images" :key="index" :src="item" alt=""> </div> <item-bottom :itemdata="item"></item-bottom></div>`,
|
||||
});
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
<div class="rentalduration">[ 租期{{ item.rentalduration }} ]</div>
|
||||
</div>
|
||||
|
||||
<div class="picture flexacenter">
|
||||
<img class="picture-item" v-for="(item, index) in 15" :key="index" src="https://axure-file.lanhuapp.com/md5__34fc6e5f5fef1d31bbd4604d33be77cc.svg" alt="">
|
||||
<div class="picture flexacenter" v-if="item.images?.length != 0">
|
||||
<img class="picture-item" v-for="(item, index) in item.images" :key="index" :src="item" alt="">
|
||||
</div>
|
||||
|
||||
<item-bottom :itemdata="item"></item-bottom>
|
||||
|
||||
Reference in New Issue
Block a user