fix: align permission-gated UI actions
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import React, { useEffect, useState, useCallback, useMemo } from 'react';
|
||||
import { Table, Input, Button, Modal, Form, Select, DatePicker, Tag, Space } from 'antd';
|
||||
import { Table, Input, Modal, Form, Select, DatePicker, Tag, Space } from 'antd';
|
||||
import { EditOutlined } from '@ant-design/icons';
|
||||
import dayjs from 'dayjs';
|
||||
import api from '../../api';
|
||||
import { message } from '../../ui/app-message';
|
||||
import EditableCell from '../../components/EditableCell';
|
||||
import PermissionButton from '../../components/PermissionButton';
|
||||
import { usePermission } from '../../hooks/usePermission';
|
||||
|
||||
interface TeacherRow {
|
||||
id: number;
|
||||
@@ -50,6 +52,8 @@ const ROLE_TYPE_LABELS: Record<string, string> = {
|
||||
const DEFAULT_PAGE_SIZE = 20;
|
||||
|
||||
const TeachersPage: React.FC = () => {
|
||||
const { hasPermission } = usePermission();
|
||||
const canEditTeachers = hasPermission('teacher:edit');
|
||||
const [data, setData] = useState<TeacherRow[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [total, setTotal] = useState(0);
|
||||
@@ -190,7 +194,8 @@ const TeachersPage: React.FC = () => {
|
||||
key: 'actions',
|
||||
width: 100,
|
||||
render: (_: unknown, r: TeacherRow) => (
|
||||
<Button
|
||||
<PermissionButton
|
||||
permission="teacher:edit"
|
||||
size="small"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => {
|
||||
@@ -203,11 +208,11 @@ const TeachersPage: React.FC = () => {
|
||||
}}
|
||||
>
|
||||
档案
|
||||
</Button>
|
||||
</PermissionButton>
|
||||
),
|
||||
},
|
||||
],
|
||||
[saveProfileCell],
|
||||
[saveProfileCell, form],
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -263,8 +268,8 @@ const TeachersPage: React.FC = () => {
|
||||
/>
|
||||
<Modal
|
||||
title={`编辑档案 — ${profileModal?.name || ''}`}
|
||||
open={!!profileModal}
|
||||
onOk={handleSaveProfile}
|
||||
open={!!profileModal && canEditTeachers}
|
||||
onOk={canEditTeachers ? handleSaveProfile : undefined}
|
||||
onCancel={() => setProfileModal(null)}
|
||||
okText="保存"
|
||||
confirmLoading={saving}
|
||||
|
||||
Reference in New Issue
Block a user