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,31 @@
// 专门用来存放所有的接口地址
var config = {
// 基地址 dev开发阶段 test测试阶段 prod正式
devUrl: 'http://127.0.0.1:3000/api/json',
testUrl: 'http://127.0.0.1:9090/api/json',
prodUrl: 'http://127.0.0.1/api/json',
stage: 'dev',
urlList: {
index: '/index',
info: '/info',
classList: '/classList'
},
checkUrl: function () {
switch (this.stage) {
case "dev":
return this.devUrl
break;
case "test":
return this.testUrl
break;
case "prod":
return this.prodUrl
break;
default:
break;
}
},
}

View File

@@ -0,0 +1,39 @@
class HTTP {
constructor() {
this.xhr = new XMLHttpRequest();
}
get(option) {
return new Promise((success, error) => {
var GetParams = ""
for (const key in option.data) {
GetParams += `&${key}=${option.data[key]}`
}
GetParams = GetParams.replace("&", "?")
option.url += GetParams;
this.xhr.open("GET", config.checkUrl() + option.url)
this.xhr.send()
this.onreadystatechange(success, error)
})
}
post() { }
onreadystatechange(success, error) {
this.xhr.onreadystatechange = () => {
if (this.xhr.readyState == 4) {
if (this.xhr.status == 200) {
success(JSON.parse(this.xhr.responseText));
} else {
console.log("暂无数据");
error(this.xhr)
}
}
}
}
}

View File

@@ -0,0 +1,25 @@
class Server {
async index(data) {
return (new HTTP()).get({
url: config.urlList.index,
data: data
})
}
async classList(data) {
return (new HTTP()).get({
url: config.urlList.classList,
data: data
})
}
async info(data) {
return (new HTTP()).get({
url: config.urlList.info,
data: data
})
}
}
var server = new Server()