44 lines
1.4 KiB
Plaintext
44 lines
1.4 KiB
Plaintext
import { Config } from "../config"
|
|
import { RequestConfig } from "@/types/HttpClientType.uts"
|
|
import { LoginData, LoginResult } from "./types"
|
|
import { HttpMethod } from "@/enum/HttpMethod"
|
|
import { HttpClient } from "@/utils/HttpClient"
|
|
export class LoginApi {
|
|
private static http = HttpClient.getInstance()
|
|
static async login(config : LoginData) : Promise<LoginResult> {
|
|
const configData : any = {
|
|
username: config.username,
|
|
password: config.password,
|
|
rememberMe: config.rememberMe,
|
|
socialCode: config.socialCode,
|
|
socialState: config.socialState,
|
|
source: config.source,
|
|
code: config.code,
|
|
uuid: config.uuid,
|
|
clientId: Config.VITE_APP_CLIENT_ID,
|
|
grantType: 'password'
|
|
}
|
|
// 请求参数处理
|
|
const Requestconfig = new RequestConfig()
|
|
Requestconfig.url = "/auth/login"
|
|
Requestconfig.headers!.isToken = false
|
|
Requestconfig.headers!.isEncrypt = true
|
|
Requestconfig.headers!.repeatSubmit = false
|
|
Requestconfig.method = HttpMethod.POST
|
|
Requestconfig.data = configData
|
|
//发起请求
|
|
const res = await this.http.request<UTSJSONObject>(Requestconfig)
|
|
const data = res.data
|
|
console.log(data);
|
|
if (data == null) {
|
|
throw new Error("登陆失败")
|
|
}
|
|
// 格式化返回数据 手动转换 UTSJSONObject 到 VerifyCodeResult
|
|
const result : LoginResult = {
|
|
access_token: data["access_token"] as string
|
|
}
|
|
console.log(result.access_token);
|
|
|
|
return result
|
|
}
|
|
} |