index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="名称" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. placeholder="请输入名称"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="平台" prop="platform">
  21. <el-select
  22. v-model="queryParams.platform"
  23. placeholder="请输入平台"
  24. clearable
  25. class="!w-240px"
  26. >
  27. <el-option
  28. v-for="dict in getStrDictOptions(DICT_TYPE.AI_PLATFORM)"
  29. :key="dict.value"
  30. :label="dict.label"
  31. :value="dict.value"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item label="状态" prop="status">
  36. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
  37. <el-option
  38. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  39. :key="dict.value"
  40. :label="dict.label"
  41. :value="dict.value"
  42. />
  43. </el-select>
  44. </el-form-item>
  45. <el-form-item>
  46. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  47. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  48. <el-button
  49. type="primary"
  50. plain
  51. @click="openForm('create')"
  52. v-hasPermi="['ai:api-key:create']"
  53. >
  54. <Icon icon="ep:plus" class="mr-5px" /> 新增
  55. </el-button>
  56. </el-form-item>
  57. </el-form>
  58. </ContentWrap>
  59. <!-- 列表 -->
  60. <ContentWrap>
  61. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  62. <el-table-column label="所属平台" align="center" prop="platform">
  63. <template #default="scope">
  64. <dict-tag :type="DICT_TYPE.AI_PLATFORM" :value="scope.row.platform" />
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="名称" align="center" prop="name" />
  68. <el-table-column label="密钥" align="center" prop="apiKey" />
  69. <el-table-column label="自定义 API URL" align="center" prop="url" />
  70. <el-table-column label="状态" align="center" prop="status">
  71. <template #default="scope">
  72. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="操作" align="center">
  76. <template #default="scope">
  77. <el-button
  78. link
  79. type="primary"
  80. @click="openForm('update', scope.row.id)"
  81. v-hasPermi="['ai:api-key:update']"
  82. >
  83. 编辑
  84. </el-button>
  85. <el-button
  86. link
  87. type="danger"
  88. @click="handleDelete(scope.row.id)"
  89. v-hasPermi="['ai:api-key:delete']"
  90. >
  91. 删除
  92. </el-button>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <!-- 分页 -->
  97. <Pagination
  98. :total="total"
  99. v-model:page="queryParams.pageNo"
  100. v-model:limit="queryParams.pageSize"
  101. @pagination="getList"
  102. />
  103. </ContentWrap>
  104. <!-- 表单弹窗:添加/修改 -->
  105. <ApiKeyForm ref="formRef" @success="getList" />
  106. </template>
  107. <script setup lang="ts">
  108. import { getIntDictOptions, DICT_TYPE, getStrDictOptions } from '@/utils/dict'
  109. import { ApiKeyApi, ApiKeyVO } from '@/api/ai/model/apiKey'
  110. import ApiKeyForm from './ApiKeyForm.vue'
  111. /** AI API 密钥 列表 */
  112. defineOptions({ name: 'AiApiKey' })
  113. const message = useMessage() // 消息弹窗
  114. const { t } = useI18n() // 国际化
  115. const loading = ref(true) // 列表的加载中
  116. const list = ref<ApiKeyVO[]>([]) // 列表的数据
  117. const total = ref(0) // 列表的总页数
  118. const queryParams = reactive({
  119. pageNo: 1,
  120. pageSize: 10,
  121. name: undefined,
  122. platform: undefined,
  123. status: undefined
  124. })
  125. const queryFormRef = ref() // 搜索的表单
  126. /** 查询列表 */
  127. const getList = async () => {
  128. loading.value = true
  129. try {
  130. const data = await ApiKeyApi.getApiKeyPage(queryParams)
  131. list.value = data.list
  132. total.value = data.total
  133. } finally {
  134. loading.value = false
  135. }
  136. }
  137. /** 搜索按钮操作 */
  138. const handleQuery = () => {
  139. queryParams.pageNo = 1
  140. getList()
  141. }
  142. /** 重置按钮操作 */
  143. const resetQuery = () => {
  144. queryFormRef.value.resetFields()
  145. handleQuery()
  146. }
  147. /** 添加/修改操作 */
  148. const formRef = ref()
  149. const openForm = (type: string, id?: number) => {
  150. formRef.value.open(type, id)
  151. }
  152. /** 删除按钮操作 */
  153. const handleDelete = async (id: number) => {
  154. try {
  155. // 删除的二次确认
  156. await message.delConfirm()
  157. // 发起删除
  158. await ApiKeyApi.deleteApiKey(id)
  159. message.success(t('common.delSuccess'))
  160. // 刷新列表
  161. await getList()
  162. } catch {}
  163. }
  164. /** 初始化 **/
  165. onMounted(() => {
  166. getList()
  167. })
  168. </script>