@@ -18,13 +18,13 @@ const props = defineProps<{
1818}>()
1919const loading = ref (false )
2020const apiKeys = ref <ApiKeyRecord []>([])
21- const revealedIds = ref (new Set <string >())
21+ const createdApiKey = ref (' ' )
22+ const createdDialogVisible = ref (false )
2223const pagination = ref ({ currentPage: 1 , pageSize: 20 , total: 0 })
2324const editDrawerRef = useTemplateRef <InstanceType <typeof EditApiKeyDrawer >>(' editDrawerRef' )
2425const apiKeyRows = computed (() => apiKeys .value .map ((record ) => ({ ... record , expiration: getApiKeyExpiration (record ) })))
2526
2627function fetchApiKeys() {
27- revealedIds .value .clear ()
2828 const request =
2929 props .applicationId !== undefined
3030 ? (props .api as typeof ApplicationApiKeyApi | typeof SystemResourceApiKeyApi ).getApiKeyPage (props .applicationId , pagination .value )
@@ -51,8 +51,9 @@ function handleCreate() {
5151 ? (props .api as typeof ApplicationApiKeyApi | typeof SystemResourceApiKeyApi ).postApiKey (props .applicationId )
5252 : (props .api as typeof SystemApiKeyApi ).postApiKey ()
5353 return request
54- .then (() => {
55- MsgSuccess (' 创建成功' )
54+ .then ((record ) => {
55+ createdApiKey .value = record .secret_key
56+ createdDialogVisible .value = true
5657 pagination .value .currentPage = 1
5758 return fetchApiKeys ()
5859 })
@@ -108,11 +109,6 @@ function handleOpenEdit(record: ApiKeyRecord) {
108109 editDrawerRef .value ?.open (record )
109110}
110111
111- function handleToggleVisible(id : string ) {
112- if (revealedIds .value .has (id )) revealedIds .value .delete (id )
113- else revealedIds .value .add (id )
114- }
115-
116112onMounted (loadApiKeys )
117113 </script >
118114
@@ -130,24 +126,16 @@ onMounted(loadApiKeys)
130126 @current-change =" loadApiKeys "
131127 @size-change =" loadApiKeys "
132128 >
133- <el-table-column label =" API Key" min-width =" 230 " >
129+ <el-table-column label =" API Key" min-width =" 160 " >
134130 <template #default =" { row } " >
135131 <div class =" flex-align-center gap-2" >
136- <span class = " min-w-0 truncate " :title = " revealedIds.has(row.id) ? row.secret_key : '********' " >
137- {{ revealedIds.has(row.id) ? row.secret_key : ' ********' }}
132+ <span >
133+ {{ ` ******${row.secret_key.slice(-4)}` }}
138134 </span >
139135 <!-- 复制完整 API Key -->
140- <MkTooltip content="复制">
141- <el-button link @click =" copyText(row.secret_key)" >
142- <MkIcon name="icon_copy_outlined" />
143- </el-button >
144- </MkTooltip >
145- <!-- 切换 API Key 显隐 -->
146- <MkTooltip :content =" revealedIds .has (row .id ) ? ' 点击隐藏' : ' 点击显示' " >
147- <el-button link @click =" handleToggleVisible(row.id)" >
148- <MkIcon :name =" revealedIds .has (row .id ) ? ' icon_visible_outlined' : ' icon_invisible_outlined' " />
149- </el-button >
150- </MkTooltip >
136+ <el-button text @click =" copyText(row.secret_key)" >
137+ <MkIcon name="icon_copy_outlined" />
138+ </el-button >
151139 </div >
152140 </template >
153141 </el-table-column >
@@ -202,5 +190,20 @@ onMounted(loadApiKeys)
202190 </el-table-column >
203191 </MkTable >
204192 </div >
193+ <MkDialog v-model =" createdDialogVisible " title="API Key" align-center @closed =" createdApiKey = ' ' " >
194+ <template #subtitle >请安全保存此密钥,不要泄露。</template >
195+ <el-input :model-value =" createdApiKey" readonly >
196+ <template #suffix >
197+ <!-- 复制新建的完整 API Key -->
198+ <el-button text @click =" copyText(createdApiKey)" class =" -mr-1" >
199+ <MkIcon name="icon_copy_outlined" />
200+ </el-button >
201+ </template >
202+ </el-input >
203+ <template #footer >
204+ <!-- 关闭创建结果弹窗 -->
205+ <el-button plain @click =" createdDialogVisible = false" >知道了</el-button >
206+ </template >
207+ </MkDialog >
205208 <EditApiKeyDrawer v-bind =" props " ref="editDrawerRef" @refresh =" loadApiKeys " />
206209</template >
0 commit comments