mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	refactor: oauth2 vxe
This commit is contained in:
		| @@ -1,5 +1,24 @@ | |||||||
| import request from '@/config/axios' | import request from '@/config/axios' | ||||||
| import { OAuth2ClientVo } from './client.types' | export interface OAuth2ClientVO { | ||||||
|  |   id: number | ||||||
|  |   clientId: string | ||||||
|  |   secret: string | ||||||
|  |   name: string | ||||||
|  |   logo: string | ||||||
|  |   description: string | ||||||
|  |   status: number | ||||||
|  |   accessTokenValiditySeconds: number | ||||||
|  |   refreshTokenValiditySeconds: number | ||||||
|  |   redirectUris: string[] | ||||||
|  |   autoApprove: boolean | ||||||
|  |   authorizedGrantTypes: string[] | ||||||
|  |   scopes: string[] | ||||||
|  |   authorities: string[] | ||||||
|  |   resourceIds: string[] | ||||||
|  |   additionalInformation: string | ||||||
|  |   isAdditionalInformationJson: boolean | ||||||
|  |   createTime: string | ||||||
|  | } | ||||||
|  |  | ||||||
| // 查询 OAuth2列表 | // 查询 OAuth2列表 | ||||||
| export const getOAuth2ClientPageApi = (params) => { | export const getOAuth2ClientPageApi = (params) => { | ||||||
| @@ -12,12 +31,12 @@ export const getOAuth2ClientApi = (id: number) => { | |||||||
| } | } | ||||||
|  |  | ||||||
| // 新增 OAuth2 | // 新增 OAuth2 | ||||||
| export const createOAuth2ClientApi = (data: OAuth2ClientVo) => { | export const createOAuth2ClientApi = (data: OAuth2ClientVO) => { | ||||||
|   return request.post({ url: '/system/oauth2-client/create', data }) |   return request.post({ url: '/system/oauth2-client/create', data }) | ||||||
| } | } | ||||||
|  |  | ||||||
| // 修改 OAuth2 | // 修改 OAuth2 | ||||||
| export const updateOAuth2ClientApi = (data: OAuth2ClientVo) => { | export const updateOAuth2ClientApi = (data: OAuth2ClientVO) => { | ||||||
|   return request.put({ url: '/system/oauth2-client/update', data }) |   return request.put({ url: '/system/oauth2-client/update', data }) | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,20 +0,0 @@ | |||||||
| export type OAuth2ClientVo = { |  | ||||||
|   id: number |  | ||||||
|   clientId: string |  | ||||||
|   secret: string |  | ||||||
|   name: string |  | ||||||
|   logo: string |  | ||||||
|   description: string |  | ||||||
|   status: number |  | ||||||
|   accessTokenValiditySeconds: number |  | ||||||
|   refreshTokenValiditySeconds: number |  | ||||||
|   redirectUris: string[] |  | ||||||
|   autoApprove: boolean |  | ||||||
|   authorizedGrantTypes: string[] |  | ||||||
|   scopes: string[] |  | ||||||
|   authorities: string[] |  | ||||||
|   resourceIds: string[] |  | ||||||
|   additionalInformation: string |  | ||||||
|   isAdditionalInformationJson: boolean |  | ||||||
|   createTime: string |  | ||||||
| } |  | ||||||
| @@ -1,7 +1,24 @@ | |||||||
| import request from '@/config/axios' | import request from '@/config/axios' | ||||||
|  |  | ||||||
|  | export interface OAuth2TokenVO { | ||||||
|  |   id: number | ||||||
|  |   accessToken: string | ||||||
|  |   refreshToken: string | ||||||
|  |   userId: number | ||||||
|  |   userType: number | ||||||
|  |   clientId: string | ||||||
|  |   createTime: string | ||||||
|  |   expiresTime: string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export interface OAuth2TokenPageReqVO extends BasePage { | ||||||
|  |   code?: string | ||||||
|  |   name?: string | ||||||
|  |   status?: number | ||||||
|  | } | ||||||
|  |  | ||||||
| // 查询 token列表 | // 查询 token列表 | ||||||
| export const getAccessTokenPageApi = (params) => { | export const getAccessTokenPageApi = (params: OAuth2TokenPageReqVO) => { | ||||||
|   return request.get({ url: '/system/oauth2-token/page', params }) |   return request.get({ url: '/system/oauth2-token/page', params }) | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,10 +0,0 @@ | |||||||
| export type OAuth2TokenVo = { |  | ||||||
|   id: number |  | ||||||
|   accessToken: string |  | ||||||
|   refreshToken: string |  | ||||||
|   userId: number |  | ||||||
|   userType: number |  | ||||||
|   clientId: string |  | ||||||
|   createTime: string |  | ||||||
|   expiresTime: string |  | ||||||
| } |  | ||||||
| @@ -45,13 +45,13 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { | |||||||
|       isHover: true // 当鼠标移到行时,是否要高亮当前行 |       isHover: true // 当鼠标移到行时,是否要高亮当前行 | ||||||
|     }, |     }, | ||||||
|     toolbarConfig: { |     toolbarConfig: { | ||||||
|       custom: true, |  | ||||||
|       slots: { buttons: 'toolbar_buttons' } |       slots: { buttons: 'toolbar_buttons' } | ||||||
|     }, |     }, | ||||||
|     printConfig: { |     printConfig: { | ||||||
|       columns: config?.allSchemas.printSchema |       columns: config?.allSchemas.printSchema | ||||||
|     }, |     }, | ||||||
|     formConfig: { |     formConfig: { | ||||||
|  |       enabled: true, | ||||||
|       titleWidth: 100, |       titleWidth: 100, | ||||||
|       titleAlign: 'right', |       titleAlign: 'right', | ||||||
|       items: config?.allSchemas.searchSchema |       items: config?.allSchemas.searchSchema | ||||||
| @@ -120,6 +120,7 @@ export const useVxeGrid = <T = any>(config?: UseVxeGridConfig<T>) => { | |||||||
|       }) |       }) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   return { |   return { | ||||||
|     gridOptions, |     gridOptions, | ||||||
|     delList |     delList | ||||||
|   | |||||||
| @@ -1,10 +1,9 @@ | |||||||
| import { reactive } from 'vue' | import { reactive } from 'vue' | ||||||
| import { useI18n } from '@/hooks/web/useI18n' | import { useI18n } from '@/hooks/web/useI18n' | ||||||
| import { required } from '@/utils/formRules' | import { required } from '@/utils/formRules' | ||||||
| import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas' |  | ||||||
| import { DICT_TYPE } from '@/utils/dict' | import { DICT_TYPE } from '@/utils/dict' | ||||||
| const { t } = useI18n() | import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas' | ||||||
| // 国际化 | const { t } = useI18n() // 国际化 | ||||||
|  |  | ||||||
| // 表单校验 | // 表单校验 | ||||||
| export const rules = reactive({ | export const rules = reactive({ | ||||||
| @@ -20,94 +19,75 @@ export const rules = reactive({ | |||||||
| }) | }) | ||||||
|  |  | ||||||
| // CrudSchema | // CrudSchema | ||||||
| const crudSchemas = reactive<CrudSchema[]>([ | const crudSchemas = reactive<VxeCrudSchema>({ | ||||||
|  |   primaryKey: 'clientId', | ||||||
|  |   primaryType: 'seq', | ||||||
|  |   action: true, | ||||||
|  |   columns: [ | ||||||
|     { |     { | ||||||
|     label: '客户端编号', |       title: '客户端密钥', | ||||||
|     field: 'clientId', |  | ||||||
|     form: { |  | ||||||
|       show: false |  | ||||||
|     }, |  | ||||||
|     detail: { |  | ||||||
|       show: false |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     label: '客户端密钥', |  | ||||||
|       field: 'secret' |       field: 'secret' | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '应用名', |       title: '应用名', | ||||||
|       field: 'name', |       field: 'name', | ||||||
|     search: { |       isSearch: true | ||||||
|       show: true |  | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '应用图标', |       title: '应用图标', | ||||||
|       field: 'logo' |       field: 'logo' | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: t('common.status'), |       title: t('common.status'), | ||||||
|       field: 'status', |       field: 'status', | ||||||
|       dictType: DICT_TYPE.COMMON_STATUS, |       dictType: DICT_TYPE.COMMON_STATUS, | ||||||
|     search: { |       isSearch: true | ||||||
|       show: true |  | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '访问令牌的有效期', |       title: '访问令牌的有效期', | ||||||
|       field: 'accessTokenValiditySeconds' |       field: 'accessTokenValiditySeconds' | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '刷新令牌的有效期', |       title: '刷新令牌的有效期', | ||||||
|       field: 'refreshTokenValiditySeconds' |       field: 'refreshTokenValiditySeconds' | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '授权类型', |       title: '授权类型', | ||||||
|       field: 'authorizedGrantTypes', |       field: 'authorizedGrantTypes', | ||||||
|     dictType: DICT_TYPE.SYSTEM_OAUTH2_GRANT_TYPE |       dictType: DICT_TYPE.SYSTEM_OAUTH2_GRANT_TYPE, | ||||||
|  |       form: { | ||||||
|  |         component: 'Select' | ||||||
|  |       } | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '授权范围', |       title: '授权范围', | ||||||
|       field: 'scopes', |       field: 'scopes', | ||||||
|     table: { |       isTable: false | ||||||
|       show: false |  | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '自动授权范围', |       title: '自动授权范围', | ||||||
|       field: 'autoApproveScopes', |       field: 'autoApproveScopes', | ||||||
|     table: { |       isTable: false | ||||||
|       show: false |  | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '可重定向的 URI 地址', |       title: '可重定向的 URI 地址', | ||||||
|       field: 'redirectUris', |       field: 'redirectUris', | ||||||
|     table: { |       isTable: false | ||||||
|       show: false |  | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '权限', |       title: '权限', | ||||||
|       field: 'authorities', |       field: 'authorities', | ||||||
|     table: { |       isTable: false | ||||||
|       show: false |  | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '资源', |       title: '资源', | ||||||
|       field: 'resourceIds', |       field: 'resourceIds', | ||||||
|     table: { |       isTable: false | ||||||
|       show: false |  | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '附加信息', |       title: '附加信息', | ||||||
|       field: 'additionalInformation', |       field: 'additionalInformation', | ||||||
|     table: { |       isTable: false, | ||||||
|       show: false |  | ||||||
|     }, |  | ||||||
|       form: { |       form: { | ||||||
|         component: 'Input', |         component: 'Input', | ||||||
|         componentProps: { |         componentProps: { | ||||||
| @@ -120,22 +100,11 @@ const crudSchemas = reactive<CrudSchema[]>([ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: t('common.createTime'), |       title: t('common.createTime'), | ||||||
|       field: 'createTime', |       field: 'createTime', | ||||||
|     form: { |       formatter: 'formatDate', | ||||||
|       show: false |       isForm: false | ||||||
|     } |     } | ||||||
|   }, |   ] | ||||||
|   { | }) | ||||||
|     label: t('table.action'), | export const { allSchemas } = useVxeCrudSchemas(crudSchemas) | ||||||
|     field: 'action', |  | ||||||
|     width: '240px', |  | ||||||
|     form: { |  | ||||||
|       show: false |  | ||||||
|     }, |  | ||||||
|     detail: { |  | ||||||
|       show: false |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| ]) |  | ||||||
| export const { allSchemas } = useCrudSchemas(crudSchemas) |  | ||||||
|   | |||||||
| @@ -1,29 +1,112 @@ | |||||||
|  | <template> | ||||||
|  |   <ContentWrap> | ||||||
|  |     <!-- 列表 --> | ||||||
|  |     <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar"> | ||||||
|  |       <!-- 操作:新增 --> | ||||||
|  |       <template #toolbar_buttons> | ||||||
|  |         <XButton | ||||||
|  |           type="primary" | ||||||
|  |           preIcon="ep:zoom-in" | ||||||
|  |           :title="t('action.add')" | ||||||
|  |           v-hasPermi="['system:oauth2-client:create']" | ||||||
|  |           @click="handleCreate()" | ||||||
|  |         /> | ||||||
|  |       </template> | ||||||
|  |       <template #authorizedGrantTypes="{ row }"> | ||||||
|  |         <el-tag | ||||||
|  |           :disable-transitions="true" | ||||||
|  |           :key="index" | ||||||
|  |           v-for="(authorizedGrantType, index) in row.authorizedGrantTypes" | ||||||
|  |           :index="index" | ||||||
|  |         > | ||||||
|  |           {{ authorizedGrantType }} | ||||||
|  |         </el-tag> | ||||||
|  |       </template> | ||||||
|  |       <template #actionbtns_default="{ row }"> | ||||||
|  |         <!-- 操作:修改 --> | ||||||
|  |         <XTextButton | ||||||
|  |           preIcon="ep:edit" | ||||||
|  |           :title="t('action.edit')" | ||||||
|  |           v-hasPermi="['system:oauth2-client:update']" | ||||||
|  |           @click="handleUpdate(row.id)" | ||||||
|  |         /> | ||||||
|  |         <!-- 操作:详情 --> | ||||||
|  |         <XTextButton | ||||||
|  |           preIcon="ep:view" | ||||||
|  |           :title="t('action.detail')" | ||||||
|  |           v-hasPermi="['system:oauth2-client:update']" | ||||||
|  |           @click="handleDetail(row.id)" | ||||||
|  |         /> | ||||||
|  |         <!-- 操作:删除 --> | ||||||
|  |         <XTextButton | ||||||
|  |           preIcon="ep:delete" | ||||||
|  |           :title="t('action.del')" | ||||||
|  |           v-hasPermi="['system:oauth2-client:delete']" | ||||||
|  |           @click="handleDelete(row.id)" | ||||||
|  |         /> | ||||||
|  |       </template> | ||||||
|  |     </vxe-grid> | ||||||
|  |   </ContentWrap> | ||||||
|  |   <!-- 弹窗 --> | ||||||
|  |   <XModal id="postModel" v-model="dialogVisible" :title="dialogTitle"> | ||||||
|  |     <template #default> | ||||||
|  |       <!-- 表单:添加/修改 --> | ||||||
|  |       <Form | ||||||
|  |         ref="formRef" | ||||||
|  |         v-if="['create', 'update'].includes(actionType)" | ||||||
|  |         :schema="allSchemas.formSchema" | ||||||
|  |         :rules="rules" | ||||||
|  |       /> | ||||||
|  |       <!-- 表单:详情 --> | ||||||
|  |       <Descriptions | ||||||
|  |         v-if="actionType === 'detail'" | ||||||
|  |         :schema="allSchemas.detailSchema" | ||||||
|  |         :data="detailRef" | ||||||
|  |       /> | ||||||
|  |     </template> | ||||||
|  |     <template #footer> | ||||||
|  |       <!-- 按钮:保存 --> | ||||||
|  |       <XButton | ||||||
|  |         v-if="['create', 'update'].includes(actionType)" | ||||||
|  |         type="primary" | ||||||
|  |         :title="t('action.save')" | ||||||
|  |         :loading="actionLoading" | ||||||
|  |         @click="submitForm" | ||||||
|  |       /> | ||||||
|  |       <!-- 按钮:关闭 --> | ||||||
|  |       <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" /> | ||||||
|  |     </template> | ||||||
|  |   </XModal> | ||||||
|  | </template> | ||||||
| <script setup lang="ts"> | <script setup lang="ts"> | ||||||
|  | // 全局相关的 import | ||||||
| import { ref, unref } from 'vue' | import { ref, unref } from 'vue' | ||||||
| import dayjs from 'dayjs' | import { ElTag } from 'element-plus' | ||||||
| import { ElMessage, ElImage, ElTag } from 'element-plus' |  | ||||||
| import { DICT_TYPE } from '@/utils/dict' |  | ||||||
| import { useTable } from '@/hooks/web/useTable' |  | ||||||
| import { useI18n } from '@/hooks/web/useI18n' | import { useI18n } from '@/hooks/web/useI18n' | ||||||
|  | import { useMessage } from '@/hooks/web/useMessage' | ||||||
|  | import { useVxeGrid } from '@/hooks/web/useVxeGrid' | ||||||
|  | import { VxeGridInstance } from 'vxe-table' | ||||||
| import { FormExpose } from '@/components/Form' | import { FormExpose } from '@/components/Form' | ||||||
| import type { OAuth2ClientVo } from '@/api/system/oauth2/client.types' | // 业务相关的 import | ||||||
| import { rules, allSchemas } from './client.data' |  | ||||||
| import * as ClientApi from '@/api/system/oauth2/client' | import * as ClientApi from '@/api/system/oauth2/client' | ||||||
|  | import { rules, allSchemas } from './client.data' | ||||||
|  |  | ||||||
| const { t } = useI18n() // 国际化 | const { t } = useI18n() // 国际化 | ||||||
|  | const message = useMessage() // 消息弹窗 | ||||||
|  |  | ||||||
| // ========== 列表相关 ========== | // 列表相关的变量 | ||||||
| const { register, tableObject, methods } = useTable<OAuth2ClientVo>({ | const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref | ||||||
|   getListApi: ClientApi.getOAuth2ClientPageApi, | const { gridOptions } = useVxeGrid<ClientApi.OAuth2ClientVO>({ | ||||||
|   delListApi: ClientApi.deleteOAuth2ClientApi |   allSchemas: allSchemas, | ||||||
|  |   getListApi: ClientApi.getOAuth2ClientPageApi | ||||||
| }) | }) | ||||||
| const { getList, setSearchParams, delList } = methods | // 弹窗相关的变量 | ||||||
|  |  | ||||||
| // ========== CRUD 相关 ========== |  | ||||||
| const actionLoading = ref(false) // 遮罩层 |  | ||||||
| const actionType = ref('') // 操作按钮的类型 |  | ||||||
| const dialogVisible = ref(false) // 是否显示弹出层 | const dialogVisible = ref(false) // 是否显示弹出层 | ||||||
| const dialogTitle = ref('edit') // 弹出层标题 | const dialogTitle = ref('edit') // 弹出层标题 | ||||||
|  | const actionType = ref('') // 操作按钮的类型 | ||||||
|  | const actionLoading = ref(false) // 按钮 Loading | ||||||
| const formRef = ref<FormExpose>() // 表单 Ref | const formRef = ref<FormExpose>() // 表单 Ref | ||||||
|  | const detailRef = ref() // 详情 Ref | ||||||
|  |  | ||||||
| // 设置标题 | // 设置标题 | ||||||
| const setDialogTile = (type: string) => { | const setDialogTile = (type: string) => { | ||||||
| @@ -40,14 +123,35 @@ const handleCreate = () => { | |||||||
| } | } | ||||||
|  |  | ||||||
| // 修改操作 | // 修改操作 | ||||||
| const handleUpdate = async (row: OAuth2ClientVo) => { | const handleUpdate = async (rowId: number) => { | ||||||
|   setDialogTile('update') |   setDialogTile('update') | ||||||
|   // 设置数据 |   // 设置数据 | ||||||
|   const res = await ClientApi.getOAuth2ClientApi(row.id) |   const res = await ClientApi.getOAuth2ClientApi(rowId) | ||||||
|   unref(formRef)?.setValues(res) |   unref(formRef)?.setValues(res) | ||||||
| } | } | ||||||
|  |  | ||||||
| // 提交按钮 | // 详情操作 | ||||||
|  | const handleDetail = async (rowId: number) => { | ||||||
|  |   setDialogTile('detail') | ||||||
|  |   const res = await ClientApi.getOAuth2ClientApi(rowId) | ||||||
|  |   detailRef.value = res | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // 删除操作 | ||||||
|  | const handleDelete = async (rowId: number) => { | ||||||
|  |   message | ||||||
|  |     .delConfirm() | ||||||
|  |     .then(async () => { | ||||||
|  |       await ClientApi.deleteOAuth2ClientApi(rowId) | ||||||
|  |       message.success(t('common.delSuccess')) | ||||||
|  |     }) | ||||||
|  |     .finally(() => { | ||||||
|  |       // 刷新列表 | ||||||
|  |       xGrid.value?.commitProxy('query') | ||||||
|  |     }) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // 提交新增/修改的表单 | ||||||
| const submitForm = async () => { | const submitForm = async () => { | ||||||
|   const elForm = unref(formRef)?.getElFormRef() |   const elForm = unref(formRef)?.getElFormRef() | ||||||
|   if (!elForm) return |   if (!elForm) return | ||||||
| @@ -56,143 +160,21 @@ const submitForm = async () => { | |||||||
|       actionLoading.value = true |       actionLoading.value = true | ||||||
|       // 提交请求 |       // 提交请求 | ||||||
|       try { |       try { | ||||||
|         const data = unref(formRef)?.formModel as OAuth2ClientVo |         const data = unref(formRef)?.formModel as ClientApi.OAuth2ClientVO | ||||||
|         if (actionType.value === 'create') { |         if (actionType.value === 'create') { | ||||||
|           await ClientApi.createOAuth2ClientApi(data) |           await ClientApi.createOAuth2ClientApi(data) | ||||||
|           ElMessage.success(t('common.createSuccess')) |           message.success(t('common.createSuccess')) | ||||||
|         } else { |         } else { | ||||||
|           await ClientApi.updateOAuth2ClientApi(data) |           await ClientApi.updateOAuth2ClientApi(data) | ||||||
|           ElMessage.success(t('common.updateSuccess')) |           message.success(t('common.updateSuccess')) | ||||||
|         } |         } | ||||||
|         // 操作成功,重新加载列表 |  | ||||||
|         dialogVisible.value = false |         dialogVisible.value = false | ||||||
|         await getList() |  | ||||||
|       } finally { |       } finally { | ||||||
|         actionLoading.value = false |         actionLoading.value = false | ||||||
|  |         // 刷新列表 | ||||||
|  |         xGrid.value?.commitProxy('query') | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   }) |   }) | ||||||
| } | } | ||||||
|  |  | ||||||
| // ========== 详情相关 ========== |  | ||||||
| const detailRef = ref() // 详情 Ref |  | ||||||
|  |  | ||||||
| // 详情操作 |  | ||||||
| const handleDetail = async (row: OAuth2ClientVo) => { |  | ||||||
|   // 设置数据 |  | ||||||
|   detailRef.value = row |  | ||||||
|   setDialogTile('detail') |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // ========== 初始化 ========== |  | ||||||
| getList() |  | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <template> |  | ||||||
|   <!-- 搜索工作区 --> |  | ||||||
|   <ContentWrap> |  | ||||||
|     <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" /> |  | ||||||
|   </ContentWrap> |  | ||||||
|   <ContentWrap> |  | ||||||
|     <!-- 操作工具栏 --> |  | ||||||
|     <div class="mb-10px"> |  | ||||||
|       <el-button type="primary" v-hasPermi="['system:oauth2-client:create']" @click="handleCreate"> |  | ||||||
|         <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }} |  | ||||||
|       </el-button> |  | ||||||
|     </div> |  | ||||||
|     <!-- 列表 --> |  | ||||||
|     <Table |  | ||||||
|       :columns="allSchemas.tableColumns" |  | ||||||
|       :selection="false" |  | ||||||
|       :data="tableObject.tableList" |  | ||||||
|       :loading="tableObject.loading" |  | ||||||
|       :pagination="{ |  | ||||||
|         total: tableObject.total |  | ||||||
|       }" |  | ||||||
|       v-model:pageSize="tableObject.pageSize" |  | ||||||
|       v-model:currentPage="tableObject.currentPage" |  | ||||||
|       @register="register" |  | ||||||
|     > |  | ||||||
|       <template #logo="{ row }"> |  | ||||||
|         <el-image :src="row.logo" :preview-src-list="[row.logo]" /> |  | ||||||
|       </template> |  | ||||||
|       <template #status="{ row }"> |  | ||||||
|         <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" /> |  | ||||||
|       </template> |  | ||||||
|       <template #authorizedGrantTypes="{ row }"> |  | ||||||
|         <el-tag |  | ||||||
|           :disable-transitions="true" |  | ||||||
|           :key="index" |  | ||||||
|           v-for="(authorizedGrantType, index) in row.authorizedGrantTypes" |  | ||||||
|           :index="index" |  | ||||||
|         > |  | ||||||
|           {{ authorizedGrantType }} |  | ||||||
|         </el-tag> |  | ||||||
|       </template> |  | ||||||
|       <template #createTime="{ row }"> |  | ||||||
|         <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span> |  | ||||||
|       </template> |  | ||||||
|       <template #action="{ row }"> |  | ||||||
|         <el-button |  | ||||||
|           link |  | ||||||
|           type="primary" |  | ||||||
|           v-hasPermi="['system:oauth2-client:update']" |  | ||||||
|           @click="handleUpdate(row)" |  | ||||||
|         > |  | ||||||
|           <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }} |  | ||||||
|         </el-button> |  | ||||||
|         <el-button |  | ||||||
|           link |  | ||||||
|           type="primary" |  | ||||||
|           v-hasPermi="['system:oauth2-client:update']" |  | ||||||
|           @click="handleDetail(row)" |  | ||||||
|         > |  | ||||||
|           <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }} |  | ||||||
|         </el-button> |  | ||||||
|         <el-button |  | ||||||
|           link |  | ||||||
|           type="primary" |  | ||||||
|           v-hasPermi="['system:oauth2-client:delete']" |  | ||||||
|           @click="delList(row.id, false)" |  | ||||||
|         > |  | ||||||
|           <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }} |  | ||||||
|         </el-button> |  | ||||||
|       </template> |  | ||||||
|     </Table> |  | ||||||
|   </ContentWrap> |  | ||||||
|  |  | ||||||
|   <Dialog v-model="dialogVisible" :title="dialogTitle" width="60%" maxHeight="420px"> |  | ||||||
|     <!-- 对话框(添加 / 修改) --> |  | ||||||
|     <Form |  | ||||||
|       v-if="['create', 'update'].includes(actionType)" |  | ||||||
|       :schema="allSchemas.formSchema" |  | ||||||
|       :rules="rules" |  | ||||||
|       ref="formRef" |  | ||||||
|     /> |  | ||||||
|     <!-- 对话框(详情) --> |  | ||||||
|     <Descriptions |  | ||||||
|       v-if="actionType === 'detail'" |  | ||||||
|       :schema="allSchemas.detailSchema" |  | ||||||
|       :data="detailRef" |  | ||||||
|     > |  | ||||||
|       <template #status="{ row }"> |  | ||||||
|         <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" /> |  | ||||||
|       </template> |  | ||||||
|       <template #createTime="{ row }"> |  | ||||||
|         <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span> |  | ||||||
|       </template> |  | ||||||
|     </Descriptions> |  | ||||||
|     <!-- 操作按钮 --> |  | ||||||
|     <template #footer> |  | ||||||
|       <el-button |  | ||||||
|         v-if="['create', 'update'].includes(actionType)" |  | ||||||
|         type="primary" |  | ||||||
|         :loading="actionLoading" |  | ||||||
|         @click="submitForm" |  | ||||||
|       > |  | ||||||
|         {{ t('action.save') }} |  | ||||||
|       </el-button> |  | ||||||
|       <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button> |  | ||||||
|     </template> |  | ||||||
|   </Dialog> |  | ||||||
| </template> |  | ||||||
|   | |||||||
| @@ -1,92 +1,69 @@ | |||||||
| <script setup lang="ts"> |  | ||||||
| import dayjs from 'dayjs' |  | ||||||
| import { useTable } from '@/hooks/web/useTable' |  | ||||||
| import { allSchemas } from './token.data' |  | ||||||
| import { DICT_TYPE } from '@/utils/dict' |  | ||||||
| import { useI18n } from '@/hooks/web/useI18n' |  | ||||||
| import type { OAuth2TokenVo } from '@/api/system/oauth2/token.types' |  | ||||||
| import * as TokenApi from '@/api/system/oauth2/token' |  | ||||||
| import { ref } from 'vue' |  | ||||||
| const { t } = useI18n() // 国际化 |  | ||||||
| // ========== 列表相关 ========== |  | ||||||
| const { register, tableObject, methods } = useTable<OAuth2TokenVo>({ |  | ||||||
|   getListApi: TokenApi.getAccessTokenPageApi, |  | ||||||
|   delListApi: TokenApi.deleteAccessTokenApi |  | ||||||
| }) |  | ||||||
| // ========== 详情相关 ========== |  | ||||||
| const detailRef = ref() // 详情 Ref |  | ||||||
| const dialogVisible = ref(false) // 是否显示弹出层 |  | ||||||
| const dialogTitle = ref(t('action.detail')) // 弹出层标题 |  | ||||||
| const { getList, setSearchParams, delList } = methods |  | ||||||
| // 详情 |  | ||||||
| const handleDetail = (row: OAuth2TokenVo) => { |  | ||||||
|   // 设置数据 |  | ||||||
|   detailRef.value = row |  | ||||||
|   dialogVisible.value = true |  | ||||||
| } |  | ||||||
| // 强退操作 |  | ||||||
| const handleForceLogout = (row: OAuth2TokenVo) => { |  | ||||||
|   delList(row.id, false) |  | ||||||
| } |  | ||||||
| getList() |  | ||||||
| </script> |  | ||||||
| <template> | <template> | ||||||
|   <ContentWrap> |   <ContentWrap> | ||||||
|     <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" /> |     <!-- 列表 --> | ||||||
|   </ContentWrap> |     <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar"> | ||||||
|   <ContentWrap> |       <template #actionbtns_default="{ row }"> | ||||||
|     <Table |         <!-- 操作:详情 --> | ||||||
|       :columns="allSchemas.tableColumns" |         <XTextButton preIcon="ep:view" :title="t('action.detail')" @click="handleDetail(row)" /> | ||||||
|       :selection="false" |         <!-- 操作:删除 --> | ||||||
|       :data="tableObject.tableList" |         <XTextButton | ||||||
|       :loading="tableObject.loading" |           preIcon="ep:delete" | ||||||
|       :pagination="{ |           :title="t('action.logout')" | ||||||
|         total: tableObject.total |  | ||||||
|       }" |  | ||||||
|       v-model:pageSize="tableObject.pageSize" |  | ||||||
|       v-model:currentPage="tableObject.currentPage" |  | ||||||
|       @register="register" |  | ||||||
|     > |  | ||||||
|       <template #userType="{ row }"> |  | ||||||
|         <DictTag :type="DICT_TYPE.USER_TYPE" :value="row.userType" /> |  | ||||||
|       </template> |  | ||||||
|       <template #createTime="{ row }"> |  | ||||||
|         <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span> |  | ||||||
|       </template> |  | ||||||
|       <template #expiresTime="{ row }"> |  | ||||||
|         <span>{{ dayjs(row.expiresTime).format('YYYY-MM-DD HH:mm:ss') }}</span> |  | ||||||
|       </template> |  | ||||||
|       <template #action="{ row }"> |  | ||||||
|         <el-button link type="primary" @click="handleDetail(row)"> |  | ||||||
|           <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }} |  | ||||||
|         </el-button> |  | ||||||
|         <el-button |  | ||||||
|           link |  | ||||||
|           type="primary" |  | ||||||
|           v-hasPermi="['system:oauth2-token:delete']" |           v-hasPermi="['system:oauth2-token:delete']" | ||||||
|           @click="handleForceLogout(row)" |           @click="handleForceLogout(row.id)" | ||||||
|         > |         /> | ||||||
|           <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.logout') }} |  | ||||||
|         </el-button> |  | ||||||
|       </template> |       </template> | ||||||
|     </Table> |     </vxe-grid> | ||||||
|   </ContentWrap> |   </ContentWrap> | ||||||
|   <Dialog v-model="dialogVisible" :title="dialogTitle"> |   <Dialog v-model="dialogVisible" :title="dialogTitle"> | ||||||
|     <!-- 对话框(详情) --> |     <!-- 对话框(详情) --> | ||||||
|     <Descriptions :schema="allSchemas.detailSchema" :data="detailRef"> |     <Descriptions :schema="allSchemas.detailSchema" :data="detailRef" /> | ||||||
|       <template #userType="{ row }"> |  | ||||||
|         <DictTag :type="DICT_TYPE.USER_TYPE" :value="row.userType" /> |  | ||||||
|       </template> |  | ||||||
|       <template #createTime="{ row }"> |  | ||||||
|         <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span> |  | ||||||
|       </template> |  | ||||||
|       <template #expiresTime="{ row }"> |  | ||||||
|         <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span> |  | ||||||
|       </template> |  | ||||||
|     </Descriptions> |  | ||||||
|     <!-- 操作按钮 --> |     <!-- 操作按钮 --> | ||||||
|     <template #footer> |     <template #footer> | ||||||
|       <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button> |       <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button> | ||||||
|     </template> |     </template> | ||||||
|   </Dialog> |   </Dialog> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
|  | <script setup lang="ts"> | ||||||
|  | import { ref } from 'vue' | ||||||
|  | import { useI18n } from '@/hooks/web/useI18n' | ||||||
|  | import { useMessage } from '@/hooks/web/useMessage' | ||||||
|  | import { useVxeGrid } from '@/hooks/web/useVxeGrid' | ||||||
|  | import { VxeGridInstance } from 'vxe-table' | ||||||
|  |  | ||||||
|  | import { allSchemas } from './token.data' | ||||||
|  | import * as TokenApi from '@/api/system/oauth2/token' | ||||||
|  |  | ||||||
|  | const { t } = useI18n() // 国际化 | ||||||
|  | const message = useMessage() // 消息弹窗 | ||||||
|  | // 列表相关的变量 | ||||||
|  | const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref | ||||||
|  | const { gridOptions } = useVxeGrid<TokenApi.OAuth2TokenVO>({ | ||||||
|  |   allSchemas: allSchemas, | ||||||
|  |   getListApi: TokenApi.getAccessTokenPageApi | ||||||
|  | }) | ||||||
|  | // ========== 详情相关 ========== | ||||||
|  | const detailRef = ref() // 详情 Ref | ||||||
|  | const dialogVisible = ref(false) // 是否显示弹出层 | ||||||
|  | const dialogTitle = ref(t('action.detail')) // 弹出层标题 | ||||||
|  | // 详情 | ||||||
|  | const handleDetail = async (row: TokenApi.OAuth2TokenVO) => { | ||||||
|  |   // 设置数据 | ||||||
|  |   detailRef.value = row | ||||||
|  |   dialogVisible.value = true | ||||||
|  | } | ||||||
|  | // 强退操作 | ||||||
|  | const handleForceLogout = (rowId: number) => { | ||||||
|  |   message | ||||||
|  |     .delConfirm() | ||||||
|  |     .then(async () => { | ||||||
|  |       await TokenApi.deleteAccessTokenApi(rowId) | ||||||
|  |       message.success(t('common.delSuccess')) | ||||||
|  |     }) | ||||||
|  |     .finally(() => { | ||||||
|  |       // 刷新列表 | ||||||
|  |       xGrid.value?.commitProxy('query') | ||||||
|  |     }) | ||||||
|  | } | ||||||
|  | </script> | ||||||
|   | |||||||
| @@ -1,68 +1,45 @@ | |||||||
| import { reactive } from 'vue' | import { reactive } from 'vue' | ||||||
| import { useI18n } from '@/hooks/web/useI18n' | import { useI18n } from '@/hooks/web/useI18n' | ||||||
| import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas' |  | ||||||
| import { DICT_TYPE } from '@/utils/dict' | import { DICT_TYPE } from '@/utils/dict' | ||||||
|  | import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas' | ||||||
| const { t } = useI18n() // 国际化 | const { t } = useI18n() // 国际化 | ||||||
| // CrudSchema | // CrudSchema | ||||||
| const crudSchemas = reactive<CrudSchema[]>([ | const crudSchemas = reactive<VxeCrudSchema>({ | ||||||
|  |   primaryKey: 'id', | ||||||
|  |   primaryType: 'seq', | ||||||
|  |   action: true, | ||||||
|  |   columns: [ | ||||||
|     { |     { | ||||||
|     label: t('common.index'), |       title: '用户编号', | ||||||
|     field: 'id', |  | ||||||
|     type: 'index', |  | ||||||
|     form: { |  | ||||||
|       show: false |  | ||||||
|     }, |  | ||||||
|     detail: { |  | ||||||
|       show: false |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     label: '用户编号', |  | ||||||
|       field: 'userId', |       field: 'userId', | ||||||
|     search: { |       isSearch: true | ||||||
|       show: true |  | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '访问令牌', |       title: '访问令牌', | ||||||
|       field: 'accessToken' |       field: 'accessToken' | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '刷新令牌', |       title: '刷新令牌', | ||||||
|       field: 'refreshToken' |       field: 'refreshToken' | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '用户类型', |       title: '用户类型', | ||||||
|       field: 'userType', |       field: 'userType', | ||||||
|       dictType: DICT_TYPE.USER_TYPE, |       dictType: DICT_TYPE.USER_TYPE, | ||||||
|     search: { |       isSearch: true | ||||||
|       show: true |  | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: t('common.createTime'), |       title: t('common.createTime'), | ||||||
|       field: 'createTime', |       field: 'createTime', | ||||||
|     form: { |       formatter: 'formatDate', | ||||||
|       show: false |       isForm: false | ||||||
|     } |  | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|     label: '过期时间', |       title: '过期时间', | ||||||
|       field: 'expiresTime', |       field: 'expiresTime', | ||||||
|     form: { |       formatter: 'formatDate', | ||||||
|       show: false |       isForm: false | ||||||
|     } |     } | ||||||
|   }, |   ] | ||||||
|   { | }) | ||||||
|     label: t('table.action'), | export const { allSchemas } = useVxeCrudSchemas(crudSchemas) | ||||||
|     field: 'action', |  | ||||||
|     width: '200px', |  | ||||||
|     form: { |  | ||||||
|       show: false |  | ||||||
|     }, |  | ||||||
|     detail: { |  | ||||||
|       show: false |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| ]) |  | ||||||
| export const { allSchemas } = useCrudSchemas(crudSchemas) |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 xingyu4j
					xingyu4j