feat: 登录接口联调
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { authOauth2TokenUsingPost } from "@renderer/api"
|
||||
import { getToken, setToken, removeToken } from '@utils/auth'
|
||||
import { Session } from '@utils/storage'
|
||||
import { encryption } from '@utils/other'
|
||||
|
||||
export const useUserStore = defineStore('userInfo', {
|
||||
state: () => ({
|
||||
token: getToken(),
|
||||
token: Session.get('token'),
|
||||
}),
|
||||
|
||||
actions: {
|
||||
@@ -15,15 +16,37 @@ export const useUserStore = defineStore('userInfo', {
|
||||
* @param {Object} data - 登录数据
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async login(data: LoginForm) {
|
||||
async login(data: any) {
|
||||
data.grant_type = 'password';
|
||||
data.scope = 'server';
|
||||
|
||||
// const { VITE_OAUTH2_PASSWORD_CLIENT, VITE_PWD_ENC_KEY } = (import.meta as any).env
|
||||
// const basicAuth = 'Basic ' + window.btoa(VITE_OAUTH2_PASSWORD_CLIENT);
|
||||
|
||||
// Session.set('basicAuth', basicAuth);
|
||||
|
||||
// let encPassword = data.password;
|
||||
// 密码加密
|
||||
// if (VITE_PWD_ENC_KEY) {
|
||||
// encPassword = encryption(data.password, VITE_PWD_ENC_KEY);
|
||||
// }
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
authOauth2TokenUsingPost({body: {...data, clientId: ''}})
|
||||
authOauth2TokenUsingPost({
|
||||
body: { clientId: '', ...data },
|
||||
options: {
|
||||
headers: {
|
||||
isToken: true,
|
||||
// Authorization: basicAuth,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Authorization': 'Basic Y3VzdG9tUEM6Y3VzdG9tUEM='
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((res: any) => {
|
||||
// 存储token 信息
|
||||
setToken(res.access_token)
|
||||
// 存储token 信息
|
||||
Session.set('token', res.access_token);
|
||||
Session.set('refresh_token', res.refresh_token);
|
||||
resolve(res)
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
Reference in New Issue
Block a user