<template>
<view id="container">
<view v-for="item of movie" :key="item.id" class="list">
<image :src="item.pic" class="i"></image>
<view class="title">{{ item.title }}</view>
<view class="span">
<block v-for="item of item.star" :key="item.id">
<image
class="star"
v-if="item >= 1.5"
src="../../../image/star.png"
/>
<image
class="star"
v-else-if="item >= 1"
src="../../../image/ban-star.png"
/>
<image class="star" v-else src="../../../image/no-star.png" />
</block>
<view class="raiting">{{ item.raiting }}</view>
</view>
</view>
</view>
</template>
<script>
import "./index.scss";
import Taro from "@tarojs/taro";
export default {
data() {
return {
movie: [],
};
},
mounted() {
Taro.request({
url: "http://47.113.106.101:6505/api/movie/top250",
data: {},
header: {
"content-type": "application/json",
},
success: (res) => {
var movie = res.data.result;
movie.forEach((item) => {
item.star = handleStart(item.raiting);
});
this.movie = movie;
},
});
},
};
function handleStart(value) {
var arr = [];
for (let i = 0; i < 5; i++) {
if (value > 2) {
arr.push(2);
} else if (value > 0) {
arr.push(value);
} else {
arr.push(0);
}
value -= 2;
}
return arr;
}
</script>
<style>
#container {
margin-left: auto;
margin-right: auto;
display: grid;
grid-template-columns: repeat(3,33vw);
justify-items: center;
align-items: center;
}
.list {
padding: 20px;
}
.title {
font-size: 25px;
text-align: center;
}
.star {
width: 20px;
height: 20px;
}
.i {
width: 150rpx;
height: 170rpx;
}
.list .span {
width: 120px;
margin-left: auto;
margin-right: auto;
}
.raiting{
text-align: center;
}
</style>