Skip to content

Commit 0512d84

Browse files
committed
feat: compact layout of operation viewer
1 parent 0485d55 commit 0512d84

File tree

2 files changed

+81
-62
lines changed

2 files changed

+81
-62
lines changed

src/components/editor/operator/EditorOperator.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ export const OperatorAvatar = ({
156156
})()
157157

158158
const sizingClassName =
159+
size &&
159160
{
160161
small: 'h-5 w-5',
161162
medium: 'h-6 w-6',
162163
large: 'h-8 w-8',
163-
}[size || 'medium'] || 'h-6 w-6'
164+
}[size]
164165

165166
const commonClassName = 'rounded-md object-cover bp4-elevation-1 bg-slate-100'
166167

src/components/viewer/OperationViewer.tsx

Lines changed: 79 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import {
33
Button,
44
ButtonGroup,
55
Card,
6+
Collapse,
67
Elevation,
78
H3,
89
H4,
9-
H5,
10+
H6,
1011
Icon,
1112
Menu,
1213
MenuItem,
@@ -21,6 +22,7 @@ import {
2122
useOperation,
2223
useRefreshOperations,
2324
} from 'apis/operation'
25+
import clsx from 'clsx'
2426
import { useAtom } from 'jotai'
2527
import { ComponentType, FC, useEffect, useState } from 'react'
2628
import { Link } from 'react-router-dom'
@@ -248,31 +250,16 @@ const OperatorCard: FC<{
248250
operator: CopilotDocV1.Operator
249251
}> = ({ operator }) => {
250252
const { name, skill } = operator
253+
const skillStr = [null, '一', '二', '三'][skill ?? 1] ?? '未知'
251254
return (
252-
<Card elevation={Elevation.ONE} className="mb-2 last:mb-0 flex">
253-
<OperatorAvatar name={name} size="large" className="mr-3" />
254-
<div className="flex items-center font-bold">{name}</div>
255-
<div className="flex-1" />
256-
<div className="flex items-center tabular-nums">
257-
技能<span className="font-bold ml-1">{skill}</span>
258-
</div>
259-
</Card>
255+
<div className="min-w-24 flex flex-col items-center">
256+
<OperatorAvatar name={name} className="w-16 h-16 mb-1" />
257+
<span className="mb-1 font-bold">{name}</span>
258+
<span className="text-xs text-zinc-500">{skillStr}技能</span>
259+
</div>
260260
)
261261
}
262262

263-
const EmptyOperator: FC<{
264-
title?: string
265-
description?: string
266-
}> = ({ title = '暂无干员', description }) => (
267-
<NonIdealState
268-
className="my-2"
269-
title={title}
270-
description={description}
271-
icon="slash"
272-
layout="horizontal"
273-
/>
274-
)
275-
276263
function OperationViewerInner({
277264
levels,
278265
operation,
@@ -390,56 +377,87 @@ function OperationViewerInner({
390377
)
391378
}
392379
function OperationViewerInnerDetails({ operation }: { operation: Operation }) {
380+
const [showOperators, setShowOperators] = useState(true)
381+
const [showActions, setShowActions] = useState(false)
382+
393383
return (
394-
<div className="grid grid-rows-1 grid-cols-3 gap-8">
395-
<div className="flex flex-col">
396-
<H4 className="mb-4">干员与干员组</H4>
397-
<H5 className="mb-4 text-slate-600">干员</H5>
398-
<div className="flex flex-col mb-4">
384+
<div>
385+
<H4
386+
className="inline-flex items-center cursor-pointer hover:text-violet-500"
387+
onClick={() => setShowOperators((v) => !v)}
388+
>
389+
干员与干员组
390+
<Tooltip2
391+
className="!flex items-center"
392+
placement="top"
393+
content="干员组:组内干员可以任选其一,自动编队时按最高练度来选择"
394+
>
395+
<Icon icon="info-sign" size={12} className="text-zinc-500 ml-1" />
396+
</Tooltip2>
397+
<Icon
398+
icon="chevron-down"
399+
className={clsx(
400+
'ml-1 transition-transform',
401+
showOperators && 'rotate-180',
402+
)}
403+
/>
404+
</H4>
405+
<Collapse isOpen={showOperators}>
406+
<div className="mt-2 flex flex-wrap -ml-4">
407+
{!operation.parsedContent.opers?.length &&
408+
!operation.parsedContent.groups?.length && (
409+
<NonIdealState
410+
className="my-2"
411+
title="暂无干员"
412+
description="作业并未添加干员"
413+
icon="slash"
414+
layout="horizontal"
415+
/>
416+
)}
399417
{operation.parsedContent.opers?.map((operator) => (
400418
<OperatorCard key={operator.name} operator={operator} />
401419
))}
402-
{!operation.parsedContent.opers?.length && (
403-
<EmptyOperator description="作业并未添加干员" />
404-
)}
405420
</div>
406-
407-
<H5 className="mb-4 text-slate-600">干员组</H5>
408-
<div className="flex flex-col">
421+
<div className="flex flex-wrap gap-4 mt-4">
409422
{operation.parsedContent.groups?.map((group) => (
410-
<Card elevation={Elevation.ONE} className="mb-4" key={group.name}>
411-
<div className="flex flex-col">
412-
<H5 className="text-gray-800 font-bold">{group.name}</H5>
413-
414-
<div className="flex flex-col">
415-
{group.opers
416-
?.filter(Boolean)
417-
.map((operator) => (
418-
<OperatorCard key={operator.name} operator={operator} />
419-
))}
420-
421-
{group.opers?.filter(Boolean).length === 0 && (
422-
<EmptyOperator description="干员组中并未添加干员" />
423-
)}
424-
</div>
423+
<Card
424+
elevation={Elevation.ONE}
425+
className="!p-2 flex flex-col items-center"
426+
key={group.name}
427+
>
428+
<H6 className="text-gray-800">{group.name}</H6>
429+
<div className="flex gap-1">
430+
{group.opers
431+
?.filter(Boolean)
432+
.map((operator) => (
433+
<OperatorCard key={operator.name} operator={operator} />
434+
))}
435+
436+
{group.opers?.filter(Boolean).length === 0 && (
437+
<span className="text-zinc-500">无干员</span>
438+
)}
425439
</div>
426440
</Card>
427441
))}
428-
429-
{!operation.parsedContent.groups?.length && (
430-
<EmptyOperator
431-
title="暂无干员组"
432-
description="作业并未添加干员组"
433-
/>
434-
)}
435442
</div>
436-
</div>
437-
438-
<div className="col-span-2">
439-
<H4 className="mb-4">动作序列</H4>
443+
</Collapse>
440444

445+
<H4
446+
className="mt-6 inline-flex items-center cursor-pointer hover:text-violet-500"
447+
onClick={() => setShowActions((v) => !v)}
448+
>
449+
动作序列
450+
<Icon
451+
icon="chevron-down"
452+
className={clsx(
453+
'ml-1 transition-transform',
454+
showActions && 'rotate-180',
455+
)}
456+
/>
457+
</H4>
458+
<Collapse isOpen={showActions}>
441459
{operation.parsedContent.actions?.length ? (
442-
<div className="flex flex-col pb-8">
460+
<div className="mt-2 flex flex-col pb-8">
443461
{operation.parsedContent.actions.map((action, i) => (
444462
<ActionCard action={action} key={i} />
445463
))}
@@ -453,7 +471,7 @@ function OperationViewerInnerDetails({ operation }: { operation: Operation }) {
453471
layout="horizontal"
454472
/>
455473
)}
456-
</div>
474+
</Collapse>
457475
</div>
458476
)
459477
}

0 commit comments

Comments
 (0)