houzhongjian
2024-08-08 820397e43a0b64d35c6d31d2a55475061438593b
提交 | 用户 | 时间
820397 1 <template>
H 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   <!-- 列表 -->
61   <ContentWrap>
62     <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
63       <el-table-column label="所属平台" align="center" prop="platform">
64         <template #default="scope">
65           <dict-tag :type="DICT_TYPE.AI_PLATFORM" :value="scope.row.platform" />
66         </template>
67       </el-table-column>
68       <el-table-column label="名称" align="center" prop="name" />
69       <el-table-column label="密钥" align="center" prop="apiKey" />
70       <el-table-column label="自定义 API URL" align="center" prop="url" />
71       <el-table-column label="状态" align="center" prop="status">
72         <template #default="scope">
73           <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
74         </template>
75       </el-table-column>
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:api-key:update']"
83           >
84             编辑
85           </el-button>
86           <el-button
87             link
88             type="danger"
89             @click="handleDelete(scope.row.id)"
90             v-hasPermi="['ai:api-key: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   <!-- 表单弹窗:添加/修改 -->
107   <ApiKeyForm ref="formRef" @success="getList" />
108 </template>
109
110 <script setup lang="ts">
111 import { getIntDictOptions, DICT_TYPE, getStrDictOptions } from '@/utils/dict'
112 import { ApiKeyApi, ApiKeyVO } from '@/api/ai/model/apiKey'
113 import ApiKeyForm from './ApiKeyForm.vue'
114
115 /** AI API 密钥 列表 */
116 defineOptions({ name: 'AiApiKey' })
117
118 const message = useMessage() // 消息弹窗
119 const { t } = useI18n() // 国际化
120
121 const loading = ref(true) // 列表的加载中
122 const list = ref<ApiKeyVO[]>([]) // 列表的数据
123 const total = ref(0) // 列表的总页数
124 const queryParams = reactive({
125   pageNo: 1,
126   pageSize: 10,
127   name: undefined,
128   platform: undefined,
129   status: undefined
130 })
131 const queryFormRef = ref() // 搜索的表单
132
133 /** 查询列表 */
134 const getList = async () => {
135   loading.value = true
136   try {
137     const data = await ApiKeyApi.getApiKeyPage(queryParams)
138     list.value = data.list
139     total.value = data.total
140   } finally {
141     loading.value = false
142   }
143 }
144
145 /** 搜索按钮操作 */
146 const handleQuery = () => {
147   queryParams.pageNo = 1
148   getList()
149 }
150
151 /** 重置按钮操作 */
152 const resetQuery = () => {
153   queryFormRef.value.resetFields()
154   handleQuery()
155 }
156
157 /** 添加/修改操作 */
158 const formRef = ref()
159 const openForm = (type: string, id?: number) => {
160   formRef.value.open(type, id)
161 }
162
163 /** 删除按钮操作 */
164 const handleDelete = async (id: number) => {
165   try {
166     // 删除的二次确认
167     await message.delConfirm()
168     // 发起删除
169     await ApiKeyApi.deleteApiKey(id)
170     message.success(t('common.delSuccess'))
171     // 刷新列表
172     await getList()
173   } catch {}
174 }
175
176 /** 初始化 **/
177 onMounted(() => {
178   getList()
179 })
180 </script>