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,47 @@
// 全局js配置,一般用来配置接口的基地址,和 短地址 等一些...
var config = {
// 开发阶段
devBaseUrl: 'http://127.0.0.1:3000/api/json',
// 测试阶段
testBaseUrl: 'http://127.0.0.2:8080/api/json',
// 正式阶段
prodBaseUrl: 'http://www.anc.com/api/json',
stage: 'dev', // dev test prod
switchStage: function () {
switch (this.stage) {
case "dev":
return this.devBaseUrl
break;
case "test":
return this.testBaseUrl
break;
case "prod":
return this.prodBaseUrl
break;
default:
break;
}
},
apiList: {
index: '/index',
info: '/info',
mechanism: '/mechanism',
type: '/class',
classList: '/classList',
mechanismList: '/classList'
},
footerArr: [
{ title: '首页', href: 'index.html', icon: 'icon-home' },
{ title: '机构', href: 'mechanism.html', icon: 'icon-jigou' },
{ title: '模特', href: 'model.html', icon: 'icon-me' },
{ title: '我的', href: 'me.html', icon: 'icon-wo' },
]
}

View File

@@ -0,0 +1,56 @@
class Http {
constructor() {
this.xhr = new XMLHttpRequest();
}
get(params) {
return new Promise((success, error) => {
var par = ""
for (const key in params.data) {
par += `&${key}=${params.data[key]}`
}
par = par.replace("&", "?")
this.xhr.open("GET", `${config.switchStage()}${params.url}${par}`)
this.xhr.send()
this.ReadyState(success, error)
})
}
post(params) {
return new Promise((success, error) => {
this.xhr.open("POST", `${params.url}`)
this.xhr.setRequestHeader('Content-Type', 'application/json');
this.xhr.send(JSON.stringify(params.data))
this.ReadyState(success, error)
})
}
ReadyState(success, error) {
this.xhr.onreadystatechange = () => {
if (this.xhr.readyState == 4) {
if (this.xhr.status == 200) {
var data = JSON.parse(this.xhr.response);
switch (data.status) {
case 200:
success(data.result)
break;
case 404:
alert(data.msg);
throw new Error(data.msg)
break;
default:
break;
}
} else {
error(this.xhr)
}
}
}
}
}