fix(management/project): task setting

This commit is contained in:
2026-02-27 10:51:29 +08:00
parent e3ca3e9c31
commit 36d5a0e5b0
4 changed files with 2168 additions and 245 deletions

View File

@@ -1,11 +1,31 @@
"use client" "use client"
import { projectConfig } from "@/components/label/api/project" import {
getProjectAdminList,
projectConfig,
} from "@/components/label/api/project"
import { ProjectDetail } from "@/components/label/api/project/typing" import { ProjectDetail } from "@/components/label/api/project/typing"
import { useAllUserStore } from "@/components/label/store/auth" import { useAllUserStore } from "@/components/label/store/auth"
import { Button, Group, Paper, Stack, Switch, Text } from "@mantine/core" import {
ActionIcon,
Collapse,
Group,
Paper,
ScrollArea,
SimpleGrid,
Stack,
Switch,
Text,
} from "@mantine/core"
import { notifications } from "@mantine/notifications" import { notifications } from "@mantine/notifications"
import { useMemo, useState } from "react" import {
IconCheck,
IconChevronDown,
IconChevronRight,
IconEdit,
IconX,
} from "@tabler/icons-react"
import { useCallback, useEffect, useMemo, useState } from "react"
import AdminUserModal from "./components/AdminUserModal" import AdminUserModal from "./components/AdminUserModal"
import LabelSchemeContainer from "./components/LabelSchemeContainer" import LabelSchemeContainer from "./components/LabelSchemeContainer"
import NoteRulesTable from "./components/NoteRulesTable" import NoteRulesTable from "./components/NoteRulesTable"
@@ -26,16 +46,55 @@ export default function InfoSettingContainer(props: {
const projectId = info?.id ?? -1 const projectId = info?.id ?? -1
const { userOpts } = useAllUserStore() const { userOpts } = useAllUserStore()
const userOptions = useMemo(() => { const fallbackUserOptions = useMemo(() => {
return userOpts.map((o) => ({ label: o.label, value: String(o.value) })) return userOpts.map((o) => ({ label: o.label, value: String(o.value) }))
}, [userOpts]) }, [userOpts])
const [adminOptions, setAdminOptions] = useState<
Array<{ label: string; value: string }>
>([])
const [adminModalOpen, setAdminModalOpen] = useState(false) const [adminModalOpen, setAdminModalOpen] = useState(false)
const [lockingValue, setLockingValue] = useState<boolean>( const [lockingValue, setLockingValue] = useState<boolean>(
!!info?.is_lock_object !!info?.is_lock_object
) )
const [lockingEditValue, setLockingEditValue] = useState<boolean>(
!!info?.is_lock_object
)
const [isLockingEdit, setIsLockingEdit] = useState(false)
const [savingLock, setSavingLock] = useState(false) const [savingLock, setSavingLock] = useState(false)
const [show, setShow] = useState({
process: true,
scheme: true,
sampling: true,
note: true,
})
useEffect(() => {
const v = !!info?.is_lock_object
setLockingValue(v)
setLockingEditValue(v)
setIsLockingEdit(false)
}, [info?.is_lock_object])
const loadAdminOptions = useCallback(async () => {
try {
const res = await getProjectAdminList()
const opts = (res ?? []).map((item) => ({
label: item.label,
value: String(item.value),
}))
setAdminOptions(opts)
} catch {
setAdminOptions([])
}
}, [])
useEffect(() => {
queueMicrotask(loadAdminOptions)
}, [loadAdminOptions])
const adminText = useMemo(() => { const adminText = useMemo(() => {
const adminUids = info?.admin_user ?? [] const adminUids = info?.admin_user ?? []
const names = adminUids.map((uid) => { const names = adminUids.map((uid) => {
@@ -51,13 +110,15 @@ export default function InfoSettingContainer(props: {
try { try {
await projectConfig({ await projectConfig({
project_id: projectId, project_id: projectId,
is_lock_object: lockingValue, is_lock_object: lockingEditValue,
}) })
notifications.show({ notifications.show({
color: "green", color: "green",
title: "操作成功", title: "操作成功",
message: "已保存配置", message: "已保存配置",
}) })
setLockingValue(lockingEditValue)
setIsLockingEdit(false)
updateAction() updateAction()
} catch (e) { } catch (e) {
notifications.show({ notifications.show({
@@ -70,9 +131,45 @@ export default function InfoSettingContainer(props: {
} }
} }
const sectionTitle = (
key: keyof typeof show,
title: string,
color: "blue" | "orange" | "teal" | "grape"
) => {
const opened = show[key]
return (
<Group justify="space-between" wrap="nowrap">
<Group gap={8}>
<div
style={{
width: 3,
height: 14,
borderRadius: 2,
backgroundColor: `var(--mantine-color-${color}-6)`,
}}
/>
<Text fw={700}>{title}</Text>
</Group>
<ActionIcon
variant="subtle"
color="gray"
onClick={() => setShow((s) => ({ ...s, [key]: !opened }))}>
{opened ? (
<IconChevronDown size={16} />
) : (
<IconChevronRight size={16} />
)}
</ActionIcon>
</Group>
)
}
const finalAdminOptions =
adminOptions.length > 0 ? adminOptions : fallbackUserOptions
return ( return (
<> <>
<Stack gap="md" style={{ flex: 1, minHeight: 0 }}> <Stack gap="md" style={{ flex: 1, minHeight: 0 }} w="100%">
<Paper <Paper
withBorder withBorder
p="sm" p="sm"
@@ -83,30 +180,61 @@ export default function InfoSettingContainer(props: {
}}> }}>
<Stack gap="sm"> <Stack gap="sm">
<Group justify="space-between" wrap="wrap"> <Group justify="space-between" wrap="wrap">
<Text fw={700}></Text> <Text fw={700}></Text>
<Button size="xs" variant="default" onClick={updateAction}> <ActionIcon variant="subtle" onClick={updateAction}>
<IconEdit size={16} />
</Button> </ActionIcon>
</Group> </Group>
<Group justify="space-between" wrap="wrap"> <SimpleGrid cols={{ base: 1, md: 2 }} spacing="sm">
<Stack gap={2}> <Paper
withBorder
p="xs"
radius="sm"
style={{
borderColor:
"light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
}}>
<Group justify="space-between" wrap="nowrap" align="center">
<Stack gap={2} style={{ minWidth: 0 }}>
<Text size="sm" fw={600}> <Text size="sm" fw={600}>
</Text> </Text>
<Text size="sm" c="dimmed"> <Text
size="sm"
c="dimmed"
style={{
maxWidth: 420,
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}>
{adminText} {adminText}
</Text> </Text>
</Stack> </Stack>
<Button <ActionIcon
size="xs" variant="subtle"
variant="default" color="blue"
onClick={() => setAdminModalOpen(true)}> onClick={() => {
setAdminModalOpen(true)
</Button> if (adminOptions.length === 0) {
queueMicrotask(loadAdminOptions)
}
}}>
<IconEdit size={16} />
</ActionIcon>
</Group> </Group>
</Paper>
<Group justify="space-between" wrap="wrap"> <Paper
withBorder
p="xs"
radius="sm"
style={{
borderColor:
"light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
}}>
<Group justify="space-between" wrap="nowrap" align="center">
<Stack gap={2}> <Stack gap={2}>
<Text size="sm" fw={600}> <Text size="sm" fw={600}>
@@ -115,42 +243,107 @@ export default function InfoSettingContainer(props: {
</Text> </Text>
</Stack> </Stack>
<Group gap="sm"> {isLockingEdit ? (
<Group gap={4} wrap="nowrap">
<Switch <Switch
checked={lockingValue} checked={lockingEditValue}
onChange={(e) => setLockingValue(e.currentTarget.checked)} onChange={(e) =>
setLockingEditValue(e.currentTarget.checked)
}
/> />
<Button size="xs" loading={savingLock} onClick={saveLock}> <ActionIcon
variant="subtle"
</Button> color="gray"
onClick={() => {
setLockingEditValue(lockingValue)
setIsLockingEdit(false)
}}>
<IconX size={16} />
</ActionIcon>
<ActionIcon
variant="subtle"
color="blue"
loading={savingLock}
onClick={saveLock}>
<IconCheck size={16} />
</ActionIcon>
</Group> </Group>
) : (
<Group gap={8} wrap="nowrap">
<Switch checked={lockingValue} readOnly />
<ActionIcon
variant="subtle"
color="blue"
onClick={() => setIsLockingEdit(true)}>
<IconEdit size={16} />
</ActionIcon>
</Group>
)}
</Group>
</Paper>
</SimpleGrid>
<Group justify="flex-end">
<ActionIcon variant="subtle" onClick={updateAction}>
<IconCheck size={16} />
</ActionIcon>
<Text size="xs" c="dimmed">
</Text>
</Group> </Group>
</Stack> </Stack>
</Paper> </Paper>
<Paper
withBorder
p="sm"
radius="md"
style={{
borderColor:
"light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
flex: 1,
minHeight: 0,
}}>
<ScrollArea h="100%" type="auto">
<Stack gap="sm">
{sectionTitle("process", "任务流程", "blue")}
<Collapse in={show.process}>
<TaskStageTabsContainer <TaskStageTabsContainer
projectId={projectId} projectId={projectId}
info={info} info={info}
userOptions={userOptions} userOptions={fallbackUserOptions}
userEnums={userEnums} userEnums={userEnums}
onUpdatedAction={updateAction} onUpdatedAction={updateAction}
/> />
</Collapse>
{sectionTitle("scheme", "标注方案", "orange")}
<Collapse in={show.scheme}>
<LabelSchemeContainer info={info} />
</Collapse>
{sectionTitle("sampling", "抽检方案", "teal")}
<Collapse in={show.sampling}>
<SamplingPlanContainer <SamplingPlanContainer
projectId={projectId} projectId={projectId}
info={info} info={info}
onUpdated={updateAction} onUpdated={updateAction}
/> />
</Collapse>
<LabelSchemeContainer info={info} /> {sectionTitle("note", "批注规则", "grape")}
<Collapse in={show.note}>
<NoteRulesTable info={info} /> <NoteRulesTable info={info} onUpdated={updateAction} />
</Collapse>
</Stack>
</ScrollArea>
</Paper>
</Stack> </Stack>
<AdminUserModal <AdminUserModal
opened={adminModalOpen} opened={adminModalOpen}
value={info?.admin_user ?? []} value={info?.admin_user ?? []}
options={userOptions} options={finalAdminOptions}
onCloseAction={async (next) => { onCloseAction={async (next) => {
setAdminModalOpen(false) setAdminModalOpen(false)
if (!next || projectId === -1) return if (!next || projectId === -1) return

View File

@@ -1,77 +1,183 @@
"use client" "use client"
import { ProjectDetail } from "@/components/label/api/project/typing" 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 { 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: { export default function LabelSchemeContainer(props: {
info: ProjectDetail.DataProps | undefined info: ProjectDetail.DataProps | undefined
}) { }) {
const schemas = props.info?.label_schema_list ?? [] const schemas = props.info?.label_schema_list ?? []
const [detailOpen, setDetailOpen] = useState(false)
const [detailRows, setDetailRows] = useState<DetailRow[]>([])
const columns = useMemo(() => { const columns: DataTableColumn<ProjectDetail.LabelSchemaList>[] = [
const cols: DataTableColumn<ProjectDetail.LabelSchemaList>[] = [ {
{ accessor: "category_id", title: "ID", width: 70 }, accessor: "label_class",
{ accessor: "label_class", title: "类别", width: 140 }, 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", accessor: "color",
title: "颜色", title: "标签颜色",
width: 120, width: 130,
render: (record) => { render: (record) => {
const color = Array.isArray(record.color) ? record.color : [] const color = Array.isArray(record.color) ? record.color : []
const bg = const idx = getColorIndex(color)
color.length >= 3 if (color.length < 3) {
? `rgb(${color[0]}, ${color[1]}, ${color[2]})` return (
: "rgba(0,0,0,0.15)" <Text size="sm" c="dimmed">
-
</Text>
)
}
return ( return (
<Group gap={8} wrap="nowrap"> <Group gap={8} wrap="nowrap">
<div <div
style={{ style={{
width: 14, width: 10,
height: 14, height: 10,
borderRadius: 4, borderRadius: 999,
background: bg, backgroundColor: `rgb(${color.join(",")})`,
border: "1px solid rgba(0,0,0,0.12)", border:
"1px solid light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
}} }}
/> />
<Text size="sm"> <Text size="sm">{idx ?? "-"}</Text>
{color.length >= 3
? `${color[0]},${color[1]},${color[2]}`
: "-"}
</Text>
</Group> </Group>
) )
}, },
}, },
{
accessor: "label_type",
title: "类型",
width: 90,
render: (record) => <Badge variant="light">{record.label_type}</Badge>,
},
{ {
accessor: "sub_attributes", accessor: "sub_attributes",
title: "子属性", title: "子属性",
width: 240, width: 180,
render: (record) => ( render: (record) => {
const attrs = Array.isArray(record.sub_attributes)
? record.sub_attributes
: []
return (
<Text <Text
size="sm" size="sm"
style={{ style={{
maxWidth: 240, maxWidth: 180,
overflow: "hidden", overflow: "hidden",
textOverflow: "ellipsis", textOverflow: "ellipsis",
whiteSpace: "nowrap", whiteSpace: "nowrap",
}}> }}>
{(record.sub_attributes ?? []).join("、") || "-"} {attrs.length ? attrs.join("、") : "-"}
</Text> </Text>
), )
},
},
{
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 cols
}, [])
return ( return (
<>
<Paper <Paper
withBorder withBorder
p="sm" p="sm"
@@ -93,5 +199,26 @@ export default function LabelSchemeContainer(props: {
/> />
</Stack> </Stack>
</Paper> </Paper>
<Modal
opened={detailOpen}
onClose={() => {
setDetailOpen(false)
setDetailRows([])
}}
title="子属性描述"
centered
size="70%">
<DataTable<DetailRow>
withTableBorder
withRowBorders
records={detailRows}
columns={detailColumns}
noRecordsText="暂无数据"
minHeight={220}
idAccessor="chinese_name"
/>
</Modal>
</>
) )
} }

View File

@@ -1,16 +1,195 @@
"use client" "use client"
import { projectConfig } from "@/components/label/api/project"
import { ProjectDetail } from "@/components/label/api/project/typing" 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: { export default function NoteRulesTable(props: {
info: ProjectDetail.DataProps | undefined info: ProjectDetail.DataProps | undefined
onUpdated: () => void
}) { }) {
const rules = props.info?.comment_rule const { info, onUpdated } = props
const textRules = rules?.text_rules ?? [] const projectId = info?.id ?? -1
const checkBoxRules = rules?.check_box_rules ?? [] 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 ( return (
<>
<Paper <Paper
withBorder withBorder
p="sm" p="sm"
@@ -19,43 +198,81 @@ export default function NoteRulesTable(props: {
borderColor: borderColor:
"light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))", "light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4))",
}}> }}>
<Stack gap="xs"> <Stack gap="sm">
<Group justify="space-between" wrap="wrap">
<Text fw={700}></Text> <Text fw={700}></Text>
<Button
size="xs"
leftSection={<IconPlus size={14} />}
onClick={() => {
setInputText("")
setOpen(true)
}}>
</Button>
</Group>
<Stack gap={4}> <Stack gap={4}>
<Text size="sm" fw={600}> <Text size="sm" fw={600}>
</Text> </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"> <Text size="sm" c="dimmed">
- {textRules.length ? textRules.join("") : "-"}
</Text> </Text>
)}
</Stack> </Stack>
<Stack gap={4}> <DataTable<RuleRow>
<Text size="sm" fw={600}> withTableBorder
withRowBorders
</Text> records={rows}
{checkBoxRules.length ? ( columns={columns}
<List size="sm" spacing={4}> noRecordsText="暂无规则"
{checkBoxRules.map((r, idx) => ( minHeight={200}
<List.Item key={idx}>{String(r)}</List.Item> idAccessor={(record) =>
))} `${record.index}_${record.text}_${record.create_user}_${record.create_date}`
</List> }
) : ( />
<Text size="sm" c="dimmed">
-
</Text>
)}
</Stack>
</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>
</>
) )
} }