gree_leran/components/CaseBox/CaseBox.vue

228 lines
5.1 KiB
Vue
Raw Normal View History

<template>
2024-06-20 15:36:19 +00:00
<view class="cardbox">
2024-06-22 07:20:39 +00:00
<view class="cardbox-top" @click="getInfo">
2024-06-20 15:36:19 +00:00
<view class="cardbox-img">
2024-06-22 14:19:10 +00:00
<img class="cardbox-img-min" :src="props.cover" alt="加载" @error="errorImg" />
2024-06-20 15:36:19 +00:00
</view>
<view class="cardbox-text">
2024-06-22 07:20:39 +00:00
<up-text :lines="1" :text="info.title" :bold="true" size="30rpx" ></up-text>
2024-06-20 15:36:19 +00:00
<up-text :lines="3" :text="info.text"></up-text>
<up-text :lines="1" :text="info.data" color="#bfbfbf"></up-text>
</view>
</view>
<view class="cardbox-bttom">
<view class="">
</view>
<view class="cardbox-icon">
<up-icon v-if="info.isLike" @click="toLike" name="heart-fill" color="#ff0004" size="28"></up-icon>
<up-icon v-else name="heart" @click="toLike" color="#ff0004" size="28"></up-icon>
<up-icon v-if="info.isCollection" @click="toCollection" name="star-fill" color="#ff0004" size="28"></up-icon>
<up-icon v-else name="star" @click="toCollection" color="#ff0004" size="28"></up-icon>
</view>
</view>
</view>
</template>
<script setup>
2024-06-22 07:20:39 +00:00
import { onMounted, reactive, ref, defineProps, defineEmits,watch } from "vue";
2024-06-20 15:36:19 +00:00
const emit = defineEmits(["ClickCollection", "ClickLike"]);
const ab = "/static/image/imgerr.png";
const errorImg = () => {
2024-06-22 14:19:10 +00:00
info.cover;
2024-06-20 15:36:19 +00:00
};
const aaa = ref("name");
const props = defineProps({
id: {
2024-06-22 07:20:39 +00:00
type: Number,
default: null
2024-06-20 15:36:19 +00:00
},
title: {
type: String,
default: "标题"
},
text: {
type: String,
default: "正文嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻徐"
},
data: {
type: String,
default: "日期"
},
cover: {
type: String,
default: "/static/image/imgerr.png"
},
userImage: {
type: String,
default: "地址"
},
userName: {
type: String,
default: "作者"
},
userId: {
2024-06-22 07:20:39 +00:00
type: Number,
default: null
2024-06-20 15:36:19 +00:00
},
isLike: {
type: Boolean,
default: false
},
likeNumber: {
type: Number,
default: 0
},
isComments: {
type: Boolean,
default: false
},
commentsNumber: {
type: Number,
default: 0
},
isCollection: {
type: Boolean,
default: false
},
collectionNumber: {
type: Number,
default: 0
},
});
const info = reactive({
id: "文章id",
title: "标题",
cover: "封面地址",
text: "正文嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻徐",
data: "发布于2024-11-11",
userImage: "",
userName: "作者",
userId: "作者id",
isLike: false,
likeNumber: 0,
isComments: false,
commentsNumber: 0,
isCollection: false,
collectionNumber: 0,
});
2024-06-22 07:20:39 +00:00
watch(props,(a)=>{
// console.log("11111",a);
ggg();
})
2024-06-20 15:36:19 +00:00
const toLike = () => {
info.isLike = !info.isLike;
2024-06-22 07:20:39 +00:00
console.log("sss",info)
2024-06-20 15:36:19 +00:00
if (info.isLike) {
info.likeNumber++;
} else {
info.likeNumber--;
}
console.log("点赞0")
emit("ClickLike", {
id: info.id,
is: info.isLike
});
console.log("点赞1")
}
const toComments = () => {
info.isComments = !info.isComments;
if (info.isComments) {
info.commentsNumber++;
} else {
info.commentsNumber--;
}
}
const toCollection = () => {
info.isCollection = !info.isCollection;
if (info.isCollection) {
info.collectionNumber++;
} else {
info.collectionNumber--;
}
emit("ClickCollection", {
id: info.id,
is: info.isCollection
});
}
const ggg = () => {
info.id = props.id;
info.title = props.title;
info.cover = props.cover;
info.text = props.text;
info.data = props.data;
info.userImage = props.userImage;
info.userName = props.userName;
info.userId = props.userId;
info.isLike = props.isLike;
info.likeNumber = props.likeNumber;
info.isComments = props.isComments;
info.commentsNumber = props.commentsNumber;
info.isCollection = props.isCollection;
info.collectionNumber = props.collectionNumber;
}
2024-06-22 07:20:39 +00:00
const getInfo=()=>{
uni.navigateTo({
url: "/pages/newsInfo/newsInfo"+"?id="+info.id,
});
}
2024-06-20 15:36:19 +00:00
onMounted(() => {
ggg();
})
</script>
2024-06-20 15:36:19 +00:00
<style lang="scss" scoped>
.cardbox-top{
2024-06-20 15:36:19 +00:00
height: 70%;
width: 100%;
margin: 0 auto;
display: flex;
justify-content: space-around;
align-items: center;
}
.cardbox{
2024-06-20 15:36:19 +00:00
height: 100%;
color: #000;
background-color: #fff;
display: flex;
flex-flow: column;
justify-content: space-around;
align-items: center;
border-radius: 20rpx;
}
.cardbox-img{
2024-06-20 15:36:19 +00:00
height: 90%;
width: 45%;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.cardbox-img .cardbox-img-min {
width: 100%;
// height: 100%;
height: 100%;
// width: 10%;
object-fit: contain; /* 保持图片长宽比,并且完全显示图片 */
}
.cardbox-text{
width: 47%;
height: 90%;
display: flex;
flex-flow: column;
justify-content: space-around;
align-items: center;
}
.cardbox-bttom {
width: 90%;
height: 10%;
overflow: hidden;
display: flex;
justify-content: space-between;
}
.cardbox-icon{
display: flex;
justify-content: space-around;
align-items: center;
}
</style>