"use client" import { ProjectDetail } from "@/components/label/api/project/typing" import { labelTypeMap, selectModeMap, staticsColor, } from "@/components/label/utils/constants" import { SettingDataTable } from "@/components/setting/PageSurface" import { Badge, Button, Group, Modal, Paper, Stack, Text } from "@mantine/core" import { DataTableColumn } from "mantine-datatable" import { useState } from "react" type DetailRow = ProjectDetail.SubAttributesDescribe function getColorIndex(color: number[] | undefined) { if (!Array.isArray(color) || color.length < 3) return undefined const key = color.slice(0, 3).join("_") for (const item of staticsColor) { const [colorKey, colorIndex] = Object.entries(item)[0] ?? [] if (colorKey === key && typeof colorIndex === "number") { return colorIndex } } return undefined } export default function LabelSchemeContainer(props: { info: ProjectDetail.DataProps | undefined }) { const schemas = props.info?.label_schema_list ?? [] const [detailOpen, setDetailOpen] = useState(false) const [detailRows, setDetailRows] = useState([]) const columns: DataTableColumn[] = [ { accessor: "label_class", title: "类别", width: 120, }, { accessor: "super_category", title: "属性", width: 120, render: (record) => record.super_category || "-", }, { accessor: "category_id", title: "ID", width: 90, }, { accessor: "label_type", title: "标注方式", width: 140, render: (record) => ( {labelTypeMap.get(record.label_type) ?? String(record.label_type ?? "-")} ), }, { accessor: "color", title: "标签颜色", width: 130, render: (record) => { const color = Array.isArray(record.color) ? record.color : [] const idx = getColorIndex(color) if (color.length < 3) { return ( - ) } return (
{idx ?? "-"} ) }, }, { accessor: "sub_attributes", title: "子属性", width: 180, render: (record) => { const attrs = Array.isArray(record.sub_attributes) ? record.sub_attributes : [] return ( {attrs.length ? attrs.join("、") : "-"} ) }, }, { accessor: "sub_attributes_describe", title: "子属性描述", width: 120, textAlign: "center", render: (record) => { const details = Array.isArray(record.sub_attributes_describe) ? record.sub_attributes_describe : [] if (!details.length) { return ( - ) } return ( ) }, }, ] const detailColumns: DataTableColumn[] = [ { accessor: "chinese_name", title: "子属性", width: 140, render: (record) => record.chinese_name || "-", }, { accessor: "select_mode", title: "输入方式", width: 100, render: (record) => selectModeMap.get(record.select_mode) ?? String(record.select_mode ?? "-"), }, { accessor: "isrequired", title: "是否必填", width: 90, render: (record) => (record.isrequired === 1 ? "是" : "否"), }, { accessor: "optional_item", title: "可选属性值", render: (record) => { const opts = Array.isArray(record.optional_item) ? record.optional_item : [] return opts.length ? opts.join(";") : "-" }, }, ] return ( <> 标注方案 idAccessor="category_id" records={schemas} columns={columns} minHeight={160} noRecordsText="暂无数据" /> { setDetailOpen(false) setDetailRows([]) }} title="子属性描述" centered size="70%"> records={detailRows} columns={detailColumns} noRecordsText="暂无数据" minHeight={220} idAccessor="chinese_name" /> ) }