fix(management/project): task setting
This commit is contained in:
@@ -1,97 +1,224 @@
|
||||
"use client"
|
||||
|
||||
import { ProjectDetail } from "@/components/label/api/project/typing"
|
||||
import { Badge, Group, Paper, Stack, Text } from "@mantine/core"
|
||||
import {
|
||||
labelTypeMap,
|
||||
selectModeMap,
|
||||
staticsColor,
|
||||
} from "@/components/label/utils/constants"
|
||||
import { Badge, Button, Group, Modal, Paper, Stack, Text } from "@mantine/core"
|
||||
import { DataTable, DataTableColumn } from "mantine-datatable"
|
||||
import { useMemo } from "react"
|
||||
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<DetailRow[]>([])
|
||||
|
||||
const columns = useMemo(() => {
|
||||
const cols: DataTableColumn<ProjectDetail.LabelSchemaList>[] = [
|
||||
{ accessor: "category_id", title: "ID", width: 70 },
|
||||
{ accessor: "label_class", title: "类别", width: 140 },
|
||||
{
|
||||
accessor: "color",
|
||||
title: "颜色",
|
||||
width: 120,
|
||||
render: (record) => {
|
||||
const color = Array.isArray(record.color) ? record.color : []
|
||||
const bg =
|
||||
color.length >= 3
|
||||
? `rgb(${color[0]}, ${color[1]}, ${color[2]})`
|
||||
: "rgba(0,0,0,0.15)"
|
||||
const columns: DataTableColumn<ProjectDetail.LabelSchemaList>[] = [
|
||||
{
|
||||
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) => (
|
||||
<Badge variant="light">
|
||||
{labelTypeMap.get(record.label_type) ??
|
||||
String(record.label_type ?? "-")}
|
||||
</Badge>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessor: "color",
|
||||
title: "标签颜色",
|
||||
width: 130,
|
||||
render: (record) => {
|
||||
const color = Array.isArray(record.color) ? record.color : []
|
||||
const idx = getColorIndex(color)
|
||||
if (color.length < 3) {
|
||||
return (
|
||||
<Group gap={8} wrap="nowrap">
|
||||
<div
|
||||
style={{
|
||||
width: 14,
|
||||
height: 14,
|
||||
borderRadius: 4,
|
||||
background: bg,
|
||||
border: "1px solid rgba(0,0,0,0.12)",
|
||||
}}
|
||||
/>
|
||||
<Text size="sm">
|
||||
{color.length >= 3
|
||||
? `${color[0]},${color[1]},${color[2]}`
|
||||
: "-"}
|
||||
</Text>
|
||||
</Group>
|
||||
<Text size="sm" c="dimmed">
|
||||
-
|
||||
</Text>
|
||||
)
|
||||
},
|
||||
}
|
||||
return (
|
||||
<Group gap={8} wrap="nowrap">
|
||||
<div
|
||||
style={{
|
||||
width: 10,
|
||||
height: 10,
|
||||
borderRadius: 999,
|
||||
backgroundColor: `rgb(${color.join(",")})`,
|
||||
border:
|
||||
"1px solid light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
|
||||
}}
|
||||
/>
|
||||
<Text size="sm">{idx ?? "-"}</Text>
|
||||
</Group>
|
||||
)
|
||||
},
|
||||
{
|
||||
accessor: "label_type",
|
||||
title: "类型",
|
||||
width: 90,
|
||||
render: (record) => <Badge variant="light">{record.label_type}</Badge>,
|
||||
},
|
||||
{
|
||||
accessor: "sub_attributes",
|
||||
title: "子属性",
|
||||
width: 240,
|
||||
render: (record) => (
|
||||
},
|
||||
{
|
||||
accessor: "sub_attributes",
|
||||
title: "子属性",
|
||||
width: 180,
|
||||
render: (record) => {
|
||||
const attrs = Array.isArray(record.sub_attributes)
|
||||
? record.sub_attributes
|
||||
: []
|
||||
return (
|
||||
<Text
|
||||
size="sm"
|
||||
style={{
|
||||
maxWidth: 240,
|
||||
maxWidth: 180,
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
}}>
|
||||
{(record.sub_attributes ?? []).join("、") || "-"}
|
||||
{attrs.length ? attrs.join("、") : "-"}
|
||||
</Text>
|
||||
),
|
||||
)
|
||||
},
|
||||
]
|
||||
return cols
|
||||
}, [])
|
||||
},
|
||||
{
|
||||
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 (
|
||||
<Text size="sm" c="dimmed">
|
||||
-
|
||||
</Text>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Button
|
||||
variant="subtle"
|
||||
size="compact-xs"
|
||||
onClick={() => {
|
||||
setDetailRows(details)
|
||||
setDetailOpen(true)
|
||||
}}>
|
||||
查看
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const detailColumns: DataTableColumn<DetailRow>[] = [
|
||||
{
|
||||
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 (
|
||||
<Paper
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{
|
||||
borderColor:
|
||||
"light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
|
||||
}}>
|
||||
<Stack gap="sm">
|
||||
<Text fw={700}>标注方案</Text>
|
||||
<DataTable<ProjectDetail.LabelSchemaList>
|
||||
<>
|
||||
<Paper
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{
|
||||
borderColor:
|
||||
"light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
|
||||
}}>
|
||||
<Stack gap="sm">
|
||||
<Text fw={700}>标注方案</Text>
|
||||
<DataTable<ProjectDetail.LabelSchemaList>
|
||||
withTableBorder
|
||||
withRowBorders
|
||||
idAccessor="category_id"
|
||||
records={schemas}
|
||||
columns={columns}
|
||||
minHeight={160}
|
||||
noRecordsText="暂无数据"
|
||||
/>
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
<Modal
|
||||
opened={detailOpen}
|
||||
onClose={() => {
|
||||
setDetailOpen(false)
|
||||
setDetailRows([])
|
||||
}}
|
||||
title="子属性描述"
|
||||
centered
|
||||
size="70%">
|
||||
<DataTable<DetailRow>
|
||||
withTableBorder
|
||||
withRowBorders
|
||||
idAccessor="category_id"
|
||||
records={schemas}
|
||||
columns={columns}
|
||||
minHeight={160}
|
||||
records={detailRows}
|
||||
columns={detailColumns}
|
||||
noRecordsText="暂无数据"
|
||||
minHeight={220}
|
||||
idAccessor="chinese_name"
|
||||
/>
|
||||
</Stack>
|
||||
</Paper>
|
||||
</Modal>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,61 +1,278 @@
|
||||
"use client"
|
||||
|
||||
import { projectConfig } from "@/components/label/api/project"
|
||||
import { ProjectDetail } from "@/components/label/api/project/typing"
|
||||
import { List, Paper, Stack, Text } from "@mantine/core"
|
||||
import { usePermissionStore } from "@/components/label/store/auth"
|
||||
import {
|
||||
ActionIcon,
|
||||
Badge,
|
||||
Button,
|
||||
Group,
|
||||
Modal,
|
||||
Paper,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
} from "@mantine/core"
|
||||
import { modals } from "@mantine/modals"
|
||||
import { notifications } from "@mantine/notifications"
|
||||
import { IconPlus, IconTrash } from "@tabler/icons-react"
|
||||
import dayjs from "dayjs"
|
||||
import { DataTable, DataTableColumn } from "mantine-datatable"
|
||||
import { useMemo, useState } from "react"
|
||||
|
||||
type RulePayload = {
|
||||
text: string
|
||||
create_user: string
|
||||
create_date: string
|
||||
}
|
||||
|
||||
type RuleRow = RulePayload & {
|
||||
index: number
|
||||
}
|
||||
|
||||
function normalizeRule(item: unknown): RulePayload {
|
||||
if (typeof item === "string") {
|
||||
return { text: item, create_user: "-", create_date: "-" }
|
||||
}
|
||||
if (item && typeof item === "object") {
|
||||
const rule = item as {
|
||||
text?: unknown
|
||||
create_user?: unknown
|
||||
create_date?: unknown
|
||||
}
|
||||
return {
|
||||
text: String(rule.text ?? ""),
|
||||
create_user: String(rule.create_user ?? "-"),
|
||||
create_date: String(rule.create_date ?? "-"),
|
||||
}
|
||||
}
|
||||
return { text: "", create_user: "-", create_date: "-" }
|
||||
}
|
||||
|
||||
export default function NoteRulesTable(props: {
|
||||
info: ProjectDetail.DataProps | undefined
|
||||
onUpdated: () => void
|
||||
}) {
|
||||
const rules = props.info?.comment_rule
|
||||
const textRules = rules?.text_rules ?? []
|
||||
const checkBoxRules = rules?.check_box_rules ?? []
|
||||
const { info, onUpdated } = props
|
||||
const projectId = info?.id ?? -1
|
||||
const userName = usePermissionStore((s) => s.user_name)
|
||||
|
||||
const [open, setOpen] = useState(false)
|
||||
const [inputText, setInputText] = useState("")
|
||||
const [saving, setSaving] = useState(false)
|
||||
|
||||
const textRules = useMemo(() => {
|
||||
const rules = (info?.comment_rule as any)?.text_rules
|
||||
return Array.isArray(rules) ? rules.map((r) => String(r ?? "")) : []
|
||||
}, [info?.comment_rule])
|
||||
|
||||
const checkBoxRules = useMemo<RulePayload[]>(() => {
|
||||
const raw = (info?.comment_rule as any)?.check_box_rules
|
||||
const list = Array.isArray(raw) ? raw : []
|
||||
return list.map((item) => normalizeRule(item))
|
||||
}, [info?.comment_rule])
|
||||
|
||||
const rows = useMemo<RuleRow[]>(() => {
|
||||
return checkBoxRules.map((rule, index) => ({ ...rule, index }))
|
||||
}, [checkBoxRules])
|
||||
|
||||
const saveRules = async (nextRules: RulePayload[], successText: string) => {
|
||||
if (projectId === -1) return
|
||||
setSaving(true)
|
||||
try {
|
||||
await projectConfig({
|
||||
project_id: projectId,
|
||||
comment_rule: {
|
||||
check_box_rules: nextRules,
|
||||
text_rules: textRules,
|
||||
},
|
||||
})
|
||||
notifications.show({
|
||||
color: "green",
|
||||
title: "操作成功",
|
||||
message: successText,
|
||||
})
|
||||
setOpen(false)
|
||||
setInputText("")
|
||||
onUpdated()
|
||||
} catch (e) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "操作失败",
|
||||
message: e instanceof Error ? e.message : "请求失败",
|
||||
})
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleAdd = async () => {
|
||||
const value = inputText.trim()
|
||||
if (!value) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "新增失败",
|
||||
message: "批注内容不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
const exists = rows.some((row) => row.text.trim() === value)
|
||||
if (exists) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "新增失败",
|
||||
message: "批注规则重复,请重新输入",
|
||||
})
|
||||
return
|
||||
}
|
||||
const next: RulePayload[] = [
|
||||
...checkBoxRules,
|
||||
{
|
||||
text: value,
|
||||
create_user: userName ? String(userName) : "-",
|
||||
create_date: dayjs().format("YYYY-MM-DD"),
|
||||
},
|
||||
]
|
||||
await saveRules(next, "已添加规则")
|
||||
}
|
||||
|
||||
const handleDelete = async (row: RuleRow) => {
|
||||
const next = checkBoxRules.filter((_, index) => index !== row.index)
|
||||
await saveRules(next, "已删除规则")
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<RuleRow>[] = [
|
||||
{
|
||||
accessor: "method",
|
||||
title: "批注方式",
|
||||
width: 90,
|
||||
render: () => <Badge variant="light">勾选</Badge>,
|
||||
},
|
||||
{
|
||||
accessor: "text",
|
||||
title: "内容",
|
||||
},
|
||||
{
|
||||
accessor: "create_user",
|
||||
title: "添加者",
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
accessor: "create_date",
|
||||
title: "添加日期",
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
accessor: "operation",
|
||||
title: "操作",
|
||||
width: 90,
|
||||
textAlign: "center",
|
||||
render: (record) => (
|
||||
<ActionIcon
|
||||
variant="subtle"
|
||||
color="red"
|
||||
onClick={() => {
|
||||
modals.openConfirmModal({
|
||||
title: "删除规则",
|
||||
centered: true,
|
||||
children: <Text size="sm">确定删除该批注规则吗?</Text>,
|
||||
labels: { confirm: "确定", cancel: "取消" },
|
||||
confirmProps: { color: "red" },
|
||||
onConfirm: () => handleDelete(record),
|
||||
})
|
||||
}}>
|
||||
<IconTrash size={16} />
|
||||
</ActionIcon>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<Paper
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{
|
||||
borderColor:
|
||||
"light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
|
||||
}}>
|
||||
<Stack gap="xs">
|
||||
<Text fw={700}>批注规则</Text>
|
||||
<>
|
||||
<Paper
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{
|
||||
borderColor:
|
||||
"light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
|
||||
}}>
|
||||
<Stack gap="sm">
|
||||
<Group justify="space-between" wrap="wrap">
|
||||
<Text fw={700}>批注规则</Text>
|
||||
<Button
|
||||
size="xs"
|
||||
leftSection={<IconPlus size={14} />}
|
||||
onClick={() => {
|
||||
setInputText("")
|
||||
setOpen(true)
|
||||
}}>
|
||||
添加规则
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
<Stack gap={4}>
|
||||
<Text size="sm" fw={600}>
|
||||
文本规则
|
||||
</Text>
|
||||
{textRules.length ? (
|
||||
<List size="sm" spacing={4}>
|
||||
{textRules.map((r, idx) => (
|
||||
<List.Item key={idx}>{r}</List.Item>
|
||||
))}
|
||||
</List>
|
||||
) : (
|
||||
<Text size="sm" c="dimmed">
|
||||
-
|
||||
<Stack gap={4}>
|
||||
<Text size="sm" fw={600}>
|
||||
文本规则
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
<Text size="sm" c="dimmed">
|
||||
{textRules.length ? textRules.join(";") : "-"}
|
||||
</Text>
|
||||
</Stack>
|
||||
|
||||
<Stack gap={4}>
|
||||
<Text size="sm" fw={600}>
|
||||
勾选规则
|
||||
</Text>
|
||||
{checkBoxRules.length ? (
|
||||
<List size="sm" spacing={4}>
|
||||
{checkBoxRules.map((r, idx) => (
|
||||
<List.Item key={idx}>{String(r)}</List.Item>
|
||||
))}
|
||||
</List>
|
||||
) : (
|
||||
<Text size="sm" c="dimmed">
|
||||
-
|
||||
</Text>
|
||||
)}
|
||||
<DataTable<RuleRow>
|
||||
withTableBorder
|
||||
withRowBorders
|
||||
records={rows}
|
||||
columns={columns}
|
||||
noRecordsText="暂无规则"
|
||||
minHeight={200}
|
||||
idAccessor={(record) =>
|
||||
`${record.index}_${record.text}_${record.create_user}_${record.create_date}`
|
||||
}
|
||||
/>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Paper>
|
||||
</Paper>
|
||||
|
||||
<Modal
|
||||
opened={open}
|
||||
onClose={() => {
|
||||
if (saving) return
|
||||
setOpen(false)
|
||||
setInputText("")
|
||||
}}
|
||||
title="添加批注规则"
|
||||
centered>
|
||||
<Stack gap="sm">
|
||||
<Group gap="sm">
|
||||
<Text size="sm" c="dimmed">
|
||||
批注方式
|
||||
</Text>
|
||||
<Badge variant="light">勾选</Badge>
|
||||
</Group>
|
||||
<TextInput
|
||||
label="批注内容"
|
||||
placeholder="请输入批注内容"
|
||||
value={inputText}
|
||||
onChange={(e) => setInputText(e.currentTarget.value)}
|
||||
/>
|
||||
<Group justify="flex-end" gap="sm">
|
||||
<Button
|
||||
variant="default"
|
||||
onClick={() => {
|
||||
setOpen(false)
|
||||
setInputText("")
|
||||
}}
|
||||
disabled={saving}>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={handleAdd} loading={saving}>
|
||||
保存
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Modal>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user