Refactor authentication and authorization

This commit is contained in:
cuigh
2021-12-22 17:43:26 +08:00
parent dfe15524a2
commit 487d73d643
52 changed files with 1348 additions and 942 deletions

View File

@@ -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;
},

View File

@@ -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
View 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

View File

@@ -2,8 +2,8 @@ import ajax, { Result } from './ajax'
export interface AuthUser {
token: string;
id: string;
name: string;
perms: string[];
}
export interface User {