user.ts
2.25 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
import request from '/@/utils/request';
export const pageList = (params?: Object) => {
return request({
url: '/admin/user/page',
method: 'get',
params,
});
};
export const addObj = (obj: Object) => {
return request({
url: '/admin/user',
method: 'post',
data: obj,
});
};
export const getObj = (id: String) => {
return request({
url: '/admin/user/details/' + id,
method: 'get',
});
};
export const delObj = (ids: Object) => {
return request({
url: '/admin/user',
method: 'delete',
data: ids,
});
};
export const putObj = (obj: Object) => {
return request({
url: '/admin/user',
method: 'put',
data: obj,
});
};
export function getDetails(obj: Object) {
return request({
url: '/admin/user/details',
method: 'get',
params: obj,
});
}
// 更改个人信息
export function editInfo(obj: Object) {
return request({
url: '/admin/user/edit',
method: 'put',
data: obj,
});
}
export function password(obj: Object) {
return request({
url: '/admin/user/password',
method: 'put',
data: obj,
});
}
export function UnbindingUser(type) {
return request({
url: '/admin/user/unbinding',
method: 'post',
params: {
type,
},
});
}
export function checkPassword(password: string) {
return request({
url: '/admin/user/check',
method: 'post',
params: {
password,
},
});
}
/**
* 注册用户
*/
export const registerUser = (userInfo: object) => {
return request({
url: '/admin/register/user',
method: 'post',
data: userInfo,
});
};
export function validateUsername(rule: any, value: any, callback: any, isEdit: boolean) {
const flag = new RegExp(/^([a-z\d]+?)$/).test(value);
if (!flag) {
callback(new Error('用户名支持小写英文、数字'));
}
if (isEdit) {
return callback();
}
getDetails({ username: value }).then((response) => {
const result = response.data;
if (result !== null) {
callback(new Error('用户名已经存在'));
} else {
callback();
}
});
}
export function validatePhone(rule: any, value: any, callback: any, isEdit: boolean) {
if (isEdit) {
return callback();
}
getDetails({ phone: value }).then((response) => {
const result = response.data;
if (result !== null) {
callback(new Error('手机号已经存在'));
} else {
callback();
}
});
}