-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: 改进控制台图标 improvement: 改进公告显示 improvement: 一个错别字 improvement: 接口拦截器 feat: 控制台 IP 统计 feat: 后台密钥管理 style: 去除无用代码 fix: 修复安装时,Redis 与 MySQL 参数一致
- Loading branch information
Showing
14 changed files
with
240 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<script setup lang="ts"> | ||
import {onMounted, ref} from 'vue'; | ||
import Button from 'primevue/button'; | ||
import Card from 'primevue/card'; | ||
import DataTable from 'primevue/datatable'; | ||
import Column from 'primevue/column'; | ||
import copy from 'copy-to-clipboard'; | ||
import type {ApiKey} from '@/types'; | ||
import {useMessage} from '@/hooks/useMessage'; | ||
import {useConfirm} from 'primevue/useconfirm'; | ||
import {deleteApiKey, generateApiKey, getApiKeyList} from '@/services/key'; | ||
const refreshing = ref(false); | ||
const items = ref<ApiKey[]>([]); | ||
const message = useMessage(); | ||
const confirm = useConfirm(); | ||
const loading = ref(false); | ||
const onDeleteApiKey = (event: Event, api: ApiKey) => { | ||
confirm.require({ | ||
target: event.target as HTMLElement, | ||
message: '您要删除此密钥吗?', | ||
icon: 'pi pi-info-circle', | ||
rejectClass: 'p-button-secondary p-button-outlined p-button-sm', | ||
acceptClass: 'p-button-danger p-button-sm', | ||
rejectLabel: '取消', | ||
acceptLabel: '确定', | ||
accept: async () => { | ||
try { | ||
message.default('正在删除……'); | ||
(await deleteApiKey(api.id)); | ||
message.success('删除成功'); | ||
const index = items.value.findIndex(v => v.id === api.id); | ||
items.value.splice(index, 1); | ||
} catch { | ||
message.warn('删除失败!'); | ||
} | ||
} | ||
}); | ||
}; | ||
const refresh = async () => { | ||
loading.value = true; | ||
try { | ||
refreshing.value = true; | ||
const response = await getApiKeyList(); | ||
if (response.data.data.length > 0) { | ||
// 清空列表 | ||
items.value.length = 0; | ||
items.value.push(...response.data.data); | ||
} | ||
} catch { | ||
message.warn('加载密钥失败!请稍后刷新页面!'); | ||
} finally { | ||
refreshing.value = false; | ||
loading.value = false; | ||
} | ||
}; | ||
const onCopyKey = (key: ApiKey) => { | ||
copy(key.key || ''); | ||
message.success('复制成功!'); | ||
}; | ||
const newApiKey = async () => { | ||
loading.value = true; | ||
try { | ||
const {data} = (await generateApiKey()).data; | ||
message.success('生成成功!已自动复制。'); | ||
copy(data.key); | ||
await refresh(); | ||
} catch { | ||
message.warn('生成失败!'); | ||
} finally { | ||
loading.value = false; | ||
} | ||
}; | ||
onMounted(refresh); | ||
</script> | ||
|
||
<template> | ||
<div class="col-12"> | ||
<Card> | ||
<template #content> | ||
<DataTable :value="items" dataKey="id" | ||
tableStyle="min-width: 60rem" :loading="refreshing"> | ||
<template #loading> | ||
正在加载,请稍后…… | ||
</template> | ||
<template #empty> | ||
暂时没有数据,添加一个吧! | ||
</template> | ||
<template #header> | ||
<div class="md:flex md:flex-row md:flex-nowrap"> | ||
<Button :loading="loading" icon="pi pi-plus" label="添加" class="mr-2 mb-2 flex-grow-0" @click="newApiKey"/> | ||
</div> | ||
</template> | ||
<Column field="id" header="ID" :sortable="true"/> | ||
<Column field="key" header="KEY"/> | ||
<Column field="use_count" header="使用次数"/> | ||
<Column header="操作"> | ||
<template #body="{data}"> | ||
<Button icon="pi pi-copy" rounded class="mb-2 mr-2" @click="onCopyKey(data)"/> | ||
<Button icon="pi pi-trash" severity="danger" rounded class="mb-2 mr-2" | ||
@click="onDeleteApiKey($event, data)"/> | ||
</template> | ||
</Column> | ||
</DataTable> | ||
</template> | ||
</Card> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import request from '@/utils/request'; | ||
import type {IPCountResponse} from '@/types'; | ||
|
||
export function getStatisticIP() { | ||
return request({ | ||
url: '/admin/statistics/get_ip', | ||
withLogin: true | ||
}); | ||
} | ||
|
||
export function getStatisticIPCount() { | ||
return request({ | ||
return request<IPCountResponse>({ | ||
url: '/admin/statistics/get_ip_count', | ||
withLogin: true | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.