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,63 @@
class AJAX {
constructor() {
this.baseUrl = config.checkBaseUrl();
this.http = new XMLHttpRequest();
}
/**
*
* @param {*object} parmas
*/
get(parmas) {
return new Promise((success, error) => {
// 将data 参数转化为 ?key=value&key=value
var str = ""
for (const key in parmas.data) {
str += `&${key}=${parmas.data[key]}`
}
str = str.replace("&", "?")
this.http.open("GET", `${this.baseUrl}${parmas.url}${str}`);
this.http.send();
this.readyState(success, error)
})
}
post(parmas) {
this.http.open("POST", `${this.baseUrl}${parmas.url}`);
this.http.setRequestHeader('Content-type', 'application/json; charset="utf-8"');
this.http.send(JSON.stringify(parmas.data));
this.readyState(parmas.success, parmas.error)
}
put() { }
delete() { }
// 给 get post put delete 进行状态监听的封装
readyState(success, error) {
this.http.onreadystatechange = () => {
if (this.http.readyState == 4) {
if (this.http.status == 200) {
var data = JSON.parse(this.http.response);
switch (data.status) {
case 200:
success(data.result)
break;
case 404:
alert(data.message)
throw new Error(data.message)
break;
}
// success(data)
} else {
error(this.http)
}
}
}
}
}
var http = new AJAX();

View File

@@ -0,0 +1,30 @@
var config = {
devBaseUrl: "http://127.0.0.1:3000/api", // 开发阶段的请求基本地址
testBaseUrl: "http://127.0.0.1:3000/api/test", // 测试阶段的请求基本地址
prodBaseUrl: "http://127.0.0.1:3000/api/prod", // 上线阶段的请求基本地址
stage: "dev", // dev开发 test测试 prod上线
apiList: {
iclass: '/index/class',
hot: '/index/hot'
},
// 检查使用什么阶段的接口地址
checkBaseUrl: function () {
switch (this.stage) {
case "dev":
return this.devBaseUrl
break;
case "test":
return this.testBaseUrl
break;
case "prod":
return this.prodBaseUrl
break;
default:
break;
}
}
}

View File

@@ -0,0 +1,16 @@
class Index {
constructor () {
this.getIndexData()
}
async getIndexData() {
var res = await index.iclass({
type: 1,
page: 1
})
console.log(res)
}
}
new Index();

View File

@@ -0,0 +1,18 @@
class IndexService {
async hot(data) {
await http.get({
url: config.apiList.hot,
data: data
})
}
async iclass(data) {
return await http.get({
url: config.apiList.iclass,
data: data
})
}
}
var index = new IndexService()

View File

@@ -0,0 +1,7 @@
请求中间层
作用?
[1,2,3,4,5]
[{id:1},{id:2},{},{}]

View File

@@ -0,0 +1,11 @@
window.onload = function () {
getRem(750, 100)
};
window.onresize = function () {
getRem(750, 100)
};
function getRem(pwidth, prem) {
var html = document.getElementsByTagName("html")[0];
var oWidth = document.body.clientWidth || document.documentElement.clientWidth;
html.style.fontSize = oWidth / pwidth * prem + "px";
}