index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
  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="handleDelete(row.id)"
  52. />
  53. </template>
  54. </vxe-grid>
  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. <template #logo>
  66. <UploadImg :imgs="uploadLogo" :limit="1" />
  67. </template>
  68. </Form>
  69. <!-- 表单:详情 -->
  70. <Descriptions
  71. v-if="actionType === 'detail'"
  72. :schema="allSchemas.detailSchema"
  73. :data="detailRef"
  74. >
  75. <template #accessTokenValiditySeconds="{ row }">
  76. {{ row.accessTokenValiditySeconds + '秒' }}
  77. </template>
  78. <template #refreshTokenValiditySeconds="{ row }">
  79. {{ row.refreshTokenValiditySeconds + '秒' }}
  80. </template>
  81. <template #authorizedGrantTypes="{ row }">
  82. <el-tag
  83. :disable-transitions="true"
  84. :key="index"
  85. v-for="(authorizedGrantType, index) in row.authorizedGrantTypes"
  86. :index="index"
  87. >
  88. {{ authorizedGrantType }}
  89. </el-tag>
  90. </template>
  91. <template #scopes="{ row }">
  92. <el-tag
  93. :disable-transitions="true"
  94. :key="index"
  95. v-for="(scopes, index) in row.scopes"
  96. :index="index"
  97. >
  98. {{ scopes }}
  99. </el-tag>
  100. </template>
  101. <template #autoApproveScopes="{ row }">
  102. <el-tag
  103. :disable-transitions="true"
  104. :key="index"
  105. v-for="(autoApproveScopes, index) in row.autoApproveScopes"
  106. :index="index"
  107. >
  108. {{ autoApproveScopes }}
  109. </el-tag>
  110. </template>
  111. <template #redirectUris="{ row }">
  112. <el-tag
  113. :disable-transitions="true"
  114. :key="index"
  115. v-for="(redirectUris, index) in row.redirectUris"
  116. :index="index"
  117. >
  118. {{ redirectUris }}
  119. </el-tag>
  120. </template>
  121. </Descriptions>
  122. <template #footer>
  123. <!-- 按钮:保存 -->
  124. <XButton
  125. v-if="['create', 'update'].includes(actionType)"
  126. type="primary"
  127. :title="t('action.save')"
  128. :loading="actionLoading"
  129. @click="submitForm()"
  130. />
  131. <!-- 按钮:关闭 -->
  132. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  133. </template>
  134. </XModal>
  135. </template>
  136. <script setup lang="ts" name="Client">
  137. // 全局相关的 import
  138. import { ref, unref } from 'vue'
  139. import { ElTag } from 'element-plus'
  140. import { useI18n } from '@/hooks/web/useI18n'
  141. import { useMessage } from '@/hooks/web/useMessage'
  142. import { useVxeGrid } from '@/hooks/web/useVxeGrid'
  143. import { VxeGridInstance } from 'vxe-table'
  144. import { FormExpose } from '@/components/Form'
  145. import { UploadImg } from '@/components/UploadFile'
  146. // 业务相关的 import
  147. import * as ClientApi from '@/api/system/oauth2/client'
  148. import { rules, allSchemas } from './client.data'
  149. const { t } = useI18n() // 国际化
  150. const message = useMessage() // 消息弹窗
  151. // 列表相关的变量
  152. const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
  153. const { gridOptions, getList, deleteData } = useVxeGrid<ClientApi.OAuth2ClientVO>({
  154. allSchemas: allSchemas,
  155. getListApi: ClientApi.getOAuth2ClientPageApi,
  156. deleteApi: ClientApi.deleteOAuth2ClientApi
  157. })
  158. // 弹窗相关的变量
  159. const dialogVisible = ref(false) // 是否显示弹出层
  160. const dialogTitle = ref('edit') // 弹出层标题
  161. const actionType = ref('') // 操作按钮的类型
  162. const actionLoading = ref(false) // 按钮 Loading
  163. const formRef = ref<FormExpose>() // 表单 Ref
  164. const detailRef = ref() // 详情 Ref
  165. const uploadLogo = ref('')
  166. // 设置标题
  167. const setDialogTile = (type: string) => {
  168. dialogTitle.value = t('action.' + type)
  169. actionType.value = type
  170. dialogVisible.value = true
  171. }
  172. // 新增操作
  173. const handleCreate = () => {
  174. uploadLogo.value = ''
  175. setDialogTile('create')
  176. }
  177. // 修改操作
  178. const handleUpdate = async (rowId: number) => {
  179. setDialogTile('update')
  180. // 设置数据
  181. const res = await ClientApi.getOAuth2ClientApi(rowId)
  182. uploadLogo.value = res.logo
  183. unref(formRef)?.setValues(res)
  184. }
  185. // 详情操作
  186. const handleDetail = async (rowId: number) => {
  187. setDialogTile('detail')
  188. const res = await ClientApi.getOAuth2ClientApi(rowId)
  189. detailRef.value = res
  190. }
  191. // 删除操作
  192. const handleDelete = async (rowId: number) => {
  193. await deleteData(xGrid, rowId)
  194. }
  195. // 提交新增/修改的表单
  196. const submitForm = async () => {
  197. const elForm = unref(formRef)?.getElFormRef()
  198. if (!elForm) return
  199. elForm.validate(async (valid) => {
  200. if (valid) {
  201. actionLoading.value = true
  202. // 提交请求
  203. try {
  204. const data = unref(formRef)?.formModel as ClientApi.OAuth2ClientVO
  205. data.logo = uploadLogo.value
  206. if (actionType.value === 'create') {
  207. await ClientApi.createOAuth2ClientApi(data)
  208. message.success(t('common.createSuccess'))
  209. } else {
  210. await ClientApi.updateOAuth2ClientApi(data)
  211. message.success(t('common.updateSuccess'))
  212. }
  213. dialogVisible.value = false
  214. } finally {
  215. actionLoading.value = false
  216. // 刷新列表
  217. await getList(xGrid)
  218. }
  219. }
  220. })
  221. }
  222. </script>