refactor(api): 统一将函数声明改为箭头函数形式
将所有api模块中的普通函数声明替换为const箭头函数形式,保持代码风格统一
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
import { API_BASE_URL, TOKEN_KEY, request } from "../plugins/axios";
|
||||
import type { AdminProfile, ApiResponse, ChangePasswordPayload, LoginPayload, UpdateProfilePayload } from "./interface";
|
||||
|
||||
export function getApiBaseUrl() {
|
||||
export const getApiBaseUrl = () => {
|
||||
return API_BASE_URL;
|
||||
}
|
||||
};
|
||||
|
||||
export function saveAuthToken(token: string) {
|
||||
export const saveAuthToken = (token: string) => {
|
||||
localStorage.setItem(TOKEN_KEY, token);
|
||||
}
|
||||
};
|
||||
|
||||
export function clearAuthToken() {
|
||||
export const clearAuthToken = () => {
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
}
|
||||
};
|
||||
|
||||
export function hasAuthToken() {
|
||||
export const hasAuthToken = () => {
|
||||
return Boolean(localStorage.getItem(TOKEN_KEY));
|
||||
}
|
||||
};
|
||||
|
||||
export async function login(payload: LoginPayload) {
|
||||
export const login = async (payload: LoginPayload) => {
|
||||
const response = await request.post<ApiResponse<{ accessToken: string }>>("/api/admin/v1/auth/login", payload);
|
||||
return response.data.data;
|
||||
}
|
||||
};
|
||||
|
||||
export async function getProfile() {
|
||||
export const getProfile = async () => {
|
||||
const response = await request.get<ApiResponse<AdminProfile>>("/api/admin/v1/auth/profile");
|
||||
return response.data.data;
|
||||
}
|
||||
};
|
||||
|
||||
export async function updateProfile(payload: UpdateProfilePayload) {
|
||||
export const updateProfile = async (payload: UpdateProfilePayload) => {
|
||||
const response = await request.patch<ApiResponse<AdminProfile>>("/api/admin/v1/auth/profile", payload);
|
||||
return response.data.data;
|
||||
}
|
||||
};
|
||||
|
||||
export async function changePassword(payload: ChangePasswordPayload) {
|
||||
export const changePassword = async (payload: ChangePasswordPayload) => {
|
||||
await request.patch("/api/admin/v1/auth/password", payload);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { fetchPage, request } from "../plugins/axios";
|
||||
import type { CreateRolePayload, PageQuery, Permission, Role } from "./interface";
|
||||
|
||||
export function listRoles(query: PageQuery) {
|
||||
export const listRoles = (query: PageQuery) => {
|
||||
return fetchPage<Role>('/api/admin/v1/roles', query);
|
||||
}
|
||||
|
||||
export function listPermissions(query: PageQuery) {
|
||||
export const listPermissions = (query: PageQuery) => {
|
||||
return fetchPage<Permission>('/api/admin/v1/permissions', query);
|
||||
}
|
||||
|
||||
export async function createRole(payload: CreateRolePayload) {
|
||||
export const createRole = async (payload: CreateRolePayload) => {
|
||||
await request.post('/api/admin/v1/roles', payload);
|
||||
}
|
||||
|
||||
export async function updateRolePermissions(
|
||||
export const updateRolePermissions = async (
|
||||
roleId: number,
|
||||
permissionIds: number[],
|
||||
) {
|
||||
) => {
|
||||
await request.patch(`/api/admin/v1/roles/${roleId}/permissions`, {
|
||||
permissionIds,
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: ['./index.html', './src/**/*.{ts,tsx}'],
|
||||
important: '#root',
|
||||
important: true,
|
||||
corePlugins: {
|
||||
preflight: false,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user