feat: add useCampus hook and CampusSwitcher component
This commit is contained in:
36
apps/admin/src/components/CampusSwitcher.tsx
Normal file
36
apps/admin/src/components/CampusSwitcher.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import React from 'react';
|
||||
import { Select, Typography } from 'antd';
|
||||
import { EnvironmentOutlined } from '@ant-design/icons';
|
||||
import { useCampus } from '../hooks/useCampus';
|
||||
|
||||
const CampusSwitcher: React.FC = () => {
|
||||
const { campuses, currentId, switchCampus, loading } = useCampus();
|
||||
|
||||
if (campuses.length <= 1) {
|
||||
return (
|
||||
<Typography.Text style={{ color: '#fff', marginRight: 24 }}>
|
||||
<EnvironmentOutlined style={{ marginRight: 4 }} />
|
||||
{campuses[0]?.name || '主校区'}
|
||||
</Typography.Text>
|
||||
);
|
||||
}
|
||||
|
||||
const options = [
|
||||
...campuses.map((c) => ({ value: String(c.id), label: c.name })),
|
||||
{ value: '', label: '全部校区' },
|
||||
];
|
||||
|
||||
return (
|
||||
<Select
|
||||
value={currentId || undefined}
|
||||
onChange={switchCampus}
|
||||
options={options}
|
||||
loading={loading}
|
||||
style={{ minWidth: 140, marginRight: 24 }}
|
||||
variant="borderless"
|
||||
popupMatchSelectWidth={false}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default CampusSwitcher;
|
||||
Reference in New Issue
Block a user