index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. <template #default>
  53. <!-- 表单:添加/修改 -->
  54. <Form
  55. ref="formRef"
  56. v-if="['create', 'update'].includes(actionType)"
  57. :schema="allSchemas.formSchema"
  58. :rules="rules"
  59. />
  60. <!-- 表单:详情 -->
  61. <!-- TODO @星语:展示详情时,有点小丑,可额能得看看 -->
  62. <Descriptions
  63. v-if="actionType === 'detail'"
  64. :schema="allSchemas.detailSchema"
  65. :data="detailRef"
  66. />
  67. </template>
  68. <template #footer>
  69. <!-- 按钮:保存 -->
  70. <XButton
  71. v-if="['create', 'update'].includes(actionType)"
  72. type="primary"
  73. :title="t('action.save')"
  74. :loading="actionLoading"
  75. @click="submitForm"
  76. />
  77. <!-- 按钮:关闭 -->
  78. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  79. </template>
  80. </XModal>
  81. </template>
  82. <script setup lang="ts">
  83. // 全局相关的 import
  84. import { ref, unref } from 'vue'
  85. import { ElTag } from 'element-plus'
  86. import { useI18n } from '@/hooks/web/useI18n'
  87. import { useMessage } from '@/hooks/web/useMessage'
  88. import { useVxeGrid } from '@/hooks/web/useVxeGrid'
  89. import { VxeGridInstance } from 'vxe-table'
  90. import { FormExpose } from '@/components/Form'
  91. // 业务相关的 import
  92. import * as ClientApi from '@/api/system/oauth2/client'
  93. import { rules, allSchemas } from './client.data'
  94. const { t } = useI18n() // 国际化
  95. const message = useMessage() // 消息弹窗
  96. // 列表相关的变量
  97. const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
  98. const { gridOptions } = useVxeGrid<ClientApi.OAuth2ClientVO>({
  99. allSchemas: allSchemas,
  100. getListApi: ClientApi.getOAuth2ClientPageApi
  101. })
  102. // 弹窗相关的变量
  103. const dialogVisible = ref(false) // 是否显示弹出层
  104. const dialogTitle = ref('edit') // 弹出层标题
  105. const actionType = ref('') // 操作按钮的类型
  106. const actionLoading = ref(false) // 按钮 Loading
  107. const formRef = ref<FormExpose>() // 表单 Ref
  108. const detailRef = ref() // 详情 Ref
  109. // 设置标题
  110. const setDialogTile = (type: string) => {
  111. dialogTitle.value = t('action.' + type)
  112. actionType.value = type
  113. dialogVisible.value = true
  114. }
  115. // 新增操作
  116. const handleCreate = () => {
  117. setDialogTile('create')
  118. // 重置表单
  119. unref(formRef)?.getElFormRef()?.resetFields()
  120. }
  121. // 修改操作
  122. const handleUpdate = async (rowId: number) => {
  123. setDialogTile('update')
  124. // 设置数据
  125. const res = await ClientApi.getOAuth2ClientApi(rowId)
  126. unref(formRef)?.setValues(res)
  127. }
  128. // 详情操作
  129. const handleDetail = async (rowId: number) => {
  130. setDialogTile('detail')
  131. const res = await ClientApi.getOAuth2ClientApi(rowId)
  132. detailRef.value = res
  133. }
  134. // 删除操作
  135. const handleDelete = async (rowId: number) => {
  136. message
  137. .delConfirm()
  138. .then(async () => {
  139. await ClientApi.deleteOAuth2ClientApi(rowId)
  140. message.success(t('common.delSuccess'))
  141. })
  142. .finally(() => {
  143. // 刷新列表
  144. xGrid.value?.commitProxy('query')
  145. })
  146. }
  147. // 提交新增/修改的表单
  148. const submitForm = async () => {
  149. const elForm = unref(formRef)?.getElFormRef()
  150. if (!elForm) return
  151. elForm.validate(async (valid) => {
  152. if (valid) {
  153. actionLoading.value = true
  154. // 提交请求
  155. try {
  156. const data = unref(formRef)?.formModel as ClientApi.OAuth2ClientVO
  157. if (actionType.value === 'create') {
  158. await ClientApi.createOAuth2ClientApi(data)
  159. message.success(t('common.createSuccess'))
  160. } else {
  161. await ClientApi.updateOAuth2ClientApi(data)
  162. message.success(t('common.updateSuccess'))
  163. }
  164. dialogVisible.value = false
  165. } finally {
  166. actionLoading.value = false
  167. // 刷新列表
  168. xGrid.value?.commitProxy('query')
  169. }
  170. }
  171. })
  172. }
  173. </script>