Skip to content

Commit a56a2f6

Browse files
committed
REVIEW OAuth2 客户端
1 parent d50bbf0 commit a56a2f6

File tree

3 files changed

+48
-46
lines changed

3 files changed

+48
-46
lines changed

src/api/system/oauth2/client.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,27 @@ export interface OAuth2ClientVO {
2121
createTime: Date
2222
}
2323

24-
export interface OAuth2ClientPageReqVO extends PageParam {
25-
name?: string
26-
status?: number
27-
}
28-
// 查询 OAuth2列表
29-
export const getOAuth2ClientPageApi = (params: OAuth2ClientPageReqVO) => {
24+
// 查询 OAuth2 客户端的列表
25+
export const getOAuth2ClientPage = (params: PageParam) => {
3026
return request.get({ url: '/system/oauth2-client/page', params })
3127
}
3228

33-
// 查询 OAuth2详情
34-
export const getOAuth2ClientApi = (id: number) => {
29+
// 查询 OAuth2 客户端的详情
30+
export const getOAuth2Client = (id: number) => {
3531
return request.get({ url: '/system/oauth2-client/get?id=' + id })
3632
}
3733

38-
// 新增 OAuth2
39-
export const createOAuth2ClientApi = (data: OAuth2ClientVO) => {
34+
// 新增 OAuth2 客户端
35+
export const createOAuth2Client = (data: OAuth2ClientVO) => {
4036
return request.post({ url: '/system/oauth2-client/create', data })
4137
}
4238

43-
// 修改 OAuth2
44-
export const updateOAuth2ClientApi = (data: OAuth2ClientVO) => {
39+
// 修改 OAuth2 客户端
40+
export const updateOAuth2Client = (data: OAuth2ClientVO) => {
4541
return request.put({ url: '/system/oauth2-client/update', data })
4642
}
4743

4844
// 删除 OAuth2
49-
export const deleteOAuth2ClientApi = (id: number) => {
45+
export const deleteOAuth2Client = (id: number) => {
5046
return request.delete({ url: '/system/oauth2-client/delete?id=' + id })
5147
}

src/views/system/oauth2/client/form.vue renamed to src/views/system/oauth2/client/ClientForm.vue

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
2-
<Dialog :title="modelTitle" v-model="modelVisible" width="800">
2+
<Dialog :title="modelTitle" v-model="modelVisible" scroll max-height="500px">
33
<el-form
44
ref="formRef"
55
:model="formData"
66
:rules="formRules"
7-
label-width="120px"
7+
label-width="160px"
88
v-loading="formLoading"
99
>
1010
<el-form-item label="客户端编号" prop="secret">
@@ -17,19 +17,20 @@
1717
<el-input v-model="formData.name" placeholder="请输入应用名" />
1818
</el-form-item>
1919
<el-form-item label="应用图标">
20-
<imageUpload v-model="formData.logo" :limit="1" />
20+
<UploadImg v-model="formData.logo" :limit="1" />
2121
</el-form-item>
2222
<el-form-item label="应用描述">
2323
<el-input type="textarea" v-model="formData.description" placeholder="请输入应用名" />
2424
</el-form-item>
2525
<el-form-item label="状态" prop="status">
2626
<el-radio-group v-model="formData.status">
2727
<el-radio
28-
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
28+
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
2929
:key="dict.value"
30-
:label="parseInt(dict.value)"
31-
>{{ dict.label }}</el-radio
30+
:label="dict.value"
3231
>
32+
{{ dict.label }}
33+
</el-radio>
3334
</el-radio-group>
3435
</el-form-item>
3536
<el-form-item label="访问令牌的有效期" prop="accessTokenValiditySeconds">
@@ -47,7 +48,7 @@
4748
style="width: 500px"
4849
>
4950
<el-option
50-
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_OAUTH2_GRANT_TYPE)"
51+
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_OAUTH2_GRANT_TYPE)"
5152
:key="dict.value"
5253
:label="dict.label"
5354
:value="dict.value"
@@ -137,15 +138,14 @@
137138
</el-form-item>
138139
</el-form>
139140
<template #footer>
140-
<div class="dialog-footer">
141-
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
142-
<el-button @click="modelVisible = false">取 消</el-button>
143-
</div>
141+
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
142+
<el-button @click="modelVisible = false">取 消</el-button>
144143
</template>
145144
</Dialog>
146145
</template>
147146
<script setup lang="ts">
148-
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
147+
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
148+
import { CommonStatusEnum } from '@/utils/constants'
149149
import * as ClientApi from '@/api/system/oauth2/client'
150150
const { t } = useI18n() // 国际化
151151
const message = useMessage() // 消息弹窗
@@ -161,7 +161,7 @@ const formData = ref({
161161
name: undefined,
162162
logo: undefined,
163163
description: undefined,
164-
status: DICT_TYPE.COMMON_STATUS,
164+
status: CommonStatusEnum.ENABLE,
165165
accessTokenValiditySeconds: 30 * 60,
166166
refreshTokenValiditySeconds: 30 * 24 * 60,
167167
redirectUris: [],
@@ -190,7 +190,7 @@ const formRules = reactive({
190190
const formRef = ref() // 表单 Ref
191191
192192
/** 打开弹窗 */
193-
const openModal = async (type: string, id?: number) => {
193+
const open = async (type: string, id?: number) => {
194194
modelVisible.value = true
195195
modelTitle.value = t('action.' + type)
196196
formType.value = type
@@ -199,13 +199,13 @@ const openModal = async (type: string, id?: number) => {
199199
if (id) {
200200
formLoading.value = true
201201
try {
202-
formData.value = await ClientApi.getOAuth2ClientApi(id)
202+
formData.value = await ClientApi.getOAuth2Client(id)
203203
} finally {
204204
formLoading.value = false
205205
}
206206
}
207207
}
208-
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
208+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
209209
210210
/** 提交表单 */
211211
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
@@ -219,10 +219,10 @@ const submitForm = async () => {
219219
try {
220220
const data = formData.value as unknown as ClientApi.OAuth2ClientVO
221221
if (formType.value === 'create') {
222-
await ClientApi.createOAuth2ClientApi(data)
222+
await ClientApi.createOAuth2Client(data)
223223
message.success(t('common.createSuccess'))
224224
} else {
225-
await ClientApi.updateOAuth2ClientApi(data)
225+
await ClientApi.updateOAuth2Client(data)
226226
message.success(t('common.updateSuccess'))
227227
}
228228
modelVisible.value = false
@@ -242,7 +242,7 @@ const resetForm = () => {
242242
name: undefined,
243243
logo: undefined,
244244
description: undefined,
245-
status: DICT_TYPE.COMMON_STATUS,
245+
status: CommonStatusEnum.ENABLE,
246246
accessTokenValiditySeconds: 30 * 60,
247247
refreshTokenValiditySeconds: 30 * 24 * 60,
248248
redirectUris: [],

src/views/system/oauth2/client/index.vue

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
placeholder="请输入应用名"
1515
clearable
1616
@keyup.enter="handleQuery"
17+
class="!w-240px"
1718
/>
1819
</el-form-item>
1920
<el-form-item label="状态" prop="status">
20-
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
21+
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
2122
<el-option
22-
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
23+
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
2324
:key="dict.value"
2425
:label="dict.label"
2526
:value="dict.value"
@@ -29,7 +30,12 @@
2930
<el-form-item>
3031
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
3132
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
32-
<el-button type="primary" @click="openModal('create')" v-hasPermi="['infra:config:create']">
33+
<el-button
34+
plain
35+
type="primary"
36+
@click="openForm('create')"
37+
v-hasPermi="['system:oauth2-client:create']"
38+
>
3339
<Icon icon="ep:plus" class="mr-5px" /> 新增
3440
</el-button>
3541
</el-form-item>
@@ -82,16 +88,16 @@
8288
<el-button
8389
link
8490
type="primary"
85-
@click="openModal('update', scope.row.id)"
86-
v-hasPermi="['infra:config:update']"
91+
@click="openForm('update', scope.row.id)"
92+
v-hasPermi="['system:oauth2-client:update']"
8793
>
8894
编辑
8995
</el-button>
9096
<el-button
9197
link
9298
type="danger"
9399
@click="handleDelete(scope.row.id)"
94-
v-hasPermi="['infra:config:delete']"
100+
v-hasPermi="['system:oauth2-client:delete']"
95101
>
96102
删除
97103
</el-button>
@@ -108,13 +114,13 @@
108114
</content-wrap>
109115

110116
<!-- 表单弹窗:添加/修改 -->
111-
<ClientForm ref="modalRef" @success="getList" />
117+
<ClientForm ref="formRef" @success="getList" />
112118
</template>
113119
<script setup lang="ts">
114-
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
120+
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
115121
import { dateFormatter } from '@/utils/formatTime'
116122
import * as ClientApi from '@/api/system/oauth2/client'
117-
import ClientForm from './form.vue'
123+
import ClientForm from './ClientForm.vue'
118124
const message = useMessage() // 消息弹窗
119125
const { t } = useI18n() // 国际化
120126
@@ -133,7 +139,7 @@ const queryFormRef = ref() // 搜索的表单
133139
const getList = async () => {
134140
loading.value = true
135141
try {
136-
const data = await ClientApi.getOAuth2ClientPageApi(queryParams)
142+
const data = await ClientApi.getOAuth2ClientPage(queryParams)
137143
list.value = data.list
138144
total.value = data.total
139145
} finally {
@@ -154,9 +160,9 @@ const resetQuery = () => {
154160
}
155161
156162
/** 添加/修改操作 */
157-
const modalRef = ref()
158-
const openModal = (type: string, id?: number) => {
159-
modalRef.value.openModal(type, id)
163+
const formRef = ref()
164+
const openForm = (type: string, id?: number) => {
165+
formRef.value.open(type, id)
160166
}
161167
162168
/** 删除按钮操作 */
@@ -165,7 +171,7 @@ const handleDelete = async (id: number) => {
165171
// 删除的二次确认
166172
await message.delConfirm()
167173
// 发起删除
168-
await ClientApi.deleteOAuth2ClientApi(id)
174+
await ClientApi.deleteOAuth2Client(id)
169175
message.success(t('common.delSuccess'))
170176
// 刷新列表
171177
await getList()

0 commit comments

Comments
 (0)