From 71f137eda340fecee9cf32dc8e6a780ba0844d15 Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Tue, 3 Sep 2024 16:46:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83(?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api/core/auth.ts | 91 +++++++++++++-- apps/web-antd/src/api/system/social/index.ts | 20 ++++ .../web-antd/src/api/system/social/model.d.ts | 26 +++++ .../_core/profile/components/account-bind.vue | 79 +++++++++++++ .../_core/profile/components/base-setting.vue | 104 ++++++++++++++++++ .../profile/components/online-device.vue | 8 ++ .../profile/components/secure-setting.vue | 5 + .../src/views/_core/profile/index.vue | 97 ++-------------- .../src/views/_core/profile/profile-panel.vue | 53 +++++++++ .../src/views/_core/profile/setting-panel.vue | 59 ++++++++++ .../common-ui/src/ui/authentication/index.ts | 1 + .../common-ui/src/ui/authentication/types.ts | 13 ++- 12 files changed, 463 insertions(+), 93 deletions(-) create mode 100644 apps/web-antd/src/api/system/social/index.ts create mode 100644 apps/web-antd/src/api/system/social/model.d.ts create mode 100644 apps/web-antd/src/views/_core/profile/components/account-bind.vue create mode 100644 apps/web-antd/src/views/_core/profile/components/base-setting.vue create mode 100644 apps/web-antd/src/views/_core/profile/components/online-device.vue create mode 100644 apps/web-antd/src/views/_core/profile/components/secure-setting.vue create mode 100644 apps/web-antd/src/views/_core/profile/profile-panel.vue create mode 100644 apps/web-antd/src/views/_core/profile/setting-panel.vue diff --git a/apps/web-antd/src/api/core/auth.ts b/apps/web-antd/src/api/core/auth.ts index a7c3ba7b..cb194362 100644 --- a/apps/web-antd/src/api/core/auth.ts +++ b/apps/web-antd/src/api/core/auth.ts @@ -1,3 +1,5 @@ +import type { GrantType } from '@vben/common-ui'; + import { useAppConfig } from '@vben/hooks'; import { requestClient } from '#/api/request'; @@ -5,16 +7,56 @@ import { requestClient } from '#/api/request'; const { clientId } = useAppConfig(import.meta.env, import.meta.env.PROD); export namespace AuthApi { - /** 登录接口参数 */ - export interface LoginParams { - code?: string; - grantType: string; - password: string; + /** + * @description: 所有登录类型都需要用到的 + * @param clientId 客户端ID 这里为必填项 但是在loginApi内部处理了 所以为可选 + * @param grantType 授权/登录类型 + * @param tenantId 租户id + */ + export interface BaseLoginParams { + clientId?: string; + grantType: GrantType; tenantId: string; - username: string; - uuid?: string; } + /** + * @description: oauth登录需要用到的参数 + * @param socialCode 第三方参数 + * @param socialState 第三方参数 + * @param source 与后端的 justauth.type.xxx的回调地址的source对应 + */ + export interface OAuthLoginParams extends BaseLoginParams { + socialCode: string; + socialState: string; + source: string; + } + + /** + * @description: 验证码登录需要用到的参数 + * @param code 验证码 可选(未开启验证码情况) + * @param uuid 验证码ID 可选(未开启验证码情况) + * @param username 用户名 + * @param password 密码 + */ + export interface SimpleLoginParams extends BaseLoginParams { + code?: string; + uuid?: string; + username: string; + password: string; + } + + export type LoginParams = OAuthLoginParams | SimpleLoginParams; + + // /** 登录接口参数 */ + // export interface LoginParams { + // code?: string; + // grantType: string; + // password: string; + // tenantId: string; + // username: string; + // uuid?: string; + // } + /** 登录接口返回值 */ export interface LoginResult { access_token: string; @@ -76,6 +118,41 @@ export function tenantList() { return requestClient.get('/auth/tenant/list'); } +/** + * vben的 先不删除 + * @returns string[] + */ export async function getAccessCodesApi() { return requestClient.get('/auth/codes'); } + +/** + * 绑定第三方账号 + * @param source 绑定的来源 + * @returns 跳转url + */ +export function authBinding(source: string, tenantId: string) { + return requestClient.get(`/auth/binding/${source}`, { + params: { + domain: window.location.host, + tenantId, + }, + }); +} + +/** + * 取消绑定 + * @param id id + */ +export function authUnbinding(id: string) { + return requestClient.deleteWithMsg(`/auth/unlock/${id}`); +} + +/** + * oauth授权回调 + * @param data oauth授权 + * @returns void + */ +export function authCallback(data: AuthApi.OAuthLoginParams) { + return requestClient.post('/auth/social/callback', data); +} diff --git a/apps/web-antd/src/api/system/social/index.ts b/apps/web-antd/src/api/system/social/index.ts new file mode 100644 index 00000000..7c50ed3a --- /dev/null +++ b/apps/web-antd/src/api/system/social/index.ts @@ -0,0 +1,20 @@ +import type { SocialInfo } from './model'; + +import { requestClient } from '#/api/request'; + +enum Api { + root = '/system/social', + socialList = '/system/social/list', +} + +/** + * 获取绑定的社交信息列表 + * @returns info + */ +export function socialList() { + return requestClient.get(Api.socialList); +} + +export function socialInfo(id: number | string) { + return requestClient.get(`${Api.root}/${id}`); +} diff --git a/apps/web-antd/src/api/system/social/model.d.ts b/apps/web-antd/src/api/system/social/model.d.ts new file mode 100644 index 00000000..1e3b0157 --- /dev/null +++ b/apps/web-antd/src/api/system/social/model.d.ts @@ -0,0 +1,26 @@ +export interface SocialInfo { + id: string; + userId: number; + tenantId: string; + authId: string; + source: string; + accessToken: string; + expireIn: number; + refreshToken: string; + openId: string; + userName: string; + nickName: string; + email: string; + avatar: string; + accessCode?: any; + unionId?: any; + scope: string; + tokenType: string; + idToken?: any; + macAlgorithm?: any; + macKey?: any; + code?: any; + oauthToken?: any; + oauthTokenSecret?: any; + createTime: string; +} diff --git a/apps/web-antd/src/views/_core/profile/components/account-bind.vue b/apps/web-antd/src/views/_core/profile/components/account-bind.vue new file mode 100644 index 00000000..51663b1d --- /dev/null +++ b/apps/web-antd/src/views/_core/profile/components/account-bind.vue @@ -0,0 +1,79 @@ + + + diff --git a/apps/web-antd/src/views/_core/profile/components/base-setting.vue b/apps/web-antd/src/views/_core/profile/components/base-setting.vue new file mode 100644 index 00000000..8889ca2f --- /dev/null +++ b/apps/web-antd/src/views/_core/profile/components/base-setting.vue @@ -0,0 +1,104 @@ + + + diff --git a/apps/web-antd/src/views/_core/profile/components/online-device.vue b/apps/web-antd/src/views/_core/profile/components/online-device.vue new file mode 100644 index 00000000..452097f2 --- /dev/null +++ b/apps/web-antd/src/views/_core/profile/components/online-device.vue @@ -0,0 +1,8 @@ + + + diff --git a/apps/web-antd/src/views/_core/profile/components/secure-setting.vue b/apps/web-antd/src/views/_core/profile/components/secure-setting.vue new file mode 100644 index 00000000..af0e1bdd --- /dev/null +++ b/apps/web-antd/src/views/_core/profile/components/secure-setting.vue @@ -0,0 +1,5 @@ + + + diff --git a/apps/web-antd/src/views/_core/profile/index.vue b/apps/web-antd/src/views/_core/profile/index.vue index ce443624..28a81f28 100644 --- a/apps/web-antd/src/views/_core/profile/index.vue +++ b/apps/web-antd/src/views/_core/profile/index.vue @@ -4,101 +4,28 @@ import type { UserProfile } from '#/api/system/profile/model'; import { onMounted, ref } from 'vue'; import { Page } from '@vben/common-ui'; -import { useUserStore } from '@vben/stores'; - -import { - Avatar, - Card, - Descriptions, - DescriptionsItem, - Tag, -} from 'ant-design-vue'; import { userProfile } from '#/api/system/profile'; -const currentActiveKey = ref('tab1'); +import ProfilePanel from './profile-panel.vue'; +import SettingPanel from './setting-panel.vue'; -const tabList = [ - { - key: 'tab1', - tab: '基本设置', - }, - { - key: 'tab2', - tab: '安全设置', - }, - { - key: 'tab3', - tab: '账号绑定', - }, -]; - -const userStore = useUserStore(); const profile = ref(); -onMounted(async () => { - console.log(userStore.userInfo); - profile.value = await userProfile(); -}); +async function loadProfile() { + const resp = await userProfile(); + profile.value = resp; +} + +onMounted(loadProfile); diff --git a/apps/web-antd/src/views/_core/profile/profile-panel.vue b/apps/web-antd/src/views/_core/profile/profile-panel.vue new file mode 100644 index 00000000..18ec2edf --- /dev/null +++ b/apps/web-antd/src/views/_core/profile/profile-panel.vue @@ -0,0 +1,53 @@ + + + diff --git a/apps/web-antd/src/views/_core/profile/setting-panel.vue b/apps/web-antd/src/views/_core/profile/setting-panel.vue new file mode 100644 index 00000000..4fb80854 --- /dev/null +++ b/apps/web-antd/src/views/_core/profile/setting-panel.vue @@ -0,0 +1,59 @@ + + + diff --git a/packages/effects/common-ui/src/ui/authentication/index.ts b/packages/effects/common-ui/src/ui/authentication/index.ts index ec6b1495..dcd05b71 100644 --- a/packages/effects/common-ui/src/ui/authentication/index.ts +++ b/packages/effects/common-ui/src/ui/authentication/index.ts @@ -6,6 +6,7 @@ export { default as AuthenticationQrCodeLogin } from './qrcode-login.vue'; export { default as AuthenticationRegister } from './register.vue'; export type { AuthenticationProps, + GrantType, LoginAndRegisterParams, LoginCodeParams, } from './types'; diff --git a/packages/effects/common-ui/src/ui/authentication/types.ts b/packages/effects/common-ui/src/ui/authentication/types.ts index 407f04a3..8098dea1 100644 --- a/packages/effects/common-ui/src/ui/authentication/types.ts +++ b/packages/effects/common-ui/src/ui/authentication/types.ts @@ -74,9 +74,19 @@ interface AuthenticationProps { usernamePlaceholder?: string; } +/** + * 登录类型 + * password 密码 + * sms 短信 + * social 第三方oauth + * email 邮箱 + * xcx 小程序 + */ +type GrantType = 'email' | 'password' | 'sms' | 'social' | 'xcx'; + interface LoginAndRegisterParams { code?: string; - grantType: string; + grantType: GrantType; password: string; tenantId: string; username: string; @@ -102,6 +112,7 @@ interface RegisterEmits { export type { AuthenticationProps, + GrantType, LoginAndRegisterParams, LoginCodeEmits, LoginCodeParams,