index.vue 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <script setup lang="ts">
  2. import dayjs from 'dayjs'
  3. import { useTable } from '@/hooks/web/useTable'
  4. import { allSchemas } from './token.data'
  5. import { DICT_TYPE } from '@/utils/dict'
  6. import { useI18n } from '@/hooks/web/useI18n'
  7. import type { OAuth2TokenVo } from '@/api/system/oauth2/token.types'
  8. import * as TokenApi from '@/api/system/oauth2/token'
  9. import { ref } from 'vue'
  10. const { t } = useI18n() // 国际化
  11. // ========== 列表相关 ==========
  12. const { register, tableObject, methods } = useTable<OAuth2TokenVo>({
  13. getListApi: TokenApi.getAccessTokenPageApi,
  14. delListApi: TokenApi.deleteAccessTokenApi
  15. })
  16. // ========== 详情相关 ==========
  17. const detailRef = ref() // 详情 Ref
  18. const dialogVisible = ref(false) // 是否显示弹出层
  19. const dialogTitle = ref(t('action.detail')) // 弹出层标题
  20. const { getList, setSearchParams, delList } = methods
  21. // 详情
  22. const handleDetail = (row: OAuth2TokenVo) => {
  23. // 设置数据
  24. detailRef.value = row
  25. dialogVisible.value = true
  26. }
  27. // 强退操作
  28. const handleForceLogout = (row: OAuth2TokenVo) => {
  29. delList(row.id, false)
  30. }
  31. getList()
  32. </script>
  33. <template>
  34. <ContentWrap>
  35. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  36. </ContentWrap>
  37. <ContentWrap>
  38. <Table
  39. :columns="allSchemas.tableColumns"
  40. :selection="false"
  41. :data="tableObject.tableList"
  42. :loading="tableObject.loading"
  43. :pagination="{
  44. total: tableObject.total
  45. }"
  46. v-model:pageSize="tableObject.pageSize"
  47. v-model:currentPage="tableObject.currentPage"
  48. @register="register"
  49. >
  50. <template #userType="{ row }">
  51. <DictTag :type="DICT_TYPE.USER_TYPE" :value="row.userType" />
  52. </template>
  53. <template #createTime="{ row }">
  54. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  55. </template>
  56. <template #expiresTime="{ row }">
  57. <span>{{ dayjs(row.expiresTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  58. </template>
  59. <template #action="{ row }">
  60. <el-button link type="primary" @click="handleDetail(row)">
  61. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
  62. </el-button>
  63. <el-button
  64. link
  65. type="primary"
  66. v-hasPermi="['system:oauth2-token:delete']"
  67. @click="handleForceLogout(row)"
  68. >
  69. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.logout') }}
  70. </el-button>
  71. </template>
  72. </Table>
  73. </ContentWrap>
  74. <Dialog v-model="dialogVisible" :title="dialogTitle">
  75. <!-- 对话框(详情) -->
  76. <Descriptions :schema="allSchemas.detailSchema" :data="detailRef">
  77. <template #userType="{ row }">
  78. <DictTag :type="DICT_TYPE.USER_TYPE" :value="row.userType" />
  79. </template>
  80. <template #createTime="{ row }">
  81. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  82. </template>
  83. <template #expiresTime="{ row }">
  84. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  85. </template>
  86. </Descriptions>
  87. <!-- 操作按钮 -->
  88. <template #footer>
  89. <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
  90. </template>
  91. </Dialog>
  92. </template>