From b00dac74debaddfa3a646a94fb352139a42b0481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=9A=E7=9A=93?= <1736436516@qq.com> Date: Mon, 30 Sep 2024 16:05:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=BC=8F=E5=88=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/boxApi.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/utils/boxApi.ts b/src/utils/boxApi.ts index 2680e5d..6125df8 100644 --- a/src/utils/boxApi.ts +++ b/src/utils/boxApi.ts @@ -136,7 +136,7 @@ class BoxApi { } catch (error) { throw error; } - } + } public async addUser(username: string, password: string, email: string = "", token: string | null = null): Promise { 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 { + public async rmUser(username: string, token: string | null = null): Promise { try { const data = { username: username @@ -177,9 +177,9 @@ class BoxApi { } catch (error) { throw error; } - } + } - public async getAllUsers(token: string | null = null): Promise { + public async getAllUsers(token: string | null = null): Promise { 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 { try { @@ -230,9 +230,9 @@ class BoxApi { // public async getEvents(token: string | null = null, pageSize: number = 10, currentPage: number = 1): Promise { // 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 { // 计算 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',