2021-04-30 14:15:31 +08:00
|
|
|
import request from '@/utils/request'
|
2022-05-09 22:46:52 +08:00
|
|
|
import {getRefreshToken} from "@/utils/auth";
|
|
|
|
import service from "@/utils/request";
|
2021-04-30 14:15:31 +08:00
|
|
|
|
|
|
|
// 登录方法
|
2022-07-05 22:00:23 +08:00
|
|
|
export function login(username, password, code, uuid,
|
|
|
|
socialType, socialCode, socialState) {
|
2021-04-30 14:15:31 +08:00
|
|
|
const data = {
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
code,
|
2022-07-05 22:00:23 +08:00
|
|
|
uuid,
|
|
|
|
// 社交相关
|
|
|
|
socialType, socialCode, socialState
|
2021-04-30 14:15:31 +08:00
|
|
|
}
|
|
|
|
return request({
|
2022-04-26 23:36:26 +08:00
|
|
|
url: '/system/auth/login',
|
2021-04-30 14:15:31 +08:00
|
|
|
method: 'post',
|
|
|
|
data: data
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取用户详细信息
|
|
|
|
export function getInfo() {
|
|
|
|
return request({
|
2022-04-26 23:36:26 +08:00
|
|
|
url: '/system/auth/get-permission-info',
|
2021-04-30 14:15:31 +08:00
|
|
|
method: 'get'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 退出方法
|
|
|
|
export function logout() {
|
|
|
|
return request({
|
2022-05-08 00:38:55 +08:00
|
|
|
url: '/system/auth/logout',
|
2021-04-30 14:15:31 +08:00
|
|
|
method: 'post'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取验证码
|
|
|
|
export function getCodeImg() {
|
|
|
|
return request({
|
|
|
|
url: '/system/captcha/get-image',
|
2022-02-17 09:23:08 +08:00
|
|
|
method: 'get',
|
|
|
|
timeout: 20000
|
2021-04-30 14:15:31 +08:00
|
|
|
})
|
|
|
|
}
|
2021-08-13 23:44:52 +08:00
|
|
|
|
2021-10-06 09:33:21 +08:00
|
|
|
// 社交授权的跳转
|
|
|
|
export function socialAuthRedirect(type, redirectUri) {
|
2021-08-13 23:44:52 +08:00
|
|
|
return request({
|
2022-04-26 23:36:26 +08:00
|
|
|
url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri,
|
2021-08-13 23:44:52 +08:00
|
|
|
method: 'get'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-26 23:36:26 +08:00
|
|
|
// 社交快捷登录,使用 code 授权码
|
2022-07-05 22:00:23 +08:00
|
|
|
export function socialLogin(type, code, state) {
|
2021-08-13 23:44:52 +08:00
|
|
|
return request({
|
2022-07-05 22:00:23 +08:00
|
|
|
url: '/system/auth/social-login',
|
2021-10-02 18:31:05 +08:00
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
type,
|
|
|
|
code,
|
|
|
|
state
|
|
|
|
}
|
2021-08-13 23:44:52 +08:00
|
|
|
})
|
|
|
|
}
|
2021-10-02 23:55:41 +08:00
|
|
|
|
2022-04-27 11:31:18 +08:00
|
|
|
// 获取登录验证码
|
2022-05-02 22:57:45 +08:00
|
|
|
export function sendSmsCode(mobile, scene) {
|
2022-04-27 11:31:18 +08:00
|
|
|
return request({
|
2022-05-02 22:57:45 +08:00
|
|
|
url: '/system/auth/send-sms-code',
|
2022-04-27 11:31:18 +08:00
|
|
|
method: 'post',
|
2022-05-02 22:57:45 +08:00
|
|
|
data: {
|
|
|
|
mobile,
|
|
|
|
scene
|
|
|
|
}
|
2022-04-27 11:31:18 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 短信验证码登录
|
|
|
|
export function smsLogin(mobile, code) {
|
|
|
|
return request({
|
2022-05-02 22:57:45 +08:00
|
|
|
url: '/system/auth/sms-login',
|
2022-04-27 11:31:18 +08:00
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
mobile,
|
|
|
|
code
|
|
|
|
}
|
|
|
|
})
|
2022-05-02 21:36:51 +08:00
|
|
|
}
|
2022-05-09 22:46:52 +08:00
|
|
|
|
|
|
|
// 刷新访问令牌
|
|
|
|
export function refreshToken() {
|
|
|
|
return service({
|
|
|
|
url: '/system/auth/refresh-token?refreshToken=' + getRefreshToken(),
|
|
|
|
method: 'post'
|
|
|
|
})
|
|
|
|
}
|
2022-05-14 15:11:58 +08:00
|
|
|
|
|
|
|
// ========== OAUTH 2.0 相关 ==========
|
2022-05-24 00:01:30 +08:00
|
|
|
|
|
|
|
export function getAuthorize(clientId) {
|
|
|
|
return request({
|
|
|
|
url: '/system/oauth2/authorize?clientId=' + clientId,
|
|
|
|
method: 'get'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export function authorize(responseType, clientId, redirectUri, state,
|
|
|
|
autoApprove, checkedScopes, uncheckedScopes) {
|
|
|
|
// 构建 scopes
|
|
|
|
const scopes = {};
|
|
|
|
for (const scope of checkedScopes) {
|
|
|
|
scopes[scope] = true;
|
|
|
|
}
|
|
|
|
for (const scope of uncheckedScopes) {
|
|
|
|
scopes[scope] = false;
|
|
|
|
}
|
|
|
|
// 发起请求
|
2022-05-14 15:11:58 +08:00
|
|
|
return service({
|
|
|
|
url: '/system/oauth2/authorize',
|
|
|
|
headers:{
|
|
|
|
'Content-type': 'application/x-www-form-urlencoded',
|
|
|
|
},
|
|
|
|
params: {
|
2022-05-24 00:01:30 +08:00
|
|
|
response_type: responseType,
|
|
|
|
client_id: clientId,
|
|
|
|
redirect_uri: redirectUri,
|
|
|
|
state: state,
|
|
|
|
auto_approve: autoApprove,
|
|
|
|
scope: JSON.stringify(scopes)
|
2022-05-14 15:11:58 +08:00
|
|
|
},
|
|
|
|
method: 'post'
|
|
|
|
})
|
|
|
|
}
|
2022-08-03 11:52:35 +08:00
|
|
|
|
|
|
|
export class socialBindLogin {
|
|
|
|
}
|