index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
  5. <!-- 操作:新增 -->
  6. <template #toolbar_buttons>
  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 #authorizedGrantTypes="{ row }">
  16. <el-tag
  17. :disable-transitions="true"
  18. :key="index"
  19. v-for="(authorizedGrantType, index) in row.authorizedGrantTypes"
  20. :index="index"
  21. >
  22. {{ authorizedGrantType }}
  23. </el-tag>
  24. </template>
  25. <template #actionbtns_default="{ row }">
  26. <!-- 操作:修改 -->
  27. <XTextButton
  28. preIcon="ep:edit"
  29. :title="t('action.edit')"
  30. v-hasPermi="['system:oauth2-client:update']"
  31. @click="handleUpdate(row.id)"
  32. />
  33. <!-- 操作:详情 -->
  34. <XTextButton
  35. preIcon="ep:view"
  36. :title="t('action.detail')"
  37. v-hasPermi="['system:oauth2-client:update']"
  38. @click="handleDetail(row.id)"
  39. />
  40. <!-- 操作:删除 -->
  41. <XTextButton
  42. preIcon="ep:delete"
  43. :title="t('action.del')"
  44. v-hasPermi="['system:oauth2-client:delete']"
  45. @click="handleDelete(row.id)"
  46. />
  47. </template>
  48. </vxe-grid>
  49. </ContentWrap>
  50. <!-- 弹窗 -->
  51. <XModal id="postModel" v-model="dialogVisible" :title="dialogTitle">
  52. <!-- 表单:添加/修改 -->
  53. <Form
  54. ref="formRef"
  55. v-if="['create', 'update'].includes(actionType)"
  56. :schema="allSchemas.formSchema"
  57. :rules="rules"
  58. />
  59. <!-- 表单:详情 -->
  60. <Descriptions
  61. v-if="actionType === 'detail'"
  62. :schema="allSchemas.detailSchema"
  63. :data="detailRef"
  64. />
  65. <template #footer>
  66. <!-- 按钮:保存 -->
  67. <XButton
  68. v-if="['create', 'update'].includes(actionType)"
  69. type="primary"
  70. :title="t('action.save')"
  71. :loading="actionLoading"
  72. @click="submitForm"
  73. />
  74. <!-- 按钮:关闭 -->
  75. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  76. </template>
  77. </XModal>
  78. </template>
  79. <script setup lang="ts">
  80. // 全局相关的 import
  81. import { ref, unref } from 'vue'
  82. import { ElTag } from 'element-plus'
  83. import { useI18n } from '@/hooks/web/useI18n'
  84. import { useMessage } from '@/hooks/web/useMessage'
  85. import { useVxeGrid } from '@/hooks/web/useVxeGrid'
  86. import { VxeGridInstance } from 'vxe-table'
  87. import { FormExpose } from '@/components/Form'
  88. // 业务相关的 import
  89. import * as ClientApi from '@/api/system/oauth2/client'
  90. import { rules, allSchemas } from './client.data'
  91. const { t } = useI18n() // 国际化
  92. const message = useMessage() // 消息弹窗
  93. // 列表相关的变量
  94. const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
  95. const { gridOptions } = useVxeGrid<ClientApi.OAuth2ClientVO>({
  96. allSchemas: allSchemas,
  97. getListApi: ClientApi.getOAuth2ClientPageApi
  98. })
  99. // 弹窗相关的变量
  100. const dialogVisible = ref(false) // 是否显示弹出层
  101. const dialogTitle = ref('edit') // 弹出层标题
  102. const actionType = ref('') // 操作按钮的类型
  103. const actionLoading = ref(false) // 按钮 Loading
  104. const formRef = ref<FormExpose>() // 表单 Ref
  105. const detailRef = ref() // 详情 Ref
  106. // 设置标题
  107. const setDialogTile = (type: string) => {
  108. dialogTitle.value = t('action.' + type)
  109. actionType.value = type
  110. dialogVisible.value = true
  111. }
  112. // 新增操作
  113. const handleCreate = () => {
  114. setDialogTile('create')
  115. }
  116. // 修改操作
  117. const handleUpdate = async (rowId: number) => {
  118. setDialogTile('update')
  119. // 设置数据
  120. const res = await ClientApi.getOAuth2ClientApi(rowId)
  121. unref(formRef)?.setValues(res)
  122. }
  123. // 详情操作
  124. const handleDetail = async (rowId: number) => {
  125. setDialogTile('detail')
  126. const res = await ClientApi.getOAuth2ClientApi(rowId)
  127. detailRef.value = res
  128. }
  129. // 删除操作
  130. const handleDelete = async (rowId: number) => {
  131. message
  132. .delConfirm()
  133. .then(async () => {
  134. await ClientApi.deleteOAuth2ClientApi(rowId)
  135. message.success(t('common.delSuccess'))
  136. })
  137. .finally(() => {
  138. // 刷新列表
  139. xGrid.value?.commitProxy('query')
  140. })
  141. }
  142. // 提交新增/修改的表单
  143. const submitForm = async () => {
  144. const elForm = unref(formRef)?.getElFormRef()
  145. if (!elForm) return
  146. elForm.validate(async (valid) => {
  147. if (valid) {
  148. actionLoading.value = true
  149. // 提交请求
  150. try {
  151. const data = unref(formRef)?.formModel as ClientApi.OAuth2ClientVO
  152. if (actionType.value === 'create') {
  153. await ClientApi.createOAuth2ClientApi(data)
  154. message.success(t('common.createSuccess'))
  155. } else {
  156. await ClientApi.updateOAuth2ClientApi(data)
  157. message.success(t('common.updateSuccess'))
  158. }
  159. dialogVisible.value = false
  160. } finally {
  161. actionLoading.value = false
  162. // 刷新列表
  163. xGrid.value?.commitProxy('query')
  164. }
  165. }
  166. })
  167. }
  168. </script>