user.ts
4.94 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { AttributeData, QueryForParams, ServiceResponse } from '@/types/global';
import { Activity } from '@/types/activity';
import axios, { AxiosRequestConfig } from 'axios';
import { User, UserCertify, UserDynamics, UserManageActivity, UserMember, UserSubmitActivity } from '@/utils/model';
import FileSaver from 'file-saver';
export default class useUserApi {
static statusOption = [
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
{ label: '注销', value: 2 },
];
static officialStatusOption = [
{ label: '已关注', value: 1 },
{ label: '未关注', value: 0 },
];
static sexOption = [
{ label: '男', value: 1 },
{ label: '女', value: 2 },
{ label: '无', value: 0 },
];
static scopeOption = [
{ label: '无权限', value: 0 },
{ label: '平台管理员', value: 1 },
{ label: '厂牌管理员', value: 2 },
];
static get(params?: QueryForParams, config = {}): Promise<ServiceResponse<User[]>> {
return axios.get(`user`, { params, ...config });
}
static async show(id: number, params?: QueryForParams): Promise<User> {
return axios.get(`user/${id}`, { params }).then((res) => Promise.resolve(res.data));
}
static async update(id: number, data: AttributeData): Promise<User> {
return axios.put(`user/${id}`, data).then((res) => Promise.resolve(res.data));
}
static destroy(id: number) {
return axios.delete(`user/${id}`);
}
static changeStatus(id: number, status: 1 | 0) {
return axios.put(`user/${id}/change-status`, { status });
}
static changePwd(id: number, data: { password: string; password_confirmation: string }) {
return axios.put(`user/${id}/change-pwd`, data);
}
static listenSongs(id: number, params?: QueryForParams): Promise<ServiceResponse<Activity[]>> {
return axios.get(`user/${id}/listen-songs`, { params });
}
static likeSongs(id: number, params?: QueryForParams): Promise<ServiceResponse<Activity[]>> {
return axios.get(`user/${id}/like-songs`, { params });
}
static manageSongs(id: number, params?: QueryForParams): Promise<ServiceResponse<UserManageActivity[]>> {
return axios.get(`user/${id}/manage-songs`, { params });
}
static submitSongs(id: number, params?: QueryForParams): Promise<ServiceResponse<UserSubmitActivity[]>> {
return axios.get(`user/${id}/submit-songs`, { params });
}
static singers(id: number, params?: QueryForParams): Promise<ServiceResponse<User[]>> {
return axios.get(`user/${id}/singers`, { params });
}
static dynamics(id: number, params?: QueryForParams): Promise<ServiceResponse<UserDynamics[]>> {
return axios.get(`user/${id}/dynamics`, { params });
}
}
export class useCertifyApi {
static sexOption = useUserApi.sexOption;
static statusOption = [
{ label: '待审核', value: 0 },
{ label: '通过', value: 1 },
{ label: '拒绝', value: 2 },
];
// eslint-disable-next-line class-methods-use-this
static get(params?: QueryForParams): Promise<ServiceResponse<UserCertify[]>> {
return axios.get('user/certifies', { params });
}
static async update(id: number, data: { status: number; reason: string }): Promise<UserCertify> {
return axios.put(`user/certifies/${id}`, data).then((res) => Promise.resolve(res.data));
}
}
export class useRegisterApi extends useUserApi {
static get(params?: QueryForParams): Promise<ServiceResponse<User[]>> {
return axios.get('user/registers', { params });
}
static async getExport(fileName: string, params?: QueryForParams) {
const config = { params: { ...params, fetchType: 'excel' }, timeout: 60000, responseType: 'blob' } as AxiosRequestConfig;
return axios.get('user/registers', config).then(({ data }) => FileSaver.saveAs(data, `${fileName}.xlsx`));
}
}
export class useSingerApi extends useUserApi {
static get(params?: QueryForParams): Promise<ServiceResponse<User[]>> {
return axios.get('user/singers', { params });
}
static async getExport(fileName: string, params?: QueryForParams) {
const config = { params: { ...params, fetchType: 'excel' }, timeout: 60000, responseType: 'blob' } as AxiosRequestConfig;
return axios.get('user/singers', config).then(({ data }) => FileSaver.saveAs(data, `${fileName}.xlsx`));
}
}
export class useBusinessApi extends useUserApi {
static get(params?: QueryForParams): Promise<ServiceResponse<User[]>> {
return axios.get('user/business', { params });
}
static async getExport(fileName: string, params?: QueryForParams) {
const config = { params: { ...params, fetchType: 'excel' }, timeout: 60000, responseType: 'blob' } as AxiosRequestConfig;
return axios.get('user/business', config).then(({ data }) => FileSaver.saveAs(data, `${fileName}.xlsx`));
}
}
export class useMemberApi {
static get(userId: number, params?: QueryForParams): Promise<ServiceResponse<UserMember[]>> {
return axios.get(`user/${userId}/members`, { params });
}
static destroy(userId: number) {
return axios.delete(`user/${userId}/members`);
}
}