index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <doc-alert title="OAuth 2.0(SSO 单点登录)" url="https://doc.iocoder.cn/oauth2/" />
  3. <!-- 搜索 -->
  4. <ContentWrap>
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="68px"
  11. >
  12. <el-form-item label="应用名" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. placeholder="请输入应用名"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. class="!w-240px"
  19. />
  20. </el-form-item>
  21. <el-form-item label="状态" prop="status">
  22. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
  23. <el-option
  24. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  25. :key="dict.value"
  26. :label="dict.label"
  27. :value="dict.value"
  28. />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  33. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  34. <el-button
  35. plain
  36. type="primary"
  37. @click="openForm('create')"
  38. v-hasPermi="['system:oauth2-client:create']"
  39. >
  40. <Icon icon="ep:plus" class="mr-5px" /> 新增
  41. </el-button>
  42. </el-form-item>
  43. </el-form>
  44. </ContentWrap>
  45. <!-- 列表 -->
  46. <ContentWrap>
  47. <el-table v-loading="loading" :data="list">
  48. <el-table-column label="客户端编号" align="center" prop="clientId" />
  49. <el-table-column label="客户端密钥" align="center" prop="secret" />
  50. <el-table-column label="应用名" align="center" prop="name" />
  51. <el-table-column label="应用图标" align="center" prop="logo">
  52. <template #default="scope">
  53. <img width="40px" height="40px" :src="scope.row.logo" />
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="状态" align="center" prop="status">
  57. <template #default="scope">
  58. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="访问令牌的有效期" align="center" prop="accessTokenValiditySeconds">
  62. <template #default="scope">{{ scope.row.accessTokenValiditySeconds }} 秒</template>
  63. </el-table-column>
  64. <el-table-column label="刷新令牌的有效期" align="center" prop="refreshTokenValiditySeconds">
  65. <template #default="scope">{{ scope.row.refreshTokenValiditySeconds }} 秒</template>
  66. </el-table-column>
  67. <el-table-column label="授权类型" align="center" prop="authorizedGrantTypes">
  68. <template #default="scope">
  69. <el-tag
  70. :disable-transitions="true"
  71. :key="index"
  72. v-for="(authorizedGrantType, index) in scope.row.authorizedGrantTypes"
  73. :index="index"
  74. class="mr-5px"
  75. >
  76. {{ authorizedGrantType }}
  77. </el-tag>
  78. </template>
  79. </el-table-column>
  80. <el-table-column
  81. label="创建时间"
  82. align="center"
  83. prop="createTime"
  84. width="180"
  85. :formatter="dateFormatter"
  86. />
  87. <el-table-column label="操作" align="center">
  88. <template #default="scope">
  89. <el-button
  90. link
  91. type="primary"
  92. @click="openForm('update', scope.row.id)"
  93. v-hasPermi="['system:oauth2-client:update']"
  94. >
  95. 编辑
  96. </el-button>
  97. <el-button
  98. link
  99. type="danger"
  100. @click="handleDelete(scope.row.id)"
  101. v-hasPermi="['system:oauth2-client:delete']"
  102. >
  103. 删除
  104. </el-button>
  105. </template>
  106. </el-table-column>
  107. </el-table>
  108. <!-- 分页 -->
  109. <Pagination
  110. :total="total"
  111. v-model:page="queryParams.pageNo"
  112. v-model:limit="queryParams.pageSize"
  113. @pagination="getList"
  114. />
  115. </ContentWrap>
  116. <!-- 表单弹窗:添加/修改 -->
  117. <ClientForm ref="formRef" @success="getList" />
  118. </template>
  119. <script setup lang="ts" name="SystemOAuth2Client">
  120. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  121. import { dateFormatter } from '@/utils/formatTime'
  122. import * as ClientApi from '@/api/system/oauth2/client'
  123. import ClientForm from './ClientForm.vue'
  124. const message = useMessage() // 消息弹窗
  125. const { t } = useI18n() // 国际化
  126. const loading = ref(true) // 列表的加载中
  127. const total = ref(0) // 列表的总页数
  128. const list = ref([]) // 列表的数据
  129. const queryParams = reactive({
  130. pageNo: 1,
  131. pageSize: 10,
  132. name: null,
  133. status: null
  134. })
  135. const queryFormRef = ref() // 搜索的表单
  136. /** 查询列表 */
  137. const getList = async () => {
  138. loading.value = true
  139. try {
  140. const data = await ClientApi.getOAuth2ClientPage(queryParams)
  141. list.value = data.list
  142. total.value = data.total
  143. } finally {
  144. loading.value = false
  145. }
  146. }
  147. /** 搜索按钮操作 */
  148. const handleQuery = () => {
  149. queryParams.pageNo = 1
  150. getList()
  151. }
  152. /** 重置按钮操作 */
  153. const resetQuery = () => {
  154. queryFormRef.value.resetFields()
  155. handleQuery()
  156. }
  157. /** 添加/修改操作 */
  158. const formRef = ref()
  159. const openForm = (type: string, id?: number) => {
  160. formRef.value.open(type, id)
  161. }
  162. /** 删除按钮操作 */
  163. const handleDelete = async (id: number) => {
  164. try {
  165. // 删除的二次确认
  166. await message.delConfirm()
  167. // 发起删除
  168. await ClientApi.deleteOAuth2Client(id)
  169. message.success(t('common.delSuccess'))
  170. // 刷新列表
  171. await getList()
  172. } catch {}
  173. }
  174. /** 初始化 **/
  175. onMounted(() => {
  176. getList()
  177. })
  178. </script>