refactor: 优化认证及客户端相关代码

This commit is contained in:
2024-12-27 20:29:59 +08:00
parent f0dff8b753
commit 6ff307251f
17 changed files with 155 additions and 190 deletions

View File

@@ -19,4 +19,4 @@ VITE_OPEN_DEVTOOLS = true
VITE_APP_SETTING = false VITE_APP_SETTING = false
# 客户端ID # 客户端ID
VITE_CLIENT_ID = '8ed5c8f9-555a-4961-ab66-9b87ddc4e3d0' VITE_CLIENT_ID = 'ef51c9a3e9046c4f2ea45142c8a8344a'

View File

@@ -27,7 +27,7 @@ export function socialLogin(req: any) {
/** @desc 三方账号登录授权 */ /** @desc 三方账号登录授权 */
export function socialAuth(source: string) { export function socialAuth(source: string) {
return http.get<T.SocialAuthAuthorizeResp>(`/oauth/${source}`) return http.get<T.SocialAuthAuthorizeResp>(`${BASE_URL}/${source}`)
} }
/** @desc 退出登录 */ /** @desc 退出登录 */

View File

@@ -49,8 +49,8 @@ export enum AuthTypeEnum {
SOCIAL = 'SOCIAL', SOCIAL = 'SOCIAL',
} }
export interface AuthReq { export interface AuthReq {
clientId: string clientId?: string
authType: string authType?: string
} }
/** 账号登录请求参数 */ /** 账号登录请求参数 */

View File

@@ -1,77 +1,31 @@
import type * as T from './type'
import http from '@/utils/http' import http from '@/utils/http'
export type * from './type'
const BASE_URL = '/system/client' const BASE_URL = '/system/client'
export interface ClientResp { /** @desc 查询客户端列表 */
id: string export function listClient(query: T.ClientPageQuery) {
clientId: string return http.get<PageRes<T.ClientResp[]>>(`${BASE_URL}`, query)
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 查询系统授权详情 */ /** @desc 查询客户端详情 */
export function getClient(id: string) { 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) { export function addClient(data: any) {
return http.post(`${BASE_URL}`, data) return http.post(`${BASE_URL}`, data)
} }
/** @desc 修改系统授权 */ /** @desc 修改客户端 */
export function updateClient(data: any, id: string) { export function updateClient(data: any, id: string) {
return http.put(`${BASE_URL}/${id}`, data) return http.put(`${BASE_URL}/${id}`, data)
} }
/** @desc 删除系统授权 */ /** @desc 删除客户端 */
export function deleteClient(id: string) { export function deleteClient(ids: string | Array<string>) {
return http.del(`${BASE_URL}/${id}`) return http.del(`${BASE_URL}/${ids}`)
}
/** @desc 导出系统授权 */
export function exportClient(query: ClientQuery) {
return http.download(`${BASE_URL}/export`, query)
} }

View File

@@ -1,4 +1,4 @@
/** 系统用户类型 */ /** 用户类型 */
export interface UserResp { export interface UserResp {
id: string id: string
username: string username: string
@@ -20,11 +20,9 @@ export interface UserResp {
roleNames: Array<string> roleNames: Array<string>
disabled: boolean disabled: boolean
} }
export type UserDetailResp = UserResp & { export type UserDetailResp = UserResp & {
pwdResetTime?: string pwdResetTime?: string
} }
export interface UserImportResp { export interface UserImportResp {
importKey: string importKey: string
totalRows: number totalRows: number
@@ -33,7 +31,6 @@ export interface UserImportResp {
duplicateEmailRows: number duplicateEmailRows: number
duplicatePhoneRows: number duplicatePhoneRows: number
} }
export interface UserQuery { export interface UserQuery {
description?: string description?: string
status?: number status?: number
@@ -42,10 +39,9 @@ export interface UserQuery {
sort: Array<string> sort: Array<string>
userIds?: Array<string> userIds?: Array<string>
} }
export interface UserPageQuery extends UserQuery, PageQuery {} export interface UserPageQuery extends UserQuery, PageQuery {}
/** 系统角色类型 */ /** 角色类型 */
export interface RoleResp { export interface RoleResp {
id: string id: string
name: string name: string
@@ -60,22 +56,19 @@ export interface RoleResp {
updateTime: string updateTime: string
disabled: boolean disabled: boolean
} }
export type RoleDetailResp = RoleResp & { export type RoleDetailResp = RoleResp & {
menuIds: Array<number> menuIds: Array<number>
deptIds: Array<number> deptIds: Array<number>
menuCheckStrictly: boolean menuCheckStrictly: boolean
deptCheckStrictly: boolean deptCheckStrictly: boolean
} }
export interface RoleQuery { export interface RoleQuery {
description?: string description?: string
sort: Array<string> sort: Array<string>
} }
export interface RolePageQuery extends RoleQuery, PageQuery {} export interface RolePageQuery extends RoleQuery, PageQuery {}
/** 系统菜单类型 */ /** 菜单类型 */
export interface MenuResp { export interface MenuResp {
id: string id: string
title: string title: string
@@ -98,13 +91,12 @@ export interface MenuResp {
updateTime: string updateTime: string
children: MenuResp[] children: MenuResp[]
} }
export interface MenuQuery { export interface MenuQuery {
title?: string title?: string
status?: number status?: number
} }
/** 系统部门类型 */ /** 部门类型 */
export interface DeptResp { export interface DeptResp {
id: string id: string
name: string name: string
@@ -119,13 +111,12 @@ export interface DeptResp {
parentId: string parentId: string
children: DeptResp[] children: DeptResp[]
} }
export interface DeptQuery { export interface DeptQuery {
description?: string description?: string
status?: number status?: number
} }
/** 系统字典类型 */ /** 字典类型 */
export interface DictResp { export interface DictResp {
id: string id: string
name: string name: string
@@ -137,12 +128,10 @@ export interface DictResp {
updateUserString: string updateUserString: string
updateTime: string updateTime: string
} }
export interface DictQuery { export interface DictQuery {
description?: string description?: string
sort: Array<string> sort: Array<string>
} }
export interface DictItemResp { export interface DictItemResp {
id: string id: string
label: string label: string
@@ -157,18 +146,16 @@ export interface DictItemResp {
updateUserString: string updateUserString: string
updateTime: string updateTime: string
} }
export interface DictItemQuery { export interface DictItemQuery {
description?: string description?: string
status?: number status?: number
sort: Array<string> sort: Array<string>
dictId: string dictId: string
} }
export interface DictItemPageQuery extends DictItemQuery, PageQuery { export interface DictItemPageQuery extends DictItemQuery, PageQuery {
} }
/** 系统公告类型 */ /** 公告类型 */
export interface NoticeResp { export interface NoticeResp {
id?: string id?: string
title?: string title?: string
@@ -184,17 +171,15 @@ export interface NoticeResp {
updateUserString?: string updateUserString?: string
updateTime?: string updateTime?: string
} }
export interface NoticeQuery { export interface NoticeQuery {
title?: string title?: string
type?: string type?: string
sort: Array<string> sort: Array<string>
} }
export interface NoticePageQuery extends NoticeQuery, PageQuery { export interface NoticePageQuery extends NoticeQuery, PageQuery {
} }
/** 系统文件类型 */ /** 文件类型 */
export interface FileItem { export interface FileItem {
id: string id: string
name: string name: string
@@ -211,7 +196,6 @@ export interface FileItem {
updateUserString: string updateUserString: string
updateTime: string updateTime: string
} }
/** 文件资源统计信息 */ /** 文件资源统计信息 */
export interface FileStatisticsResp { export interface FileStatisticsResp {
type: string type: string
@@ -220,17 +204,15 @@ export interface FileStatisticsResp {
unit: string unit: string
data: Array<FileStatisticsResp> data: Array<FileStatisticsResp>
} }
export interface FileQuery { export interface FileQuery {
name?: string name?: string
type?: string type?: string
sort: Array<string> sort: Array<string>
} }
export interface FilePageQuery extends FileQuery, PageQuery { export interface FilePageQuery extends FileQuery, PageQuery {
} }
/** 系统存储类型 */ /** 存储类型 */
export interface StorageResp { export interface StorageResp {
id: string id: string
name: string name: string
@@ -250,16 +232,59 @@ export interface StorageResp {
updateUserString: string updateUserString: string
updateTime: string updateTime: string
} }
export interface StorageQuery { export interface StorageQuery {
description?: string description?: string
status?: number status?: number
sort: Array<string> sort: Array<string>
} }
export interface StoragePageQuery extends StorageQuery, PageQuery { 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 { export interface OptionResp {
id: string id: string

View File

@@ -51,21 +51,21 @@ const storeSetup = () => {
// 登录 // 登录
const accountLogin = async (req: AccountLoginReq) => { 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) setToken(res.data.token)
token.value = res.data.token token.value = res.data.token
} }
// 邮箱登录 // 邮箱登录
const emailLogin = async (req: EmailLoginReq) => { 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) setToken(res.data.token)
token.value = res.data.token token.value = res.data.token
} }
// 手机号登录 // 手机号登录
const phoneLogin = async (req: PhoneLoginReq) => { 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) setToken(res.data.token)
token.value = res.data.token token.value = res.data.token
} }

View File

@@ -154,9 +154,6 @@ const formColumns: Columns = reactive([
label: '作者名称', label: '作者名称',
field: 'author', field: 'author',
type: 'input', type: 'input',
props: {
placeholder: '请输入作者名称',
},
rules: [{ required: true, message: '请输入作者名称' }], rules: [{ required: true, message: '请输入作者名称' }],
}, },
{ {

View File

@@ -43,7 +43,6 @@ import { useStorage } from '@vueuse/core'
import { getImageCaptcha } from '@/apis/common' import { getImageCaptcha } from '@/apis/common'
import { useTabsStore, useUserStore } from '@/stores' import { useTabsStore, useUserStore } from '@/stores'
import { encryptByRsa } from '@/utils/encrypt' import { encryptByRsa } from '@/utils/encrypt'
import { AuthTypeEnum } from '@/apis'
const loginConfig = useStorage('login-config', { const loginConfig = useStorage('login-config', {
rememberMe: true, rememberMe: true,
@@ -120,8 +119,6 @@ const handleLogin = async () => {
password: encryptByRsa(form.password) || '', password: encryptByRsa(form.password) || '',
captcha: form.captcha, captcha: form.captcha,
uuid: form.uuid, uuid: form.uuid,
clientId: import.meta.env.VITE_CLIENT_ID,
authType: AuthTypeEnum.ACCOUNT,
}) })
tabsStore.reset() tabsStore.reset()
const { redirect, ...othersQuery } = router.currentRoute.value.query const { redirect, ...othersQuery } = router.currentRoute.value.query
@@ -135,8 +132,7 @@ const handleLogin = async () => {
loginConfig.value.username = rememberMe ? form.username : '' loginConfig.value.username = rememberMe ? form.username : ''
Message.success('欢迎使用') Message.success('欢迎使用')
} catch (error) { } catch (error) {
console.log('error', error) console.error(error)
getCaptcha() getCaptcha()
form.captcha = '' form.captcha = ''
} finally { } finally {

View File

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

View File

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

View File

@@ -68,7 +68,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { type LogDetailResp, getLog as getData } from '@/apis/monitor' import { type LogDetailResp, getLog as getDetail } from '@/apis/monitor'
const dataId = ref('') const dataId = ref('')
const dataDetail = ref<LogDetailResp>() const dataDetail = ref<LogDetailResp>()
@@ -76,7 +76,7 @@ const visible = ref(false)
// 查询详情 // 查询详情
const getDataDetail = async () => { const getDataDetail = async () => {
const { data } = await getData(dataId.value) const { data } = await getDetail(dataId.value)
dataDetail.value = data dataDetail.value = data
} }

View File

@@ -17,7 +17,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useWindowSize } from '@vueuse/core' import { useWindowSize } from '@vueuse/core'
import { type AppResp, getApp as getData } from '@/apis/open/app' import { type AppResp, getApp as getDetail } from '@/apis/open/app'
const { width } = useWindowSize() const { width } = useWindowSize()
@@ -27,7 +27,7 @@ const visible = ref(false)
// 查询详情 // 查询详情
const getDataDetail = async () => { const getDataDetail = async () => {
const { data } = await getData(dataId.value) const { data } = await getDetail(dataId.value)
dataDetail.value = data dataDetail.value = data
} }

View File

@@ -4,8 +4,8 @@
:title="title" :title="title"
:mask-closable="false" :mask-closable="false"
:esc-to-close="false" :esc-to-close="false"
draggable
:width="width >= 600 ? 600 : '100%'" :width="width >= 600 ? 600 : '100%'"
draggable
@before-ok="save" @before-ok="save"
@close="reset" @close="reset"
> >
@@ -19,6 +19,7 @@ import { useWindowSize } from '@vueuse/core'
import CryptoJS from 'crypto-js' import CryptoJS from 'crypto-js'
import { addClient, getClient, updateClient } from '@/apis/system/client' import { addClient, getClient, updateClient } from '@/apis/system/client'
import { type Columns, GiForm, type Options } from '@/components/GiForm' import { type Columns, GiForm, type Options } from '@/components/GiForm'
import { DisEnableStatusList } from '@/constant/common'
import { useResetReactive } from '@/hooks' import { useResetReactive } from '@/hooks'
import { useDict } from '@/hooks/app' import { useDict } from '@/hooks/app'
@@ -31,15 +32,14 @@ const { width } = useWindowSize()
const dataId = ref('') const dataId = ref('')
const visible = ref(false) const visible = ref(false)
const isUpdate = computed(() => !!dataId.value) const isUpdate = computed(() => !!dataId.value)
const title = computed(() => (isUpdate.value ? '修改客户端管理' : '新增客户端管理')) const title = computed(() => (isUpdate.value ? '修改客户端' : '新增客户端'))
const formRef = ref<InstanceType<typeof GiForm>>() const formRef = ref<InstanceType<typeof GiForm>>()
const { auth_type_enum, client_type, dis_enable_status_enum } = useDict('auth_type_enum', 'client_type', 'dis_enable_status_enum') const { client_type, auth_type_enum } = useDict('auth_type_enum', 'client_type')
const options: Options = { const options: Options = {
form: { layout: 'vertical' }, form: { size: 'large', layout: 'vertical' },
btns: { hide: true }, btns: { hide: true },
grid: { cols: 2 }, grid: { cols: 2 },
} }
const [form, resetForm] = useResetReactive({ const [form, resetForm] = useResetReactive({
@@ -53,12 +53,13 @@ const handleGenerate = () => {
const timestamp = Date.now() const timestamp = Date.now()
form.clientSecret = CryptoJS.MD5(`${timestamp}`).toString(CryptoJS.enc.Hex) form.clientSecret = CryptoJS.MD5(`${timestamp}`).toString(CryptoJS.enc.Hex)
} }
const columns: Columns = reactive([ const columns: Columns = reactive([
{ {
label: '客户端Key', label: '客户端 Key',
field: 'clientKey', field: 'clientKey',
type: 'input', type: 'input',
rules: [{ required: true, message: '请输入客户端Key' }], rules: [{ required: true, message: '请输入客户端 Key' }],
span: 2, span: 2,
disabled: () => { disabled: () => {
return isUpdate.value return isUpdate.value
@@ -91,48 +92,54 @@ const columns: Columns = reactive([
options: auth_type_enum, options: auth_type_enum,
props: { props: {
multiple: true, multiple: true,
maxTagCount: 2,
}, },
rules: [{ required: true, message: '请输入认证类型' }], rules: [{ required: true, message: '请选择认证类型' }],
}, },
{ {
label: '客户端类型', label: '客户端类型',
field: 'clientType', field: 'clientType',
type: 'select', type: 'select',
options: client_type, options: client_type,
rules: [{ required: true, message: '请输入客户端类型' }], rules: [{ required: true, message: '请选择客户端类型' }],
}, },
{ {
label: () => ( label: () => (
<a-tooltip content="-1 代表不限制,永不冻结"> <a-tooltip content="-1 代表不限制,永不冻结">
Token最低活跃频率 Token 最低活跃频率
<icon-info-circle-fill /> <icon-info-circle-fill />
</a-tooltip> </a-tooltip>
), ),
field: 'activeTimeout', field: 'activeTimeout',
type: 'input-number', type: 'input-number',
rules: [{ required: true, message: 'Token最低活跃频率不能为空' }],
slots: { slots: {
append: () => ( append: () => (
<span style={{ width: '30px', textAlign: 'center' }}></span> <span style={{ width: '30px', textAlign: 'center' }}></span>
), ),
}, },
props: {
placeholder: '请输入 Token 最低活跃频率',
},
rules: [{ required: true, message: '请输入 Token 最低活跃频率' }],
}, },
{ {
label: () => ( label: () => (
<a-tooltip content="-1 代表永不过期"> <a-tooltip content="-1 代表永不过期">
Token有效期 Token 有效期
<icon-info-circle-fill /> <icon-info-circle-fill />
</a-tooltip> </a-tooltip>
), ),
field: 'timeout', field: 'timeout',
type: 'input-number', type: 'input-number',
rules: [{ required: true, message: 'Token有效期不能为空' }],
slots: { slots: {
append: () => ( append: () => (
<span style={{ width: '30px', textAlign: 'center' }}></span> <span style={{ width: '30px', textAlign: 'center' }}></span>
), ),
}, },
props: {
placeholder: '请输入 Token 有效期',
},
rules: [{ required: true, message: '请输入 Token 有效期' }],
}, },
{ {
label: '状态', label: '状态',
@@ -140,7 +147,7 @@ const columns: Columns = reactive([
type: 'radio-group', type: 'radio-group',
props: { props: {
type: 'button', type: 'button',
options: dis_enable_status_enum, options: DisEnableStatusList,
}, },
rules: [{ required: true, message: '请选择状态' }], rules: [{ required: true, message: '请选择状态' }],
}, },

View File

@@ -1,8 +1,8 @@
<template> <template>
<a-drawer v-model:visible="visible" title="客户端管理详情" :width="width >= 600 ? 600 : '100%'" :footer="false"> <a-drawer v-model:visible="visible" title="客户端详情" :width="width >= 600 ? 600 : '100%'" :footer="false">
<a-descriptions :column="1" size="large" class="general-description"> <a-descriptions :column="1" size="large" class="general-description">
<a-descriptions-item label="ID">{{ dataDetail?.id }}</a-descriptions-item> <a-descriptions-item label="ID">{{ dataDetail?.id }}</a-descriptions-item>
<a-descriptions-item label="客户端ID">{{ dataDetail?.clientId }}</a-descriptions-item> <a-descriptions-item label="客户端ID"><a-typography-paragraph :copyable="!!dataDetail?.clientId">{{ dataDetail?.clientId }}</a-typography-paragraph></a-descriptions-item>
<a-descriptions-item label="客户端Key">{{ dataDetail?.clientKey }}</a-descriptions-item> <a-descriptions-item label="客户端Key">{{ dataDetail?.clientKey }}</a-descriptions-item>
<a-descriptions-item label="客户端秘钥">{{ dataDetail?.clientSecret }}</a-descriptions-item> <a-descriptions-item label="客户端秘钥">{{ dataDetail?.clientSecret }}</a-descriptions-item>
<a-descriptions-item label="认证类型"> <a-descriptions-item label="认证类型">
@@ -16,7 +16,7 @@
<a-descriptions-item label="Token最低活跃频率">{{ dataDetail?.activeTimeout }}</a-descriptions-item> <a-descriptions-item label="Token最低活跃频率">{{ dataDetail?.activeTimeout }}</a-descriptions-item>
<a-descriptions-item label="Token有效期">{{ dataDetail?.timeout }}</a-descriptions-item> <a-descriptions-item label="Token有效期">{{ dataDetail?.timeout }}</a-descriptions-item>
<a-descriptions-item label="状态"> <a-descriptions-item label="状态">
<GiCellTag :value="dataDetail?.status" :dict="dis_enable_status_enum" /> <GiCellStatus :status="dataDetail?.status" />
</a-descriptions-item> </a-descriptions-item>
<a-descriptions-item label="创建人">{{ dataDetail?.createUserString }}</a-descriptions-item> <a-descriptions-item label="创建人">{{ dataDetail?.createUserString }}</a-descriptions-item>
<a-descriptions-item label="创建时间">{{ dataDetail?.createTime }}</a-descriptions-item> <a-descriptions-item label="创建时间">{{ dataDetail?.createTime }}</a-descriptions-item>
@@ -30,13 +30,11 @@
import { useWindowSize } from '@vueuse/core' import { useWindowSize } from '@vueuse/core'
import { type ClientDetailResp, getClient as getDetail } from '@/apis/system/client' import { type ClientDetailResp, getClient as getDetail } from '@/apis/system/client'
import { useDict } from '@/hooks/app' import { useDict } from '@/hooks/app'
import GiCellTag from '@/components/GiCell/GiCellTag.vue'
const { const {
auth_type_enum,
client_type, client_type,
dis_enable_status_enum, auth_type_enum,
} = useDict('auth_type_enum', 'client_type', 'dis_enable_status_enum') } = useDict('client_type', 'auth_type_enum')
const { width } = useWindowSize() const { width } = useWindowSize()

View File

@@ -6,60 +6,38 @@
:data="dataList" :data="dataList"
:columns="columns" :columns="columns"
:loading="loading" :loading="loading"
:scroll="{ x: '100%', y: '100%', minWidth: 1000 }" :scroll="{ x: '100%', y: '100%', minWidth: 1500 }"
:pagination="pagination" :pagination="pagination"
:disabled-tools="['size']" :disabled-tools="['size']"
:disabled-column-keys="['name']" :disabled-column-keys="['clientKey']"
@refresh="search" @refresh="search"
> >
<template #toolbar-left> <template #toolbar-left>
<a-input v-model="queryForm.clientKey" placeholder="请输入客户端Key" allow-clear @change="search"> <a-input-search v-model="queryForm.clientKey" placeholder="搜索客户端Key" allow-clear @search="search" />
<template #prefix> <a-input-search v-model="queryForm.clientSecret" placeholder="搜索客户端秘钥" allow-clear @search="search" />
<icon-search />
</template>
</a-input>
<a-input v-model="queryForm.clientSecret" placeholder="请输入客户端秘钥" allow-clear @change="search">
<template #prefix>
<icon-search />
</template>
</a-input>
<a-select <a-select
v-model="queryForm.clientType" v-model="queryForm.clientType"
:options="client_type" :options="client_type"
placeholder="请选择客户端类型" placeholder="请选择客户端类型"
allow-clear allow-clear
style="width: 150px" style="width: 160px"
@change="search" @change="search"
/> />
<a-select <a-select
v-model="queryForm.status" :options="dis_enable_status_enum" placeholder="请选择状态" allow-clear v-model="queryForm.status" :options="DisEnableStatusList" placeholder="请选择状态" allow-clear
style="width: 150px" style="width: 150px"
@change="search" @change="search"
> />
<template #prefix>
<icon-search />
</template>
</a-select>
<a-button @click="reset"> <a-button @click="reset">
<template #icon> <template #icon><icon-refresh /></template>
<icon-refresh />
</template>
<template #default>重置</template> <template #default>重置</template>
</a-button> </a-button>
</template> </template>
<template #toolbar-right> <template #toolbar-right>
<a-button v-permission="['system:client:add']" type="primary" @click="onAdd"> <a-button v-permission="['system:client:add']" type="primary" @click="onAdd">
<template #icon> <template #icon><icon-plus /></template>
<icon-plus />
</template>
<template #default>新增</template> <template #default>新增</template>
</a-button> </a-button>
<a-button v-permission="['system:client:export']" @click="onExport">
<template #icon>
<icon-download />
</template>
<template #default>导出</template>
</a-button>
</template> </template>
<template #action="{ record }"> <template #action="{ record }">
<a-space> <a-space>
@@ -87,22 +65,24 @@
import type { LabelValue } from '@arco-design/web-vue/es/tree-select/interface' import type { LabelValue } from '@arco-design/web-vue/es/tree-select/interface'
import ClientAddModal from './ClientAddModal.vue' import ClientAddModal from './ClientAddModal.vue'
import ClientDetailDrawer from './ClientDetailDrawer.vue' import ClientDetailDrawer from './ClientDetailDrawer.vue'
import { type ClientQuery, type ClientResp, deleteClient, exportClient, listClient } from '@/apis/system/client' import { type ClientQuery, type ClientResp, deleteClient, listClient } from '@/apis/system/client'
import type { TableInstanceColumns } from '@/components/GiTable/type' import type { TableInstanceColumns } from '@/components/GiTable/type'
import { useDownload, useTable } from '@/hooks' import { DisEnableStatusList } from '@/constant/common'
import { useTable } from '@/hooks'
import { useDict } from '@/hooks/app' import { useDict } from '@/hooks/app'
import { isMobile } from '@/utils' import { isMobile } from '@/utils'
import has from '@/utils/has' import has from '@/utils/has'
import CellCopy from '@/components/CellCopy/index.vue'
import GiCellTag from '@/components/GiCell/GiCellTag.vue' import GiCellTag from '@/components/GiCell/GiCellTag.vue'
import GiCellTags from '@/components/GiCell/GiCellTags.vue' import GiCellTags from '@/components/GiCell/GiCellTags.vue'
import GiCellStatus from '@/components/GiCell/GiCellStatus.vue'
defineOptions({ name: 'Client' }) defineOptions({ name: 'SystemClient' })
const { const {
auth_type_enum,
client_type, client_type,
dis_enable_status_enum, auth_type_enum,
} = useDict('auth_type_enum', 'client_type', 'dis_enable_status_enum') } = useDict('client_type', 'auth_type_enum')
const queryForm = reactive<ClientQuery>({ const queryForm = reactive<ClientQuery>({
clientKey: '', clientKey: '',
@@ -117,6 +97,7 @@ const formatAuthType = (data: string[]) => {
return auth_type_enum.value.find((d: LabelValue) => d.value === item).label return auth_type_enum.value.find((d: LabelValue) => d.value === item).label
}) })
} }
const { const {
tableData: dataList, tableData: dataList,
loading, loading,
@@ -125,8 +106,26 @@ const {
handleDelete, handleDelete,
} = useTable((page) => listClient({ ...queryForm, ...page }), { immediate: true }) } = useTable((page) => listClient({ ...queryForm, ...page }), { immediate: true })
const columns: TableInstanceColumns[] = [ const columns: TableInstanceColumns[] = [
{ title: '客户端ID', dataIndex: 'clientId', slotName: 'clientId', ellipsis: true, tooltip: true }, {
{ title: '客户端Key', dataIndex: 'clientKey', slotName: 'clientKey', ellipsis: true, tooltip: true, align: 'center' }, title: '序号',
width: 66,
align: 'center',
render: ({ rowIndex }) => h('span', {}, rowIndex + 1 + (pagination.current - 1) * pagination.pageSize),
fixed: !isMobile() ? 'left' : undefined,
},
{
title: '客户端 ID',
dataIndex: 'clientId',
slotName: 'clientId',
ellipsis: true,
tooltip: true,
render: ({ record }) => {
return (
<CellCopy content={record.clientId} />
)
},
},
{ title: '客户端 Key', dataIndex: 'clientKey', slotName: 'clientKey', ellipsis: true, tooltip: true, align: 'center' },
{ title: '客户端秘钥', dataIndex: 'clientSecret', slotName: 'clientSecret', ellipsis: true, tooltip: true, align: 'center' }, { title: '客户端秘钥', dataIndex: 'clientSecret', slotName: 'clientSecret', ellipsis: true, tooltip: true, align: 'center' },
{ {
title: '认证类型', title: '认证类型',
@@ -152,18 +151,21 @@ const columns: TableInstanceColumns[] = [
return <GiCellTag value={record.clientType} dict={client_type.value} /> return <GiCellTag value={record.clientType} dict={client_type.value} />
}, },
}, },
{ title: 'Token最低活跃频率', dataIndex: 'activeTimeout', slotName: 'activeTimeout', align: 'center' }, { title: 'Token 最低活跃频率', dataIndex: 'activeTimeout', slotName: 'activeTimeout', width: 180, align: 'center', render: ({ record }) => `${record.activeTimeout} s` },
{ title: 'Token有效期', dataIndex: 'timeout', slotName: 'timeout', align: 'center' }, { title: 'Token 有效期', dataIndex: 'timeout', slotName: 'timeout', align: 'center', render: ({ record }) => `${record.timeout} s` },
{ {
title: '状态', title: '状态',
dataIndex: 'status', dataIndex: 'status',
slotName: 'status', slotName: 'status',
align: 'center', align: 'center',
render: ({ record }) => { render: ({ record }) => {
return <GiCellTag value={record.status} dict={dis_enable_status_enum.value} /> return <GiCellStatus status={record.status} />
}, },
}, },
{ title: '创建时间', dataIndex: 'createTime', slotName: 'createTime' }, { title: '创建', dataIndex: 'createUserString', width: 140, ellipsis: true, tooltip: true, show: false },
{ title: '创建时间', dataIndex: 'createTime', width: 180 },
{ title: '修改人', dataIndex: 'updateUserString', width: 140, ellipsis: true, tooltip: true, show: false },
{ title: '修改时间', dataIndex: 'updateTime', width: 180, show: false },
{ {
title: '操作', title: '操作',
dataIndex: 'action', dataIndex: 'action',
@@ -188,16 +190,11 @@ const reset = () => {
// 删除 // 删除
const onDelete = (record: ClientResp) => { const onDelete = (record: ClientResp) => {
return handleDelete(() => deleteClient(record.id), { return handleDelete(() => deleteClient(record.id), {
content: `是否确定删除该条数据`, content: `是否确定删除客户端「${record.clientKey}(${record.clientId})」`,
showModal: true, showModal: true,
}) })
} }
// 导出
const onExport = () => {
useDownload(() => exportClient(queryForm))
}
const ClientAddModalRef = ref<InstanceType<typeof ClientAddModal>>() const ClientAddModalRef = ref<InstanceType<typeof ClientAddModal>>()
// 新增 // 新增
const onAdd = () => { const onAdd = () => {

View File

@@ -53,7 +53,6 @@ const columns: Columns = reactive([
field: 'username', field: 'username',
type: 'input', type: 'input',
props: { props: {
placeholder: '请输入用户名',
maxLength: 64, maxLength: 64,
showWordLimit: true, showWordLimit: true,
}, },
@@ -64,7 +63,6 @@ const columns: Columns = reactive([
field: 'nickname', field: 'nickname',
type: 'input', type: 'input',
props: { props: {
placeholder: '请输入昵称',
maxLength: 30, maxLength: 30,
showWordLimit: true, showWordLimit: true,
}, },
@@ -75,7 +73,6 @@ const columns: Columns = reactive([
field: 'password', field: 'password',
type: 'input-password', type: 'input-password',
props: { props: {
placeholder: '请输入密码',
maxLength: 32, maxLength: 32,
showWordLimit: true, showWordLimit: true,
}, },
@@ -89,7 +86,6 @@ const columns: Columns = reactive([
field: 'phone', field: 'phone',
type: 'input', type: 'input',
props: { props: {
placeholder: '请输入手机号码',
maxLength: 11, maxLength: 11,
}, },
}, },
@@ -98,7 +94,6 @@ const columns: Columns = reactive([
field: 'email', field: 'email',
type: 'input', type: 'input',
props: { props: {
placeholder: '请输入邮箱',
maxLength: 255, maxLength: 255,
}, },
}, },
@@ -114,7 +109,6 @@ const columns: Columns = reactive([
type: 'tree-select', type: 'tree-select',
data: deptList, data: deptList,
props: { props: {
placeholder: '请选择所属部门',
allowClear: true, allowClear: true,
allowSearch: true, allowSearch: true,
fallbackOption: false, fallbackOption: false,
@@ -133,7 +127,6 @@ const columns: Columns = reactive([
type: 'select', type: 'select',
options: roleList, options: roleList,
props: { props: {
placeholder: '请选择角色',
multiple: true, multiple: true,
allowClear: true, allowClear: true,
allowSearch: true, allowSearch: true,
@@ -145,7 +138,6 @@ const columns: Columns = reactive([
field: 'description', field: 'description',
type: 'textarea', type: 'textarea',
props: { props: {
placeholder: '请输入描述',
maxLength: 200, maxLength: 200,
showWordLimit: true, showWordLimit: true,
autoSize: { minRows: 3, maxRows: 5 }, autoSize: { minRows: 3, maxRows: 5 },

View File

@@ -48,7 +48,6 @@ const columns: Columns = reactive([
multiple: true, multiple: true,
allowClear: true, allowClear: true,
allowSearch: { retainInputValue: true }, allowSearch: { retainInputValue: true },
placeholder: '请选择角色',
}, },
rules: [{ required: true, message: '请选择角色' }], rules: [{ required: true, message: '请选择角色' }],
}, },