Skip to content

Commit

Permalink
refactor: 优化认证及客户端相关代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Dec 27, 2024
1 parent f0dff8b commit 6ff3072
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ VITE_OPEN_DEVTOOLS = true
VITE_APP_SETTING = false

# 客户端ID
VITE_CLIENT_ID = '8ed5c8f9-555a-4961-ab66-9b87ddc4e3d0'
VITE_CLIENT_ID = 'ef51c9a3e9046c4f2ea45142c8a8344a'
2 changes: 1 addition & 1 deletion src/apis/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function socialLogin(req: any) {

/** @desc 三方账号登录授权 */
export function socialAuth(source: string) {
return http.get<T.SocialAuthAuthorizeResp>(`/oauth/${source}`)
return http.get<T.SocialAuthAuthorizeResp>(`${BASE_URL}/${source}`)
}

/** @desc 退出登录 */
Expand Down
4 changes: 2 additions & 2 deletions src/apis/auth/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export enum AuthTypeEnum {
SOCIAL = 'SOCIAL',
}
export interface AuthReq {
clientId: string
authType: string
clientId?: string
authType?: string
}

/** 账号登录请求参数 */
Expand Down
72 changes: 13 additions & 59 deletions src/apis/system/client.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,31 @@
import type * as T from './type'
import http from '@/utils/http'

const BASE_URL = '/system/client'
export type * from './type'

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 {}
const BASE_URL = '/system/client'

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

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

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

/** @desc 修改系统授权 */
/** @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)
/** @desc 删除客户端 */
export function deleteClient(ids: string | Array<string>) {
return http.del(`${BASE_URL}/${ids}`)
}
81 changes: 53 additions & 28 deletions src/apis/system/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** 系统用户类型 */
/** 用户类型 */
export interface UserResp {
id: string
username: string
Expand All @@ -20,11 +20,9 @@ export interface UserResp {
roleNames: Array<string>
disabled: boolean
}

export type UserDetailResp = UserResp & {
pwdResetTime?: string
}

export interface UserImportResp {
importKey: string
totalRows: number
Expand All @@ -33,7 +31,6 @@ export interface UserImportResp {
duplicateEmailRows: number
duplicatePhoneRows: number
}

export interface UserQuery {
description?: string
status?: number
Expand All @@ -42,10 +39,9 @@ export interface UserQuery {
sort: Array<string>
userIds?: Array<string>
}

export interface UserPageQuery extends UserQuery, PageQuery {}

/** 系统角色类型 */
/** 角色类型 */
export interface RoleResp {
id: string
name: string
Expand All @@ -60,22 +56,19 @@ export interface RoleResp {
updateTime: string
disabled: boolean
}

export type RoleDetailResp = RoleResp & {
menuIds: Array<number>
deptIds: Array<number>
menuCheckStrictly: boolean
deptCheckStrictly: boolean
}

export interface RoleQuery {
description?: string
sort: Array<string>
}

export interface RolePageQuery extends RoleQuery, PageQuery {}

/** 系统菜单类型 */
/** 菜单类型 */
export interface MenuResp {
id: string
title: string
Expand All @@ -98,13 +91,12 @@ export interface MenuResp {
updateTime: string
children: MenuResp[]
}

export interface MenuQuery {
title?: string
status?: number
}

/** 系统部门类型 */
/** 部门类型 */
export interface DeptResp {
id: string
name: string
Expand All @@ -119,13 +111,12 @@ export interface DeptResp {
parentId: string
children: DeptResp[]
}

export interface DeptQuery {
description?: string
status?: number
}

/** 系统字典类型 */
/** 字典类型 */
export interface DictResp {
id: string
name: string
Expand All @@ -137,12 +128,10 @@ export interface DictResp {
updateUserString: string
updateTime: string
}

export interface DictQuery {
description?: string
sort: Array<string>
}

export interface DictItemResp {
id: string
label: string
Expand All @@ -157,18 +146,16 @@ export interface DictItemResp {
updateUserString: string
updateTime: string
}

export interface DictItemQuery {
description?: string
status?: number
sort: Array<string>
dictId: string
}

export interface DictItemPageQuery extends DictItemQuery, PageQuery {
}

/** 系统公告类型 */
/** 公告类型 */
export interface NoticeResp {
id?: string
title?: string
Expand All @@ -184,17 +171,15 @@ export interface NoticeResp {
updateUserString?: string
updateTime?: string
}

export interface NoticeQuery {
title?: string
type?: string
sort: Array<string>
}

export interface NoticePageQuery extends NoticeQuery, PageQuery {
}

/** 系统文件类型 */
/** 文件类型 */
export interface FileItem {
id: string
name: string
Expand All @@ -211,7 +196,6 @@ export interface FileItem {
updateUserString: string
updateTime: string
}

/** 文件资源统计信息 */
export interface FileStatisticsResp {
type: string
Expand All @@ -220,17 +204,15 @@ export interface FileStatisticsResp {
unit: string
data: Array<FileStatisticsResp>
}

export interface FileQuery {
name?: string
type?: string
sort: Array<string>
}

export interface FilePageQuery extends FileQuery, PageQuery {
}

/** 系统存储类型 */
/** 存储类型 */
export interface StorageResp {
id: string
name: string
Expand All @@ -250,16 +232,59 @@ export interface StorageResp {
updateUserString: string
updateTime: string
}

export interface StorageQuery {
description?: string
status?: number
sort: Array<string>
}

export interface StoragePageQuery extends StorageQuery, PageQuery {
}

/** 客户端类型 */
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 {}

/** 系统参数类型 */
export interface OptionResp {
id: string
Expand Down
6 changes: 3 additions & 3 deletions src/stores/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ const storeSetup = () => {

// 登录
const accountLogin = async (req: AccountLoginReq) => {
const res = await accountLoginApi(req)
const res = await accountLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.ACCOUNT })
setToken(res.data.token)
token.value = res.data.token
}

// 邮箱登录
const emailLogin = async (req: EmailLoginReq) => {
const res = await emailLoginApi(req)
const res = await emailLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.EMAIL })
setToken(res.data.token)
token.value = res.data.token
}

// 手机号登录
const phoneLogin = async (req: PhoneLoginReq) => {
const res = await phoneLoginApi(req)
const res = await phoneLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.PHONE })
setToken(res.data.token)
token.value = res.data.token
}
Expand Down
3 changes: 0 additions & 3 deletions src/views/code/generator/GenConfigDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ const formColumns: Columns = reactive([
label: '作者名称',
field: 'author',
type: 'input',
props: {
placeholder: '请输入作者名称',
},
rules: [{ required: true, message: '请输入作者名称' }],
},
{
Expand Down
Loading

0 comments on commit 6ff3072

Please sign in to comment.