feat: 为访问令牌增加名称
- 支持创建和编辑访问令牌名称 - 在列表首列展示名称并兼容历史数据
This commit is contained in:
@@ -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')"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user