index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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="model">
  21. <el-input
  22. v-model="queryParams.model"
  23. placeholder="请输入模型标识"
  24. clearable
  25. @keyup.enter="handleQuery"
  26. class="!w-240px"
  27. />
  28. </el-form-item>
  29. <el-form-item label="模型平台" prop="platform">
  30. <el-input
  31. v-model="queryParams.platform"
  32. placeholder="请输入模型平台"
  33. clearable
  34. @keyup.enter="handleQuery"
  35. class="!w-240px"
  36. />
  37. </el-form-item>
  38. <el-form-item>
  39. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  40. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  41. <el-button
  42. type="primary"
  43. plain
  44. @click="openForm('create')"
  45. v-hasPermi="['ai:chat-model:create']"
  46. >
  47. <Icon icon="ep:plus" class="mr-5px" /> 新增
  48. </el-button>
  49. </el-form-item>
  50. </el-form>
  51. </ContentWrap>
  52. <!-- 列表 -->
  53. <ContentWrap>
  54. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  55. <el-table-column label="所属平台" align="center" prop="platform">
  56. <template #default="scope">
  57. <dict-tag :type="DICT_TYPE.AI_PLATFORM" :value="scope.row.platform" />
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="模型名字" align="center" prop="name" />
  61. <el-table-column label="模型标识" align="center" prop="model" />
  62. <el-table-column label="API 秘钥" align="center" prop="keyId" min-width="140">
  63. <template #default="scope">
  64. <span>{{ apiKeyList.find((item) => item.id === scope.row.keyId)?.name }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="排序" align="center" prop="sort" />
  68. <el-table-column label="状态" align="center" prop="status">
  69. <template #default="scope">
  70. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="温度参数" align="center" prop="temperature" />
  74. <el-table-column label="回复数 Token 数" align="center" prop="maxTokens" min-width="140" />
  75. <el-table-column label="上下文数量" align="center" prop="maxContexts" />
  76. <el-table-column label="操作" align="center">
  77. <template #default="scope">
  78. <el-button
  79. link
  80. type="primary"
  81. @click="openForm('update', scope.row.id)"
  82. v-hasPermi="['ai:chat-model:update']"
  83. >
  84. 编辑
  85. </el-button>
  86. <el-button
  87. link
  88. type="danger"
  89. @click="handleDelete(scope.row.id)"
  90. v-hasPermi="['ai:chat-model:delete']"
  91. >
  92. 删除
  93. </el-button>
  94. </template>
  95. </el-table-column>
  96. </el-table>
  97. <!-- 分页 -->
  98. <Pagination
  99. :total="total"
  100. v-model:page="queryParams.pageNo"
  101. v-model:limit="queryParams.pageSize"
  102. @pagination="getList"
  103. />
  104. </ContentWrap>
  105. <!-- 表单弹窗:添加/修改 -->
  106. <ChatModelForm ref="formRef" @success="getList" />
  107. </template>
  108. <script setup lang="ts">
  109. import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel'
  110. import ChatModelForm from './ChatModelForm.vue'
  111. import { DICT_TYPE } from '@/utils/dict'
  112. import { ApiKeyApi, ApiKeyVO } from '@/api/ai/model/apiKey'
  113. /** API 聊天模型 列表 */
  114. defineOptions({ name: 'AiChatModel' })
  115. const message = useMessage() // 消息弹窗
  116. const { t } = useI18n() // 国际化
  117. const loading = ref(true) // 列表的加载中
  118. const list = ref<ChatModelVO[]>([]) // 列表的数据
  119. const total = ref(0) // 列表的总页数
  120. const queryParams = reactive({
  121. pageNo: 1,
  122. pageSize: 10,
  123. name: undefined,
  124. model: undefined,
  125. platform: undefined
  126. })
  127. const queryFormRef = ref() // 搜索的表单
  128. const apiKeyList = ref([] as ApiKeyVO[]) // API 密钥列表
  129. /** 查询列表 */
  130. const getList = async () => {
  131. loading.value = true
  132. try {
  133. const data = await ChatModelApi.getChatModelPage(queryParams)
  134. list.value = data.list
  135. total.value = data.total
  136. } finally {
  137. loading.value = false
  138. }
  139. }
  140. /** 搜索按钮操作 */
  141. const handleQuery = () => {
  142. queryParams.pageNo = 1
  143. getList()
  144. }
  145. /** 重置按钮操作 */
  146. const resetQuery = () => {
  147. queryFormRef.value.resetFields()
  148. handleQuery()
  149. }
  150. /** 添加/修改操作 */
  151. const formRef = ref()
  152. const openForm = (type: string, id?: number) => {
  153. formRef.value.open(type, id)
  154. }
  155. /** 删除按钮操作 */
  156. const handleDelete = async (id: number) => {
  157. try {
  158. // 删除的二次确认
  159. await message.delConfirm()
  160. // 发起删除
  161. await ChatModelApi.deleteChatModel(id)
  162. message.success(t('common.delSuccess'))
  163. // 刷新列表
  164. await getList()
  165. } catch {}
  166. }
  167. /** 初始化 **/
  168. onMounted(async () => {
  169. getList()
  170. // 获得下拉数据
  171. apiKeyList.value = await ApiKeyApi.getApiKeySimpleList()
  172. })
  173. </script>