gree_leran/components/cardVideo.vue

113 lines
2.3 KiB
Vue
Raw Normal View History

2024-06-16 23:47:03 +00:00
<template>
2024-06-20 15:36:19 +00:00
<div class="container">
<div class="video-box">
<video class="video" ref="videoStatus" @play="propsPlay" :src="Videos.src"></video>
<div class="box-bottom">
<!-- 点赞按钮 -->
<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>
</div>
<div class="bottom-title">
<span class="title">{{ Videos.titleName }}</span>
</div>
</div>
</div>
2024-06-16 23:47:03 +00:00
</template>
2024-06-20 15:36:19 +00:00
<script setup>
import { ref, reactive, onMounted } from 'vue';
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
// Props
const props = defineProps({
VideoId: {
type: Number,
default: null
},
Videos: {
type: Object,
default: () => ({
src: "",
avatar: '',
username: 'sdsd',
titleName: 'asdsdas',
tagName: 'sdasd'
})
}
});
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
// Local state
const videoContent = ref(null);
const info = reactive({
isLike: false,
isCollection: false
});
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
// Methods
const propsPlay = (e) => {
const videoContext = videoContent.value;
const videoStatus = ref(null);
videoStatus.value = e.target;
// Emit event to parent
emit('onplay', {
e,
videoStatus,
videoContext
});
};
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
const toLike = () => {
info.isLike = !info.isLike;
};
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
const toCollection = () => {
info.isCollection = !info.isCollection;
};
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
// Lifecycle hook
onMounted(() => {
videoContent.value = uni.createVideoContext('video', this);
});
</script>
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
<style scoped lang="scss">
$videoBoxradius: 30rpx;
$backColor: rgba(170, 85, 255, 0.6);
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
.container {
padding: 20rpx;
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
.video-box {
overflow: hidden;
border-radius: $videoBoxradius;
background-color: $backColor;
width: 100%;
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
.video {
width: 100%;
}
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
.box-bottom {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 4%;
}
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
.bottom-title {
text-align: center;
color: #fff;
font-size: $uni-font-size-subtitle;
height: 80rpx;
2024-06-16 23:47:03 +00:00
2024-06-20 15:36:19 +00:00
.title {
line-height: 80rpx;
}
}
}
}
</style>