<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://unpkg.com/axios@0.24.0/dist/axios.min.js"></script>
<script src="https://unpkg.com/art-template@4.13.2/lib/template-web.js"></script>
<style>
a {
text-decoration: none;
}
h2 {
font-weight: normal;
}
h2 .rank,
h2 a {
font-weight: bold;
}
.score {
font-weight: bold;
color: red;
}
.person-number {
font-style: italic;
font-weight: bold;
}
p {
margin-bottom: 50px;
}
div.container {
width: 1000px;
margin: 50px auto;
}
.actor {
font-style: italic;
color: blue;
}
.show-date {
font-weight: bold;
color: orangered;
}
</style>
</head>
<body>
<div class="container" id="douban-movie">
<h1>豆瓣电影热度top10</h1>
{{each movieArray}}
<h2>
<span class="rank">排行: {{$value.info.rank}}</span>
<a href="{{$value.info.url}}">{{$value.title}}</a> 评分:
<span class="score">{{$value.info.pingfen}}</span>(<span
class="person-number"
>{{$value.info.markCount}}</span
>人评价)
</h2>
<div>
<img src="{{$value.info.imgurl}}" alt="" />
</div>
<h3>上映时间: <span class="show-date">{{$value.info.showTime}}</span></h3>
<p>
<b>演员:</b>
<span class="actor">{{$value.info.actors}}</span>
</p>
{{/esch}}
</div>
</body>
<script>
const url = `http://129.226.179.254/douban/index.php`;
axios
.get(url, {
params: { format: "json" },
})
.then(function (response) {
let movieArray = response.data.data;
movieArray.forEach((element, index) => {
console.log(element);
const showTimeArray = [];
const actorArray = [];
const markCount = element.info.pingjia.slice(1, -4);
element.info.markCount = markCount;
const yanyuanArray = element.info.yanyuan.split(" / ");
yanyuanArray.forEach((el) => {
if (el.search(/\d{4}-\d{2}/) !== -1) {
showTimeArray.push(el);
} else {
actorArray.push(el);
}
});
element.info.showTime = showTimeArray.join(" / ");
element.info.actors = actorArray.join(" / ");
element.info.rank = String(index + 1).padStart(3, "0");
});
const tempString = template("douban-movie", { movieArray });
document.querySelector("div.container").innerHTML = tempString;
})
.catch(function (error) {
console.log(error);
});
</script>
</html>