新增管理员权限检查和模型选择逻辑优化
- 在用户 API 中新增 `checkIsSuperAdmin` 函数,用于检查用户是否为超级管理员。 - 更新模型选择器,非管理员用户只能选择内置模型并需配置 API Key,提升安全性和用户体验。 - 优化模型配置页面,动态显示操作按钮,确保管理员与普通用户的操作权限区分明确。
This commit is contained in:
@@ -19,13 +19,13 @@
|
||||
v-for="model in modelList"
|
||||
:key="model.id"
|
||||
class="model-card"
|
||||
:class="{ selected: selectedModel?.id === model.id, 'system-model': model.tenantId === 1 }"
|
||||
:class="{ selected: selectedModel?.id === model.id, 'builtin-model': !model.apiKey }"
|
||||
@click="handleSelectModel(model)"
|
||||
>
|
||||
<div class="model-card-header">
|
||||
<div class="model-type">{{ getModelTypeName(model.modelsType) }}</div>
|
||||
<div class="model-badges">
|
||||
<el-tag v-if="model.tenantId === 1" type="warning" size="small">系统模型</el-tag>
|
||||
<el-tag v-if="!model.apiKey" type="warning" size="small">内置模型</el-tag>
|
||||
<el-icon v-if="selectedModel?.id === model.id" class="check-icon" color="#67c23a"><CircleCheck /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
@@ -62,12 +62,12 @@
|
||||
<!-- 新建模型弹窗 -->
|
||||
<EditModule ref="editModuleRef" @refresh="handleRefresh" />
|
||||
|
||||
<!-- 系统模型 API Key 输入弹窗 -->
|
||||
<el-dialog v-model="apiKeyDialogVisible" title="配置系统模型" width="500px" :close-on-click-modal="false" append-to-body>
|
||||
<!-- 内置模型 API Key 输入弹窗 -->
|
||||
<el-dialog v-model="apiKeyDialogVisible" title="配置内置模型" width="500px" :close-on-click-modal="false" append-to-body>
|
||||
<el-alert type="info" :closable="false" style="margin-bottom: 16px">
|
||||
<template #title>
|
||||
<div style="line-height: 1.6">
|
||||
您选择的是系统模型,需要配置您自己的 API Key。<br />
|
||||
您选择的是内置模型,需要配置您自己的 API Key。<br />
|
||||
系统将为您创建一个模型副本。
|
||||
</div>
|
||||
</template>
|
||||
@@ -89,10 +89,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, watch } from 'vue';
|
||||
import { ref, reactive, watch, onMounted } from 'vue';
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus';
|
||||
import { Search, CircleCheck } from '@element-plus/icons-vue';
|
||||
import { getModelModuleList, addModelModule } from '/@/api/digitalHuman/modelConfig/modelModule';
|
||||
import { checkIsSuperAdmin } from '/@/api/system/user/index';
|
||||
import { getApiErrorMessage } from '/@/utils/request';
|
||||
import EditModule from '/@/views/digitalHuman/modelConfig/modelModule/component/editModule.vue';
|
||||
|
||||
@@ -147,8 +148,9 @@ const modelList = ref<ModelItem[]>([]);
|
||||
const loading = ref(false);
|
||||
const selectedModel = ref<ModelItem | null>(null);
|
||||
const editModuleRef = ref();
|
||||
const isSuperAdmin = ref(false); // 是否为管理员
|
||||
|
||||
// 系统模型 API Key 配置
|
||||
// 内置模型 API Key 配置
|
||||
const apiKeyDialogVisible = ref(false);
|
||||
const apiKeyFormRef = ref<FormInstance>();
|
||||
const apiKeyForm = reactive({
|
||||
@@ -162,6 +164,16 @@ const apiKeyRules: FormRules = {
|
||||
const creatingModel = ref(false);
|
||||
const systemModelToClone = ref<ModelItem | null>(null);
|
||||
|
||||
// 检查是否为管理员
|
||||
const checkAdminStatus = async () => {
|
||||
try {
|
||||
const res: any = await checkIsSuperAdmin();
|
||||
isSuperAdmin.value = res.data?.isSuperAdmin || false;
|
||||
} catch {
|
||||
isSuperAdmin.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val) => {
|
||||
@@ -195,6 +207,7 @@ const fetchModelList = async () => {
|
||||
pageNum: pagination.pageNum,
|
||||
pageSize: pagination.pageSize,
|
||||
modelName: searchParams.modelName || undefined,
|
||||
modelType: 1, // 只获取推理模型
|
||||
};
|
||||
const res: any = await getModelModuleList(params);
|
||||
modelList.value = res.data?.list || [];
|
||||
@@ -218,15 +231,21 @@ const handlePageChange = () => {
|
||||
};
|
||||
|
||||
const handleSelectModel = (model: ModelItem) => {
|
||||
// 判断是否是系统模型(tenantId === 1)
|
||||
if (model.tenantId === 1) {
|
||||
// 系统模型,需要用户配置 API Key
|
||||
// 如果是管理员,直接选中任何模型,不需要配置 API Key
|
||||
if (isSuperAdmin.value) {
|
||||
selectedModel.value = model;
|
||||
return;
|
||||
}
|
||||
|
||||
// 非管理员:判断是否是内置模型(apiKey 为空)
|
||||
if (!model.apiKey) {
|
||||
// 内置模型,需要用户配置 API Key
|
||||
systemModelToClone.value = model;
|
||||
apiKeyForm.modelName = model.modelName;
|
||||
apiKeyForm.apiKey = '';
|
||||
apiKeyDialogVisible.value = true;
|
||||
} else {
|
||||
// 非系统模型,直接选中
|
||||
// 用户模型,直接选中
|
||||
selectedModel.value = model;
|
||||
}
|
||||
};
|
||||
@@ -239,7 +258,7 @@ const handleCreatePrivateModel = async () => {
|
||||
|
||||
creatingModel.value = true;
|
||||
|
||||
// 基于系统模型创建新模型(继承原模型的所有配置,只替换 apiKey)
|
||||
// 基于内置模型创建新模型(继承原模型的所有配置,只替换 apiKey)
|
||||
const systemModel = systemModelToClone.value;
|
||||
const createParams = {
|
||||
modelName: apiKeyForm.modelName,
|
||||
@@ -312,6 +331,10 @@ const handleClose = () => {
|
||||
apiKeyDialogVisible.value = false;
|
||||
systemModelToClone.value = null;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
checkAdminStatus();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@@ -360,12 +383,12 @@ const handleClose = () => {
|
||||
background: #f0f9ff;
|
||||
}
|
||||
|
||||
.model-card.system-model {
|
||||
.model-card.builtin-model {
|
||||
border-color: #fbbf24;
|
||||
background: #fffbeb;
|
||||
}
|
||||
|
||||
.model-card.system-model:hover {
|
||||
.model-card.builtin-model:hover {
|
||||
border-color: #f59e0b;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user