feat: 为访问令牌增加名称

- 支持创建和编辑访问令牌名称

- 在列表首列展示名称并兼容历史数据
This commit is contained in:
2026-08-07 12:55:04 +08:00
parent d244a0404d
commit 13dec6c216
8 changed files with 220 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
{
"id": "Id",
"name": "Name",
"apiKey": "ApiKey",
"created": "Created",
"status": "Status",
@@ -18,5 +19,8 @@
"knowledgeImportPermission": "Knowledge Import",
"knowledgeMaintenancePermission": "Knowledge Maintenance",
"workflowApiPermission": "Workflow API",
"addApiKeyNotice": "This operation will generate an API key. Please confirm whether to proceed"
"addApiKeyNotice": "Enter an access token name",
"namePlaceholder": "Enter a name",
"nameRequired": "Name is required",
"nameTooLong": "Name cannot exceed 100 characters"
}

View File

@@ -1,5 +1,6 @@
{
"id": "id",
"name": "名称",
"apiKey": "apiKey",
"created": "创建时间",
"status": "数据状态",
@@ -18,5 +19,8 @@
"knowledgeImportPermission": "知识导入",
"knowledgeMaintenancePermission": "知识库维护",
"workflowApiPermission": "工作流 API 调用授权",
"addApiKeyNotice": "该操作会生成一个apiKey,请确认是否生成"
"addApiKeyNotice": "请输入访问令牌名称",
"namePlaceholder": "请输入名称",
"nameRequired": "名称不能为空",
"nameTooLong": "名称不能超过100个字符"
}

View File

@@ -92,22 +92,51 @@ function remove(row: any) {
}).catch(() => {});
}
function addNewApiKey() {
ElMessageBox.confirm(
ElMessageBox.prompt(
$t('sysApiKey.addApiKeyNotice'),
$t('message.noticeTitle'),
{
confirmButtonText: $t('message.ok'),
cancelButtonText: $t('message.cancel'),
type: 'warning',
inputPlaceholder: $t('sysApiKey.namePlaceholder'),
inputValidator: (value) => {
const normalizedValue = value.trim();
if (!normalizedValue) {
return $t('sysApiKey.nameRequired');
}
if (normalizedValue.length > 100) {
return $t('sysApiKey.nameTooLong');
}
return true;
},
beforeClose: (action, instance, done) => {
if (action !== 'confirm') {
done();
return;
}
instance.confirmButtonLoading = true;
api
.post('/api/v1/sysApiKey/key/save', {
name: instance.inputValue.trim(),
})
.then((res) => {
if (res.errorCode === 0) {
ElMessage.success($t('message.saveOkMessage'));
pageDataRef.value.setQuery({});
done();
} else {
ElMessage.error(res.message || $t('message.saveFailMessage'));
}
})
.catch(() => {
ElMessage.error($t('message.saveFailMessage'));
})
.finally(() => {
instance.confirmButtonLoading = false;
});
},
},
).then(() => {
api.post('/api/v1/sysApiKey/key/save', {}).then((res) => {
if (res.errorCode === 0) {
ElMessage.success($t('message.saveOkMessage'));
pageDataRef.value.setQuery({});
}
});
});
).catch(() => {});
}
</script>
@@ -129,6 +158,12 @@ function addNewApiKey() {
>
<template #default="{ pageList }">
<ElTable :data="pageList" border>
<ElTableColumn
prop="name"
:label="$t('sysApiKey.name')"
min-width="160"
show-overflow-tooltip
/>
<ElTableColumn
prop="apiKey"
:label="$t('sysApiKey.apiKey')"

View File

@@ -11,6 +11,7 @@ import {
ElDatePicker,
ElForm,
ElFormItem,
ElInput,
ElMessage,
} from 'element-plus';
@@ -27,6 +28,7 @@ interface ResourcePermission {
// 定义表单数据接口
interface Entity {
name: string;
apiKey: string;
status: number | string;
deptId: number | string;
@@ -49,6 +51,7 @@ const dialogVisible = ref(false);
const isAdd = ref(true);
// 表单数据(初始化默认值)
const entity = ref<Entity>({
name: '',
apiKey: '',
status: '',
deptId: '',
@@ -66,6 +69,19 @@ const resourcePermissionList = ref<ResourcePermission[]>([]);
// 表单校验规则(必填项校验)
const rules = ref({
name: [
{
required: true,
whitespace: true,
message: $t('sysApiKey.nameRequired'),
trigger: 'blur',
},
{
max: 100,
message: $t('sysApiKey.nameTooLong'),
trigger: 'change',
},
],
status: [
{
required: true,
@@ -136,6 +152,7 @@ function createDefaultEntity(row: Partial<Entity> = {}): Entity {
const knowledgeMaintenanceEnabled = Boolean(row.knowledgeMaintenanceEnabled);
const workflowApiEnabled = Boolean(row.workflowApiEnabled);
return {
name: '',
apiKey: '',
status: '',
deptId: '',
@@ -170,6 +187,7 @@ function save() {
saveForm.value?.validate((valid) => {
if (valid) {
btnLoading.value = true;
entity.value.name = entity.value.name.trim();
const url = isAdd.value
? 'api/v1/sysApiKey/save'
: 'api/v1/sysApiKey/update';
@@ -198,6 +216,7 @@ function closeDialog() {
saveForm.value?.resetFields();
// 重置表单数据
entity.value = {
name: '',
apiKey: '',
status: '',
deptId: '',
@@ -240,6 +259,16 @@ defineExpose({
label-position="top"
class="easyflow-modal-form easyflow-modal-form--compact form-container"
>
<ElFormItem prop="name" :label="$t('sysApiKey.name')">
<ElInput
v-model="entity.name"
clearable
:maxlength="100"
show-word-limit
:placeholder="$t('sysApiKey.namePlaceholder')"
/>
</ElFormItem>
<!-- 状态选择 -->
<ElFormItem prop="status" :label="$t('sysApiKey.status')">
<DictSelect