index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <script setup lang="ts">
  2. import { ref, unref } from 'vue'
  3. import dayjs from 'dayjs'
  4. import { ElMessage, ElImage, ElTag } from 'element-plus'
  5. import { DICT_TYPE } from '@/utils/dict'
  6. import { useTable } from '@/hooks/web/useTable'
  7. import { useI18n } from '@/hooks/web/useI18n'
  8. import { FormExpose } from '@/components/Form'
  9. import type { OAuth2ClientVo } from '@/api/system/oauth2/client.types'
  10. import { rules, allSchemas } from './client.data'
  11. import * as ClientApi from '@/api/system/oauth2/client'
  12. const { t } = useI18n() // 国际化
  13. // ========== 列表相关 ==========
  14. const { register, tableObject, methods } = useTable<OAuth2ClientVo>({
  15. getListApi: ClientApi.getOAuth2ClientPageApi,
  16. delListApi: ClientApi.deleteOAuth2ClientApi
  17. })
  18. const { getList, setSearchParams, delList } = methods
  19. // ========== CRUD 相关 ==========
  20. const actionLoading = ref(false) // 遮罩层
  21. const actionType = ref('') // 操作按钮的类型
  22. const dialogVisible = ref(false) // 是否显示弹出层
  23. const dialogTitle = ref('edit') // 弹出层标题
  24. const formRef = ref<FormExpose>() // 表单 Ref
  25. // 设置标题
  26. const setDialogTile = (type: string) => {
  27. dialogTitle.value = t('action.' + type)
  28. actionType.value = type
  29. dialogVisible.value = true
  30. }
  31. // 新增操作
  32. const handleCreate = () => {
  33. setDialogTile('create')
  34. // 重置表单
  35. unref(formRef)?.getElFormRef()?.resetFields()
  36. }
  37. // 修改操作
  38. const handleUpdate = async (row: OAuth2ClientVo) => {
  39. setDialogTile('update')
  40. // 设置数据
  41. const res = await ClientApi.getOAuth2ClientApi(row.id)
  42. unref(formRef)?.setValues(res)
  43. }
  44. // 提交按钮
  45. const submitForm = async () => {
  46. actionLoading.value = true
  47. // 提交请求
  48. try {
  49. const data = unref(formRef)?.formModel as OAuth2ClientVo
  50. if (actionType.value === 'create') {
  51. await ClientApi.createOAuth2ClientApi(data)
  52. ElMessage.success(t('common.createSuccess'))
  53. } else {
  54. await ClientApi.updateOAuth2ClientApi(data)
  55. ElMessage.success(t('common.updateSuccess'))
  56. }
  57. // 操作成功,重新加载列表
  58. dialogVisible.value = false
  59. await getList()
  60. } finally {
  61. actionLoading.value = false
  62. }
  63. }
  64. // ========== 详情相关 ==========
  65. const detailRef = ref() // 详情 Ref
  66. // 详情操作
  67. const handleDetail = async (row: OAuth2ClientVo) => {
  68. // 设置数据
  69. detailRef.value = row
  70. setDialogTile('detail')
  71. }
  72. // ========== 初始化 ==========
  73. getList()
  74. </script>
  75. <template>
  76. <!-- 搜索工作区 -->
  77. <ContentWrap>
  78. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  79. </ContentWrap>
  80. <ContentWrap>
  81. <!-- 操作工具栏 -->
  82. <div class="mb-10px">
  83. <el-button type="primary" v-hasPermi="['system:oauth2-client:create']" @click="handleCreate">
  84. <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
  85. </el-button>
  86. </div>
  87. <!-- 列表 -->
  88. <Table
  89. :columns="allSchemas.tableColumns"
  90. :selection="false"
  91. :data="tableObject.tableList"
  92. :loading="tableObject.loading"
  93. :pagination="{
  94. total: tableObject.total
  95. }"
  96. v-model:pageSize="tableObject.pageSize"
  97. v-model:currentPage="tableObject.currentPage"
  98. @register="register"
  99. >
  100. <template #logo="{ row }">
  101. <el-image :src="row.logo" :preview-src-list="[row.logo]" />
  102. </template>
  103. <template #status="{ row }">
  104. <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
  105. </template>
  106. <template #authorizedGrantTypes="{ row }">
  107. <el-tag
  108. :disable-transitions="true"
  109. :key="index"
  110. v-for="(authorizedGrantType, index) in row.authorizedGrantTypes"
  111. :index="index"
  112. >
  113. {{ authorizedGrantType }}
  114. </el-tag>
  115. </template>
  116. <template #createTime="{ row }">
  117. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  118. </template>
  119. <template #action="{ row }">
  120. <el-button
  121. link
  122. type="primary"
  123. v-hasPermi="['system:oauth2-client:update']"
  124. @click="handleUpdate(row)"
  125. >
  126. <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
  127. </el-button>
  128. <el-button
  129. link
  130. type="primary"
  131. v-hasPermi="['system:oauth2-client:update']"
  132. @click="handleDetail(row)"
  133. >
  134. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
  135. </el-button>
  136. <el-button
  137. link
  138. type="primary"
  139. v-hasPermi="['system:oauth2-client:delete']"
  140. @click="delList(row.id, false)"
  141. >
  142. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
  143. </el-button>
  144. </template>
  145. </Table>
  146. </ContentWrap>
  147. <Dialog v-model="dialogVisible" :title="dialogTitle" width="60%" maxHeight="420px">
  148. <!-- 对话框(添加 / 修改) -->
  149. <Form
  150. v-if="['create', 'update'].includes(actionType)"
  151. :schema="allSchemas.formSchema"
  152. :rules="rules"
  153. ref="formRef"
  154. />
  155. <!-- 对话框(详情) -->
  156. <Descriptions
  157. v-if="actionType === 'detail'"
  158. :schema="allSchemas.detailSchema"
  159. :data="detailRef"
  160. >
  161. <template #status="{ row }">
  162. <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
  163. </template>
  164. <template #createTime="{ row }">
  165. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  166. </template>
  167. </Descriptions>
  168. <!-- 操作按钮 -->
  169. <template #footer>
  170. <el-button
  171. v-if="['create', 'update'].includes(actionType)"
  172. type="primary"
  173. :loading="actionLoading"
  174. @click="submitForm"
  175. >
  176. {{ t('action.save') }}
  177. </el-button>
  178. <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
  179. </template>
  180. </Dialog>
  181. </template>