You've already forked DataMate
feat(template): 移除模板类型和版本字段并添加管理员权限控制
- 移除了模板详情页面中的类型和版本显示字段 - 移除了模板列表页面中的类型和版本列 - 添加了管理员权限检查功能,通过 localStorage 键控制 - 将编辑和删除操作按钮限制为仅管理员可见 - 将创建模板按钮限制为仅管理员可见
This commit is contained in:
@@ -43,14 +43,6 @@ const TemplateDetail: React.FC<TemplateDetailProps> = ({
|
|||||||
<Descriptions.Item label="样式">
|
<Descriptions.Item label="样式">
|
||||||
{template.style}
|
{template.style}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="类型">
|
|
||||||
<Tag color={template.builtIn ? "gold" : "default"}>
|
|
||||||
{template.builtIn ? "系统内置" : "自定义"}
|
|
||||||
</Tag>
|
|
||||||
</Descriptions.Item>
|
|
||||||
<Descriptions.Item label="版本">
|
|
||||||
{template.version}
|
|
||||||
</Descriptions.Item>
|
|
||||||
<Descriptions.Item label="创建时间" span={2}>
|
<Descriptions.Item label="创建时间" span={2}>
|
||||||
{new Date(template.createdAt).toLocaleString()}
|
{new Date(template.createdAt).toLocaleString()}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Table,
|
Table,
|
||||||
@@ -32,7 +32,16 @@ import {
|
|||||||
TemplateTypeMap
|
TemplateTypeMap
|
||||||
} from "@/pages/DataAnnotation/annotation.const.tsx";
|
} from "@/pages/DataAnnotation/annotation.const.tsx";
|
||||||
|
|
||||||
|
const TEMPLATE_ADMIN_KEY = "datamate_template_admin";
|
||||||
|
|
||||||
const TemplateList: React.FC = () => {
|
const TemplateList: React.FC = () => {
|
||||||
|
const [isAdmin, setIsAdmin] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// 检查 localStorage 中是否存在特殊键
|
||||||
|
const hasAdminKey = localStorage.getItem(TEMPLATE_ADMIN_KEY) !== null;
|
||||||
|
setIsAdmin(hasAdminKey);
|
||||||
|
}, []);
|
||||||
const filterOptions = [
|
const filterOptions = [
|
||||||
{
|
{
|
||||||
key: "category",
|
key: "category",
|
||||||
@@ -225,23 +234,7 @@ const TemplateList: React.FC = () => {
|
|||||||
<Tag color={getCategoryColor(category)}>{ClassificationMap[category as keyof typeof ClassificationMap]?.label || category}</Tag>
|
<Tag color={getCategoryColor(category)}>{ClassificationMap[category as keyof typeof ClassificationMap]?.label || category}</Tag>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: "类型",
|
|
||||||
dataIndex: "builtIn",
|
|
||||||
key: "builtIn",
|
|
||||||
width: 100,
|
|
||||||
render: (builtIn: boolean) => (
|
|
||||||
<Tag color={builtIn ? "gold" : "default"}>
|
|
||||||
{builtIn ? "系统内置" : "自定义"}
|
|
||||||
</Tag>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "版本",
|
|
||||||
dataIndex: "version",
|
|
||||||
key: "version",
|
|
||||||
width: 80,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: "创建时间",
|
title: "创建时间",
|
||||||
dataIndex: "createdAt",
|
dataIndex: "createdAt",
|
||||||
@@ -263,6 +256,7 @@ const TemplateList: React.FC = () => {
|
|||||||
onClick={() => handleView(record)}
|
onClick={() => handleView(record)}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
{isAdmin && (
|
||||||
<>
|
<>
|
||||||
<Tooltip title="编辑">
|
<Tooltip title="编辑">
|
||||||
<Button
|
<Button
|
||||||
@@ -286,6 +280,7 @@ const TemplateList: React.FC = () => {
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</>
|
</>
|
||||||
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -310,11 +305,13 @@ const TemplateList: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right side: Create button */}
|
{/* Right side: Create button */}
|
||||||
|
{isAdmin && (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleCreate}>
|
<Button type="primary" icon={<PlusOutlined />} onClick={handleCreate}>
|
||||||
创建模板
|
创建模板
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
|
|||||||
Reference in New Issue
Block a user