Files
test/components/theme-item/theme-item.vue

112 lines
2.6 KiB
Vue
Raw Permalink 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.
<template>
<view class="themeItem">
<navigator :url="'/pages/classlist/classlist?id='+item._id + '&name='+item.name"
class="box"
v-if="!isMore">
<!-- 组件里面使用组件名小程序要报警告 -->
<image class="pic" :src="item.picurl" mode="aspectFill"></image>
<!-- 遮罩层 -->
<view class="mask">{{item.name}}</view>
<!-- 标签 -->
<!-- 父元素里面有发布时间的时间戳 -->
<!--
这里如果更新时间超过3个月了就返回一个null
如果返回null的话就不会有xx月/xx日前更新这个标签了
-->
<view class="tab" v-if="compareTimestamp(item.updateTime)">{{compareTimestamp(item.updateTime)}}前更新</view>
</navigator>
<navigator url="/pages/classify/classify" open-type="reLaunch" class="box more" v-else>
<!-- 组件里面使用组件名小程序要报警告 -->
<image class="pic" src="/common/images/more.jpg" mode="aspectFill"></image>
<!-- 遮罩层 -->
<view class="mask">
<uni-icons type="more-filled" size="34" color="#fff"></uni-icons>
<view class="text">更多</view>
</view>
</navigator>
</view>
</template>
<script setup>
import {ref} from "vue"
import {compareTimestamp} from "@/utils/common.js"
defineProps({
isMore:{
type: Boolean,
default: false
},
item:{
type:Object,
default(){
return {
name:"默认名称",
picurl:"/common/images/classify1.jpg",
updateTime:Date.now()
}
}
}
}
)
</script>
<style lang="scss" scoped>
.themeItem {
.box {
height: 340rpx;
border-radius: 10rpx;
overflow: hidden;
// 让要布局的子元素相对于这个 class=box 的元素进行操作
position: relative;
.pic {
// 图片会有默认的宽度,你不让它继承父级的宽度,原本图片的宽度会将方框撑开
width: 100%;
height: 100%;
}
.mask {
width: 100%;
height: 70rpx;
position: absolute;
font-size: 40rpx;
font-weight: 600;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.2);
color: #fff;
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(20rpx);
}
.tab {
position: absolute;
left: 0;
top: 0;
background: rgba(250, 129, 90, 0.7);
backdrop-filter: blur(20rpx);
color: #fff;
// 浏览器最小就是11px了22rpx = 11px
font-size: 22rpx;
border-radius: 0 0 20rpx 0;
padding: 6rpx 12rpx;
transform: scale(0.8);
transform-origin: left top;
}
}
.box.more{
.mask{
width: 100%;
height: 100%;
flex-direction: column;
}
.text{
font-size: 28rpx;
}
}
}
</style>