fix(detail): change detail
This commit is contained in:
59
app/management/project/detail/components/AdminUserModal.tsx
Normal file
59
app/management/project/detail/components/AdminUserModal.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
"use client"
|
||||
|
||||
import { Button, Group, Modal, MultiSelect, Stack } from "@mantine/core"
|
||||
import { useForm } from "@mantine/form"
|
||||
import { useEffect } from "react"
|
||||
|
||||
export default function AdminUserModal(props: {
|
||||
opened: boolean
|
||||
value: number[]
|
||||
options: Array<{ label: string; value: string }>
|
||||
onCloseAction: (next?: number[]) => void
|
||||
}) {
|
||||
const { opened, value, options, onCloseAction } = props
|
||||
|
||||
const form = useForm({
|
||||
initialValues: { users: value.map(String) },
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!opened) return
|
||||
form.setValues({ users: value.map(String) })
|
||||
form.resetDirty()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [opened, value])
|
||||
|
||||
return (
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={() => onCloseAction()}
|
||||
title="编辑项目管理员"
|
||||
centered
|
||||
size={560}>
|
||||
<form
|
||||
onSubmit={form.onSubmit((values) => {
|
||||
const next = values.users
|
||||
.map((v) => Number(v))
|
||||
.filter((v) => Number.isFinite(v))
|
||||
onCloseAction(next)
|
||||
})}>
|
||||
<Stack gap="sm">
|
||||
<MultiSelect
|
||||
label="项目管理员"
|
||||
data={options}
|
||||
searchable
|
||||
clearable
|
||||
value={form.values.users}
|
||||
onChange={(v) => form.setFieldValue("users", v)}
|
||||
/>
|
||||
<Group justify="flex-end" gap="sm">
|
||||
<Button variant="default" onClick={() => onCloseAction()}>
|
||||
取消
|
||||
</Button>
|
||||
<Button type="submit">保存</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</form>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
149
app/management/project/detail/components/DispatchModal.tsx
Normal file
149
app/management/project/detail/components/DispatchModal.tsx
Normal file
@@ -0,0 +1,149 @@
|
||||
"use client"
|
||||
|
||||
import { dispatchOpts } from "@/app/management/person/collection/config"
|
||||
import { taskDispatch } from "@/components/label/api/task"
|
||||
import { Task } from "@/components/label/api/task/typing"
|
||||
import { usePermissionStore } from "@/components/label/store/auth"
|
||||
import {
|
||||
Button,
|
||||
Group,
|
||||
Modal,
|
||||
Select,
|
||||
Stack,
|
||||
Switch,
|
||||
Text,
|
||||
} from "@mantine/core"
|
||||
import { useForm } from "@mantine/form"
|
||||
import { notifications } from "@mantine/notifications"
|
||||
|
||||
export default function DispatchModal(props: {
|
||||
opened: boolean
|
||||
record: Task.DataProps | null
|
||||
userOptions: Array<{ label: string; value: string }>
|
||||
onCloseAction: (refresh?: boolean) => void
|
||||
}) {
|
||||
const { opened, record, userOptions, onCloseAction } = props
|
||||
const operation_uid = usePermissionStore((s) => s.user_id)
|
||||
|
||||
const form = useForm({
|
||||
initialValues: {
|
||||
reject: false,
|
||||
task_status_dst: "",
|
||||
uid_dst: "",
|
||||
},
|
||||
})
|
||||
|
||||
const taskStatusSrc = record?.label_status ?? 0
|
||||
const dstOptions =
|
||||
dispatchOpts[taskStatusSrc]?.opts?.map((o) => ({
|
||||
label: o.label,
|
||||
value: String(o.value),
|
||||
})) ?? []
|
||||
|
||||
return (
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={() => onCloseAction()}
|
||||
title="调度任务"
|
||||
centered
|
||||
size={520}>
|
||||
<form
|
||||
onSubmit={form.onSubmit(async (values) => {
|
||||
const opUid =
|
||||
typeof operation_uid === "number"
|
||||
? operation_uid
|
||||
: Number(operation_uid ?? 0)
|
||||
if (!record?.id || !opUid) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "操作失败",
|
||||
message: "缺少必要参数",
|
||||
})
|
||||
return
|
||||
}
|
||||
const taskStatusDst = Number(values.task_status_dst)
|
||||
if (!Number.isFinite(taskStatusDst)) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "校验失败",
|
||||
message: "请选择目标状态",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const uidDst = values.uid_dst ? Number(values.uid_dst) : null
|
||||
if (values.uid_dst && !Number.isFinite(uidDst)) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "校验失败",
|
||||
message: "请选择目标人员",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await taskDispatch({
|
||||
operation_uid: opUid,
|
||||
reject: values.reject,
|
||||
task_ids: [record.id],
|
||||
task_status_src: taskStatusSrc,
|
||||
task_status_dst: taskStatusDst,
|
||||
uid_src: record.current_uid ?? null,
|
||||
uid_dst: uidDst,
|
||||
})
|
||||
notifications.show({
|
||||
color: "green",
|
||||
title: "操作成功",
|
||||
message: "已调度任务",
|
||||
})
|
||||
onCloseAction(true)
|
||||
} catch (e) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "操作失败",
|
||||
message: e instanceof Error ? e.message : "请求失败",
|
||||
})
|
||||
}
|
||||
})}>
|
||||
<Stack gap="sm">
|
||||
<Text size="sm" c="dimmed">
|
||||
当前任务:{record?.id ?? "-"}(源状态:{taskStatusSrc})
|
||||
</Text>
|
||||
|
||||
<Select
|
||||
label="目标状态"
|
||||
data={dstOptions}
|
||||
searchable
|
||||
clearable
|
||||
value={form.values.task_status_dst}
|
||||
onChange={(v) => form.setFieldValue("task_status_dst", v ?? "")}
|
||||
/>
|
||||
|
||||
<Select
|
||||
label="目标人员"
|
||||
data={userOptions}
|
||||
searchable
|
||||
clearable
|
||||
value={form.values.uid_dst}
|
||||
onChange={(v) => form.setFieldValue("uid_dst", v ?? "")}
|
||||
/>
|
||||
|
||||
<Switch
|
||||
label="是否返工"
|
||||
checked={form.values.reject}
|
||||
onChange={(e) =>
|
||||
form.setFieldValue("reject", e.currentTarget.checked)
|
||||
}
|
||||
/>
|
||||
|
||||
<Group justify="flex-end" gap="sm">
|
||||
<Button variant="default" onClick={() => onCloseAction()}>
|
||||
取消
|
||||
</Button>
|
||||
<Button type="submit">确定</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</form>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
"use client"
|
||||
|
||||
import { ProjectDetail } from "@/components/label/api/project/typing"
|
||||
import { Badge, Group, Paper, Stack, Text } from "@mantine/core"
|
||||
import { DataTable, DataTableColumn } from "mantine-datatable"
|
||||
import { useMemo } from "react"
|
||||
|
||||
export default function LabelSchemeContainer(props: {
|
||||
info: ProjectDetail.DataProps | undefined
|
||||
}) {
|
||||
const schemas = props.info?.label_schema_list ?? []
|
||||
|
||||
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)"
|
||||
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>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
accessor: "label_type",
|
||||
title: "类型",
|
||||
width: 90,
|
||||
render: (record) => <Badge variant="light">{record.label_type}</Badge>,
|
||||
},
|
||||
{
|
||||
accessor: "sub_attributes",
|
||||
title: "子属性",
|
||||
width: 240,
|
||||
render: (record) => (
|
||||
<Text
|
||||
size="sm"
|
||||
style={{
|
||||
maxWidth: 240,
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
}}>
|
||||
{(record.sub_attributes ?? []).join("、") || "-"}
|
||||
</Text>
|
||||
),
|
||||
},
|
||||
]
|
||||
return cols
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Paper
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{ borderColor: "rgba(0,0,0,0.06)" }}>
|
||||
<Stack gap="sm">
|
||||
<Text fw={700}>标注方案</Text>
|
||||
<DataTable<ProjectDetail.LabelSchemaList>
|
||||
withTableBorder
|
||||
withRowBorders
|
||||
idAccessor="category_id"
|
||||
records={schemas}
|
||||
columns={columns}
|
||||
minHeight={160}
|
||||
noRecordsText="暂无数据"
|
||||
/>
|
||||
</Stack>
|
||||
</Paper>
|
||||
)
|
||||
}
|
||||
58
app/management/project/detail/components/NoteRulesTable.tsx
Normal file
58
app/management/project/detail/components/NoteRulesTable.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
"use client"
|
||||
|
||||
import { ProjectDetail } from "@/components/label/api/project/typing"
|
||||
import { List, Paper, Stack, Text } from "@mantine/core"
|
||||
|
||||
export default function NoteRulesTable(props: {
|
||||
info: ProjectDetail.DataProps | undefined
|
||||
}) {
|
||||
const rules = props.info?.comment_rule
|
||||
const textRules = rules?.text_rules ?? []
|
||||
const checkBoxRules = rules?.check_box_rules ?? []
|
||||
|
||||
return (
|
||||
<Paper
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{ borderColor: "rgba(0,0,0,0.06)" }}>
|
||||
<Stack gap="xs">
|
||||
<Text fw={700}>批注规则</Text>
|
||||
|
||||
<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">
|
||||
-
|
||||
</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>
|
||||
)}
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Paper>
|
||||
)
|
||||
}
|
||||
90
app/management/project/detail/components/ReleaseModal.tsx
Normal file
90
app/management/project/detail/components/ReleaseModal.tsx
Normal file
@@ -0,0 +1,90 @@
|
||||
"use client"
|
||||
|
||||
import { taskRelease } from "@/components/label/api/task"
|
||||
import { Task } from "@/components/label/api/task/typing"
|
||||
import { usePermissionStore } from "@/components/label/store/auth"
|
||||
import { Button, Group, Modal, Stack, Switch, Text } from "@mantine/core"
|
||||
import { useForm } from "@mantine/form"
|
||||
import { notifications } from "@mantine/notifications"
|
||||
|
||||
export default function ReleaseModal(props: {
|
||||
opened: boolean
|
||||
record: Task.DataProps | null
|
||||
onCloseAction: (refresh?: boolean) => void
|
||||
}) {
|
||||
const { opened, record, onCloseAction } = props
|
||||
const operation_uid = usePermissionStore((s) => s.user_id)
|
||||
|
||||
const form = useForm({
|
||||
initialValues: {
|
||||
reject: false,
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={() => onCloseAction()}
|
||||
title="释放任务"
|
||||
centered
|
||||
size={520}>
|
||||
<form
|
||||
onSubmit={form.onSubmit(async (values) => {
|
||||
const opUid =
|
||||
typeof operation_uid === "number"
|
||||
? operation_uid
|
||||
: Number(operation_uid ?? 0)
|
||||
if (!record?.id || !opUid || !record.current_uid) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "操作失败",
|
||||
message: "缺少必要参数",
|
||||
})
|
||||
return
|
||||
}
|
||||
try {
|
||||
await taskRelease({
|
||||
operation_uid: opUid,
|
||||
reject: values.reject,
|
||||
task_ids: [record.id],
|
||||
task_status: record.label_status,
|
||||
uid: record.current_uid,
|
||||
})
|
||||
notifications.show({
|
||||
color: "green",
|
||||
title: "操作成功",
|
||||
message: "已释放任务",
|
||||
})
|
||||
onCloseAction(true)
|
||||
} catch (e) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "操作失败",
|
||||
message: e instanceof Error ? e.message : "请求失败",
|
||||
})
|
||||
}
|
||||
})}>
|
||||
<Stack gap="sm">
|
||||
<Text size="sm" c="dimmed">
|
||||
当前任务:{record?.id ?? "-"}(状态:{record?.label_status ?? "-"})
|
||||
</Text>
|
||||
<Switch
|
||||
label="是否返工"
|
||||
checked={form.values.reject}
|
||||
onChange={(e) =>
|
||||
form.setFieldValue("reject", e.currentTarget.checked)
|
||||
}
|
||||
/>
|
||||
<Group justify="flex-end" gap="sm">
|
||||
<Button variant="default" onClick={() => onCloseAction()}>
|
||||
取消
|
||||
</Button>
|
||||
<Button type="submit" color="red">
|
||||
确定释放
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</form>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
"use client"
|
||||
|
||||
import { projectConfig } from "@/components/label/api/project"
|
||||
import { ProjectDetail } from "@/components/label/api/project/typing"
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Group,
|
||||
NumberInput,
|
||||
Paper,
|
||||
SimpleGrid,
|
||||
Stack,
|
||||
Text,
|
||||
} from "@mantine/core"
|
||||
import { useForm } from "@mantine/form"
|
||||
import { notifications } from "@mantine/notifications"
|
||||
import { useEffect } from "react"
|
||||
|
||||
type GradeKey = "A" | "B" | "C"
|
||||
|
||||
export default function SamplingPlanContainer(props: {
|
||||
projectId: number
|
||||
info: ProjectDetail.DataProps | undefined
|
||||
onUpdated: () => void
|
||||
}) {
|
||||
const { projectId, info, onUpdated } = props
|
||||
|
||||
const form = useForm({
|
||||
initialValues: {
|
||||
check_task: false,
|
||||
check_frame: false,
|
||||
A_task: 0,
|
||||
A_frame: 0,
|
||||
B_task: 0,
|
||||
B_frame: 0,
|
||||
C_task: 0,
|
||||
C_frame: 0,
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!info) return
|
||||
const grade = info.user_grade ?? ({} as any)
|
||||
const toPercent = (v?: number) => Number(((v ?? 0) * 100).toFixed(2))
|
||||
form.setValues({
|
||||
check_task: !!info.check_task,
|
||||
check_frame: !!info.check_frame,
|
||||
A_task: toPercent(grade.A?.task),
|
||||
A_frame: toPercent(grade.A?.frame),
|
||||
B_task: toPercent(grade.B?.task),
|
||||
B_frame: toPercent(grade.B?.frame),
|
||||
C_task: toPercent(grade.C?.task),
|
||||
C_frame: toPercent(grade.C?.frame),
|
||||
})
|
||||
form.resetDirty()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [info])
|
||||
|
||||
const save = async () => {
|
||||
try {
|
||||
const toRatio = (v: number) => Number((v / 100).toFixed(4))
|
||||
await projectConfig({
|
||||
project_id: projectId,
|
||||
check_task: form.values.check_task,
|
||||
check_frame: form.values.check_frame,
|
||||
user_grade: {
|
||||
A: {
|
||||
task: toRatio(form.values.A_task),
|
||||
frame: toRatio(form.values.A_frame),
|
||||
},
|
||||
B: {
|
||||
task: toRatio(form.values.B_task),
|
||||
frame: toRatio(form.values.B_frame),
|
||||
},
|
||||
C: {
|
||||
task: toRatio(form.values.C_task),
|
||||
frame: toRatio(form.values.C_frame),
|
||||
},
|
||||
},
|
||||
})
|
||||
notifications.show({
|
||||
color: "green",
|
||||
title: "操作成功",
|
||||
message: "已保存抽检配置",
|
||||
})
|
||||
onUpdated()
|
||||
} catch (e) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "操作失败",
|
||||
message: e instanceof Error ? e.message : "请求失败",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Paper
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{ borderColor: "rgba(0,0,0,0.06)" }}>
|
||||
<Stack gap="sm">
|
||||
<Group justify="space-between" wrap="wrap">
|
||||
<Text fw={700}>抽检方案</Text>
|
||||
<Button size="xs" onClick={save}>
|
||||
保存
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
<Group gap="md" wrap="wrap">
|
||||
<Checkbox
|
||||
label="抽检任务"
|
||||
checked={form.values.check_task}
|
||||
onChange={(e) =>
|
||||
form.setFieldValue("check_task", e.currentTarget.checked)
|
||||
}
|
||||
/>
|
||||
<Checkbox
|
||||
label="抽检帧"
|
||||
checked={form.values.check_frame}
|
||||
onChange={(e) =>
|
||||
form.setFieldValue("check_frame", e.currentTarget.checked)
|
||||
}
|
||||
/>
|
||||
</Group>
|
||||
|
||||
<SimpleGrid cols={{ base: 1, sm: 3 }} spacing="sm">
|
||||
{(["A", "B", "C"] as GradeKey[]).map((g) => (
|
||||
<Paper
|
||||
key={g}
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{ borderColor: "rgba(0,0,0,0.06)" }}>
|
||||
<Stack gap="xs">
|
||||
<Text fw={600}>等级 {g}</Text>
|
||||
<NumberInput
|
||||
label="任务抽检比例(%)"
|
||||
min={0}
|
||||
max={100}
|
||||
decimalScale={2}
|
||||
value={form.values[`${g}_task` as const]}
|
||||
onChange={(v) =>
|
||||
form.setFieldValue(`${g}_task` as any, Number(v ?? 0))
|
||||
}
|
||||
hideControls
|
||||
/>
|
||||
<NumberInput
|
||||
label="帧抽检比例(%)"
|
||||
min={0}
|
||||
max={100}
|
||||
decimalScale={2}
|
||||
value={form.values[`${g}_frame` as const]}
|
||||
onChange={(v) =>
|
||||
form.setFieldValue(`${g}_frame` as any, Number(v ?? 0))
|
||||
}
|
||||
hideControls
|
||||
/>
|
||||
</Stack>
|
||||
</Paper>
|
||||
))}
|
||||
</SimpleGrid>
|
||||
</Stack>
|
||||
</Paper>
|
||||
)
|
||||
}
|
||||
60
app/management/project/detail/components/StageUserModal.tsx
Normal file
60
app/management/project/detail/components/StageUserModal.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
"use client"
|
||||
|
||||
import { Button, Group, Modal, MultiSelect, Stack } from "@mantine/core"
|
||||
import { useForm } from "@mantine/form"
|
||||
import { useEffect } from "react"
|
||||
|
||||
export default function StageUserModal(props: {
|
||||
opened: boolean
|
||||
title: string
|
||||
value: number[]
|
||||
options: Array<{ label: string; value: string }>
|
||||
onCloseAction: (next?: number[]) => void
|
||||
}) {
|
||||
const { opened, title, value, options, onCloseAction } = props
|
||||
|
||||
const form = useForm({
|
||||
initialValues: { users: value.map(String) },
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!opened) return
|
||||
form.setValues({ users: value.map(String) })
|
||||
form.resetDirty()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [opened, value])
|
||||
|
||||
return (
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={() => onCloseAction()}
|
||||
title={title}
|
||||
centered
|
||||
size={560}>
|
||||
<form
|
||||
onSubmit={form.onSubmit((values) => {
|
||||
const next = values.users
|
||||
.map((v) => Number(v))
|
||||
.filter((v) => Number.isFinite(v))
|
||||
onCloseAction(next)
|
||||
})}>
|
||||
<Stack gap="sm">
|
||||
<MultiSelect
|
||||
label="人员"
|
||||
data={options}
|
||||
searchable
|
||||
clearable
|
||||
value={form.values.users}
|
||||
onChange={(v) => form.setFieldValue("users", v)}
|
||||
/>
|
||||
<Group justify="flex-end" gap="sm">
|
||||
<Button variant="default" onClick={() => onCloseAction()}>
|
||||
取消
|
||||
</Button>
|
||||
<Button type="submit">保存</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</form>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
"use client"
|
||||
|
||||
import { projectConfig } from "@/components/label/api/project"
|
||||
import { ProjectDetail } from "@/components/label/api/project/typing"
|
||||
import { Button, Group, Paper, Stack, Text } from "@mantine/core"
|
||||
import { notifications } from "@mantine/notifications"
|
||||
import { useMemo, useState } from "react"
|
||||
import StageUserModal from "./StageUserModal"
|
||||
|
||||
type StageKey = "label" | "review1" | "review2"
|
||||
|
||||
function stageTitle(stage: StageKey) {
|
||||
if (stage === "label") return "标注阶段"
|
||||
if (stage === "review1") return "审核阶段"
|
||||
return "复审阶段"
|
||||
}
|
||||
|
||||
// function stageAction(stage: StageKey) {
|
||||
// if (stage === "label") return 1
|
||||
// if (stage === "review1") return 2
|
||||
// return 3
|
||||
// }
|
||||
|
||||
export default function TaskStageTabsContainer(props: {
|
||||
projectId: number
|
||||
info: ProjectDetail.DataProps | undefined
|
||||
userOptions: Array<{ label: string; value: string }>
|
||||
userEnums: {
|
||||
allEnum: Map<any, any>
|
||||
labelEnum: Map<any, any>
|
||||
review1Enum: Map<any, any>
|
||||
review2Enum: Map<any, any>
|
||||
}
|
||||
onUpdatedAction: () => void
|
||||
}) {
|
||||
const { projectId, info, userOptions, userEnums, onUpdatedAction } = props
|
||||
|
||||
const stageUsers = useMemo(() => {
|
||||
const detail = info?.label_process?.step_detail ?? []
|
||||
const findUsers = (action: number) => {
|
||||
const item = detail.find((d) => d.action === action)
|
||||
return (item?.user_list ?? []) as number[]
|
||||
}
|
||||
return {
|
||||
label: findUsers(1),
|
||||
review1: findUsers(2),
|
||||
review2: findUsers(3),
|
||||
}
|
||||
}, [info])
|
||||
|
||||
const [editingStage, setEditingStage] = useState<StageKey | null>(null)
|
||||
|
||||
const currentStageValue = useMemo(() => {
|
||||
if (!editingStage) return []
|
||||
return stageUsers[editingStage] ?? []
|
||||
}, [editingStage, stageUsers])
|
||||
|
||||
const saveStageUsers = async (stage: StageKey, users: number[]) => {
|
||||
try {
|
||||
if (stage === "label") {
|
||||
await projectConfig({ project_id: projectId, label_users: users })
|
||||
} else if (stage === "review1") {
|
||||
await projectConfig({ project_id: projectId, review1_users: users })
|
||||
} else {
|
||||
await projectConfig({ project_id: projectId, review2_users: users })
|
||||
}
|
||||
notifications.show({
|
||||
color: "green",
|
||||
title: "操作成功",
|
||||
message: "已保存阶段人员",
|
||||
})
|
||||
onUpdatedAction()
|
||||
} catch (e) {
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "操作失败",
|
||||
message: e instanceof Error ? e.message : "请求失败",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const renderUsersText = (uids: number[]) => {
|
||||
const names = uids.map((uid) => {
|
||||
const name = userEnums.allEnum.get(uid)
|
||||
return name ? String(name) : String(uid)
|
||||
})
|
||||
return names.length ? names.join("、") : "-"
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Paper
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{ borderColor: "rgba(0,0,0,0.06)" }}>
|
||||
<Stack gap="sm">
|
||||
<Text fw={700}>任务工序配置</Text>
|
||||
<Group gap="sm" align="stretch" wrap="wrap">
|
||||
{(["label", "review1", "review2"] as StageKey[]).map((stage) => (
|
||||
<Paper
|
||||
key={stage}
|
||||
withBorder
|
||||
p="sm"
|
||||
radius="md"
|
||||
style={{
|
||||
borderColor: "rgba(0,0,0,0.06)",
|
||||
flex: "1 1 260px",
|
||||
minWidth: 260,
|
||||
}}>
|
||||
<Stack gap="xs">
|
||||
<Group justify="space-between" wrap="wrap">
|
||||
<Text fw={600}>{stageTitle(stage)}</Text>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="default"
|
||||
onClick={() => setEditingStage(stage)}>
|
||||
编辑人员
|
||||
</Button>
|
||||
</Group>
|
||||
<Text size="sm" c="dimmed">
|
||||
{renderUsersText(stageUsers[stage] ?? [])}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Paper>
|
||||
))}
|
||||
</Group>
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
<StageUserModal
|
||||
opened={editingStage !== null}
|
||||
title={
|
||||
editingStage ? `${stageTitle(editingStage)}-人员配置` : "人员配置"
|
||||
}
|
||||
value={currentStageValue}
|
||||
options={userOptions}
|
||||
onCloseAction={async (next) => {
|
||||
const stage = editingStage
|
||||
setEditingStage(null)
|
||||
if (!stage || !next) return
|
||||
await saveStageUsers(stage, next)
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
50
app/management/project/detail/components/TaskStatusTag.tsx
Normal file
50
app/management/project/detail/components/TaskStatusTag.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
"use client"
|
||||
|
||||
import { TaskStatusEnum } from "@/components/label/utils/constants"
|
||||
import { Badge, Group } from "@mantine/core"
|
||||
import { useMemo } from "react"
|
||||
|
||||
function statusColor(status?: number | null) {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return "yellow"
|
||||
case 2:
|
||||
case 4:
|
||||
case 6:
|
||||
return "blue"
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
return "green"
|
||||
case 8:
|
||||
return "red"
|
||||
default:
|
||||
return "gray"
|
||||
}
|
||||
}
|
||||
|
||||
export default function TaskStatusTag(props: {
|
||||
status: number
|
||||
rejected?: boolean
|
||||
center?: boolean
|
||||
}) {
|
||||
const text = useMemo(
|
||||
() => TaskStatusEnum.get(props.status) || "默认",
|
||||
[props.status]
|
||||
)
|
||||
return (
|
||||
<Group
|
||||
gap={6}
|
||||
justify={props.center ? "center" : "flex-start"}
|
||||
wrap="nowrap">
|
||||
<Badge color={statusColor(props.status)} size="sm">
|
||||
{text}
|
||||
</Badge>
|
||||
{props.rejected ? (
|
||||
<Badge variant="outline" color="yellow" size="sm">
|
||||
返工
|
||||
</Badge>
|
||||
) : null}
|
||||
</Group>
|
||||
)
|
||||
}
|
||||
80
app/management/project/detail/components/WorkflowModal.tsx
Normal file
80
app/management/project/detail/components/WorkflowModal.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
"use client"
|
||||
|
||||
import { getTaskWorkFlow } from "@/components/label/api/task"
|
||||
import { Button, Group, Modal, ScrollArea, Stack, Text } from "@mantine/core"
|
||||
import { notifications } from "@mantine/notifications"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
export default function WorkflowModal(props: {
|
||||
opened: boolean
|
||||
taskId: number | null
|
||||
onCloseAction: () => void
|
||||
}) {
|
||||
const { opened, taskId, onCloseAction } = props
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [records, setRecords] = useState<any[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
if (!opened || !taskId) return
|
||||
const run = async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const res = await getTaskWorkFlow(taskId)
|
||||
setRecords(res ?? [])
|
||||
} catch (e) {
|
||||
setRecords([])
|
||||
notifications.show({
|
||||
color: "red",
|
||||
title: "加载失败",
|
||||
message: e instanceof Error ? e.message : "请求失败",
|
||||
})
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
run()
|
||||
}, [opened, taskId])
|
||||
|
||||
return (
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={onCloseAction}
|
||||
title="工作流"
|
||||
centered
|
||||
size={720}>
|
||||
<Stack gap="sm">
|
||||
<ScrollArea h={360} type="auto">
|
||||
<Stack gap="xs">
|
||||
{records.length ? (
|
||||
records.map((r, idx) => (
|
||||
<Text
|
||||
key={idx}
|
||||
size="sm"
|
||||
style={{
|
||||
fontFamily:
|
||||
'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
||||
whiteSpace: "pre-wrap",
|
||||
wordBreak: "break-word",
|
||||
background: "rgba(0,0,0,0.03)",
|
||||
borderRadius: 6,
|
||||
padding: 10,
|
||||
}}>
|
||||
{JSON.stringify(r, null, 2)}
|
||||
</Text>
|
||||
))
|
||||
) : (
|
||||
<Text size="sm" c="dimmed">
|
||||
{loading ? "加载中..." : "暂无数据"}
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
<Group justify="flex-end">
|
||||
<Button variant="default" onClick={onCloseAction}>
|
||||
关闭
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
90
app/management/project/detail/components/config.ts
Normal file
90
app/management/project/detail/components/config.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
type FormItemProps = {
|
||||
label: string
|
||||
name: string
|
||||
type: "input" | "select" | "radio"
|
||||
options?: Array<{ label: any; value: any }>
|
||||
}
|
||||
|
||||
const monthOpt = Array.from({ length: 12 }).map((_, idx) => {
|
||||
const n = idx + 1
|
||||
return { label: n, value: n }
|
||||
})
|
||||
|
||||
export const confirmOpt = [
|
||||
{ label: "否", value: false },
|
||||
{ label: "是", value: true },
|
||||
]
|
||||
|
||||
export const labelStageConfig: FormItemProps[] = [
|
||||
{ label: "可领取最多任务条数", name: "max_size", type: "input" },
|
||||
{ label: "单次可领取任务条数", name: "acquire_size", type: "input" },
|
||||
{
|
||||
label: "标注配置更新月份",
|
||||
name: "label_update_month",
|
||||
type: "select",
|
||||
options: monthOpt,
|
||||
},
|
||||
{ label: "动态标注倍速", name: "dynamic_label_speed", type: "input" },
|
||||
{ label: "静态标注倍速", name: "static_label_speed", type: "input" },
|
||||
{ label: "标注准确率", name: "label_accuracy_rate", type: "input" },
|
||||
{ label: "标注结果数量倍数", name: "avg_remind_threshold", type: "input" },
|
||||
{
|
||||
label: "标注结果数量告警阈值",
|
||||
name: "fix_remind_threshold",
|
||||
type: "input",
|
||||
},
|
||||
{
|
||||
label: "领取顺序",
|
||||
name: "acquire_mode",
|
||||
type: "radio",
|
||||
options: [
|
||||
{ label: "顺序领取", value: 0 },
|
||||
{ label: "乱序领取", value: 1 },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export const reviewStageConfig: FormItemProps[] = [
|
||||
{ label: "可领取最多任务条数", name: "max_size", type: "input" },
|
||||
{ label: "单次可领取任务条数", name: "acquire_size", type: "input" },
|
||||
{
|
||||
label: "审核配置更新月份",
|
||||
name: "review1_update_month",
|
||||
type: "select",
|
||||
options: monthOpt,
|
||||
},
|
||||
{ label: "动态审核倍速", name: "dynamic_review1_speed", type: "input" },
|
||||
{ label: "静态审核倍速", name: "static_review1_speed", type: "input" },
|
||||
{ label: "审核准确率", name: "review1_accuracy_rate", type: "input" },
|
||||
{
|
||||
label: "领取顺序",
|
||||
name: "acquire_mode",
|
||||
type: "radio",
|
||||
options: [
|
||||
{ label: "顺序领取", value: 0 },
|
||||
{ label: "乱序领取", value: 1 },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export const recheckStageConfig: FormItemProps[] = [
|
||||
{ label: "可领取最多任务条数", name: "max_size", type: "input" },
|
||||
{ label: "单次可领取任务条数", name: "acquire_size", type: "input" },
|
||||
{
|
||||
label: "复审配置更新月份",
|
||||
name: "review2_update_month",
|
||||
type: "select",
|
||||
options: monthOpt,
|
||||
},
|
||||
{ label: "动态复审倍速", name: "dynamic_review2_speed", type: "input" },
|
||||
{ label: "静态复审倍速", name: "static_review2_speed", type: "input" },
|
||||
{
|
||||
label: "领取顺序",
|
||||
name: "acquire_mode",
|
||||
type: "radio",
|
||||
options: [
|
||||
{ label: "顺序领取", value: 0 },
|
||||
{ label: "乱序领取", value: 1 },
|
||||
],
|
||||
},
|
||||
]
|
||||
Reference in New Issue
Block a user