Skip to content

Commit

Permalink
feat(system/client): 新增客户端管理
Browse files Browse the repository at this point in the history
  • Loading branch information
KAI authored and Charles7c committed Dec 26, 2024
1 parent 4ec42d1 commit bc3a5cf
Show file tree
Hide file tree
Showing 15 changed files with 605 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ VITE_BASE = '/'
VITE_OPEN_DEVTOOLS = false

# 应用配置面板
VITE_APP_SETTING = true
VITE_APP_SETTING = true

# 客户端ID
VITE_CLIENT_ID = 'ef51c9a3e9046c4f2ea45142c8a8344a'
5 changes: 4 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ VITE_API_WS_URL = 'wss://api.continew.top'
VITE_BASE = '/'

# 应用配置面板
VITE_APP_SETTING = true
VITE_APP_SETTING = true

# 客户端ID
VITE_CLIENT_ID = 'ef51c9a3e9046c4f2ea45142c8a8344a'
5 changes: 4 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ VITE_BASE = '/test'
VITE_OPEN_DEVTOOLS = true

# 应用配置面板
VITE_APP_SETTING = false
VITE_APP_SETTING = false

# 客户端ID
VITE_CLIENT_ID = '8ed5c8f9-555a-4961-ab66-9b87ddc4e3d0'
10 changes: 5 additions & 5 deletions src/apis/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ const BASE_URL = '/auth'

/** @desc 账号登录 */
export function accountLogin(req: T.AccountLoginReq) {
return http.post<T.LoginResp>(`${BASE_URL}/account`, req)
return http.post<T.LoginResp>(`${BASE_URL}/login`, req)
}

/** @desc 手机号登录 */
export function phoneLogin(req: T.PhoneLoginReq) {
return http.post<T.LoginResp>(`${BASE_URL}/phone`, req)
return http.post<T.LoginResp>(`${BASE_URL}/login`, req)
}

/** @desc 邮箱登录 */
export function emailLogin(req: T.EmailLoginReq) {
return http.post<T.LoginResp>(`${BASE_URL}/email`, req)
return http.post<T.LoginResp>(`${BASE_URL}/login`, req)
}

/** @desc 三方账号登录 */
export function socialLogin(source: string, req: any) {
return http.post<T.LoginResp>(`/oauth/${source}`, req)
export function socialLogin(req: any) {
return http.post<T.LoginResp>(`${BASE_URL}/login`, req)
}

/** @desc 三方账号登录授权 */
Expand Down
18 changes: 15 additions & 3 deletions src/apis/auth/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,34 @@ export interface RouteItem {
affix: boolean
}

/** 认证类型 */
export enum AuthTypeEnum {
ACCOUNT = 'account',
PHONE = 'phone',
EMAIL = 'email',
SOCIAL_AUTH = 'socialAuth',
}
export interface AuthReq {
clientId: string
authType: string
}

/** 账号登录请求参数 */
export interface AccountLoginReq {
export interface AccountLoginReq extends AuthReq {
username: string
password: string
captcha: string
uuid: string
}

/** 手机号登录请求参数 */
export interface PhoneLoginReq {
export interface PhoneLoginReq extends AuthReq {
phone: string
captcha: string
}

/** 邮箱登录请求参数 */
export interface EmailLoginReq {
export interface EmailLoginReq extends AuthReq {
email: string
captcha: string
}
Expand Down
77 changes: 77 additions & 0 deletions src/apis/system/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import http from '@/utils/http'

const BASE_URL = '/system/client'

export interface ClientResp {
id: string
clientId: string
clientKey: string
clientSecret: string
authType: string
clientType: string
activeTimeout: string
timeout: string
status: string
createUser: string
createTime: string
updateUser: string
updateTime: string
createUserString: string
updateUserString: string
}
export interface ClientDetailResp {
id: string
clientId: string
clientKey: string
clientSecret: string
authType: string
clientType: string
activeTimeout: string
timeout: string
status: string
createUser: string
createTime: string
updateUser: string
updateTime: string
createUserString: string
updateUserString: string
}
export interface ClientQuery {
clientKey: string
clientSecret: string
authType: string[]
clientType: string
status: string
sort: Array<string>
}
export interface ClientPageQuery extends ClientQuery, PageQuery {}

/** @desc 查询系统授权列表 */
export function listClient(query: ClientPageQuery) {
return http.get<PageRes<ClientResp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询系统授权详情 */
export function getClient(id: string) {
return http.get<ClientDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增系统授权 */
export function addClient(data: any) {
return http.post(`${BASE_URL}`, data)
}

/** @desc 修改系统授权 */
export function updateClient(data: any, id: string) {
return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除系统授权 */
export function deleteClient(id: string) {
return http.del(`${BASE_URL}/${id}`)
}

/** @desc 导出系统授权 */
export function exportClient(query: ClientQuery) {
return http.download(`${BASE_URL}/export`, query)
}
3 changes: 2 additions & 1 deletion src/stores/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { computed, reactive, ref } from 'vue'
import { resetRouter } from '@/router'
import {
type AccountLoginReq,
AuthTypeEnum,
type EmailLoginReq,
type PhoneLoginReq,
type UserInfo,
Expand Down Expand Up @@ -71,7 +72,7 @@ const storeSetup = () => {

// 三方账号登录
const socialLogin = async (source: string, req: any) => {
const res = await socialLoginApi(source, req)
const res = await socialLoginApi({ ...req, source, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.SOCIAL_AUTH })
setToken(res.data.token)
token.value = res.data.token
}
Expand Down
1 change: 0 additions & 1 deletion src/types/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ declare module 'vue' {
Chart: typeof import('./../components/Chart/index.vue')['default']
CronForm: typeof import('./../components/GenCron/CronForm/index.vue')['default']
CronModal: typeof import('./../components/GenCron/CronModal/index.vue')['default']
CronModel: typeof import('./../components/GenCron/CronModel/index.vue')['default']
DateRangePicker: typeof import('./../components/DateRangePicker/index.vue')['default']
DayForm: typeof import('./../components/GenCron/CronForm/component/day-form.vue')['default']
FilePreview: typeof import('./../components/FilePreview/index.vue')['default']
Expand Down
1 change: 1 addition & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface ImportMetaEnv {
readonly VITE_API_BASE_URL: string
readonly VITE_BASE: string
readonly VITE_APP_SETTING: string
readonly VITE_CLIENT_ID: string
}

interface ImportMeta {
Expand Down
5 changes: 5 additions & 0 deletions src/views/login/components/account/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { useStorage } from '@vueuse/core'
import { getImageCaptcha } from '@/apis/common'
import { useTabsStore, useUserStore } from '@/stores'
import { encryptByRsa } from '@/utils/encrypt'
import { AuthTypeEnum } from '@/apis'
const loginConfig = useStorage('login-config', {
rememberMe: true,
Expand Down Expand Up @@ -119,6 +120,8 @@ const handleLogin = async () => {
password: encryptByRsa(form.password) || '',
captcha: form.captcha,
uuid: form.uuid,
clientId: import.meta.env.VITE_CLIENT_ID,
authType: AuthTypeEnum.ACCOUNT,
})
tabsStore.reset()
const { redirect, ...othersQuery } = router.currentRoute.value.query
Expand All @@ -132,6 +135,8 @@ const handleLogin = async () => {
loginConfig.value.username = rememberMe ? form.username : ''
Message.success('欢迎使用')
} catch (error) {
console.log('error', error)
getCaptcha()
form.captcha = ''
} finally {
Expand Down
4 changes: 2 additions & 2 deletions src/views/login/components/email/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<script setup lang="ts">
import { type FormInstance, Message } from '@arco-design/web-vue'
import type { BehaviorCaptchaReq } from '@/apis'
import { AuthTypeEnum, type BehaviorCaptchaReq } from '@/apis'
// import { type BehaviorCaptchaReq, getEmailCaptcha } from '@/apis'
import { useTabsStore, useUserStore } from '@/stores'
import * as Regexp from '@/utils/regexp'
Expand Down Expand Up @@ -69,7 +69,7 @@ const handleLogin = async () => {
const isInvalid = await formRef.value?.validate()
if (isInvalid) return
loading.value = true
await userStore.emailLogin(form)
await userStore.emailLogin({ ...form, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.EMAIL })
tabsStore.reset()
const { redirect, ...othersQuery } = router.currentRoute.value.query
await router.push({
Expand Down
4 changes: 2 additions & 2 deletions src/views/login/components/phone/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<script setup lang="ts">
import { type FormInstance, Message } from '@arco-design/web-vue'
import type { BehaviorCaptchaReq } from '@/apis'
import { AuthTypeEnum, type BehaviorCaptchaReq } from '@/apis'
// import { type BehaviorCaptchaReq, getSmsCaptcha } from '@/apis'
import { useTabsStore, useUserStore } from '@/stores'
import * as Regexp from '@/utils/regexp'
Expand Down Expand Up @@ -69,7 +69,7 @@ const handleLogin = async () => {
if (isInvalid) return
try {
loading.value = true
await userStore.phoneLogin(form)
await userStore.phoneLogin({ ...form, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.PHONE })
tabsStore.reset()
const { redirect, ...othersQuery } = router.currentRoute.value.query
await router.push({
Expand Down
Loading

0 comments on commit bc3a5cf

Please sign in to comment.