新增管理员权限检查和模型选择逻辑优化

- 在用户 API 中新增 `checkIsSuperAdmin` 函数,用于检查用户是否为超级管理员。
- 更新模型选择器,非管理员用户只能选择内置模型并需配置 API Key,提升安全性和用户体验。
- 优化模型配置页面,动态显示操作按钮,确保管理员与普通用户的操作权限区分明确。
This commit is contained in:
2026-05-12 13:52:24 +08:00
parent 87b25dee42
commit 72af38ea00
5 changed files with 103 additions and 40 deletions

View File

@@ -4,7 +4,14 @@
<div class="system-user-search mb15">
<el-input v-model="state.tableData.param.modelName" size="default" placeholder="请输入模型名称" style="max-width: 180px" clearable>
</el-input>
<el-select v-model="state.tableData.param.modelType" size="default" placeholder="请选择模型类型" style="max-width: 180px" clearable class="ml10">
<el-select
v-model="state.tableData.param.modelType"
size="default"
placeholder="请选择模型类型"
style="max-width: 180px"
clearable
class="ml10"
>
<el-option v-for="type in state.modelTypes" :key="type.id" :label="type.label" :value="type.id" />
</el-select>
<el-button size="default" type="primary" class="ml10" @click="getTableData">
@@ -31,7 +38,7 @@
<!-- <el-table-column prop="baseUrl" label="模型服务地址" show-overflow-tooltip width="200"></el-table-column> -->
<el-table-column prop="isPrivate" label="访问类型" width="100">
<template #default="scope">
<el-tag :type="scope.row.isPrivate === 1 ? 'primary' : 'info'">{{ scope.row.isPrivate === 1 ? '公共' : '私有' }}</el-tag>
<el-tag :type="scope.row.isPrivate === 1 ? 'primary' : 'info'">{{ scope.row.isPrivate === 1 ? '本地模型' : '服务商模型' }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="httpMethod" label="请求方式" width="100"></el-table-column>
@@ -45,27 +52,30 @@
<el-table-column prop="remark" label="备注" show-overflow-tooltip></el-table-column>
<el-table-column prop="createdAt" label="创建时间" show-overflow-tooltip width="160"></el-table-column>
<el-table-column prop="updatedAt" label="修改时间" show-overflow-tooltip width="160"></el-table-column>
<el-table-column label="操作" width="300" fixed="right">
<el-table-column label="操作" :width="isSuperAdmin ? 150 : 300" fixed="right">
<template #default="scope">
<div class="action-buttons">
<el-button size="small" text type="primary" @click="onOpenEditModule('edit', scope.row)">修改</el-button>
<el-button
v-if="isInferenceModel(scope.row.modelsType) && Number(scope.row.isChatModel) !== 1"
size="small"
text
type="warning"
@click="onSetChatModel(scope.row)"
>
设为会话模型
</el-button>
<el-tag
v-if="isInferenceModel(scope.row.modelsType) && Number(scope.row.isChatModel) === 1"
type="success"
effect="dark"
size="default"
>
当前会话模型
</el-tag>
<!-- 非管理员才显示会话模型按钮 -->
<template v-if="!isSuperAdmin">
<el-button
v-if="isInferenceModel(scope.row.modelsType) && Number(scope.row.isChatModel) !== 1"
size="small"
text
type="warning"
@click="onSetChatModel(scope.row)"
>
设为会话模型
</el-button>
<el-tag
v-if="isInferenceModel(scope.row.modelsType) && Number(scope.row.isChatModel) === 1"
type="success"
effect="dark"
size="default"
>
当前会话模型
</el-tag>
</template>
<el-button size="small" text type="danger" @click="onRowDel(scope.row)">删除</el-button>
</div>
</template>
@@ -85,7 +95,7 @@
>
</el-pagination>
</el-card>
<EditModule ref="editModuleRef" :model-types="state.modelTypes" @refresh="getTableData()" />
<EditModule ref="editModuleRef" :model-types="state.modelTypes" :is-super-admin="isSuperAdmin" @refresh="getTableData()" />
<!-- 系统模型 API Key 输入弹窗 -->
<el-dialog v-model="apiKeyDialogVisible" title="配置系统模型" width="500px" :close-on-click-modal="false">
@@ -124,11 +134,13 @@ import {
updateChatModel,
addModelModule,
} from '/@/api/digitalHuman/modelConfig/modelModule/index';
import { checkIsSuperAdmin } from '/@/api/system/user/index';
import { getApiErrorMessage } from '/@/utils/request';
const EditModule = defineAsyncComponent(() => import('/@/views/digitalHuman/modelConfig/modelModule/component/editModule.vue'));
const editModuleRef = ref();
const isSuperAdmin = ref(false); // 是否为管理员
const state = reactive({
modelTypes: [] as Array<{ id: number | string; label: string }>,
tableData: {
@@ -158,6 +170,16 @@ const apiKeyRules: FormRules = {
const creatingModel = ref(false);
const systemModelToClone = ref<any>(null);
// 检查是否为管理员
const checkAdminStatus = async () => {
try {
const res: any = await checkIsSuperAdmin();
isSuperAdmin.value = res.data?.isSuperAdmin || false;
} catch {
isSuperAdmin.value = false;
}
};
// 判断是否为推理模型(只有推理模型才能设置为会话模型)
const isInferenceModel = (modelsType: number | string | undefined | null) => {
if (modelsType === undefined || modelsType === null || modelsType === '') {
@@ -322,6 +344,7 @@ const onHandleCurrentChange = (val: number) => {
// 页面加载时
onMounted(async () => {
await checkAdminStatus(); // 检查管理员状态
await loadModelTypes();
getTableData();
});
@@ -348,7 +371,7 @@ onMounted(async () => {
display: flex;
align-items: center;
gap: 8px;
.el-button {
margin: 0;
}