mirror of
https://github.com/cuigh/swirl
synced 2025-06-26 18:16:50 +00:00
Refactor authentication and authorization
This commit is contained in:
@@ -25,23 +25,19 @@ class Ajax {
|
||||
|
||||
this.ajax.interceptors.request.use(
|
||||
(config: any) => {
|
||||
if (store.state.token) {
|
||||
config.headers.Authorization = "Bearer " + store.state.token
|
||||
if (store.state.user?.token) {
|
||||
config.headers.Authorization = "Bearer " + store.state.user.token
|
||||
}
|
||||
// store.commit(Mutations.SetAjaxLoading, true);
|
||||
return config;
|
||||
},
|
||||
(error: any) => {
|
||||
console.error(error); // for debug
|
||||
return Promise.reject(error);
|
||||
}
|
||||
)
|
||||
|
||||
this.ajax.interceptors.response.use(
|
||||
(response: any) => {
|
||||
if (response.headers.authorization) {
|
||||
store.commit(Mutations.SetToken, response.headers.authorization)
|
||||
}
|
||||
// store.commit(Mutations.SetAjaxLoading, false);
|
||||
return response;
|
||||
},
|
||||
|
||||
@@ -32,29 +32,6 @@ export interface Chart {
|
||||
};
|
||||
}
|
||||
|
||||
export interface Dashboard {
|
||||
name: string;
|
||||
key: string;
|
||||
period: number;
|
||||
interval: number;
|
||||
charts: ChartInfo[];
|
||||
}
|
||||
|
||||
export interface ChartInfo {
|
||||
id: string;
|
||||
title: string;
|
||||
type: 'line' | 'bar' | 'pie' | 'gauge';
|
||||
unit: string;
|
||||
width: number;
|
||||
height: number;
|
||||
margin: {
|
||||
left?: number;
|
||||
right?: number;
|
||||
top?: number;
|
||||
bottom?: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface SearchArgs {
|
||||
name?: string;
|
||||
dashboard?: string;
|
||||
@@ -83,18 +60,6 @@ export class ChartApi {
|
||||
delete(id: string, title: string) {
|
||||
return ajax.post<Result<Object>>('/chart/delete', { id, title })
|
||||
}
|
||||
|
||||
fetchData(key: string, charts: string[], period: number) {
|
||||
return ajax.get<any>('/chart/fetch-data', { key, charts: charts.join(","), period })
|
||||
}
|
||||
|
||||
findDashboard(name: string, key: string) {
|
||||
return ajax.get<Dashboard>('/chart/find-dashboard', { name, key })
|
||||
}
|
||||
|
||||
saveDashboard(dashboard: Dashboard) {
|
||||
return ajax.post<Result<Object>>('/chart/save-dashboard', dashboard)
|
||||
}
|
||||
}
|
||||
|
||||
export default new ChartApi
|
||||
|
||||
40
ui/src/api/dashboard.ts
Normal file
40
ui/src/api/dashboard.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import ajax, { Result } from './ajax'
|
||||
|
||||
export interface Dashboard {
|
||||
name: string;
|
||||
key: string;
|
||||
period: number;
|
||||
interval: number;
|
||||
charts: ChartInfo[];
|
||||
}
|
||||
|
||||
export interface ChartInfo {
|
||||
id: string;
|
||||
title: string;
|
||||
type: 'line' | 'bar' | 'pie' | 'gauge';
|
||||
unit: string;
|
||||
width: number;
|
||||
height: number;
|
||||
margin: {
|
||||
left?: number;
|
||||
right?: number;
|
||||
top?: number;
|
||||
bottom?: number;
|
||||
};
|
||||
}
|
||||
|
||||
export class DashboardApi {
|
||||
fetchData(key: string, charts: string[], period: number) {
|
||||
return ajax.get<any>('/dashboard/fetch-data', { key, charts: charts.join(","), period })
|
||||
}
|
||||
|
||||
find(name: string, key: string) {
|
||||
return ajax.get<Dashboard>('/dashboard/find', { name, key })
|
||||
}
|
||||
|
||||
save(dashboard: Dashboard) {
|
||||
return ajax.post<Result<Object>>('/dashboard/save', dashboard)
|
||||
}
|
||||
}
|
||||
|
||||
export default new DashboardApi
|
||||
@@ -2,8 +2,8 @@ import ajax, { Result } from './ajax'
|
||||
|
||||
export interface AuthUser {
|
||||
token: string;
|
||||
id: string;
|
||||
name: string;
|
||||
perms: string[];
|
||||
}
|
||||
|
||||
export interface User {
|
||||
|
||||
Reference in New Issue
Block a user