client-list.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view>
  3. <!-- 搜索组件 -->
  4. <ClientSearchForm @search="handleQuery" @reset="handleReset" />
  5. <!-- OAuth2 客户端列表 -->
  6. <view class="p-24rpx">
  7. <view
  8. v-for="item in list"
  9. :key="item.id"
  10. class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
  11. @click="handleDetail(item)"
  12. >
  13. <view class="p-24rpx">
  14. <view class="mb-16rpx flex items-center justify-between">
  15. <view class="text-32rpx text-[#333] font-semibold">
  16. {{ item.name }}
  17. </view>
  18. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="item.status" />
  19. </view>
  20. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  21. <text class="mr-8rpx shrink-0 text-[#999]">客户端编号:</text>
  22. <text class="min-w-0 flex-1 truncate">{{ item.clientId || '-' }}</text>
  23. </view>
  24. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  25. <text class="mr-8rpx text-[#999]">客户端密钥:</text>
  26. <text class="min-w-0 flex-1 truncate">{{ item.secret || '-' }}</text>
  27. </view>
  28. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  29. <text class="mr-8rpx text-[#999]">访问令牌有效期:</text>
  30. <text>{{ item.accessTokenValiditySeconds }} 秒</text>
  31. </view>
  32. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  33. <text class="mr-8rpx text-[#999]">刷新令牌有效期:</text>
  34. <text>{{ item.refreshTokenValiditySeconds }} 秒</text>
  35. </view>
  36. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  37. <text class="mr-8rpx text-[#999]">创建时间:</text>
  38. <text>{{ formatDateTime(item.createTime) || '-' }}</text>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 加载更多 -->
  43. <view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
  44. <wd-status-tip image="content" tip="暂无 OAuth2 客户端数据" />
  45. </view>
  46. <wd-loadmore
  47. v-if="list.length > 0"
  48. :state="loadMoreState"
  49. @reload="loadMore"
  50. />
  51. </view>
  52. <!-- 新增按钮 -->
  53. <wd-fab
  54. v-if="hasAccessByCodes(['system:oauth2-client:create'])"
  55. position="right-bottom"
  56. type="primary"
  57. :expandable="false"
  58. @click="handleAdd"
  59. />
  60. </view>
  61. </template>
  62. <script lang="ts" setup>
  63. import type { OAuth2Client } from '@/api/system/oauth2/client'
  64. import type { LoadMoreState } from '@/http/types'
  65. import { onMounted, ref } from 'vue'
  66. import { getOAuth2ClientPage } from '@/api/system/oauth2/client'
  67. import { useAccess } from '@/hooks/useAccess'
  68. import { DICT_TYPE } from '@/utils/constants'
  69. import { formatDateTime } from '@/utils/date'
  70. import ClientSearchForm from './client-search-form.vue'
  71. const { hasAccessByCodes } = useAccess()
  72. const total = ref(0)
  73. const list = ref<OAuth2Client[]>([])
  74. const loadMoreState = ref<LoadMoreState>('loading')
  75. const queryParams = ref({
  76. pageNo: 1,
  77. pageSize: 10,
  78. })
  79. /** 查询 OAuth2 客户端列表 */
  80. async function getList() {
  81. loadMoreState.value = 'loading'
  82. try {
  83. const data = await getOAuth2ClientPage(queryParams.value)
  84. list.value = [...list.value, ...data.list]
  85. total.value = data.total
  86. loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
  87. } catch {
  88. queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
  89. loadMoreState.value = 'error'
  90. }
  91. }
  92. /** 搜索按钮操作 */
  93. function handleQuery(data?: Record<string, any>) {
  94. queryParams.value = {
  95. ...data,
  96. pageNo: 1,
  97. pageSize: queryParams.value.pageSize,
  98. }
  99. list.value = []
  100. getList()
  101. }
  102. /** 重置按钮操作 */
  103. function handleReset() {
  104. handleQuery()
  105. }
  106. /** 加载更多 */
  107. function loadMore() {
  108. if (loadMoreState.value === 'finished') {
  109. return
  110. }
  111. queryParams.value.pageNo++
  112. getList()
  113. }
  114. /** 新增 OAuth2 客户端 */
  115. function handleAdd() {
  116. uni.navigateTo({
  117. url: '/pages-system/oauth2/client/form/index',
  118. })
  119. }
  120. /** 查看详情 */
  121. function handleDetail(item: OAuth2Client) {
  122. uni.navigateTo({
  123. url: `/pages-system/oauth2/client/detail/index?id=${item.id}`,
  124. })
  125. }
  126. /** 触底加载更多 */
  127. onReachBottom(() => {
  128. loadMore()
  129. })
  130. /** 初始化 */
  131. onMounted(() => {
  132. getList()
  133. })
  134. </script>