fix(materials): handle API response format and color rendering
Some checks failed
Admin CI / build-and-push-web (push) Failing after 1m43s

Update the subjects API to handle the nested list structure in the response, and fix color rendering by using direct inline styles instead of CSS custom properties that weren't being properly applied
This commit is contained in:
lafay
2026-04-10 01:16:38 +08:00
parent 4991dae691
commit 0b16613be4
2 changed files with 17 additions and 17 deletions

View File

@@ -94,7 +94,7 @@ export interface MaterialQueryParams {
export const subjectsApi = {
// 获取学科列表
getSubjects: () =>
apiClient.get<ApiResponse<MaterialSubject[]>>('/admin/materials/subjects'),
apiClient.get<ApiResponse<{ list: MaterialSubject[] }>>('/admin/materials/subjects'),
// 创建学科
createSubject: (data: SubjectUpsertRequest) =>

View File

@@ -123,7 +123,7 @@ export default function MaterialSubjects() {
setLoading(true)
try {
const response = await subjectsApi.getSubjects()
const list = response.data.data || []
const list = response.data.data?.list ?? []
setSubjects(list)
} catch (error) {
console.error('Failed to load subjects:', error)
@@ -273,13 +273,13 @@ export default function MaterialSubjects() {
<TableRow key={subject.id}>
<TableCell>{subject.sort_order}</TableCell>
<TableCell>
<IconComponent className="h-6 w-6 text-dynamic-color" style={{ '--dynamic-color': subject.color } as React.CSSProperties} />
<IconComponent className="h-6 w-6" style={{ color: subject.color }} />
</TableCell>
<TableCell className="font-medium">{subject.name}</TableCell>
<TableCell>
<div
className="w-6 h-6 rounded bg-dynamic-color"
style={{ '--dynamic-color': subject.color } as React.CSSProperties}
className="w-6 h-6 rounded"
style={{ backgroundColor: subject.color }}
/>
</TableCell>
<TableCell className="max-w-[200px] truncate">
@@ -389,12 +389,12 @@ export default function MaterialSubjects() {
key={color.value}
type="button"
onClick={() => setFormData({ ...formData, color: color.value })}
className={`w-8 h-8 rounded-full border-2 transition-colors bg-dynamic-color ${
className={`w-8 h-8 rounded-full border-2 transition-colors ${
formData.color === color.value
? 'border-primary scale-110'
: 'border-transparent hover:scale-105'
}`}
style={{ '--dynamic-color': color.value } as React.CSSProperties}
style={{ backgroundColor: color.value }}
title={color.name}
/>
))}