From 94b003356edee9f389692e648845996e1436deb9 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 7 Aug 2026 14:24:04 +0800 Subject: [PATCH] Add visual approval flow designer --- README.md | 36 ++- app/AdminApp.tsx | 252 ++++++++++++++++ app/approval/ApprovalDesigner.module.css | 366 +++++++++++++++++++++++ app/approval/page.tsx | 300 +++++++++++++++++++ app/data/approval-flow.json | 78 +++++ app/page.module.css | 32 ++ app/page.tsx | 255 +--------------- 7 files changed, 1062 insertions(+), 257 deletions(-) create mode 100644 app/AdminApp.tsx create mode 100644 app/approval/ApprovalDesigner.module.css create mode 100644 app/approval/page.tsx create mode 100644 app/data/approval-flow.json create mode 100644 app/page.module.css diff --git a/README.md b/README.md index f00135f..e5b6ec8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OrbitFlow React 后台模板 -一个无需后端即可运行的现代后台管理模板。项目基于 React 19、Next.js 与 vinext,所有演示业务数据来自本地 JSON;定时任务配置通过 `localStorage` 保存在当前浏览器。 +一个无需后端即可运行的现代后台管理模板。项目基于 React 19、Next.js 与 vinext,所有演示业务数据来自本地 JSON;定时任务和审批流程配置通过 `localStorage` 保存在当前浏览器。 ## 已包含 @@ -9,9 +9,24 @@ - 图片文字列表和响应式卡片视图 - 支持拖放的四列流程泳道 - 定时任务列表、启停开关和新建配置弹窗 +- 类飞书的审批流程设计器 - 全局搜索、待办勾选、Toast 提示等交互 - 桌面、平板和手机响应式布局 +## 审批流程设计器 + +打开 `/approval`,或点击后台右下角的“审批流程设计”入口。设计器包含: + +- 左侧审批、条件分支和抄送节点库 +- 节点点击添加及拖入画布 +- 审批条件双分支与合流展示 +- 单人审批、或签、会签规则 +- 审批人、表单权限与高级规则配置 +- 流程校验、模拟预览、JSON 查看与复制 +- 自动保存、恢复示例及本地发布状态 + +示例流程数据位于 `app/data/approval-flow.json`,不会调用后端接口。 + ## 本地运行 需要 Node.js `>=22.13.0`。 @@ -30,22 +45,19 @@ npm test ## 数据位置 -演示数据集中在 `app/data/mock-data.json`,包含: +- `app/data/mock-data.json`:概览、项目、泳道和定时任务数据 +- `app/data/approval-flow.json`:审批流程、条件分支和节点配置 -- `stats`:概览指标 -- `projects`:项目与图文内容 -- `board`:泳道及任务卡片 -- `schedules`:定时任务初始配置 - -后续接入真实接口时,可以保留页面组件,只替换这一层的数据读取方式。当前 `.openai/hosting.json` 中的 D1 和 R2 均为 `null`,项目不依赖数据库或对象存储。 +后续接入真实接口时,可以保留页面组件,只替换数据读取方式。当前 `.openai/hosting.json` 中的 D1 和 R2 均为 `null`,项目不依赖数据库或对象存储。 ## 主要文件 -- `app/page.tsx`:页面、导航和交互逻辑 -- `app/globals.css`:完整视觉系统与响应式样式 -- `app/data/mock-data.json`:可直接修改的模拟数据 +- `app/AdminApp.tsx`:后台主界面和交互逻辑 +- `app/approval/page.tsx`:审批流程设计器逻辑 +- `app/approval/ApprovalDesigner.module.css`:设计器视觉与布局 +- `app/globals.css`:后台视觉系统与响应式样式 - `tests/rendered-html.test.mjs`:渲染与纯前端约束检查 ## 注意 -任务启停和新建任务会写入浏览器本地存储。清除浏览器站点数据后会恢复为 JSON 中的初始内容。 +任务启停、新建任务和审批流程修改都会写入浏览器本地存储。清除浏览器站点数据后会恢复为 JSON 中的初始内容。 diff --git a/app/AdminApp.tsx b/app/AdminApp.tsx new file mode 100644 index 0000000..c7c8b65 --- /dev/null +++ b/app/AdminApp.tsx @@ -0,0 +1,252 @@ +"use client"; + +import { useEffect, useMemo, useState } from "react"; +import mockData from "./data/mock-data.json"; + +type View = "overview" | "components" | "content" | "board" | "schedule"; +type Toast = { id: number; message: string }; +type BoardColumn = (typeof mockData.board)[number]; + +const navGroups = [ + { + label: "工作台", + items: [ + { id: "overview" as View, icon: "⌂", label: "概览" }, + { id: "components" as View, icon: "◈", label: "组件样式", badge: "18" }, + ], + }, + { + label: "业务管理", + items: [ + { id: "content" as View, icon: "▤", label: "内容管理", children: ["图文列表", "卡片内容", "分类标签"] }, + { id: "board" as View, icon: "▦", label: "流程泳道", badge: "9" }, + { id: "schedule" as View, icon: "◷", label: "定时任务" }, + ], + }, + { + label: "系统设置", + items: [ + { id: "components" as View, icon: "♙", label: "成员与权限" }, + { id: "components" as View, icon: "⚙", label: "基础设置" }, + ], + }, +]; + +const pageMeta: Record = { + overview: { title: "下午好,林知夏", subtitle: "这里是团队今天的工作概览,祝你高效完成每一项计划。" }, + components: { title: "组件样式", subtitle: "可直接复用的标签、按钮、菜单与交互状态。" }, + content: { title: "内容管理", subtitle: "通过图片文字列表与卡片视图管理业务内容。" }, + board: { title: "流程泳道", subtitle: "拖动任务卡片,快速同步团队当前进度。" }, + schedule: { title: "定时任务", subtitle: "纯前端模拟任务配置、状态切换与执行记录。" }, +}; + +export default function Home() { + const [activeView, setActiveView] = useState("overview"); + const [expandedMenus, setExpandedMenus] = useState(["内容管理"]); + const [sidebarOpen, setSidebarOpen] = useState(false); + const [search, setSearch] = useState(""); + const [toasts, setToasts] = useState([]); + const [board, setBoard] = useState(mockData.board); + const [dragged, setDragged] = useState<{ cardId: string; columnId: string } | null>(null); + const [schedules, setSchedules] = useState(mockData.schedules); + const [scheduleModal, setScheduleModal] = useState(false); + const [profileOpen, setProfileOpen] = useState(false); + + useEffect(() => { + const saved = window.localStorage.getItem("orbit-schedules"); + if (saved) { + try { setSchedules(JSON.parse(saved)); } + catch { window.localStorage.removeItem("orbit-schedules"); } + } + }, []); + + useEffect(() => { + window.localStorage.setItem("orbit-schedules", JSON.stringify(schedules)); + }, [schedules]); + + const notify = (message: string) => { + const id = Date.now(); + setToasts((current) => [...current, { id, message }]); + window.setTimeout(() => setToasts((current) => current.filter((item) => item.id !== id)), 2600); + }; + + const navigate = (view: View) => { + setActiveView(view); + setSidebarOpen(false); + setSearch(""); + }; + + const filteredProjects = useMemo( + () => mockData.projects.filter((project) => `${project.title}${project.description}${project.tag}`.toLowerCase().includes(search.toLowerCase())), + [search], + ); + + const moveCard = (targetColumnId: string) => { + if (!dragged || dragged.columnId === targetColumnId) return; + let movingCard: BoardColumn["cards"][number] | undefined; + const nextBoard = board.map((column) => { + if (column.id !== dragged.columnId) return column; + movingCard = column.cards.find((card) => card.id === dragged.cardId); + return { ...column, cards: column.cards.filter((card) => card.id !== dragged.cardId) }; + }); + if (!movingCard) return; + setBoard(nextBoard.map((column) => column.id === targetColumnId ? { ...column, cards: [...column.cards, movingCard!] } : column)); + setDragged(null); + notify("任务状态已更新"); + }; + + const toggleSchedule = (id: number) => { + setSchedules((current) => current.map((schedule) => schedule.id === id ? { ...schedule, enabled: !schedule.enabled } : schedule)); + notify("任务状态已保存到本地"); + }; + + return ( +
+ + {sidebarOpen && + +
+ + + +
+ + {profileOpen &&
} +
+
+ + +
+
+

{activeView === "overview" ? "2026 年 8 月 7 日 · 星期五" : "ORBITFLOW TEMPLATE"}

{pageMeta[activeView].title}

{pageMeta[activeView].subtitle}

+
+
+ {activeView === "overview" && } + {activeView === "components" && } + {activeView === "content" && } + {activeView === "board" && } + {activeView === "schedule" && setScheduleModal(true)} />} +
+ + + {scheduleModal && setScheduleModal(false)} onSave={(name, frequency) => { + setSchedules((current) => [...current, { id: Math.max(...current.map((item) => item.id), 0) + 1, name, type: "自定义任务", cron: frequency === "每天" ? "0 9 * * *" : "0 9 * * 1", frequency: frequency === "每天" ? "每天 09:00" : "每周一 09:00", lastRun: "尚未执行", nextRun: frequency === "每天" ? "明天 09:00" : "下周一 09:00", enabled: true, success: 100 }]); + setScheduleModal(false); notify("新任务已保存到本地"); + }} />} +
{toasts.map((toast) =>
{toast.message}
)}
+
+ ); +} + +function Overview({ onNavigate, notify }: { onNavigate: (view: View) => void; notify: (message: string) => void }) { + return ( + <> +
+ {mockData.stats.map((stat, index) =>
{["▣", "✓", "♙", "↗"][index]}

{stat.label}

{stat.value}
{stat.change}
)} +
+
+
+ onNavigate("content")} /> +
+ {mockData.projects.map((project) =>
{project.title}{project.status}

{project.description}

{project.progress}%
{project.owner.slice(-1)}{project.owner}{project.date}
)} +
+
+
+ onNavigate("board")} /> +
+
+ {[["评审新版工作台原型", "10:00", true], ["与研发确认排期", "11:30", true], ["整理组件规范文档", "14:00", false], ["增长实验周会", "16:30", false]].map(([title, time, done]) => )} +
+ +
+
+
+ notify("暂无更多动态")} /> +
+ {[["周", "周屿", "完成了任务", "后台筛选器交互优化", "12 分钟前", "green"], ["许", "许言", "上传了文件", "八月增长计划-v3.pdf", "35 分钟前", "blue"], ["陈", "陈序", "评论了", "确认新用户引导文案", "1 小时前", "orange"], ["林", "林知夏", "创建了项目", "新版工作台视觉升级", "2 小时前", "purple"]].map(([avatar, name, verb, target, time, tone]) =>
{avatar}

{name} {verb} {target}{time}

)} +
+
+ + ); +} + +function ComponentsShowcase({ notify }: { notify: (message: string) => void }) { + const [tab, setTab] = useState("基础组件"); + return ( +
+
{["基础组件", "状态样式", "菜单示例"].map((item) => )}
+ {tab === "基础组件" && <> +
+
进行中已完成待处理评审中已逾期默认标签可关闭 ×
+
+ } + {tab === "状态样式" &&
保存成功你的修改已经同步到本地。
i版本提示这是一个纯前端 JSON 数据模板。
!注意浏览器缓存清除后,本地修改将会重置。
×操作失败请检查必填字段后重试。
} + {tab === "菜单示例" &&

项目操作


快速前往

最近访问
} +
+ ); +} + +function ContentView({ projects, notify }: { projects: typeof mockData.projects; notify: (message: string) => void }) { + const [display, setDisplay] = useState<"list" | "cards">("list"); + return ( +
+
+ {projects.length === 0 ?

没有找到匹配内容

试试更换搜索关键词。

: display === "list" ?
{projects.map((project) =>
{`${project.title}项目配图`}
{project.tag}{project.status}

{project.title}

{project.description}

负责人 {project.owner} · 截止 {project.date}
{project.progress}%
)}
:
{projects.map((project) =>
{project.tag}
{project.status}

{project.title}

{project.description}

{project.owner.slice(-1)}{project.owner}{project.progress}%
)}
} +
+ ); +} + +function BoardView({ board, dragged, setDragged, moveCard, notify }: { board: BoardColumn[]; dragged: { cardId: string; columnId: string } | null; setDragged: (value: { cardId: string; columnId: string } | null) => void; moveCard: (columnId: string) => void; notify: (message: string) => void }) { + return <>
+8
{board.map((column) =>
event.preventDefault()} onDrop={() => moveCard(column.id)}>
{column.title}{column.cards.length}
{column.cards.map((card) =>
setDragged({ cardId: card.id, columnId: column.id })} onDragEnd={() => setDragged(null)}>
{card.id}

{card.title}

{card.tag}{card.priority === "紧急" && 紧急}
{card.owner.slice(-1)}{card.owner}
)}
)}
; +} + +function ScheduleView({ schedules, toggleSchedule, notify, onCreate }: { schedules: typeof mockData.schedules; toggleSchedule: (id: number) => void; notify: (message: string) => void; onCreate: () => void }) { + const activeCount = schedules.filter((item) => item.enabled).length; + return <>

任务总数{schedules.length}

运行中{activeCount}

本月执行128

平均成功率98.5%

{schedules.map((schedule) => )}
任务名称执行规则最近执行下次执行成功率状态
{schedule.type === "消息通知" ? "✧" : schedule.type === "文件归档" ? "▤" : "↻"}
{schedule.name}{schedule.type}
{schedule.frequency}{schedule.cron}{schedule.lastRun}{schedule.nextRun}{schedule.success}%{schedule.enabled ? "运行中" : "已停用"}
; +} + +function ScheduleModal({ onClose, onSave }: { onClose: () => void; onSave: (name: string, frequency: string) => void }) { + const [name, setName] = useState(""); const [frequency, setFrequency] = useState("每天"); + return
event.stopPropagation()} onSubmit={(event) => { event.preventDefault(); if (name.trim()) onSave(name.trim(), frequency); }}>

新建定时任务

配置完成后会保存到当前浏览器。

执行频率
; +} + +function PanelHeader({ title, subtitle, action, onAction }: { title: string; subtitle: string; action?: string; onAction?: () => void }) { + return

{title}

{subtitle}

{action && }
; +} diff --git a/app/approval/ApprovalDesigner.module.css b/app/approval/ApprovalDesigner.module.css new file mode 100644 index 0000000..905fca6 --- /dev/null +++ b/app/approval/ApprovalDesigner.module.css @@ -0,0 +1,366 @@ +.designerShell { + --navy: #142033; + --text: #2a3548; + --muted: #7d8798; + --line: #e5e8ee; + --blue: #3370ff; + --blueSoft: #eaf1ff; + --green: #25a66a; + --greenSoft: #eaf8f1; + --orange: #e79024; + --orangeSoft: #fff4e5; + --purple: #7656d6; + --purpleSoft: #f0ecfd; + min-width: 1040px; + min-height: 100vh; + overflow: hidden; + background: #f4f6f9; + color: var(--text); + font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; +} + +.topbar { + position: relative; + z-index: 30; + height: 68px; + display: flex; + align-items: center; + justify-content: space-between; + gap: 20px; + padding: 0 22px; + border-bottom: 1px solid var(--line); + background: #fff; + box-shadow: 0 2px 9px rgba(27, 38, 59, .04); +} + +.topbarLeft, .topbarActions, .processIdentity > div, .settingsHeader > div, .previewModal header > div { + display: flex; + align-items: center; +} + +.topbarLeft { gap: 12px; } +.backButton { + width: 34px; + height: 34px; + display: grid; + place-items: center; + border: 1px solid #e2e6ec; + border-radius: 8px; + color: #6f7a8c; + text-decoration: none; + font-size: 18px; +} +.backButton:hover { border-color: #abc2fa; color: var(--blue); background: #f7f9ff; } +.brandMark { position: relative; width: 25px; height: 25px; display: block; margin-left: 2px; transform: rotate(-11deg); } +.brandMark i { position: absolute; bottom: 1px; display: block; width: 6px; border-radius: 4px; background: var(--blue); } +.brandMark i:nth-child(1) { left: 1px; height: 12px; background: #7ca5ff; } +.brandMark i:nth-child(2) { left: 9px; height: 22px; background: var(--navy); } +.brandMark i:nth-child(3) { left: 17px; height: 16px; } +.processIdentity { min-width: 260px; display: flex; flex-direction: column; gap: 2px; } +.processIdentity > div { gap: 8px; } +.processIdentity input { + width: 185px; + padding: 0; + border: 0; + outline: 0; + background: transparent; + color: var(--navy); + font-size: 14px; + font-weight: 750; +} +.processIdentity small { color: #8e97a6; font-size: 9px; } +.draft, .published { padding: 3px 7px; border-radius: 5px; font-size: 8px; font-weight: 700; } +.draft { background: var(--orangeSoft); color: var(--orange); } +.published { background: var(--greenSoft); color: var(--green); } +.topbarActions { gap: 8px; } +.topbarActions button { min-height: 36px; padding: 0 13px; border-radius: 7px; cursor: pointer; font-size: 10px; font-weight: 650; } +.quietButton { border: 1px solid #dde2e9; background: #fff; color: #5e6b7f; } +.quietButton:hover { border-color: #b7c8e9; background: #f9fbff; color: var(--blue); } +.publishButton { border: 1px solid var(--blue); background: var(--blue); color: #fff; box-shadow: 0 5px 13px rgba(51,112,255,.2); } +.publishButton:hover { background: #235bd4; } + +.workspace { + height: calc(100vh - 68px); + display: grid; + grid-template-columns: 235px minmax(520px, 1fr) 326px; +} + +.palette, .propertyPanel { position: relative; z-index: 10; overflow-y: auto; background: #fff; } +.palette { border-right: 1px solid var(--line); } +.propertyPanel { border-left: 1px solid var(--line); } +.paletteHeader { + height: 68px; + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 17px; + border-bottom: 1px solid #edf0f4; +} +.paletteHeader > div { display: flex; flex-direction: column; gap: 4px; } +.paletteHeader strong { color: var(--navy); font-size: 13px; } +.paletteHeader small { color: #98a1af; font-size: 9px; } +.paletteHeader > button { display: none; border: 0; background: none; color: #8490a2; font-size: 18px; } +.paletteSection { padding: 17px 13px 4px; } +.paletteSection > p { margin: 0 4px 10px; color: #98a0ae; font-size: 9px; font-weight: 750; letter-spacing: .7px; } +.paletteItem { + width: 100%; + min-height: 64px; + display: flex; + align-items: center; + gap: 10px; + margin-bottom: 8px; + padding: 9px 10px; + border: 1px solid #e5e9ef; + border-radius: 9px; + background: #fff; + cursor: grab; + text-align: left; + transition: border-color .16s, box-shadow .16s, transform .16s; +} +.paletteItem:hover { border-color: #a9c2fa; box-shadow: 0 7px 18px rgba(38,72,137,.08); transform: translateY(-1px); } +.paletteItem:active { cursor: grabbing; } +.paletteIcon, .nodeIcon { + display: grid; + place-items: center; + flex: 0 0 auto; + border-radius: 8px; + font-weight: 800; +} +.paletteIcon { width: 35px; height: 35px; font-size: 15px; } +.blue { background: var(--blueSoft); color: var(--blue); } +.green { background: var(--greenSoft); color: var(--green); } +.orange { background: var(--orangeSoft); color: var(--orange); } +.purple { background: var(--purpleSoft); color: var(--purple); } +.gray { background: #edf0f4; color: #697589; } +.paletteItem > span:nth-child(2) { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; } +.paletteItem strong { color: #36445b; font-size: 10px; } +.paletteItem small { overflow: hidden; color: #8e98a8; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; } +.paletteItem > b { color: #a1a9b6; font-size: 15px; } +.disabledItem { background: #fbfcfd; } +.helpCard { display: flex; gap: 10px; margin: 20px 13px; padding: 13px; border: 1px solid #dbe5fb; border-radius: 9px; background: #f6f9ff; } +.helpCard > span { width: 24px; height: 24px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: var(--blueSoft); color: var(--blue); font-size: 10px; font-weight: 800; } +.helpCard div { min-width: 0; } +.helpCard strong { color: #405273; font-size: 9px; } +.helpCard p { margin: 4px 0 0; color: #77849a; font-size: 8px; line-height: 1.6; } + +.canvasArea { min-width: 0; display: flex; flex-direction: column; background: #f2f4f8; } +.canvasToolbar { + height: 47px; + display: flex; + align-items: center; + justify-content: space-between; + gap: 18px; + padding: 0 16px; + border-bottom: 1px solid #e2e6ec; + background: rgba(255,255,255,.86); +} +.breadcrumb { min-width: 0; display: flex; align-items: center; gap: 8px; color: #8993a4; font-size: 9px; } +.breadcrumb strong { overflow: hidden; color: #536077; text-overflow: ellipsis; white-space: nowrap; } +.breadcrumb b { color: #bdc3cc; font-weight: 400; } +.canvasTools { display: flex; align-items: center; overflow: hidden; border: 1px solid #dde2e9; border-radius: 7px; background: #fff; } +.canvasTools button { height: 29px; padding: 0 9px; border: 0; border-right: 1px solid #edf0f3; background: #fff; color: #647085; cursor: pointer; font-size: 9px; } +.canvasTools button:hover { background: #f3f6fc; color: var(--blue); } +.canvasTools span { min-width: 43px; color: #7e899a; font-size: 8px; text-align: center; } +.mobilePaletteButton { display: none; padding: 6px 10px; border: 1px solid #bfd0f5; border-radius: 6px; background: #fff; color: var(--blue); font-size: 9px; } +.canvasScroller { min-height: 0; flex: 1; overflow: auto; } +.canvasGrid { min-width: 750px; min-height: 100%; padding: 42px 34px 120px; background: #f4f6f9; } +.flowWrap { + width: 680px; + margin: 0 auto; + display: flex; + flex-direction: column; + align-items: center; + transform-origin: center top; + transition: transform .18s ease; +} +.flowStep { width: 100%; display: flex; flex-direction: column; align-items: center; } +.processNode { + position: relative; + width: 310px; + min-height: 86px; + display: flex; + align-items: center; + gap: 12px; + padding: 12px 15px; + border: 1px solid #dfe4eb; + border-radius: 10px; + background: #fff; + box-shadow: 0 5px 16px rgba(28,42,68,.07); + cursor: pointer; + text-align: left; + transition: border-color .16s, box-shadow .16s, transform .16s; +} +.processNode:hover { border-color: #a9c3fb; box-shadow: 0 9px 22px rgba(28,67,143,.1); transform: translateY(-1px); } +.selectedNode { border: 2px solid var(--blue); box-shadow: 0 0 0 4px rgba(51,112,255,.1), 0 9px 22px rgba(28,67,143,.1); } +.nodeIcon { width: 39px; height: 39px; font-size: 16px; } +.nodeCopy { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; } +.nodeCopy small { color: #9aa3b0; font-size: 7px; font-weight: 750; letter-spacing: .4px; text-transform: uppercase; } +.nodeCopy strong { overflow: hidden; color: #28374e; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; } +.nodeCopy em { overflow: hidden; color: #8791a1; font-size: 8px; font-style: normal; text-overflow: ellipsis; white-space: nowrap; } +.approverPreview { display: flex; align-items: center; flex: 0 0 auto; } +.approverPreview i { width: 22px; height: 22px; display: grid; place-items: center; margin-left: -5px; border: 2px solid #fff; border-radius: 50%; background: #dce8ff; color: #3567c8; font-size: 7px; font-style: normal; font-weight: 700; } +.approverPreview b { margin-left: 5px; color: #7f8999; font-size: 7px; font-weight: 600; } +.nodeMore { position: absolute; top: 7px; right: 9px; color: #b0b6c0; font-size: 7px; letter-spacing: 1px; } +.node_start, .node_end { width: 270px; min-height: 72px; } +.connector { position: relative; width: 2px; height: 42px; background: #b8c1cf; } +.connector::after { content: ""; position: absolute; bottom: -1px; left: -3px; width: 6px; height: 6px; border-right: 2px solid #9ca7b7; border-bottom: 2px solid #9ca7b7; transform: rotate(45deg); } +.connector i { position: absolute; top: 16px; left: -3px; width: 8px; height: 8px; border: 2px solid #fff; border-radius: 50%; background: #b6c0cd; } + +.conditionGroup { position: relative; width: 680px; padding: 0 18px 22px; border: 1px dashed transparent; border-radius: 13px; } +.selectedCondition { border-color: #94b4f8; background: rgba(233,240,255,.5); } +.conditionTitle { + width: 310px; + min-height: 72px; + display: flex; + align-items: center; + gap: 11px; + margin: 0 auto; + padding: 11px 14px; + border: 1px solid #f0d7b2; + border-radius: 10px; + background: #fff; + box-shadow: 0 5px 16px rgba(28,42,68,.06); + cursor: pointer; + text-align: left; +} +.conditionTitle > span:nth-child(2) { flex: 1; display: flex; flex-direction: column; gap: 3px; } +.conditionTitle small { color: var(--orange); font-size: 7px; font-weight: 750; } +.conditionTitle strong { color: #2e3b50; font-size: 11px; } +.conditionTitle > b { color: #a0a7b2; font-size: 8px; font-weight: 500; } +.branchRail { position: relative; width: calc(50% + 2px); height: 37px; margin: 0 auto; border-right: 2px solid #b8c1cf; border-bottom: 2px solid #b8c1cf; border-left: 2px solid #b8c1cf; } +.branchRail::before { content: ""; position: absolute; top: 0; left: 50%; width: 2px; height: 18px; background: #b8c1cf; } +.branchGrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; } +.branchLane { display: flex; flex-direction: column; align-items: center; } +.branchLabel { width: 100%; min-height: 56px; padding: 9px 11px; border: 1px solid #e3e7ed; border-radius: 8px; background: #fff; } +.branchLabel > span { width: 17px; height: 17px; display: grid; place-items: center; float: left; margin-right: 7px; border-radius: 4px; background: var(--orangeSoft); color: var(--orange); font-size: 7px; font-weight: 750; } +.branchLabel strong { display: block; color: #4a5669; font-size: 9px; } +.branchLabel code { display: block; margin: 5px 0 0 24px; color: #9a7b55; font-size: 7px; } +.branchConnector { width: 2px; height: 23px; background: #b8c1cf; } +.branchLane .processNode { width: 100%; } +.branchJoin { position: relative; width: calc(50% + 2px); height: 37px; margin: 0 auto; border-right: 2px solid #b8c1cf; border-top: 2px solid #b8c1cf; border-left: 2px solid #b8c1cf; } +.branchJoin i { position: absolute; bottom: -1px; left: 50%; width: 2px; height: 20px; background: #b8c1cf; } +.canvasAdd { display: flex; align-items: center; gap: 7px; margin-top: 18px; padding: 7px 12px; border: 1px dashed #aeb9c9; border-radius: 8px; background: rgba(255,255,255,.75); color: #7a8799; cursor: pointer; font-size: 8px; } +.canvasAdd:hover { border-color: var(--blue); color: var(--blue); } +.canvasAdd span { font-size: 13px; } + +.settingsHeader { min-height: 67px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid #edf0f4; } +.settingsHeader > div { gap: 10px; } +.settingsHeader .nodeIcon { width: 33px; height: 33px; font-size: 13px; } +.settingsHeader > div > span:last-child { display: flex; flex-direction: column; gap: 3px; } +.settingsHeader strong { max-width: 190px; overflow: hidden; color: var(--navy); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; } +.settingsHeader small { color: #98a1af; font-size: 7px; } +.settingsHeader > button { width: 27px; height: 27px; border: 0; border-radius: 6px; background: #fff2f2; color: #d85656; cursor: pointer; } +.settingsTabs { height: 42px; display: flex; padding: 0 13px; border-bottom: 1px solid #edf0f4; } +.settingsTabs button { position: relative; flex: 1; border: 0; background: transparent; color: #8791a1; cursor: pointer; font-size: 9px; } +.settingsTabs button.activeTab { color: var(--blue); font-weight: 700; } +.settingsTabs button.activeTab::after { content: ""; position: absolute; right: 20%; bottom: -1px; left: 20%; height: 2px; border-radius: 2px; background: var(--blue); } +.settingsBody { padding: 18px 16px 45px; } +.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; } +.field > span, .settingLabel strong { color: #536076; font-size: 9px; font-weight: 700; } +.field input, .field textarea { + width: 100%; + padding: 9px 10px; + border: 1px solid #dde2e9; + border-radius: 7px; + outline: 0; + background: #fff; + color: #3e4b60; + font: inherit; + font-size: 9px; + resize: vertical; +} +.field input:focus, .field textarea:focus { border-color: #8eb0fa; box-shadow: 0 0 0 3px rgba(51,112,255,.08); } +.settingGroup, .approverSetting, .branchSettings { margin: 19px 0; padding-top: 17px; border-top: 1px solid #edf0f4; } +.settingLabel { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; } +.settingLabel small { color: #99a2b0; font-size: 7px; } +.segmented { display: flex; padding: 3px; border-radius: 7px; background: #f0f2f5; } +.segmented button { flex: 1; height: 28px; border: 0; border-radius: 5px; background: transparent; color: #7e899b; cursor: pointer; font-size: 8px; } +.segmented button.segmentActive { background: #fff; color: var(--blue); box-shadow: 0 2px 6px rgba(43,56,81,.08); font-weight: 700; } +.peopleList { display: flex; flex-direction: column; gap: 7px; } +.peopleList > div { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid #e5e9ef; border-radius: 7px; } +.peopleList > div > span { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 50%; background: var(--blueSoft); color: #3b68c6; font-size: 8px; font-weight: 700; } +.peopleList p { flex: 1; display: flex; flex-direction: column; gap: 2px; margin: 0; } +.peopleList p strong { color: #47556b; font-size: 9px; } +.peopleList p small { color: #9ba3b0; font-size: 7px; } +.peopleList button { border: 0; background: none; color: #a2aab6; cursor: pointer; } +.addPeople { width: 100%; height: 34px; margin-top: 8px; border: 1px dashed #b8c4d7; border-radius: 7px; background: #fbfcfe; color: var(--blue); cursor: pointer; font-size: 8px; } +.branchSettings > div { margin-bottom: 12px; padding: 11px; border: 1px solid #e5e9ef; border-radius: 8px; background: #fafbfc; } +.branchSettings > div > div:first-child { display: flex; align-items: center; gap: 7px; margin-bottom: 12px; } +.branchSettings > div > div:first-child span { width: 18px; height: 18px; display: grid; place-items: center; border-radius: 4px; background: var(--orangeSoft); color: var(--orange); font-size: 7px; font-weight: 700; } +.branchSettings > div > div:first-child strong { color: #566276; font-size: 9px; } +.branchSettings .field { margin-bottom: 10px; } +.branchSettings .field:last-child { margin-bottom: 0; } +.infoBox { display: flex; gap: 9px; padding: 11px; border: 1px solid #dbe5fa; border-radius: 8px; background: #f6f9ff; } +.infoBox span { width: 20px; height: 20px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: var(--blueSoft); color: var(--blue); font-size: 8px; font-weight: 800; } +.infoBox p { margin: 1px 0 0; color: #6e7c92; font-size: 8px; line-height: 1.6; } +.permissions { border: 1px solid #e5e9ef; border-radius: 8px; overflow: hidden; } +.permissions > div { min-height: 40px; display: grid; grid-template-columns: 1fr 42px 42px; align-items: center; padding: 0 9px; border-bottom: 1px solid #edf0f4; } +.permissions > div:last-child { border-bottom: 0; } +.permissions span, .permissions strong { color: #627086; font-size: 8px; } +.permissions input { accent-color: var(--blue); } +.permissionHead { background: #f7f8fa; } +.advancedSettings { display: flex; flex-direction: column; gap: 10px; } +.advancedSettings > label { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px; border: 1px solid #e5e9ef; border-radius: 8px; } +.advancedSettings > label span { display: flex; flex-direction: column; gap: 4px; } +.advancedSettings strong { color: #506076; font-size: 9px; } +.advancedSettings small { color: #98a1af; font-size: 7px; } +.advancedSettings input { width: 32px; height: 18px; accent-color: var(--blue); } +.advancedSettings > button { height: 36px; border: 1px dashed #b8c4d7; border-radius: 7px; background: #fbfcfe; color: var(--blue); cursor: pointer; font-size: 8px; } +.noSelection { min-height: 360px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px; text-align: center; } +.noSelection > span { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; background: #f0f3f7; color: #9aa3b1; font-size: 22px; } +.noSelection strong { margin: 14px 0 5px; color: #556176; font-size: 11px; } +.noSelection p { margin: 0; color: #949dab; font-size: 8px; line-height: 1.6; } + +.modalBackdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 25px; background: rgba(16,25,42,.5); backdrop-filter: blur(4px); } +.previewModal { width: 580px; max-height: calc(100vh - 50px); overflow: auto; border-radius: 13px; background: #fff; box-shadow: 0 30px 80px rgba(12,21,37,.28); } +.previewModal header, .jsonDrawer header { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px; border-bottom: 1px solid #edf0f4; } +.previewModal header > div { gap: 11px; } +.previewModal header > div > span { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; background: var(--blueSoft); color: var(--blue); } +.previewModal h2, .jsonDrawer h2 { margin: 0 0 4px; color: var(--navy); font-size: 15px; } +.previewModal header p, .jsonDrawer header p { margin: 0; color: #929cab; font-size: 8px; } +.previewModal header > button, .jsonDrawer header > button { width: 28px; height: 28px; border: 0; border-radius: 50%; background: #f2f4f7; color: #778296; cursor: pointer; font-size: 16px; } +.previewForm { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 15px 20px; border-bottom: 1px solid #edf0f4; background: #fafbfc; } +.previewForm > div { display: flex; flex-direction: column; gap: 4px; } +.previewForm span { color: #98a1af; font-size: 7px; } +.previewForm strong { color: #4b586d; font-size: 9px; } +.previewForm .hitBranch { color: var(--orange); } +.previewRoute { padding: 20px 85px 25px; } +.previewRoute > div { position: relative; display: flex; gap: 11px; min-height: 62px; } +.previewDot { position: relative; z-index: 2; width: 25px; height: 25px; display: grid; place-items: center; flex: 0 0 auto; border: 2px solid #fff; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 1px #a9c2fa; color: #fff; font-size: 7px; font-weight: 700; } +.previewRoute p { display: flex; flex-direction: column; gap: 4px; margin: 3px 0 0; } +.previewRoute strong { color: #435168; font-size: 9px; } +.previewRoute small { color: #9099a8; font-size: 7px; } +.previewRoute i { position: absolute; top: 24px; left: 12px; bottom: 0; width: 1px; background: #cbd3df; } +.previewModal footer, .jsonDrawer footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid #edf0f4; } +.previewModal footer button, .jsonDrawer footer button { min-height: 34px; padding: 0 13px; border: 1px solid #dce1e8; border-radius: 7px; background: #fff; color: #657187; cursor: pointer; font-size: 8px; } +.previewModal footer button:last-child, .jsonDrawer footer button:last-child { border-color: var(--blue); background: var(--blue); color: #fff; } +.jsonDrawer { position: fixed; inset: 0 0 0 auto; width: 520px; display: flex; flex-direction: column; background: #fff; box-shadow: -20px 0 60px rgba(12,21,37,.18); } +.jsonDrawer pre { flex: 1; margin: 0; padding: 18px; overflow: auto; background: #101a2c; color: #c9d9f5; font: 9px/1.7 "SFMono-Regular", Consolas, monospace; white-space: pre-wrap; } +.toast { position: fixed; right: 25px; bottom: 24px; z-index: 100; min-width: 225px; display: flex; align-items: center; gap: 9px; padding: 12px 14px; border: 1px solid #dce3ec; border-radius: 9px; background: #fff; box-shadow: 0 16px 35px rgba(23,35,58,.18); color: #4b596e; font-size: 9px; animation: toastIn .2s ease-out; } +.toast span { width: 19px; height: 19px; display: grid; place-items: center; border-radius: 50%; background: var(--greenSoft); color: var(--green); font-weight: 800; } +@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } } + +@media (max-width: 1180px) { + .designerShell { min-width: 840px; } + .workspace { grid-template-columns: minmax(500px, 1fr) 320px; } + .palette { position: fixed; top: 68px; bottom: 0; left: 0; z-index: 50; width: 235px; transform: translateX(-100%); box-shadow: 14px 0 30px rgba(24,38,61,.13); transition: transform .2s ease; } + .paletteOpen { transform: translateX(0); } + .paletteHeader > button, .mobilePaletteButton { display: block; } +} + +@media (max-width: 860px) { + .designerShell { min-width: 680px; } + .topbar { padding: 0 13px; } + .processIdentity { min-width: 210px; } + .processIdentity input { width: 145px; } + .topbarActions .quietButton:first-child { display: none; } + .workspace { grid-template-columns: minmax(390px, 1fr) 290px; } + .conditionGroup { width: 640px; } + .flowWrap { width: 640px; } + .canvasGrid { padding-right: 16px; padding-left: 16px; } +} + +@media (prefers-reduced-motion: reduce) { + .processNode, .paletteItem, .flowWrap, .palette { transition: none; } + .toast { animation: none; } +} diff --git a/app/approval/page.tsx b/app/approval/page.tsx new file mode 100644 index 0000000..81a0299 --- /dev/null +++ b/app/approval/page.tsx @@ -0,0 +1,300 @@ +"use client"; + +import Link from "next/link"; +import { useEffect, useMemo, useState } from "react"; +import defaultFlow from "../data/approval-flow.json"; +import styles from "./ApprovalDesigner.module.css"; + +type NodeType = "start" | "approval" | "condition" | "cc" | "end"; +type ApprovalMode = "single" | "any" | "all"; + +type FlowNode = { + id: string; + type: NodeType; + title: string; + description: string; + approvers: string[]; + mode: ApprovalMode; + allowTransfer?: boolean; + autoPass?: boolean; + branches?: Branch[]; +}; + +type Branch = { + id: string; + label: string; + expression: string; + node: FlowNode; +}; + +type FlowData = { + id: string; + name: string; + description: string; + status: string; + version: string; + updatedAt: string; + nodes: FlowNode[]; +}; + +const library: Array<{ type: NodeType; label: string; description: string; icon: string; tone: string }> = [ + { type: "approval", label: "审批人", description: "指定成员或角色审批", icon: "✓", tone: "blue" }, + { type: "condition", label: "条件分支", description: "根据表单字段自动分流", icon: "⑂", tone: "orange" }, + { type: "cc", label: "抄送人", description: "将审批结果通知成员", icon: "◎", tone: "purple" }, +]; + +const people = ["直属主管", "部门负责人", "财务负责人", "预算管理员", "采购专员", "法务负责人"]; + +export default function ApprovalDesignerPage() { + const [flow, setFlow] = useState(defaultFlow as unknown as FlowData); + const [selectedId, setSelectedId] = useState("approval-1"); + const [zoom, setZoom] = useState(1); + const [previewOpen, setPreviewOpen] = useState(false); + const [jsonOpen, setJsonOpen] = useState(false); + const [paletteOpen, setPaletteOpen] = useState(false); + const [toast, setToast] = useState(""); + const [saved, setSaved] = useState(true); + const [loaded, setLoaded] = useState(false); + + useEffect(() => { + const stored = window.localStorage.getItem("orbit-approval-flow"); + if (stored) { + try { setFlow(JSON.parse(stored)); } + catch { window.localStorage.removeItem("orbit-approval-flow"); } + } + setLoaded(true); + }, []); + + useEffect(() => { + if (!loaded) return; + setSaved(false); + const timer = window.setTimeout(() => { + window.localStorage.setItem("orbit-approval-flow", JSON.stringify(flow)); + setSaved(true); + }, 500); + return () => window.clearTimeout(timer); + }, [flow, loaded]); + + const selectedNode = useMemo(() => flow.nodes.find((node) => node.id === selectedId), [flow.nodes, selectedId]); + + const notify = (message: string) => { + setToast(message); + window.setTimeout(() => setToast(""), 2400); + }; + + const updateNode = (patch: Partial) => { + setFlow((current) => ({ + ...current, + nodes: current.nodes.map((node) => node.id === selectedId ? { ...node, ...patch } : node), + updatedAt: new Date().toLocaleString("zh-CN", { hour12: false }), + })); + }; + + const addNode = (type: NodeType) => { + const id = `${type}-${Date.now()}`; + const common = { id, type, approvers: [] as string[], mode: "single" as ApprovalMode }; + let node: FlowNode; + if (type === "approval") node = { ...common, title: "新审批节点", description: "请选择审批人", approvers: ["直属主管"], allowTransfer: true }; + else if (type === "cc") node = { ...common, title: "新抄送节点", description: "审批通过后自动抄送", approvers: ["申请人"] }; + else node = { + ...common, + title: "新条件分支", + description: "根据表单字段设置条件", + branches: [ + { id: `${id}-a`, label: "条件 1", expression: "totalAmount >= 1000", node: { ...common, id: `${id}-node-a`, type: "approval", title: "条件审批人", description: "满足条件时执行", approvers: ["部门负责人"] } }, + { id: `${id}-b`, label: "其他情况", expression: "otherwise", node: { ...common, id: `${id}-node-b`, type: "cc", title: "默认抄送", description: "未满足条件时执行", approvers: ["申请人"] } }, + ], + }; + setFlow((current) => { + const endIndex = current.nodes.findIndex((item) => item.type === "end"); + const nodes = [...current.nodes]; + nodes.splice(endIndex < 0 ? nodes.length : endIndex, 0, node); + return { ...current, nodes, updatedAt: new Date().toLocaleString("zh-CN", { hour12: false }) }; + }); + setSelectedId(id); + setPaletteOpen(false); + notify(`已添加${type === "approval" ? "审批" : type === "condition" ? "条件" : "抄送"}节点`); + }; + + const deleteNode = () => { + if (!selectedNode || selectedNode.type === "start" || selectedNode.type === "end") return; + setFlow((current) => ({ ...current, nodes: current.nodes.filter((node) => node.id !== selectedId) })); + setSelectedId("start-1"); + notify("节点已删除"); + }; + + const validateFlow = () => { + const emptyApprovers = flow.nodes.filter((node) => (node.type === "approval" || node.type === "cc") && node.approvers.length === 0); + const invalidBranches = flow.nodes.filter((node) => node.type === "condition" && (!node.branches || node.branches.length < 2)); + if (emptyApprovers.length || invalidBranches.length) notify(`发现 ${emptyApprovers.length + invalidBranches.length} 项配置需要完善`); + else notify(`流程校验通过,共 ${flow.nodes.length} 个主节点`); + }; + + const publish = () => { + window.localStorage.setItem("orbit-approval-flow", JSON.stringify({ ...flow, status: "published" })); + setFlow((current) => ({ ...current, status: "published" })); + notify("演示流程已发布到本地"); + }; + + const resetFlow = () => { + setFlow(defaultFlow as unknown as FlowData); + setSelectedId("approval-1"); + window.localStorage.removeItem("orbit-approval-flow"); + notify("已恢复 JSON 示例流程"); + }; + + return ( +
+
+
+ ← + +
+
setFlow((current) => ({ ...current, name: event.target.value }))} aria-label="流程名称" />{flow.status === "published" ? "已发布" : "草稿"}
+ {saved ? "✓ 已自动保存到本地" : "正在保存…"} · {flow.version} +
+
+
+ + + + +
+
+ +
+ + +
event.preventDefault()} onDrop={(event) => { const type = event.dataTransfer.getData("nodeType") as NodeType; if (type) addNode(type); }}> +
+ +
审批管理/流程设计/{flow.name}
+
{Math.round(zoom * 100)}%
+
+
+
+
+ {flow.nodes.map((node, index) => ( +
+ {node.type === "condition" ? ( + setSelectedId(node.id)} /> + ) : ( + setSelectedId(node.id)} /> + )} + {index < flow.nodes.length - 1 &&
} +
+ ))} + +
+
+
+
+ + +
+ + {previewOpen && setPreviewOpen(false)} />} + {jsonOpen && setJsonOpen(false)} notify={notify} />} + {toast &&
{toast}
} +
+ ); +} + +function ProcessNode({ node, selected, onSelect }: { node: FlowNode; selected: boolean; onSelect: () => void }) { + const meta = { + start: { icon: "▶", tone: "green", eyebrow: "流程发起" }, + approval: { icon: "✓", tone: "blue", eyebrow: node.mode === "all" ? "会签审批" : node.mode === "any" ? "或签审批" : "单人审批" }, + cc: { icon: "◎", tone: "purple", eyebrow: "抄送通知" }, + end: { icon: "■", tone: "gray", eyebrow: "流程完成" }, + condition: { icon: "⑂", tone: "orange", eyebrow: "条件分支" }, + }[node.type]; + return ( + + ); +} + +function ConditionNode({ node, selected, onSelect }: { node: FlowNode; selected: boolean; onSelect: () => void }) { + return ( +
+ +
+
+ {node.branches?.map((branch, index) => ( +
+
{index + 1}{branch.label}{branch.expression}
+
+ +
+ ))} +
+
+
+ ); +} + +function NodeSettings({ node, updateNode, deleteNode, notify }: { node: FlowNode; updateNode: (patch: Partial) => void; deleteNode: () => void; notify: (message: string) => void }) { + const [tab, setTab] = useState("节点设置"); + const addPerson = () => { + const next = people.find((person) => !node.approvers.includes(person)); + if (!next) return notify("可选示例审批人已全部添加"); + updateNode({ approvers: [...node.approvers, next] }); + }; + return ( + <> +
{node.type === "condition" ? "⑂" : node.type === "cc" ? "◎" : "✓"}{node.title}节点 ID · {node.id}
{node.type !== "start" && node.type !== "end" && }
+
{["节点设置", "表单权限", "高级"].map((item) => )}
+
+ {tab === "节点设置" && <> + +