|
|
@ -1,5 +1,6 @@ |
|
|
|
<template> |
|
|
|
<image v-if="selectedItem" :src="selectedItem.image" class="random-image" mode="" /> |
|
|
|
<view> |
|
|
|
<image v-if="selectedItem" :src="selectedItem.image" class="random-image" mode=""></image> |
|
|
|
<view v-if="selectedItem" class="random-image-name"> |
|
|
|
{{selectedItem.name}} |
|
|
|
</view> |
|
|
@ -7,54 +8,65 @@ |
|
|
|
{{selectedItem.desc}} |
|
|
|
</view> |
|
|
|
<MusicControl /> |
|
|
|
</view> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script setup> |
|
|
|
import { |
|
|
|
ref, |
|
|
|
onMounted |
|
|
|
} from 'vue' |
|
|
|
<script> |
|
|
|
import MusicControl from './MusicControl.vue' |
|
|
|
|
|
|
|
const props = defineProps({ |
|
|
|
export default { |
|
|
|
components: { |
|
|
|
MusicControl |
|
|
|
}, |
|
|
|
props: { |
|
|
|
images: { |
|
|
|
type: Array, |
|
|
|
required: true |
|
|
|
} |
|
|
|
}) |
|
|
|
const selectedItem = ref(null) |
|
|
|
|
|
|
|
// 随机选择一项 |
|
|
|
const selectRandomImage = () => { |
|
|
|
if (props.images && props.images.length > 0) { |
|
|
|
const randomIndex = Math.floor(Math.random() * props.images.length) |
|
|
|
selectedItem.value = props.images[randomIndex] |
|
|
|
}, |
|
|
|
data() { |
|
|
|
return { |
|
|
|
selectedItem: null |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
this.selectRandomImage() |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
selectRandomImage() { |
|
|
|
if (this.images && this.images.length > 0) { |
|
|
|
const randomIndex = Math.floor(Math.random() * this.images.length) |
|
|
|
this.selectedItem = this.images[randomIndex] |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
computed: { |
|
|
|
exposedMethods() { |
|
|
|
return { |
|
|
|
selectRandomImage: this.selectRandomImage, |
|
|
|
selectedItem: this.selectedItem |
|
|
|
} |
|
|
|
} |
|
|
|
onMounted(() => { |
|
|
|
selectRandomImage() |
|
|
|
}) |
|
|
|
defineExpose({ |
|
|
|
selectRandomImage, |
|
|
|
selectedItem |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
|
|
|
|
<style scoped> |
|
|
|
.random-image { |
|
|
|
.random-image { |
|
|
|
width: 100%; |
|
|
|
height: 100%; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
.random-image-name { |
|
|
|
.random-image-name { |
|
|
|
position: absolute; |
|
|
|
bottom: 30%; |
|
|
|
left: 50%; |
|
|
|
transform: translate(-50%, -50%); |
|
|
|
color: #ffffff; |
|
|
|
font-size: 52rpx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
.random-image-desc { |
|
|
|
.random-image-desc { |
|
|
|
white-space: nowrap; |
|
|
|
position: absolute; |
|
|
|
bottom: 25%; |
|
|
@ -64,5 +76,5 @@ |
|
|
|
font-size: 24rpx; |
|
|
|
font-weight: 300; |
|
|
|
opacity: .8; |
|
|
|
} |
|
|
|
} |
|
|
|
</style> |