Skip to content

Commit b17ad60

Browse files
committed
feat: delete subject module
1 parent b4338d8 commit b17ad60

16 files changed

Lines changed: 239 additions & 167 deletions

File tree

config.example.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ Sentry:
3131
Auth:
3232
Secret: "<random>"
3333
Issuer: "MJCLOUDS"
34+
FastGPT:
35+
BaseURL: "http://localhost:3000/api"
36+
APIKey: "fastgpt-your-api-key"

config/vars.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type GlobalConfig struct {
2222

2323
type FastGPT struct {
2424
BaseURL string `yaml:"BaseURL"`
25-
APIKey string `yaml:"APIKey"` // 默认 API Key(用于非聊天功能)
2625
}
2726

2827
type OAuth struct {

frontend/src/api/fastgpt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const getAuthHeader = (token) => ({ Authorization: `Bearer ${token}` });
55

66
export const getAppList = (token, page = 1, pageSize = 10) => {
77
return axios.post(`${BASE_URL}/fastgpt/apps/list`, {
8-
page,
9-
pageSize
8+
offset: (page - 1) * pageSize,
9+
limit: pageSize
1010
}, {
1111
headers: getAuthHeader(token)
1212
});

frontend/src/api/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ export const updateUserSubject = (data, token) =>
249249
*/
250250
export const getFastgptAppList = (token, page = 1, pageSize = 10) => {
251251
return axios.post(`${BASE_URL}/fastgpt/apps/list`, {
252-
page,
253-
pageSize
252+
offset: (page - 1) * pageSize,
253+
limit: pageSize
254254
}, {
255255
headers: { Authorization: `Bearer ${token}` }
256256
});

frontend/src/pages/AdminDashboard.jsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
22
import { Layout, Menu, Typography, Space, Button, message } from 'antd';
33
import {
44
UserOutlined, LogoutOutlined, TeamOutlined,
5-
FileExcelOutlined, BookOutlined, AppstoreOutlined
5+
FileExcelOutlined, BookOutlined, AppstoreOutlined, HomeOutlined
66
} from '@ant-design/icons';
77
import { useNavigate } from 'react-router-dom';
88
import { getManagerInfo } from '../api';
@@ -20,9 +20,13 @@ const { Title, Text } = Typography;
2020
const AdminDashboard = () => {
2121
const navigate = useNavigate();
2222
const [currentUser, setCurrentUser] = useState(null);
23-
const [activeTab, setActiveTab] = useState('import');
23+
const [activeTab, setActiveTab] = useState(localStorage.getItem('adminActiveTab') || 'import');
2424
const [isAuthenticated, setIsAuthenticated] = useState(false);
2525

26+
useEffect(() => {
27+
localStorage.setItem('adminActiveTab', activeTab);
28+
}, [activeTab]);
29+
2630
useEffect(() => {
2731
const token = localStorage.getItem('adminToken') || localStorage.getItem('token');
2832
if (!token) {
@@ -105,6 +109,7 @@ const AdminDashboard = () => {
105109
<Title level={4} style={{ margin: 0 }}>学业辅助系统 - 管理后台</Title>
106110
<Space>
107111
<Text>欢迎, {currentUser?.name || '管理员'}</Text>
112+
<Button icon={<HomeOutlined />} onClick={() => navigate('/subjects')}>进入学生端</Button>
108113
<Button icon={<LogoutOutlined />} onClick={handleLogout}>退出</Button>
109114
</Space>
110115
</Header>
@@ -127,20 +132,15 @@ const AdminDashboard = () => {
127132
icon: <UserOutlined />,
128133
label: '学生科目管理',
129134
},
130-
{
131-
key: 'subjects',
132-
icon: <BookOutlined />,
133-
label: '学科管理',
134-
},
135135
{
136136
key: 'managers',
137137
icon: <TeamOutlined />,
138138
label: '管理员管理',
139139
},
140140
{
141141
key: 'fastgpt-apps',
142-
icon: <AppstoreOutlined />,
143-
label: 'FastGPT 应用管理',
142+
icon: <BookOutlined />,
143+
label: '学科管理',
144144
},
145145
]}
146146
/>

frontend/src/pages/StudentSubjectsManagement.jsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,6 @@ const StudentSubjectsManagement = () => {
171171
dataIndex: 'subject_name',
172172
key: 'subject_name',
173173
},
174-
{
175-
title: '创建时间',
176-
dataIndex: 'created_at',
177-
key: 'created_at',
178-
render: (text) => text ? new Date(text).toLocaleString('zh-CN') : '-',
179-
},
180174
{
181175
title: '操作',
182176
key: 'action',

frontend/src/pages/admin/FastGPTAppsTab.jsx

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const FastGPTAppsTab = () => {
2323
try {
2424
const response = await getFastgptAppList(token, page, pageSize);
2525
if (response.data?.code === 0 || response.data?.code === 200) {
26-
setFastgptApps(response.data.data?.list || []);
26+
setFastgptApps(response.data.data?.apps || []);
2727
setPagination({
28-
current: response.data.data?.page || page,
29-
pageSize: response.data.data?.pageSize || pageSize,
28+
current: page,
29+
pageSize: pageSize,
3030
total: response.data.data?.total || 0,
3131
});
3232
}
@@ -47,12 +47,10 @@ const FastGPTAppsTab = () => {
4747
id: editingFastgptApp.id,
4848
appName: values.appName,
4949
apiKey: values.apiKey,
50-
description: values.description,
51-
status: values.status
50+
description: values.description
5251
}, token);
5352
} else {
5453
response = await createFastgptApp({
55-
appId: values.appId,
5654
appName: values.appName,
5755
apiKey: values.apiKey,
5856
description: values.description
@@ -99,11 +97,9 @@ const FastGPTAppsTab = () => {
9997
const openEditModal = (record) => {
10098
setEditingFastgptApp(record);
10199
form.setFieldsValue({
102-
appId: record.appId,
103100
appName: record.appName,
104101
apiKey: record.apiKey,
105-
description: record.description,
106-
status: record.status
102+
description: record.description
107103
});
108104
setModalVisible(true);
109105
};
@@ -113,10 +109,9 @@ const FastGPTAppsTab = () => {
113109
};
114110

115111
const columns = [
116-
{ title: 'App ID', dataIndex: 'appId', key: 'appId' },
117-
{ title: '应用名称', dataIndex: 'appName', key: 'appName' },
112+
{ title: '学科名称', dataIndex: 'appName', key: 'appName' },
118113
{
119-
title: 'API Key',
114+
title: '密钥',
120115
dataIndex: 'apiKey',
121116
key: 'apiKey',
122117
render: (text) => (
@@ -126,16 +121,6 @@ const FastGPTAppsTab = () => {
126121
)
127122
},
128123
{ title: '描述', dataIndex: 'description', key: 'description', ellipsis: true },
129-
{
130-
title: '状态',
131-
dataIndex: 'status',
132-
key: 'status',
133-
render: (status) => (
134-
<Tag color={status === 1 ? 'success' : 'error'}>
135-
{status === 1 ? '启用' : '禁用'}
136-
</Tag>
137-
)
138-
},
139124
{
140125
title: '操作',
141126
key: 'action',
@@ -153,13 +138,13 @@ const FastGPTAppsTab = () => {
153138
return (
154139
<div>
155140
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
156-
<Title level={4} style={{ margin: 0 }}>FastGPT 应用管理</Title>
141+
<Title level={4} style={{ margin: 0 }}>学科管理</Title>
157142
<Button
158143
type="primary"
159144
icon={<PlusOutlined />}
160145
onClick={openAddModal}
161146
>
162-
添加应用
147+
添加学科
163148
</Button>
164149
</div>
165150

@@ -173,7 +158,7 @@ const FastGPTAppsTab = () => {
173158
/>
174159

175160
<Modal
176-
title={editingFastgptApp ? "编辑应用" : "添加应用"}
161+
title={editingFastgptApp ? "编辑学科" : "添加学科"}
177162
open={modalVisible}
178163
onCancel={() => {
179164
setModalVisible(false);
@@ -186,49 +171,27 @@ const FastGPTAppsTab = () => {
186171
form={form}
187172
layout="vertical"
188173
onFinish={handleAddOrUpdateFastgptApp}
189-
initialValues={{ status: 1 }}
190174
>
191-
<Form.Item
192-
name="appId"
193-
label="App ID"
194-
rules={[{ required: true, message: '请输入 App ID' }]}
195-
>
196-
<Input placeholder="FastGPT 应用 ID" disabled={!!editingFastgptApp} />
197-
</Form.Item>
198175
<Form.Item
199176
name="appName"
200-
label="应用名称"
201-
rules={[{ required: true, message: '请输入应用名称' }]}
177+
label="学科名称"
178+
rules={[{ required: true, message: '请输入学科名称' }]}
202179
>
203-
<Input placeholder="给应用起个名字" />
180+
<Input placeholder="给学科起个名字" />
204181
</Form.Item>
205182
<Form.Item
206183
name="apiKey"
207-
label="API Key"
208-
rules={[{ required: true, message: '请输入 API Key' }]}
184+
label="密钥"
185+
rules={[{ required: true, message: '请输入密钥' }]}
209186
>
210187
<Input.Password placeholder="FastGPT API Key" />
211188
</Form.Item>
212189
<Form.Item
213190
name="description"
214191
label="描述"
215192
>
216-
<Input.TextArea placeholder="应用描述" />
193+
<Input.TextArea placeholder="学科描述" />
217194
</Form.Item>
218-
219-
{editingFastgptApp && (
220-
<Form.Item
221-
name="status"
222-
label="状态"
223-
rules={[{ required: true, message: '请选择状态' }]}
224-
>
225-
<Radio.Group>
226-
<Radio value={1}>启用</Radio>
227-
<Radio value={0}>禁用</Radio>
228-
</Radio.Group>
229-
</Form.Item>
230-
)}
231-
232195
<Form.Item>
233196
<Space style={{ width: '100%', justifyContent: 'flex-end' }}>
234197
<Button onClick={() => {

frontend/src/pages/admin/StudentSubjectsTab.jsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
2-
import { Table, Button, Modal, Form, Input, Space, Popconfirm, Typography, message } from 'antd';
2+
import { Table, Button, Modal, Form, Input, Select, Space, Popconfirm, Typography, message } from 'antd';
33
import { DeleteOutlined, PlusOutlined, EditOutlined, SearchOutlined, ReloadOutlined } from '@ant-design/icons';
4-
import { getUserSubjectList, addUserSubject, deleteUserSubject, updateUserSubject } from '../../api';
4+
import { getUserSubjectList, addUserSubject, deleteUserSubject, updateUserSubject, getFastgptAppList } from '../../api';
55

66
const { Title } = Typography;
77

@@ -12,12 +12,27 @@ const StudentSubjectsTab = () => {
1212
const [filters, setFilters] = useState({ staffId: '', subjectName: '' });
1313
const [modalVisible, setModalVisible] = useState(false);
1414
const [editingUserSubject, setEditingUserSubject] = useState(null);
15+
const [availableSubjects, setAvailableSubjects] = useState([]);
1516
const [form] = Form.useForm();
1617

1718
useEffect(() => {
1819
fetchUserSubjects(1, 10, filters);
20+
fetchAvailableSubjects();
1921
}, []);
2022

23+
const fetchAvailableSubjects = async () => {
24+
const token = localStorage.getItem('adminToken');
25+
try {
26+
// Fetch up to 100 apps to populate the select list
27+
const response = await getFastgptAppList(token, 1, 100);
28+
if (response.data?.code === 0 || response.data?.code === 200) {
29+
setAvailableSubjects(response.data.data?.apps || []);
30+
}
31+
} catch (error) {
32+
console.error('获取学科列表失败:', error);
33+
}
34+
};
35+
2136
const fetchUserSubjects = async (page = 1, pageSize = 10, searchFilters = {}) => {
2237
setLoading(true);
2338
const token = localStorage.getItem('adminToken');
@@ -127,28 +142,21 @@ const StudentSubjectsTab = () => {
127142
title: 'ID',
128143
dataIndex: 'id',
129144
key: 'id',
130-
width: 200,
145+
width: 300,
131146
ellipsis: true,
132147
},
133148
{
134149
title: '学号',
135150
dataIndex: 'staff_id',
136151
key: 'staff_id',
137-
width: 120,
152+
width: 200,
138153
},
139154
{
140155
title: '科目名称',
141156
dataIndex: 'subject_name',
142157
key: 'subject_name',
143158
width: 150,
144159
},
145-
{
146-
title: '创建时间',
147-
dataIndex: 'created_at',
148-
key: 'created_at',
149-
width: 180,
150-
render: (text) => text ? new Date(text).toLocaleString() : '-',
151-
},
152160
{
153161
title: '操作',
154162
key: 'action',
@@ -241,9 +249,15 @@ const StudentSubjectsTab = () => {
241249
<Form.Item
242250
name="subjectName"
243251
label="科目名称"
244-
rules={[{ required: true, message: '请输入科目名称' }]}
252+
rules={[{ required: true, message: '请选择科目名称' }]}
245253
>
246-
<Input placeholder="请输入科目名称" />
254+
<Select placeholder="请选择科目名称">
255+
{availableSubjects.map((subject) => (
256+
<Select.Option key={subject.appName} value={subject.appName}>
257+
{subject.appName}
258+
</Select.Option>
259+
))}
260+
</Select>
247261
</Form.Item>
248262

249263
<Form.Item>

0 commit comments

Comments
 (0)