role.ts
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { AnyObject, QueryForParams, ServiceResponse } from '@/types/global';
import { SystemRole } from '@/types/system-role';
import { SystemPermission } from '@/types/system-permission';
import axios from 'axios';
export default class useRoleApi {
static statusOption = [
{ value: 1, label: '启用' },
{ value: 0, label: '禁用' },
];
static async get(params?: QueryForParams): Promise<ServiceResponse<SystemRole[]>> {
return axios.get('system/roles', { params });
}
static async create(data: AnyObject): Promise<SystemRole> {
return axios.post('system/roles', data).then((res) => Promise.resolve(res.data));
}
static async update(id: number, data: AnyObject): Promise<SystemRole> {
return axios.put(`system/roles/${id}`, data).then((res) => Promise.resolve(res.data));
}
static async changeStatus(id: number, status: number) {
return axios.put(`system/roles/${id}/change-status`, { status });
}
static async changePermission(id: number, permission: number[]) {
return axios.put(`system/roles/${id}/change-permission`, { permission });
}
static async destroy(id: number) {
return axios.delete(`system/roles/${id}`).then((res) => Promise.resolve(res.data));
}
}
export class usePermissionApi {
static async get(params?: QueryForParams): Promise<ServiceResponse<SystemPermission[]>> {
return axios.get('system/permissions', { params });
}
}