first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
class Ajax {
//url接口
http = new XMLHttpRequest();
constructor() {
}
get(option) {
var params = ""//留空进行处理
for (const key in option.data) {
console.log(key);
console.log(option.data[key]);
params += `&${key}=${option.data[key]}`//拼接字符串
}
params = params.replace("&", "?");//替换字符串
option.url = option.url + params;//拼接字符串
this.http.open("GET", option.url);//发送请求
this.http.send()//发送请求
this.onreadystatechange(option);//传方法
console.log(option.url)
}
post(option) {
this.http.open("POST", option.url);
this.http.setRequestHeader('Content-Type', 'application/josn');
this.http.send(JSON.stringify(option.data))
this.onreadystatechange(option)
}
onreadystatechange(callback){
this.http.onreadystatechange = () =>{
if (this.http.readyState == 4) {
if (this.http.status == 200) {
callback.success(JSON.parse(this.http.response))
} else {
callback.error(this.http)
}
}
}
}
}
var ajax = new Ajax()

View File

@@ -0,0 +1,64 @@
<!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>Title</title>
</head>
<body>
<ul>
</ul>
<button>下一页</button>
</body>
<script src="./ajax.js"></script>
<script src="./utils.js"></script>
<script>
var page=0;
var totalpage=0;
function getIndexList(){
ajax.get(
{
url:'http://127.0.0.1:3000/api/json/classList',
data:{
id:245,
page:page
},
success:(res)=>{
totalpage=res.result.total_page
renderList(res.result)
},
error:(err)=>{
console.log(err)
},
}
)
}
function renderList(list){
list.data.forEach(v=>{
$("ul").innerHTML+=`
<li>
<a href="./info.html?id=${v.id}">
<img width="200px" src="${replace(v.preview)}" alt="">//preview是后端给的地址
<p>${v.title}</p>
</a>
</li>
`
})
}
getIndexList()
$("button").onclick=function (){
page+=1
if(page<=totalpage){
getIndexList()
}else {
alert("没有数据了=")
}
}
</script>
</html>

View File

@@ -0,0 +1,59 @@
<!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>Title</title>
</head>
<body>
<div class="info">
</div>
<button>下一页</button>
</body>
<script src="ajax.js"></script>
<script src="./utils.js"></script>
<script>
var id =location.search.split("=")[1];
var page=1;
var total_page=0;
console.log(id)
function GetInfo(){
ajax.get(
{
url:'http://127.0.0.1:3000/api/json/info',
data:{
id:id,
page:page
},
success:(res)=>{
total_page=res.result.total_page;
renderImg(res.result.data)
},
error:(err)=>{
console.log(err)
},
}
)
function renderImg(list){
console.log(list)
list.forEach(v =>{
$(".info").innerHTML+=`<img width="100%" src="${replace(v.src)}" alt="">`
})
}
$("button").onclick=function (){
page+=1
if(page<=total_page){
GetInfo()
}else {
alert("没有数据了=")
}
}
}
GetInfo()
</script>
</html>

View File

@@ -0,0 +1,7 @@
function $(className){
return document.querySelector(className)
}
function replace(url){
var s ="http://47.114.153.249:3000/api/json/url?url=";
return url.replace(s,'')
}