diff --git a/apps/app-mobile/src/api/index.ts b/apps/app-mobile/src/api/index.ts index 044406c8..1396642d 100644 --- a/apps/app-mobile/src/api/index.ts +++ b/apps/app-mobile/src/api/index.ts @@ -1,5 +1,24 @@ import {HttpClient, resolveHttpTimeout} from "@coding-flow/flow-core"; import { message } from "antd"; +import { getOperatorIdentity } from "@/config/identity"; + +/** + * 全局向流程引擎接口注入当前操作身份(issue #288 / #297 / #301)。 + * + *

与 {@code app-pc} 同一做法:后端控制器统一声明当前身份,因此在 HttpClient 的公共请求头里注入, + * 待办查询、审批、发起等包共用一个出口,页面之间不需要各自拼参数。 + * + *

必须走请求头而不是 query:引擎的查询接口用 {@code SearchRequest} 接收请求,会把 query 参数 + * 当作实体过滤字段解析,多带一个 {@code operatorIdentity} 就会报 + * `Field operatorIdentity not found in class hierarchy`,待办/已办/抄送/流程列表全部 500(issue #301)。 + * + *

返回值约定:未设置过身份时返回空对象,让后端回退到登录用户自身的身份; + * 设置过(包括显式选择「默认身份」的空串)时始终携带该请求头,保证「切回默认身份」能被后端识别。 + */ +HttpClient.defaultHeaders = () => { + const identity = getOperatorIdentity(); + return identity === null ? {} : {"X-Operator-Identity": identity}; +}; export const httpClient = new HttpClient(resolveHttpTimeout(),{ success:(msg:string)=>{ @@ -9,4 +28,4 @@ export const httpClient = new HttpClient(resolveHttpTimeout(),{ console.log(msg); message.error(msg) } -}) \ No newline at end of file +}) diff --git a/apps/app-mobile/src/components/identity-switch/index.module.css b/apps/app-mobile/src/components/identity-switch/index.module.css new file mode 100644 index 00000000..b5f77209 --- /dev/null +++ b/apps/app-mobile/src/components/identity-switch/index.module.css @@ -0,0 +1,78 @@ +/** + * 移动端「操作身份」入口样式(挂在首页,不占待办列表空间)。 + */ +.card { + display: flex; + align-items: center; + gap: 8px; + margin: 12px 16px; + padding: 10px 14px; + border-radius: 10px; + background: #fff; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); + cursor: pointer; + user-select: none; + -webkit-tap-highlight-color: transparent; +} + +.card:active { + background: #f5f5f5; +} + +.dot { + flex: none; + width: 6px; + height: 6px; + border-radius: 50%; + background: #bfbfbf; +} + +.dotActive { + background: var(--adm-color-primary, #1677ff); +} + +.label { + font-size: 13px; + color: #666; +} + +.value { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 13px; + font-weight: 600; + color: #333; +} + +.valueActive { + color: var(--adm-color-primary, #1677ff); +} + +.action { + margin-left: auto; + flex: none; + font-size: 13px; + color: var(--adm-color-primary, #1677ff); +} + +.popupBody { + border-top-left-radius: 12px; + border-top-right-radius: 12px; +} + +.popupContent { + padding: 16px; +} + +.popupTitle { + margin-bottom: 12px; + font-size: 16px; + font-weight: 600; +} + +.popupTip { + margin: 8px 0 16px; + font-size: 12px; + color: #999; +} diff --git a/apps/app-mobile/src/components/identity-switch/index.tsx b/apps/app-mobile/src/components/identity-switch/index.tsx new file mode 100644 index 00000000..a22f2a5c --- /dev/null +++ b/apps/app-mobile/src/components/identity-switch/index.tsx @@ -0,0 +1,118 @@ +import React from "react"; +import { Button, Popup, Selector, Toast } from "antd-mobile"; +import { IDENTITY_OPTIONS, getOperatorIdentity, setOperatorIdentity } from "@/config/identity"; +import styles from "./index.module.css"; + +/** + * 移动端「操作身份」切换(演示用)。 + * + *

身份是「以什么身份办事」,不是「能看到什么数据」(issue #297):切换后所有 {@code /api/} 请求 + * 都会带上 {@code X-Operator-Identity},引擎据此决定取人脚本走哪条分支,并把本次操作身份写进记录留痕; + * 但列表可见范围不随身份变化(默认按人员跨身份查询)。 + * + *

入口是**首页({@code pages/home.tsx})上的一张卡片**,点击后弹出底部选择层: + * 待办列表不再为身份条预留顶部空间,审批页底部是「通过 / 拒绝」操作区也不会被遮挡。 + * + *

切换后整页刷新:身份同时影响审批面板的可用动作、取人脚本上下文与本次提交的留痕身份。 + */ +const DEFAULT_OPTION_VALUE = '__default__'; + +const toOptionValue = (identity: string): string => identity || DEFAULT_OPTION_VALUE; + +const fromOptionValue = (value: string): string => ( + value === DEFAULT_OPTION_VALUE ? '' : value +); + +const IdentitySwitch: React.FC = () => { + + // 展示值必须随外部变化同步:登录态失效、其他标签页改动身份都要反映到界面上, + // 否则会出现「横条显示 department1、请求其实按默认身份发出」的假象。 + const [applied, setApplied] = React.useState(getOperatorIdentity() ?? ''); + const [open, setOpen] = React.useState(false); + const [value, setValue] = React.useState(applied); + + React.useEffect(() => { + const sync = () => { + const next = getOperatorIdentity() ?? ''; + setApplied(next); + }; + sync(); + window.addEventListener('hashchange', sync); + window.addEventListener('storage', sync); + return () => { + window.removeEventListener('hashchange', sync); + window.removeEventListener('storage', sync); + }; + }, []); + + const handleOpen = () => { + // 每次打开都以「已生效身份」为初值,避免上次未确认的选择残留 + setValue(applied); + setOpen(true); + }; + + const handleApply = () => { + setOperatorIdentity(value); + setOpen(false); + Toast.show({content: `已切换为${value || '默认身份'}`, duration: 800}); + window.location.reload(); + }; + + return ( + <> + {/* 入口卡片:挂在首页(pages/home.tsx),不占待办列表的顶部空间 */} +

+ + 操作身份 + + {applied || '默认身份'} + + 切换 +
+ + setOpen(false)} + onClose={() => setOpen(false)} + bodyClassName={styles.popupBody} + > +
+
选择操作身份
+ ({ + label: item.label, + value: toOptionValue(item.value), + }))} + onChange={(selected) => { + if (selected.length === 0) { + // antd-mobile 允许点空已选项,这里不允许「无选择」 + return; + } + setValue(fromOptionValue(selected[0])); + }} + /> +
+ 身份只影响流程操作与脚本匹配,不影响列表可见范围 +
+ +
+
+ + ); +}; + +export default IdentitySwitch; diff --git a/apps/app-mobile/src/config/identity.ts b/apps/app-mobile/src/config/identity.ts new file mode 100644 index 00000000..7d32509b --- /dev/null +++ b/apps/app-mobile/src/config/identity.ts @@ -0,0 +1,43 @@ +/** + * 移动端示例应用的「操作身份」(operatorIdentity)配置。 + * + *

与 {@code app-pc} 保持同一口径(issue #288 / #297):身份是**运行期选择的操作视角**, + * 同一用户(如 user1)可以在不同事项上以 department1 / department2 参与流程。 + * 示例把当前身份存在 localStorage,并通过所有 {@code /api/} 请求的 query 参数 + * {@code operatorIdentity} 传给后端:取人脚本按该身份走对应分支,本次操作身份写入记录留痕 + * ({@code createOperatorIdentity} / {@code submitOperatorIdentity})。 + * + *

身份**不决定数据可见范围**(issue #297):待办 / 已办 / 抄送默认按人员跨身份查询, + * 只有显式传 {@code identityScope=LOCKED} 才按身份锁定。 + * + *

两个示例应用各自维护一份,是为了让示例保持「可整块删除」的独立性; + * 真实项目应把身份选项替换为自己的组织模型(部门 / 岗位 / 任职关系),并用同样的方式随请求下发。 + */ + +/** localStorage 中保存当前身份标识的键(与 app-pc 共用同一个键,便于两端联调同一身份) */ +export const FLOW_OPERATOR_IDENTITY_KEY = 'flow_operator_identity'; + +/** 示例身份选项:与多身份演示场景对应(issue #288 / #297) */ +export const IDENTITY_OPTIONS = [ + { label: '默认身份', value: '' }, + { label: '部门1(department1)', value: 'department1' }, + { label: '部门2(department2)', value: 'department2' }, +]; + +/** + * 读取当前身份标识。 + * + * @return 身份标识,空串表示默认身份;未设置时返回 null(由后端回退到登录用户自身身份) + */ +export const getOperatorIdentity = (): string | null => { + return localStorage.getItem(FLOW_OPERATOR_IDENTITY_KEY); +}; + +/** + * 保存当前身份标识 + * + * @param identity 身份标识,空串表示默认身份 + */ +export const setOperatorIdentity = (identity: string) => { + localStorage.setItem(FLOW_OPERATOR_IDENTITY_KEY, identity); +}; diff --git a/apps/app-mobile/src/hooks/registrations.tsx b/apps/app-mobile/src/hooks/registrations.tsx index db9f3de9..bcc3d88e 100644 --- a/apps/app-mobile/src/hooks/registrations.tsx +++ b/apps/app-mobile/src/hooks/registrations.tsx @@ -11,8 +11,11 @@ import { registerFormView } from "@/hooks/register-form-view"; * * 通过 React.lazy 动态加载本模块,注册相关依赖(antd-mobile Form、表单组件等) * 不会进入首屏 chunk。 + * + * 组件会把 children 透传下去,用于「路由必须晚于注册挂载」的约束: + * 见 src/index.tsx 中的 Single Suspense 写法。 */ -const Registrations: React.FC = () => { +const Registrations: React.FC<{ children?: React.ReactNode }> = ({ children }) => { registerFormTypes(); registerFormView(); @@ -21,7 +24,7 @@ const Registrations: React.FC = () => { console.log('register flow success.'); }, []); - return null; + return <>{children}; }; export default Registrations; \ No newline at end of file diff --git a/apps/app-mobile/src/index.tsx b/apps/app-mobile/src/index.tsx index e4a9745b..5d88505c 100644 --- a/apps/app-mobile/src/index.tsx +++ b/apps/app-mobile/src/index.tsx @@ -10,14 +10,16 @@ const Registrations = React.lazy(() => import('@/hooks/registrations')); const App = () => { return ( - {/* 注册组件必须在渲染期执行(registerFormItems 内部调用了 hook), - 不能放在 useEffect 异步回调里调用 */} + {/* 注册与路由必须处在同一个 Suspense 边界内,且路由作为注册组件的子节点: + 注册结果写入 @coding-form/form-engine 的模块级单例 FormRegistry, + 若两个边界并列,路由页面可能先于注册 commit(表单实例未注册, + 打开审批详情会抛 Form Instance must register);同时 lazy chunk + 加载期间 fallback 为空,注册失败会被静默吞掉。 + 由 Registrations 包住路由后,路由一定在注册完成后才挂载。 */} - - - {/* 路由页面均为 React.lazy 动态加载,必须提供 Suspense 兜底 */} - - + + + ) diff --git a/apps/app-mobile/src/pages/home.tsx b/apps/app-mobile/src/pages/home.tsx index a1d84403..72512328 100644 --- a/apps/app-mobile/src/pages/home.tsx +++ b/apps/app-mobile/src/pages/home.tsx @@ -2,6 +2,7 @@ import {Button, Space } from "antd-mobile"; import React from "react"; import { useNavigate } from "react-router"; import {routers} from "@/config/routers.tsx"; +import IdentitySwitch from "@/components/identity-switch"; const HomePage:React.FC = ()=>{ @@ -16,6 +17,11 @@ const HomePage:React.FC = ()=>{ justifyContent: "center", alignItems:'center' }}>

Flow-Engine Home Page

+ {/* + 操作身份切换(issue #297):身份决定取人脚本走哪条分支、本次操作写哪个身份留痕, + 但不影响列表可见范围。入口固定在首页,待办列表与审批页不再为它让出空间。 + */} + {routers.filter(item=>item.path!=='/' && !item.hidden).map(item => { return ( diff --git a/apps/app-mobile/src/pages/todo.tsx b/apps/app-mobile/src/pages/todo.tsx index f1cbfb51..c4893d5d 100644 --- a/apps/app-mobile/src/pages/todo.tsx +++ b/apps/app-mobile/src/pages/todo.tsx @@ -1,4 +1,4 @@ -import {Empty, List, Tabs} from "antd-mobile"; +import {Empty, List, Tag, Tabs} from "antd-mobile"; import React from "react"; import {done, list, notify, todo} from "@/api/record.ts"; import dayjs from "dayjs"; @@ -52,34 +52,53 @@ const TodoList: React.FC = ({type}) => { - {records.map((record) => ( - { - handleApproval(record.recordId); - }} - key={record.recordId} - prefix={( - - )} - description={( - <> -
{record.nodeName} {record.workTitle}
-
实例编码:{record.processId}
- - )} - extra={ -
- {dayjs(record.createTime).format("YYYY-MM-DD HH:mm:ss")} - {record.currentOperatorName} -
- } - > - {record.title} -
- ))} + {records.map((record) => { + // 「谁 + 以什么身份」合并展示,避免单独一列「身份」语义不清。 + // 待办/抄送/全部:展示待办归属人与归属身份(issue #288); + // 已办:优先展示实际办理人与办理身份(issue #306),历史数据回退到归属人。 + // 列表本身不按身份过滤(issue #297),身份为空表示默认身份。 + const isDone = type === 'done'; + const operatorName = isDone + ? (record.handleOperatorName || record.currentOperatorName) + : record.currentOperatorName; + const operatorIdentity = isDone + ? (record.handleOperatorIdentity || record.currentOperatorIdentity) + : record.currentOperatorIdentity; + return ( + { + handleApproval(record.recordId); + }} + key={record.recordId} + prefix={( + + )} + description={( + <> +
{record.nodeName} {record.workTitle}
+
实例编码:{record.processId}
+ + )} + extra={ +
+ {dayjs(record.createTime).format("YYYY-MM-DD HH:mm:ss")} + {operatorName} + + {operatorIdentity || '默认身份'} + +
+ } + > + {record.title} +
+ ); + })}
); }; @@ -88,20 +107,22 @@ const TodoPage: React.FC = () => { const [currentKey, setCurrentKey] = React.useState('todo'); return ( - - - - - - - - - - - - - - +
+ + + + + + + + + + + + + + +
); }; diff --git a/apps/app-pc/src/api/index.ts b/apps/app-pc/src/api/index.ts index 044406c8..9259c17f 100644 --- a/apps/app-pc/src/api/index.ts +++ b/apps/app-pc/src/api/index.ts @@ -1,5 +1,24 @@ import {HttpClient, resolveHttpTimeout} from "@coding-flow/flow-core"; import { message } from "antd"; +import { getOperatorIdentity } from "@/config/identity"; + +/** + * 全局向流程引擎接口注入当前身份(issue #288 / #301)。 + * + *

引擎的身份来自「操作者对象」,后端控制器统一声明当前身份,因此这里在 HttpClient 的 + * 公共请求头里注入。发起 / 审批 / 待办 / 设计等包共用同一个 HttpClient 出口,不需要每个页面各自拼参数。 + * + *

必须走请求头而不是 query:引擎的查询接口用 {@code SearchRequest} 接收请求,会把 query 参数 + * 当作实体过滤字段解析,多带一个 {@code operatorIdentity} 就会报 + * `Field operatorIdentity not found in class hierarchy`,待办/已办/抄送/流程列表全部 500(issue #301)。 + * + *

返回值约定:未设置过身份时返回空对象,让后端回退到登录用户自身的身份; + * 设置过(包括显式选择「默认身份」)时始终携带该请求头,保证「切回默认身份」能被后端识别。 + */ +HttpClient.defaultHeaders = () => { + const identity = getOperatorIdentity(); + return identity === null ? {} : {"X-Operator-Identity": identity}; +}; export const httpClient = new HttpClient(resolveHttpTimeout(),{ success:(msg:string)=>{ @@ -9,4 +28,4 @@ export const httpClient = new HttpClient(resolveHttpTimeout(),{ console.log(msg); message.error(msg) } -}) \ No newline at end of file +}) diff --git a/apps/app-pc/src/components/identity-switch/index.tsx b/apps/app-pc/src/components/identity-switch/index.tsx new file mode 100644 index 00000000..52e4b53b --- /dev/null +++ b/apps/app-pc/src/components/identity-switch/index.tsx @@ -0,0 +1,77 @@ +import React from "react"; +import { AutoComplete, Button, Card, Space, Tag, Typography } from "antd"; +import { IDENTITY_OPTIONS, getOperatorIdentity, setOperatorIdentity } from "@/config/identity"; + +/** + * 当前操作身份切换器(演示用)。 + * + *

身份是「以什么身份办事」,不是「能看到什么数据」(issue #297): + * 切换后后续请求仍带上 {@code operatorIdentity},引擎据此决定取人脚本走哪条路径 + * (例如 a 身份对应 L1 领导、b 身份对应 L2 领导),并把本次操作身份写进记录留痕 + * ({@code createOperatorIdentity} / {@code submitOperatorIdentity})。 + * + *

但列表可见范围不再随身份变化:待办 / 已办 / 抄送默认按人员跨身份查询, + * 只有显式传 {@code identityScope=LOCKED} 才锁定身份。 + * + *

切换后整页刷新:身份同时影响审批面板的可用动作、取人脚本上下文与本次提交的留痕身份, + * 刷新是最简单可靠的重新拉取方式。 + */ +const IdentitySwitch: React.FC = () => { + + // 展示值必须随外部变化同步:登录态失效会清 token,其他标签页 / 路由切换也可能改动身份。 + // 若只在首次挂载时读一次,就会出现「卡片显示 department1、请求其实按默认身份发出」的假象。 + const [applied, setApplied] = React.useState(getOperatorIdentity() ?? ''); + const [value, setValue] = React.useState(applied); + + React.useEffect(() => { + const sync = () => { + const next = getOperatorIdentity() ?? ''; + setApplied(next); + setValue(next); + }; + sync(); + window.addEventListener('hashchange', sync); + window.addEventListener('storage', sync); + return () => { + window.removeEventListener('hashchange', sync); + window.removeEventListener('storage', sync); + }; + }, []); + + const dirty = applied !== value; + + const handleApply = () => { + setOperatorIdentity(value); + window.location.reload(); + }; + + return ( +

+ + + + 当前身份 + {applied || '默认身份'} + + + setValue(next)} + placeholder={"如 department1"} + style={{width: 180}} + /> + + + + 身份只影响流程操作与脚本匹配,不影响列表可见范围 + + + +
+ ) +}; + +export default IdentitySwitch; diff --git a/apps/app-pc/src/config/identity.ts b/apps/app-pc/src/config/identity.ts new file mode 100644 index 00000000..43199945 --- /dev/null +++ b/apps/app-pc/src/config/identity.ts @@ -0,0 +1,42 @@ +/** + * 示例应用的「操作身份」(operatorIdentity)配置。 + * + *

身份是**运行期选择的操作视角**:同一用户(如 user1)可以在不同事项上以 department1 / department2 参与流程。 + * 示例把当前身份存在 localStorage 并通过所有请求的 query 参数 {@code operatorIdentity} 传给后端, + * 后端据此加载「带身份的操作者副本」:取人脚本按该身份走对应分支,本次操作身份写入记录留痕 + * ({@code createOperatorIdentity} / {@code submitOperatorIdentity})。 + * + *

身份**不决定数据可见范围**(issue #297):待办 / 已办 / 抄送默认按人员跨身份查询, + * 只有显式传 {@code identityScope=LOCKED} 才按身份锁定。 + * + *

真实项目应把身份选项替换为自己的组织模型(部门 / 岗位 / 任职关系), + * 并用同样的方式随请求下发。 + */ + +/** localStorage 中保存当前身份标识的键 */ +export const FLOW_OPERATOR_IDENTITY_KEY = 'flow_operator_identity'; + +/** 示例身份选项:与多身份演示场景对应(issue #288 / #297) */ +export const IDENTITY_OPTIONS = [ + { label: '默认身份', value: '' }, + { label: '部门1(department1)', value: 'department1' }, + { label: '部门2(department2)', value: 'department2' }, +]; + +/** + * 读取当前身份标识。 + * + * @return 身份标识,空串表示默认身份;未设置时返回 null(由后端回退到登录用户自身身份) + */ +export const getOperatorIdentity = (): string | null => { + return localStorage.getItem(FLOW_OPERATOR_IDENTITY_KEY); +}; + +/** + * 保存当前身份标识 + * + * @param identity 身份标识,空串表示默认身份 + */ +export const setOperatorIdentity = (identity: string) => { + localStorage.setItem(FLOW_OPERATOR_IDENTITY_KEY, identity); +}; diff --git a/apps/app-pc/src/hooks/registrations.tsx b/apps/app-pc/src/hooks/registrations.tsx index ab594419..4dbae883 100644 --- a/apps/app-pc/src/hooks/registrations.tsx +++ b/apps/app-pc/src/hooks/registrations.tsx @@ -12,8 +12,11 @@ import { registerPluginView } from "@/hooks/register-plugin-view"; * * 通过 React.lazy 动态加载本模块,注册相关依赖(antd Form、表单组件、flow-design 等) * 不会进入首屏 chunk。 + * + * 组件会把 children 透传下去,用于「路由必须晚于注册挂载」的约束: + * 见 src/index.tsx 中的 Single Suspense 写法。 */ -const Registrations: React.FC = () => { +const Registrations: React.FC<{ children?: React.ReactNode }> = ({ children }) => { registerFormTypes(); registerPluginView(); @@ -23,7 +26,7 @@ const Registrations: React.FC = () => { console.log('register flow success.'); }, []); - return null; + return <>{children}; }; export default Registrations; diff --git a/apps/app-pc/src/index.tsx b/apps/app-pc/src/index.tsx index 78ba6a06..a437156f 100644 --- a/apps/app-pc/src/index.tsx +++ b/apps/app-pc/src/index.tsx @@ -7,6 +7,7 @@ import zhCN from 'antd/locale/zh_CN'; import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn'; import "./index.css"; +import IdentitySwitch from "@/components/identity-switch"; dayjs.locale('zh'); @@ -14,20 +15,39 @@ dayjs.locale('zh'); // 注册逻辑动态加载:注册依赖(antd Form、表单组件、flow-design 等)不进入首屏 chunk const Registrations = React.lazy(() => import('@/hooks/registrations')); +/** + * 身份切换器只在登录后的页面展示(登录页没有身份概念) + */ +const IdentitySwitchHost: React.FC = () => { + const [visible, setVisible] = React.useState(() => !window.location.hash.startsWith('#/login')); + + React.useEffect(() => { + const sync = () => setVisible(!window.location.hash.startsWith('#/login')); + window.addEventListener('hashchange', sync); + return () => window.removeEventListener('hashchange', sync); + }, []); + + return visible ? : null; +} + const App = () => { return ( - {/* 注册组件必须在渲染期执行(registerFormItems 内部调用了 hook), - 不能放在 useEffect 异步回调里调用 */} - - - - {/* 路由页面均为 React.lazy 动态加载,必须提供 Suspense 兜底 */} + {/* 注册与路由必须处在同一个 Suspense 边界内,且路由作为注册组件的子节点: + 注册结果写入 @coding-form/form-engine 的模块级单例 FormRegistry, + 若两个边界并列,路由页面可能先于注册 commit(表单实例未注册, + 打开流程详情会抛 Form Instance must register);同时 lazy chunk + 加载期间 fallback 为空,注册失败会被静默吞掉。 + 由 Registrations 包住路由后,路由一定在注册完成后才挂载。 */} - + + + + {/* 全局操作身份切换:身份只影响脚本匹配与操作留痕,不影响列表可见范围 */} + ) diff --git a/apps/app-pc/src/pages/todo.tsx b/apps/app-pc/src/pages/todo.tsx index e102edaf..674d8fe8 100644 --- a/apps/app-pc/src/pages/todo.tsx +++ b/apps/app-pc/src/pages/todo.tsx @@ -3,7 +3,7 @@ import { done, list, notify, todo } from "@/api/record.ts"; import { forceSync, forceSyncPermission, type ForceSyncResult } from "@/api/workflow.ts"; import { ApprovalPanelDrawer, FlowTitle, WorkflowSelectModal } from "@coding-flow/flow-pc-approval"; import { Table, type TableProps } from "@coding-flow/flow-pc-ui"; -import { Button, message, Popconfirm, Space, Tabs, type TabsProps } from "antd"; +import { Button, message, Popconfirm, Space, Tabs, Tag, type TabsProps } from "antd"; import dayjs from "dayjs"; import { EventBus, type ActionType } from "@coding-flow/flow-core"; @@ -53,14 +53,19 @@ const TodoPage: React.FC = () => { { dataIndex: 'recordId', title: '编号', + width: 80, }, { dataIndex: 'processId', title: '实例编码', + width: 210, + ellipsis: true, }, { dataIndex: 'title', title: '流程名称', + width: 180, + ellipsis: true, render: (value) => { return } @@ -68,6 +73,7 @@ const TodoPage: React.FC = () => { { dataIndex: 'readTime', title: '读取状态', + width: 90, render: (value) => { return value ? '已读' : '未读'; } @@ -75,26 +81,51 @@ const TodoPage: React.FC = () => { { dataIndex: 'nodeName', title: '节点名称', + width: 120, + ellipsis: true, }, { dataIndex: 'createTime', title: '创建时间', + width: 170, render: (text) => { return dayjs(text).format('YYYY-MM-DD HH:mm:ss'); } }, { dataIndex: 'currentOperatorId', - title: '审批人', + title: '办理人', hidden: true, }, { - dataIndex: 'currentOperatorName', - title: '审批人', + title: '办理人', + width: 180, + render: (_, record) => { + // 「谁 + 以什么身份」合并展示,避免「审批人」「身份」两列各自取值的语义歧义。 + // 待办/抄送/全部流程:展示待办归属人与归属身份(issue #288); + // 已办:优先展示实际办理人与办理身份(issue #306),历史数据没有办理人时回退到归属人。 + // 列表本身不按身份过滤(issue #297),身份为空表示该人员未启用多身份,即默认身份。 + const isDone = !!record.recordState; + const operatorName = isDone + ? (record.handleOperatorName || record.currentOperatorName) + : record.currentOperatorName; + const operatorIdentity = isDone + ? (record.handleOperatorIdentity || record.currentOperatorIdentity) + : record.currentOperatorIdentity; + return ( + + {operatorName} + + {operatorIdentity || '默认身份'} + + + ); + } }, { dataIndex: 'recordState', title: '状态', + width: 80, render: (text) => { return text ? '已办' : '待办'; } @@ -102,6 +133,7 @@ const TodoPage: React.FC = () => { { dataIndex: 'option', title: '操作', + width: 90, render: (_, record) => { if (currentTab === 'todo') { return ( @@ -165,6 +197,7 @@ const TodoPage: React.FC = () => { children: ( { @@ -179,6 +212,7 @@ const TodoPage: React.FC = () => { children: (
{ @@ -193,6 +227,7 @@ const TodoPage: React.FC = () => { children: (
{ @@ -207,6 +242,7 @@ const TodoPage: React.FC = () => { children: (
{ @@ -248,6 +284,11 @@ const TodoPage: React.FC = () => { return (
+ {/* + 列表查询默认不按身份过滤(issue #297):同一人员的所有身份记录都在列表里, + 身份只作为记录留痕在下方的「身份」列展示。当前操作身份由右下角切换器统一控制, + 这里不再重复提示,避免误导成「换个身份就看不到待办了」。 + */} 请求上下文(例如当前操作身份)应放在请求头而不是 query:引擎的查询接口用 + * `SearchRequest` 接收请求,会把 query 参数当作实体过滤字段解析,多带一个 + * `operatorIdentity` 就会报 `Field operatorIdentity not found in class hierarchy`。 + * + *

返回值约定:`undefined` / `null` 的键会被忽略;空字符串会被保留, + * 用于表达「显式选择默认身份」与「未携带」的区别。 + */ +export type DefaultHeadersProvider = () => Record; + +/** + * 把宿主注入的默认请求头合并到已有请求头上(issue #301)。 + * + *

合并规则:`undefined` / `null` 的键跳过(表示本次不携带);空字符串保留, + * 用于表达「显式选择默认身份」与「未携带该头」的区别。已有请求头中同名的值会被覆盖。 + * + * @param headers 已有请求头 + * @param provider 默认请求头提供者 + * @returns 合并后的新对象,不修改入参 + */ +export function mergeDefaultHeaders( + headers: Record, + provider: DefaultHeadersProvider +): Record { + const merged: Record = {...headers}; + const defaults = provider ? provider() : undefined; + if (defaults) { + Object.keys(defaults).forEach((key) => { + const value = defaults[key]; + if (value !== undefined && value !== null) { + merged[key] = value; + } + }); + } + return merged; +} + +/** + * 全局默认查询参数提供者:每次请求都会被调用,返回的键值会合并到请求的 query 参数中。 + * + *

用于宿主向所有接口声明公共上下文(例如当前操作者身份 {@code operatorIdentity}), + * 避免每个页面、每个包各自拼参数。返回空对象表示不注入。 + * + *

注意:身份等请求上下文请改用 {@link HttpClient.defaultHeaders},不要放进 query, + * 否则会污染基于 `SearchRequest` 的列表接口(issue #301)。 + */ +export type DefaultQueryParamsProvider = () => Record; + export class HttpClient { + /** + * 全局默认查询参数提供者。宿主应在应用启动时设置一次,对所有 HttpClient 实例生效。 + * + *

+     * HttpClient.defaultQueryParams = () => ({ operatorIdentity: localStorage.getItem('flow_operator_identity') || undefined });
+     * 
+ */ + public static defaultQueryParams: DefaultQueryParamsProvider = () => ({}); + + /** + * 全局默认请求头提供者。宿主应在应用启动时设置一次,对所有 HttpClient 实例生效。 + * + *
+     * HttpClient.defaultHeaders = () => ({ 'X-Operator-Identity': getOperatorIdentity() ?? undefined });
+     * 
+ */ + public static defaultHeaders: DefaultHeadersProvider = () => ({}); + + /** + * 公共查询参数生效的接口路径前缀,默认只注入流程引擎自身的接口({@code /api/})。 + * + *

**不要**把默认值放宽成「所有请求」:宿主的自有接口常把 query 参数直接映射成查询条件 + * (例如基于 `SearchRequest` / `FastRepository` 的列表接口),多一个未声明的参数就会 + * 抛 `Field xxx not found in class hierarchy`,表现为页面 500。缩到 {@code /api/} 前缀 + * 即可避免污染宿主接口,同时不影响流程的发起、查询、审批等全部引擎接口。 + */ + public static defaultQueryParamsPathPrefixes: string[] = ['/api/']; + private readonly api: AxiosInstance; private messageBox: MessageBox; @@ -63,13 +141,49 @@ export class HttpClient { } + /** + * 判断当前请求是否落在公共查询参数的注入范围内。 + * + *

比较时把 {@code baseURL} 与 {@code url} 拼成完整路径,避免宿主配置了 baseURL 后前缀匹配失效。 + * 白名单为空时不注入任何请求(显式关闭)。 + */ + private static matchesDefaultQueryScope(config: any): boolean { + const prefixes = HttpClient.defaultQueryParamsPathPrefixes; + if (!prefixes || prefixes.length === 0) { + return false; + } + const baseURL: string = config?.baseURL || ''; + const url: string = config?.url || ''; + // 绝对地址(http/https)说明请求发往第三方,不注入身份等上下文 + if (/^https?:\/\//i.test(url)) { + return false; + } + const target = `${baseURL.replace(/\/$/, '')}${url}`; + return prefixes.some(prefix => target.startsWith(prefix)); + } + private addRequestInterceptors() { this.api.interceptors.request.use((config: any) => { + let headers: Record = {...(config.headers || {})}; const token = localStorage.getItem("token"); if (token) { - config.headers = { - Authorization: `${token}`, - } as any; + headers.Authorization = `${token}`; + } + // 合并宿主注入的公共请求头(例如当前操作身份)。 + // 身份等上下文必须走请求头:query 会被 SearchRequest 当成实体字段解析(issue #301)。 + headers = mergeDefaultHeaders(headers, HttpClient.defaultHeaders); + config.headers = headers; + // 合并宿主注入的公共 query 参数(例如当前操作者身份), + // POST 请求同样以 query 形式携带,后端用 request.getParameter 统一读取。 + // 仅对白名单前缀(默认流程引擎的 /api/)生效,避免污染宿主自有接口的查询参数解析。 + if (HttpClient.matchesDefaultQueryScope(config)) { + const defaultParams = HttpClient.defaultQueryParams(); + if (defaultParams && Object.keys(defaultParams).length > 0) { + config.params = { + ...(config.params || {}), + ...defaultParams, + }; + } } return config; }, (error: any) => { @@ -97,7 +211,10 @@ export class HttpClient { if ("token.expire" === errCode || "token.error" === errCode) { this.messageBox.error(FlowMessageRegistry.getInstance().get(FlowMessageKey.HTTP_TOKEN_EXPIRED)); await sleep(1500); - localStorage.clear(); + // 只清登录态,不能 localStorage.clear(): + // 那会顺手抹掉宿主存放的身份(operatorIdentity)、接口超时等配置, + // 表现为「切换器显示 department1、请求却按默认身份发出」,排查成本很高 + localStorage.removeItem("token"); window.location.href = '/#login'; } else { if ("login.error" === errCode) { diff --git a/packages/flow-core/tests/http.test.ts b/packages/flow-core/tests/http.test.ts index d780c027..63304500 100644 --- a/packages/flow-core/tests/http.test.ts +++ b/packages/flow-core/tests/http.test.ts @@ -1,5 +1,5 @@ import {describe, expect, it, beforeEach, afterEach} from '@rstest/core'; -import {FLOW_HTTP_TIMEOUT_KEY, resolveHttpTimeout} from "@/http"; +import {FLOW_HTTP_TIMEOUT_KEY, mergeDefaultHeaders, resolveHttpTimeout} from "@/http"; describe('resolveHttpTimeout', () => { @@ -45,4 +45,46 @@ describe('resolveHttpTimeout', () => { const timeout = resolveHttpTimeout(); expect(timeout).toEqual(2500.5); }); +}); + +describe('mergeDefaultHeaders(issue #301)', () => { + + it('未注入默认请求头时保持原样', () => { + const headers = {Authorization: 'token'}; + expect(mergeDefaultHeaders(headers, () => ({}))).toEqual(headers); + }); + + it('注入身份请求头且不覆盖 Authorization', () => { + const merged = mergeDefaultHeaders( + {Authorization: 'token'}, + () => ({'X-Operator-Identity': 'department1'}) + ); + expect(merged.Authorization).toEqual('token'); + expect(merged['X-Operator-Identity']).toEqual('department1'); + }); + + it('身份为空串时保留该请求头,表达「显式默认身份」', () => { + const merged = mergeDefaultHeaders({}, () => ({'X-Operator-Identity': ''})); + expect(Object.keys(merged)).toContain('X-Operator-Identity'); + expect(merged['X-Operator-Identity']).toEqual(''); + }); + + it('值为 undefined 时跳过该请求头,表达「未设置身份」', () => { + const merged = mergeDefaultHeaders({}, () => ({'X-Operator-Identity': undefined})); + expect(Object.keys(merged)).not.toContain('X-Operator-Identity'); + }); + + it('同名请求头由默认值覆盖', () => { + const merged = mergeDefaultHeaders( + {'X-Operator-Identity': 'old'}, + () => ({'X-Operator-Identity': 'department2'}) + ); + expect(merged['X-Operator-Identity']).toEqual('department2'); + }); + + it('不修改传入的请求头对象', () => { + const headers = {Authorization: 'token'}; + mergeDefaultHeaders(headers, () => ({'X-Operator-Identity': 'department1'})); + expect(headers).toEqual({Authorization: 'token'}); + }); }); \ No newline at end of file diff --git a/packages/flow-design/CHANGELOG.md b/packages/flow-design/CHANGELOG.md index 31ad72a7..8b37cf28 100644 --- a/packages/flow-design/CHANGELOG.md +++ b/packages/flow-design/CHANGELOG.md @@ -1,5 +1,11 @@ # @coding-flow/flow-design +## 0.3.0 + +### Minor Changes + +- 版本号升级至 0.3.0(配合后端 0.3.0「操作者身份标识」issue #288,本包无对外功能变更) + ## 0.2.22 ### Patch Changes diff --git a/packages/flow-design/package.json b/packages/flow-design/package.json index 801b9748..58f9a858 100644 --- a/packages/flow-design/package.json +++ b/packages/flow-design/package.json @@ -1,6 +1,6 @@ { "name": "@coding-flow/flow-design", - "version": "0.2.22", + "version": "0.3.0", "description": "flow-engine design components ", "type": "module", "sideEffects": [ diff --git a/packages/flow-design/src/plugins/view/error-trigger-view.tsx b/packages/flow-design/src/plugins/view/error-trigger-view.tsx index b6b22b58..9a3548a5 100644 --- a/packages/flow-design/src/plugins/view/error-trigger-view.tsx +++ b/packages/flow-design/src/plugins/view/error-trigger-view.tsx @@ -1,10 +1,13 @@ import React from "react"; import {GroovyScriptConvertorUtil} from "@coding-flow/flow-core"; -import {Button, Form, Select, Space} from "antd"; +import {Button, Form, Input, Select, Space} from "antd"; import {CodeOutlined, ReloadOutlined} from "@ant-design/icons"; import {ErrorTriggerViewPlugin, VIEW_KEY} from "@/plugins/error-trigger-view-type"; import {ViewBindPlugin} from "@coding-flow/flow-core"; -import {SCRIPT_DEFAULT_ERROR_TRIGGER} from "@/script-components/default-script"; +import { + DEFAULT_ERROR_TRIGGER_MESSAGE, + SCRIPT_DEFAULT_ERROR_TRIGGER +} from "@/script-components/default-script"; import {useNodeRouterManager} from "@/components/design-panel/hooks/use-node-router-manager"; import {useNodeRenderContext} from "@/components/design-editor/hooks/use-node-render-context"; import {ErrorTriggerScriptUtils} from "@/script-components/services/node-error-trigger"; @@ -12,13 +15,28 @@ import {useScriptMetaData} from "@/script-components/hooks/use-script-meta-data" import styles from "./error_trigger_view.module.scss"; /** + * 异常处理方式(issue #296) + * + * 三种语义:跳转节点、跳转用户(暂未开放)、异常提示。 + * 异常提示不推进流程,提交时由后端阻断并把文案返回给用户。 + */ +export const ERROR_TRIGGER_TYPE_OPTIONS = [ + {label: '跳转节点', value: 'node'}, + {label: '跳转用户', value: 'user'}, + {label: '异常提示', value: 'prompt'}, +]; + +/** + * 异常配置视图 + *

+ * 支持三种处理方式(issue #296):跳转节点、跳转用户(暂未开放)、异常提示。 + * 异常提示不会推进流程,提交时由后端阻断并把文案返回给用户。 * * @param props * @constructor */ export const ErrorTriggerPluginView: React.FC = (props) => { const ErrorTriggerPluginViewComponent = ViewBindPlugin.getInstance().get(VIEW_KEY); - const [type, setType] = React.useState('node'); const nodeRouterManager = useNodeRouterManager(); const {node} = useNodeRenderContext(); @@ -26,6 +44,25 @@ export const ErrorTriggerPluginView: React.FC = (props) const mappingData = nodeRouterManager.mapping(data); + // 元数据缺失时按脚本内容推断:手写的 prompt 脚本不能回显成「跳转节点」 + const resolveType = () => { + if (mappingData.type) { + return mappingData.type; + } + return ErrorTriggerScriptUtils.isPromptScript(props.script) ? 'prompt' : 'node'; + }; + + const [type, setType] = React.useState(resolveType()); + const [message, setMessage] = React.useState( + mappingData.message || ErrorTriggerScriptUtils.getPromptMessage(props.script) + ); + + // 脚本被外部替换(高级配置 / 重置)时同步表单展示,避免视图状态与脚本不一致 + React.useEffect(() => { + setType(resolveType()); + setMessage(mappingData.message || ErrorTriggerScriptUtils.getPromptMessage(props.script)); + }, [props.script]); + if (ErrorTriggerPluginViewComponent) { return ( @@ -36,17 +73,21 @@ export const ErrorTriggerPluginView: React.FC = (props)

{!props.nodeOnly && ( - +