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,66 @@
class Http {
defaultOption = {
timeout: 6000,
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
}
constructor() {
this.xhr = new XMLHttpRequest()
}
get(par) {
return new Promise((success, error) => {
this.setOption(par)
let urlParams = ""
for (const key in par.data) {
urlParams += `&${key}=${par.data[key]}`
}
urlParams = urlParams.replace("&", "")
this.xhr.open("GET", `${par.url}?${urlParams}`)
this.xhr.timeout = this.defaultOption.timeout
this.setHeader(par.headers)
this.xhr.send()
this.statechange(success, error);
})
}
post(par) {
return new Promise((success, error) => {
this.setOption(par)
this.xhr.open("POST", par.url)
this.xhr.timeout = this.defaultOption.timeout
this.setHeader(par.headers)
this.xhr.send(JSON.stringify(par.data))
this.statechange(success, error);
})
}
setOption(par) {
this.defaultOption.timeout = par.timeout || this.defaultOption.timeout
// ....
}
setHeader(headerObject = {}) {
Object.assign(headerObject, this.defaultOption.headers)
for (const key in headerObject) {
this.xhr.setRequestHeader(key, headerObject[key]);
}
}
statechange(success, error) {
this.xhr.onreadystatechange = () => {
if (this.xhr.readyState == 4) {
if (this.xhr.status == 200) {
let data = JSON.parse(this.xhr.response)
success(data.result)
} else {
error(this.xhr)
}
}
}
}
}
var http = new Http();

View File

@@ -0,0 +1,84 @@
<!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>
<style>
body,li{
margin: 0;
padding: 0;
list-style: none;
}
ul {
display: flex;
flex-wrap: wrap;
}
li {
width: 20%;
margin-bottom: 30px;
}
li img {
width: 100%;
}
</style>
</head>
<body>
<ul>
</a>
</ul>
<button>点我</button>
<div class="result"></div>
</body>
<script src="./http.js"></script>
<script>
let page = 1, total_page = 0;
let getList = async () => {
let res = await http.get({
url: 'http://127.0.0.1:3000/api/json/classList',
data: {
id: 253,
page
}
});
total_page = res.total_page
renderPage(res)
}
let renderPage = (res) => {
res.data.forEach(v => {
$("ul").innerHTML += `
<li>
<a target="_blank" href="./info.html?id=${v.id}&total=${v.total}">
<img src="${v.preview}" alt="">
<p>${v.title}</p>
</a>
</li>`
});
}
$("button").onclick = () => {
page +=1;
if (page <= total_page) {
getList()
} else {
$(".result").innerText = "没有数据了"
}
}
getList()
function $(className) {
return document.querySelector(className);
}
</script>
</html>

View File

@@ -0,0 +1,67 @@
<!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>
<style>
body,
li {
margin: 0;
padding: 0;
list-style: none;
}
img {
width: 100%;
}
</style>
</head>
<body>
<div class="info">
</div>
</body>
<script src="./http.js"></script>
<script>
let getInfo = async () => {
let res = await http.get({
url: 'http://127.0.0.1:3000/api/json/info',
data: {
id: query("id"),
quantity: query("total")
}
});
renderPage(res)
}
let renderPage = (res) => {
console.log(res);
res.forEach(v => {
$(".info").innerHTML += `
<img src="${v}" alt="">
`
});
}
getInfo()
function query(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null)
return unescape(r[2]);
return null;
}
function $(className) {
return document.querySelector(className);
}
</script>
</html>