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