index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <XTable @register="registerTable">
  5. <template #toolbar_buttons>
  6. <!-- 操作:新增 -->
  7. <XButton
  8. type="primary"
  9. preIcon="ep:zoom-in"
  10. :title="t('action.add')"
  11. v-hasPermi="['system:oauth2-client:create']"
  12. @click="handleCreate()"
  13. />
  14. </template>
  15. <template #accessTokenValiditySeconds_default="{ row }">
  16. {{ row.accessTokenValiditySeconds + '秒' }}
  17. </template>
  18. <template #refreshTokenValiditySeconds_default="{ row }">
  19. {{ row.refreshTokenValiditySeconds + '秒' }}
  20. </template>
  21. <template #authorizedGrantTypes_default="{ row }">
  22. <el-tag
  23. :disable-transitions="true"
  24. :key="index"
  25. v-for="(authorizedGrantType, index) in row.authorizedGrantTypes"
  26. :index="index"
  27. >
  28. {{ authorizedGrantType }}
  29. </el-tag>
  30. </template>
  31. <template #actionbtns_default="{ row }">
  32. <!-- 操作:修改 -->
  33. <XTextButton
  34. preIcon="ep:edit"
  35. :title="t('action.edit')"
  36. v-hasPermi="['system:oauth2-client:update']"
  37. @click="handleUpdate(row.id)"
  38. />
  39. <!-- 操作:详情 -->
  40. <XTextButton
  41. preIcon="ep:view"
  42. :title="t('action.detail')"
  43. v-hasPermi="['system:oauth2-client:query']"
  44. @click="handleDetail(row.id)"
  45. />
  46. <!-- 操作:删除 -->
  47. <XTextButton
  48. preIcon="ep:delete"
  49. :title="t('action.del')"
  50. v-hasPermi="['system:oauth2-client:delete']"
  51. @click="deleteData(row.id)"
  52. />
  53. </template>
  54. </XTable>
  55. </ContentWrap>
  56. <!-- 弹窗 -->
  57. <XModal id="postModel" v-model="dialogVisible" :title="dialogTitle">
  58. <!-- 表单:添加/修改 -->
  59. <Form
  60. ref="formRef"
  61. v-if="['create', 'update'].includes(actionType)"
  62. :schema="allSchemas.formSchema"
  63. :rules="rules"
  64. />
  65. <!-- 表单:详情 -->
  66. <Descriptions
  67. v-if="actionType === 'detail'"
  68. :schema="allSchemas.detailSchema"
  69. :data="detailData"
  70. >
  71. <template #accessTokenValiditySeconds="{ row }">
  72. {{ row.accessTokenValiditySeconds + '秒' }}
  73. </template>
  74. <template #refreshTokenValiditySeconds="{ row }">
  75. {{ row.refreshTokenValiditySeconds + '秒' }}
  76. </template>
  77. <template #authorizedGrantTypes="{ row }">
  78. <el-tag
  79. :disable-transitions="true"
  80. :key="index"
  81. v-for="(authorizedGrantType, index) in row.authorizedGrantTypes"
  82. :index="index"
  83. >
  84. {{ authorizedGrantType }}
  85. </el-tag>
  86. </template>
  87. <template #scopes="{ row }">
  88. <el-tag
  89. :disable-transitions="true"
  90. :key="index"
  91. v-for="(scopes, index) in row.scopes"
  92. :index="index"
  93. >
  94. {{ scopes }}
  95. </el-tag>
  96. </template>
  97. <template #autoApproveScopes="{ row }">
  98. <el-tag
  99. :disable-transitions="true"
  100. :key="index"
  101. v-for="(autoApproveScopes, index) in row.autoApproveScopes"
  102. :index="index"
  103. >
  104. {{ autoApproveScopes }}
  105. </el-tag>
  106. </template>
  107. <template #redirectUris="{ row }">
  108. <el-tag
  109. :disable-transitions="true"
  110. :key="index"
  111. v-for="(redirectUris, index) in row.redirectUris"
  112. :index="index"
  113. >
  114. {{ redirectUris }}
  115. </el-tag>
  116. </template>
  117. </Descriptions>
  118. <template #footer>
  119. <!-- 按钮:保存 -->
  120. <XButton
  121. v-if="['create', 'update'].includes(actionType)"
  122. type="primary"
  123. :title="t('action.save')"
  124. :loading="actionLoading"
  125. @click="submitForm()"
  126. />
  127. <!-- 按钮:关闭 -->
  128. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  129. </template>
  130. </XModal>
  131. </template>
  132. <script setup lang="ts" name="Client">
  133. // 全局相关的 import
  134. import { useI18n } from '@/hooks/web/useI18n'
  135. import { useMessage } from '@/hooks/web/useMessage'
  136. import { useXTable } from '@/hooks/web/useXTable'
  137. import type { FormExpose } from '@/components/Form'
  138. // 业务相关的 import
  139. import * as ClientApi from '@/api/system/oauth2/client'
  140. import { rules, allSchemas } from './client.data'
  141. const { t } = useI18n() // 国际化
  142. const message = useMessage() // 消息弹窗
  143. // 列表相关的变量
  144. const [registerTable, { reload, deleteData }] = useXTable({
  145. allSchemas: allSchemas,
  146. getListApi: ClientApi.getOAuth2ClientPageApi,
  147. deleteApi: ClientApi.deleteOAuth2ClientApi
  148. })
  149. // 弹窗相关的变量
  150. const dialogVisible = ref(false) // 是否显示弹出层
  151. const dialogTitle = ref('edit') // 弹出层标题
  152. const actionType = ref('') // 操作按钮的类型
  153. const actionLoading = ref(false) // 按钮 Loading
  154. const formRef = ref<FormExpose>() // 表单 Ref
  155. const detailData = ref() // 详情 Ref
  156. // 设置标题
  157. const setDialogTile = (type: string) => {
  158. dialogTitle.value = t('action.' + type)
  159. actionType.value = type
  160. dialogVisible.value = true
  161. }
  162. // 新增操作
  163. const handleCreate = () => {
  164. setDialogTile('create')
  165. }
  166. // 修改操作
  167. const handleUpdate = async (rowId: number) => {
  168. setDialogTile('update')
  169. // 设置数据
  170. const res = await ClientApi.getOAuth2ClientApi(rowId)
  171. unref(formRef)?.setValues(res)
  172. }
  173. // 详情操作
  174. const handleDetail = async (rowId: number) => {
  175. setDialogTile('detail')
  176. const res = await ClientApi.getOAuth2ClientApi(rowId)
  177. detailData.value = res
  178. }
  179. // 提交新增/修改的表单
  180. const submitForm = async () => {
  181. const elForm = unref(formRef)?.getElFormRef()
  182. if (!elForm) return
  183. elForm.validate(async (valid) => {
  184. if (valid) {
  185. actionLoading.value = true
  186. // 提交请求
  187. try {
  188. const data = unref(formRef)?.formModel as ClientApi.OAuth2ClientVO
  189. if (actionType.value === 'create') {
  190. await ClientApi.createOAuth2ClientApi(data)
  191. message.success(t('common.createSuccess'))
  192. } else {
  193. await ClientApi.updateOAuth2ClientApi(data)
  194. message.success(t('common.updateSuccess'))
  195. }
  196. dialogVisible.value = false
  197. } finally {
  198. actionLoading.value = false
  199. // 刷新列表
  200. await reload()
  201. }
  202. }
  203. })
  204. }
  205. </script>