图书馆小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

148 lines
3.3 KiB

<template>
<view class="item-container" @click="$emit('click')">
<view class="item-box">
<view class="item-box-left">
<image
class="img-item"
:src="actualCover"
mode="scaleToFill"
@error="onImgError"
></image>
</view>
<view class="item-box-right">
<view class="item-title line-clamp-2">{{ data.title || data.name || '暂无标题' }}</view>
<text class="item-author">{{ data.author || '佚名' }}</text>
<text class="item-publish">{{ data.publisher || '暂无出版社数据' }}</text>
</view>
</view>
</view>
</template>
<script>
export default {
name: "book-list-item",
props: {
data: {
type: Object,
required: true
}
},
computed: {
actualCover() {
// 优先使用 cover
if (this.data.cover) {
return this.data.cover;
}
// 其次使用 base64Cover(兼容推荐页面)
if (this.data.base64Cover) {
return this.data.base64Cover;
}
// 最后使用默认图片
return '/static/images/default-book.png';
}
},
methods: {
/**
* 检查封面链接是否有效
* @param {string} coverlink - 封面链接
* @returns {boolean} - 是否有效
*/
isValidCoverLink(coverlink) {
if (!coverlink || typeof coverlink !== 'string') {
return false;
}
// 支持 base64 图片格式
if (coverlink.indexOf('data:image/') === 0) {
return true;
}
// 检查是否包含 http
if (coverlink.indexOf('http') === -1) {
return false;
}
// 已知无法访问的域名列表
const blockedDomains = [
'doubanio.com',
'douban.com'
];
// 检查是否包含被阻止的域名
for (const domain of blockedDomains) {
if (coverlink.includes(domain)) {
return false;
}
}
return true;
},
/**
* 图片加载失败处理
*/
onImgError(e) {
e.target.src = "/static/images/default-book.png";
}
}
};
</script>
<style lang="scss" scoped>
.item-container {
padding-bottom: 10px;
.item-box {
display: flex;
justify-content: flex-start;
align-items: flex-start;
padding: 10px;
background-color: #fff;
border-radius: 6px;
border-bottom: 1px solid #f4f4f4;
.item-box-left {
margin-right: 8px;
.img-item{
width: 64px;
height: 90px;
margin: 0 12px 0 0;
border-radius: 5px;
}
}
.item-box-right {
display: flex;
flex-direction: column;
justify-content: flex-start;
flex: 1;
.item-title {
font-size: 15px;
font-weight: bold;
color: #000;
padding-bottom: 10px;
}
.item-author,
.item-publish {
font-size: 12px;
color: #888;
padding-bottom: 10px;
}
.hot-text {
font-size: 12px;
color: #ff4444;
}
.item-desc {
padding-top: 5px;
font-size: 13px;
color: #666;
line-height: 1.4;
}
.item-bottom-box {
margin-top: 8px;
display: flex;
justify-content: space-between;
align-items: center;
}
}
}
}
</style>