错误漏删
This commit is contained in:
parent
688658d1c2
commit
b00dac74de
|
@ -136,7 +136,7 @@ class BoxApi {
|
|||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async addUser(username: string, password: string, email: string = "", token: string | null = null): Promise<any> {
|
||||
try {
|
||||
|
@ -145,24 +145,24 @@ class BoxApi {
|
|||
password: password,
|
||||
email: email
|
||||
};
|
||||
|
||||
|
||||
const res = await this.axios.post(this.apiAdduser, data, this._authHeader(token));
|
||||
|
||||
|
||||
if (res.data.err.ec === 0) {
|
||||
return res.data.ret;
|
||||
return res.data.ret;
|
||||
} else {
|
||||
throw res.data.err;
|
||||
throw res.data.err;
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.response && error.response.data && error.response.data.err) {
|
||||
throw error.response.data.err;
|
||||
throw error.response.data.err;
|
||||
} else {
|
||||
throw new Error("网络错误或服务器未响应");
|
||||
throw new Error("网络错误或服务器未响应");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async rmUser(username: string, token: string | null = null): Promise<any> {
|
||||
public async rmUser(username: string, token: string | null = null): Promise<any> {
|
||||
try {
|
||||
const data = {
|
||||
username: username
|
||||
|
@ -177,9 +177,9 @@ class BoxApi {
|
|||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async getAllUsers(token: string | null = null): Promise<any> {
|
||||
public async getAllUsers(token: string | null = null): Promise<any> {
|
||||
try {
|
||||
const res = await this.axios.get(this.apiAllusers, this._authHeader(token));
|
||||
if (res.data.err.ec === 0) {
|
||||
|
@ -190,7 +190,7 @@ class BoxApi {
|
|||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async getCamerasByUrl(url: string, token: string | null = null): Promise<any> {
|
||||
try {
|
||||
|
@ -230,9 +230,9 @@ class BoxApi {
|
|||
|
||||
// public async getEvents(token: string | null = null, pageSize: number = 10, currentPage: number = 1): Promise<any> {
|
||||
// const offset = (currentPage - 1) * pageSize;
|
||||
|
||||
|
||||
// const url = `${this.apiEvents}?limit=${pageSize}&offset=${offset}`;
|
||||
|
||||
|
||||
// try {
|
||||
// const res = await this.axios.get(url, this._authHeader(token));
|
||||
// if (res.data.err.ec === 0) {
|
||||
|
@ -248,11 +248,11 @@ class BoxApi {
|
|||
public async getEvents(token: string | null = null, pageSize: number = 20, currentPage: number = 1): Promise<any> {
|
||||
// 计算 offset
|
||||
const offset = (currentPage - 1) * pageSize;
|
||||
|
||||
|
||||
try {
|
||||
// 发送请求,携带 limit 和 offset 参数
|
||||
const res = await this.axios.get(`${this.apiEvents}?limit=${pageSize}&offset=${offset}`, this._authHeader(token));
|
||||
|
||||
|
||||
// 请求成功,返回数据
|
||||
if (res.data.err.ec === 0) {
|
||||
return {
|
||||
|
@ -339,7 +339,7 @@ class BoxApi {
|
|||
|
||||
private _authHeader(token: string | null = null): object {
|
||||
// const access_token = token === "" ? this.token : token;
|
||||
const alertToken = localStorage.getItem(`alertToken`) || token || this.token || "" ||"";
|
||||
const alertToken = localStorage.getItem(`alertToken`) || token || this.token || "" || "";
|
||||
return {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
Loading…
Reference in New Issue