diff --git a/clients/components/data-filter/index.tsx b/clients/components/data-filter/index.tsx index e0f255a20..6179f652d 100644 --- a/clients/components/data-filter/index.tsx +++ b/clients/components/data-filter/index.tsx @@ -39,7 +39,7 @@ type FieldCondition = { export type RefProps = { empty: () => void; - getDataValues: () => FilterConfig; + getDataValues: (data?: any) => FilterConfig; validate: () => Promise; } @@ -158,9 +158,9 @@ function DataFilter({ setConditions(conditions.filter(({ id }) => _id !== id)); }; - const getDataValues = (): FilterConfig => { + const getDataValues = (data = {}): FilterConfig => { if (conditions.length === 0) { - return { condition: [], tag }; + return { condition: [], tag, ...data }; } const formData = getValues(); @@ -191,6 +191,7 @@ function DataFilter({ return { condition: _conditions, tag, + ...data, }; }; diff --git a/clients/components/file-upload/uploader/useFileStore.ts b/clients/components/file-upload/uploader/useFileStore.ts index 3eecfa4d7..02cd10ea4 100644 --- a/clients/components/file-upload/uploader/useFileStore.ts +++ b/clients/components/file-upload/uploader/useFileStore.ts @@ -1,8 +1,11 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import FileStore from './store'; import type { FileStoreProps } from './store'; export default function useFileStore(props: FileStoreProps): FileStore { - const [store] = useState(new FileStore(props)); + const [store, setStore] = useState(new FileStore(props)); + useEffect(()=>{ + setStore(new FileStore(props)); + }, [props.files.length]); return store; } diff --git a/clients/components/form-builder/registry/associated-data/filter-config/index.tsx b/clients/components/form-builder/registry/associated-data/filter-config/index.tsx index e743867af..c5efd3cdc 100644 --- a/clients/components/form-builder/registry/associated-data/filter-config/index.tsx +++ b/clients/components/form-builder/registry/associated-data/filter-config/index.tsx @@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from 'react'; import Modal from '@c/modal'; import Button from '@c/button'; +import Checkbox from '@c/checkbox'; import PageLoading from '@c/page-loading'; import DataFilter, { RefProps } from '@c/data-filter'; import { FILTER_FIELD } from '@c/data-filter/utils'; @@ -18,6 +19,7 @@ type Props = { currentFormSchema?: ISchema; customSchemaFields?: SchemaFieldItem[]; filterFunc?: (field: SchemaFieldItem) => boolean; + showSelectAll?: any; } type FieldsProps = { @@ -56,13 +58,13 @@ function FilterConfig({ const [schemaFields, setSchemaFields] = useState([]); const [currentFields, setCurrentFields] = useState([]); const dataFilterRef = useRef(null); - + const [selectAll, setSelectAll] = useState(value?.selectAll); const allowSelect = (!!tableID && !!appID) || (customSchemaFields && customSchemaFields.length); const handleSave = (): void => { dataFilterRef.current?.validate().then((flag) => { if (flag) { - onChange(dataFilterRef.current?.getDataValues() as FilterConfig); + onChange(dataFilterRef.current?.getDataValues({ selectAll }) as FilterConfig); setVisible(false); } }); @@ -92,6 +94,10 @@ function FilterConfig({ } }, [allowSelect, visible, customSchemaFields]); + const handleSelectAll = ()=>{ + setSelectAll(!selectAll); + }; + return ( <> @@ -119,6 +125,17 @@ function FilterConfig({
{!allowSelect && (
请选择关联表
)} {loading && allowSelect && ()} + { + value?.showSelectAll && + (
+ e.stopPropagation()} + /> + 默认选择全部 +
) + } {!loading && allowSelect && ( []; @@ -60,9 +63,12 @@ function AssociatedRecords({ readOnly, className, }: Props): JSX.Element { + const { selectAll = false } = filterConfig || {}; const [showSelectModal, setShowSelectModal] = useState(false); - const [selectedValue, setSelectValue] = useState(multiple ? '' : defaultValues[0]?._id); + const [index, setIndex] = useState(0); + const [selectedValue, setSelectValue] = useState((multiple || selectAll) ? '' : defaultValues[0]?._id); const tableColumns = computeTableColumns(associatedTable, columns); + !readOnly && tableColumns.push({ id: 'remove', Header: '操作', @@ -82,6 +88,14 @@ function AssociatedRecords({ }, }); + useEffect(()=>{ + if (index > 1) return; + if (selectAll && index === 1) { + onChange(value); + } + setIndex(index + 1); + }, [JSON.stringify(value)]); + return (
{ - if (multiple) { + if (multiple || selectAll) { const selecteds = value.concat( newSelectedRecords.filter(({ _id }) => value.findIndex(({ _id: id }) => _id === id) < 0), ); @@ -127,20 +141,45 @@ function AssociatedRecords({ function AssociatedRecordsFields(props: Partial): JSX.Element { const componentProps = props.props['x-component-props']; // todo handle error case + const [selectAllData, setSelectAllData] = useState([]); + const [hasChanged, setHasChanged] = useState(false); + const { selectAll = false } = componentProps?.filterConfig || {}; + const { appID, tableID, isNew } = componentProps; + const { condition = [], tag = 'must' } = componentProps.filterConfig || {}; + const getSelectAllData = async ()=>{ + const res = await fetchFormDataList(appID, tableID, { + sort: ['-created_at'], + page: 1, + size: 1000, + query: toEs({ tag, condition: [...condition] }), + }).catch((e) => { + console.log(e); + }); + setSelectAllData(res?.entities || []); + }; + + useEffect(()=>{ + selectAll && getSelectAllData(); + }, []); return ( props?.mutators?.change(selectedKeys)} + onChange={(selectedKeys) => { + setHasChanged(true); + props?.mutators?.change(selectedKeys); + }} /> ); } diff --git a/clients/components/form-builder/registry/associated-records/associated-records/select-records-modal.tsx b/clients/components/form-builder/registry/associated-records/associated-records/select-records-modal.tsx index 937207315..49a92d1d3 100644 --- a/clients/components/form-builder/registry/associated-records/associated-records/select-records-modal.tsx +++ b/clients/components/form-builder/registry/associated-records/associated-records/select-records-modal.tsx @@ -25,11 +25,11 @@ export default function SelectRecordsModal({ const tableRef: React.Ref = useRef(); const [selected, setSelected] = useState[]>(defaultValues || []); const defaultSelectIDs = selected.map(({ _id }) => _id); + const handleSubmit = (): void => { if (!tableRef.current) { return; } - onSubmit(selected); }; diff --git a/clients/components/form-builder/registry/associated-records/config.tsx b/clients/components/form-builder/registry/associated-records/config.tsx index 2479219f3..3a15691b9 100644 --- a/clients/components/form-builder/registry/associated-records/config.tsx +++ b/clients/components/form-builder/registry/associated-records/config.tsx @@ -61,10 +61,22 @@ function AssociatedRecordsConfig({ initialValue, onChange }: Props): JSX.Element return ( onChange({ ...initialValue, ...values })} + onChange={(values) => { + const _initialValue = JSON.parse(JSON.stringify(initialValue)); + const _values = JSON.parse(JSON.stringify(values)); + delete _initialValue?.filterConfig?.showSelectAll; + delete _values?.filterConfig?.showSelectAll; + onChange({ ..._initialValue, ..._values }); + }} components={COMPONENTS} schema={configSchema} /> diff --git a/clients/components/form-builder/registry/user-picker/picker.tsx b/clients/components/form-builder/registry/user-picker/picker.tsx index ee097efce..04423eb56 100644 --- a/clients/components/form-builder/registry/user-picker/picker.tsx +++ b/clients/components/form-builder/registry/user-picker/picker.tsx @@ -25,11 +25,12 @@ const Picker = ({ value = [], onChange, isMy, rangeList }: Props) => { const handleChange = useCallback((list: EmployeeOrDepartmentOfRole[]) => { valueListRef.current = list; - onChange(list); + // onChange(list); }, [onChange]); const handleSubmit = useCallback(() => { - onChange(valueListRef.current); + const list = JSON.parse(JSON.stringify(valueListRef.current)); + onChange(list); setDefaultValue(valueListRef.current); close(); }, [onChange, close]); diff --git a/clients/components/form-builder/registry/user-picker/user-picker.tsx b/clients/components/form-builder/registry/user-picker/user-picker.tsx index 025af8c53..0e8466831 100644 --- a/clients/components/form-builder/registry/user-picker/user-picker.tsx +++ b/clients/components/form-builder/registry/user-picker/user-picker.tsx @@ -121,12 +121,22 @@ const UserPicker = ({ const { options } = componentsProps; + const handleValue = ()=>{ + const data = value?.filter((item: any)=>{ + return options?.find((option: any)=>option.value === item.value); + }); + if (!data?.length) { + onChange && onChange(data); + } + return data; + }; + return ( + */} this.query, this.fetchAll); + reaction(() => this.query, this.getFetch); } @computed get query(): Record { @@ -20,6 +23,18 @@ class AllApprovalStore extends Store { }; } + @action + getFetch = ()=>{ + switch (this.type) { + case FILL_IN: + this.fetchFillInAll(); + break; + default: + this.fetchAll(); + break; + } + }; + @action fetchAll = async () => { this.loading = true; @@ -32,6 +47,24 @@ class AllApprovalStore extends Store { toast.error(err); } }; + + // 填写节点任务集合 + @action + fetchFillInAll = async () => { + this.loading = true; + try { + const { list, total } = await getMyApplyFillInList('ALL_PAGE', { + page: this.query.page, + limit: this.query.size, + }); + // filter item without id + this.approvals = list.filter((item: ApprovalTask) => item.id); + this.total = total; + this.loading = false; + } catch (err) { + toast.error(err); + } + }; } export default new AllApprovalStore(); diff --git a/clients/home/pages/approvals/api.ts b/clients/home/pages/approvals/api.ts index 5be023d65..6a5db3ce9 100644 --- a/clients/home/pages/approvals/api.ts +++ b/clients/home/pages/approvals/api.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ // flow instance apis import httpClient from '@lib/http-client'; @@ -16,6 +17,26 @@ export const getMyApplyList = async (params: Record): Promise<{ dat return await httpClient('/api/v1/flow/instance/myApplyList', params); }; +// 分页查询我申请的填写流程 +export const getMyApplyFillInList = async (type: string, params: Record): Promise => { + return await httpClient(`/api/v1/flow/fill/list/${type}`, params); +}; + +// 分页查询我申请的填写流程 +export const getMobileMyApplyFillInList = async (params: any, type: string): Promise => { + return await httpClient(`/api/v1/flow/fill/list/${type}`, params); +}; + +// 获取待填写的总数 +export const getTodoFillInCount = async (params: Record): Promise => { + return await httpClient('/api/v1/flow/fill/pending/count', params); +}; + +// 获取填写节点详情 +export const getFillInDetail = async (type: string, taskID: string, params: Record): Promise => { + return await httpClient(`/api/v1/flow/fill/${type}/${taskID}`, params); +}; + // 分页查询抄送给我的流程 export const getCCToMeList = async (params: Record): Promise<{ dataList: any, total: number }> => { return await httpClient('/api/v1/flow/instance/ccToMeList', params); @@ -86,6 +107,10 @@ export const reviewTask = async (processInstanceId: string, taskId: string, para return await httpClient(`/api/v1/flow/instance/reviewTask/${processInstanceId}/${taskId}`, params); }; +// 提交填写 +export const submitFillTask = async ( params: { id: string; formData: any, [key: string]: any }): Promise<{ data: any }> => { + return await httpClient('/api/v1/flow/fill', params); +}; // 加签 export const signTask = async (processInstanceId: string, taskID: string, params: Record) => { return await httpClient(`/api/v1/flow/instance/addSign/${processInstanceId}/${taskID}`, params); diff --git a/clients/home/pages/approvals/cc-to-me-approvals/index.tsx b/clients/home/pages/approvals/cc-to-me-approvals/index.tsx index 94f99983a..ee5ea5735 100644 --- a/clients/home/pages/approvals/cc-to-me-approvals/index.tsx +++ b/clients/home/pages/approvals/cc-to-me-approvals/index.tsx @@ -2,13 +2,10 @@ import React, { useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; import { observer } from 'mobx-react'; -import Search from '@c/search'; import Pagination from '@c/pagination'; import Button from '@c/button'; import Modal from '@c/modal'; import toast from '@lib/toast'; -import Select from '@c/select'; -import IconBtn from '@c/icon-btn'; import RadioButtonGroup from '@c/radio/radio-button-group'; import store from './store'; @@ -66,8 +63,8 @@ function TodoApprovals(): JSX.Element { currentValue={store.status} /> - + {/* */} - - + */} { + this.loading = true; + try { + const { list, total } = await getMyApplyFillInList('CC_PAGE', this.query); + // filter item without id + this.approvals = list.filter((item: ApprovalTask) => item.id); + this.total = total; + this.loading = false; + } catch (err) { + toast.error(err); + } + }; + @action reset = (): void => { this.total = 0; diff --git a/clients/home/pages/approvals/constant.ts b/clients/home/pages/approvals/constant.ts index e077449f3..2bfc5d210 100644 --- a/clients/home/pages/approvals/constant.ts +++ b/clients/home/pages/approvals/constant.ts @@ -19,3 +19,16 @@ export enum TaskHandleType { hasResubmitBtn = 'hasResubmitBtn', hasUrgeBtn = 'hasUrgeBtn', } + +export const APPROVAL = 'approval'; +export const FILL_IN = 'fillIn'; +export const listData = [ + { + label: '审批', + value: 'approval', + }, + { + label: '填写', + value: 'fillIn', + }, +]; diff --git a/clients/home/pages/approvals/detail/action-map.ts b/clients/home/pages/approvals/detail/action-map.ts index 92d075e07..ce912a032 100644 --- a/clients/home/pages/approvals/detail/action-map.ts +++ b/clients/home/pages/approvals/detail/action-map.ts @@ -2,7 +2,8 @@ const actionMap: Record = { CANCEL: { text: '撤回', icon: '' }, AGREE: { text: '通过', icon: 'done' }, REFUSE: { text: '拒绝', icon: 'close' }, - FILL_IN: { text: '补充', icon: 'free_breakfast' }, + // FILL_IN: { text: '补充', icon: 'free_breakfast' }, + FILL_IN: { text: '提交', icon: 'send' }, DELIVER: { text: '转交', icon: 'send' }, STEP_BACK: { text: '退回某步', icon: 'subdirectory_arrow_left' }, SEND_BACK: { text: '打回重填', icon: 'settings_backup_restore' }, diff --git a/clients/home/pages/approvals/detail/action-modals.tsx b/clients/home/pages/approvals/detail/action-modals.tsx index 674be545e..f69254c7e 100644 --- a/clients/home/pages/approvals/detail/action-modals.tsx +++ b/clients/home/pages/approvals/detail/action-modals.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { observer } from 'mobx-react'; import { useMutation } from 'react-query'; import { useHistory, useParams } from 'react-router-dom'; @@ -27,8 +27,8 @@ interface Props { schema: ISchema; formData: Record; defaultValue: Record; - appID: string; - tableID: string; + appID?: string; + tableID?: string; } function ActionModals({ @@ -44,6 +44,12 @@ function ActionModals({ const [addSignType, setAddSignType] = useState(''); const [addSignValue, setAddSignValue] = useState(''); + const formRef = useRef(); + + useEffect(()=>{ + formRef?.current && handleSubmit(); + }, [formRef?.current]); + function handleSubmit(): void { form.submit(); } @@ -64,7 +70,7 @@ function ActionModals({ if ([ TaskHandleType.agree, TaskHandleType.refuse, - TaskHandleType.fill_in, + // TaskHandleType.fill_in, ].includes(action as TaskHandleType)) { let _formData = {}; if (isEmpty(defaultValue)) { @@ -81,6 +87,23 @@ function ActionModals({ }); } + if ([ + TaskHandleType.fill_in, + ].includes(action as TaskHandleType)) { + let _formData = {}; + if (isEmpty(defaultValue)) { + _formData = buildFormDataReqParams(schema, 'create', formData); + } else { + const newValue = formDataDiff(formData, defaultValue, schema); + _formData = buildFormDataReqParams(schema, 'updated', newValue); + } + + return apis.submitFillTask({ + id: taskID, + formData: _formData, + }); + } + // 撤回 if (action === TaskHandleType.cancel) { return apis.cancelTask(processInstanceID); @@ -215,8 +238,7 @@ function ActionModals({ const { payload } = store.modalInfo; if ([ TaskHandleType.agree, - TaskHandleType.refuse, - TaskHandleType.fill_in].includes(action as TaskHandleType) + TaskHandleType.refuse].includes(action as TaskHandleType) ) { return ( 是否对流程进行催办? ); } + + // 填写 + if (action === TaskHandleType.fill_in) { + return ( +
是否确定提交?
+ ); + } }; if (!store.modalOpen) { diff --git a/clients/home/pages/approvals/detail/active.d.ts b/clients/home/pages/approvals/detail/active.d.ts index 9fface791..7ac6b92d7 100644 --- a/clients/home/pages/approvals/detail/active.d.ts +++ b/clients/home/pages/approvals/detail/active.d.ts @@ -1,6 +1,6 @@ type StatusValues = 'FILL_IN' | 'AGREE' | 'REFUSE' | 'SEND_BACK' | 'READ' | 'DELIVER' | 'STEP_BACK' | 'UNTREATED' | 'IN_REVIEW' | 'AUTO_REVIEW' | 'AUTO_SKIP' - | 'CANCEL' | 'RE_SUBMIT' | 'CC'; + | 'CANCEL' | 'RE_SUBMIT' | 'CC' | 'FILL'; type NoOperationStatus = 'CC' | 'REVIEW'; type Colors = 'text-blue-600' | 'text-green-600' | 'text-red-600' | 'text-yellow-600'; type BgColors = 'bg-blue-100' | 'bg-green-100' | 'bg-red-100' | 'bg-yellow-100'; diff --git a/clients/home/pages/approvals/detail/components/approval-status.tsx b/clients/home/pages/approvals/detail/components/approval-status.tsx index ca4077e94..722f9300e 100644 --- a/clients/home/pages/approvals/detail/components/approval-status.tsx +++ b/clients/home/pages/approvals/detail/components/approval-status.tsx @@ -8,6 +8,7 @@ type Status = Record void; + showIcon?: boolean; + showName?: boolean; } -export default function UserList({ userList, clickHandle }: Props): JSX.Element { +export default function UserList({ userList, clickHandle, showIcon = true, showName }: Props): JSX.Element { return (
{ const username = user.creatorName ? user.creatorName.substring(0, 1) : ''; return ( -
+
+ {showName && + {user?.creatorName} + }
); }) }
-
- -
+ { + showIcon && + (
+ +
) + }
); } diff --git a/clients/home/pages/approvals/detail/dynamic-info/index.tsx b/clients/home/pages/approvals/detail/dynamic-info/index.tsx index cfbafafa4..7fbe60046 100644 --- a/clients/home/pages/approvals/detail/dynamic-info/index.tsx +++ b/clients/home/pages/approvals/detail/dynamic-info/index.tsx @@ -14,7 +14,7 @@ export default function Index({ workData, returnFlowPage }: Props): JSX.Element const { taskType } = workData; function handleShow(): JSX.Element { - if (['OR_APPROVAL', 'AND_APPROVAL'].includes(taskType)) { + if (['OR_APPROVAL', 'AND_APPROVAL', 'FILL'].includes(taskType)) { return ; } diff --git a/clients/home/pages/approvals/detail/dynamic/approval.tsx b/clients/home/pages/approvals/detail/dynamic/approval.tsx index 369e872a0..0989a0a94 100644 --- a/clients/home/pages/approvals/detail/dynamic/approval.tsx +++ b/clients/home/pages/approvals/detail/dynamic/approval.tsx @@ -25,6 +25,7 @@ export default function Approval({ workData, clickHandle }: Props): JSX.Element const { taskName, taskType, modifyTime, operationRecords, status } = workData; function goLeaderHandle(): void { + if (taskType === 'FILL') return; clickHandle(workData); } @@ -56,20 +57,29 @@ export default function Approval({ workData, clickHandle }: Props): JSX.Element const username = operationRecords ? get(operationRecords, '[0].creatorName', '') : ''; const isHandle = ['REVIEW', 'IN_REVIEW'].includes(status); const isSingle = operationRecords?.length === 1; + const isFill = taskType === 'FILL'; + const confirmBack = ['REFUSE', 'SEND_BACK', 'READ', 'DELIVER', 'STEP_BACK'].includes(status); + const renderNumUser = ()=>{ + return ( + <> + ({operationRecords.length}人处理中 · {NoOperationValue[taskType]}) + + ); + }; return (
- {isHandle && } - { (!isHandle && isSingle) && } + {(isHandle) && } + { ((!isHandle && isSingle )) && } { (!isHandle && !isSingle) && }
{ - isHandle ? ( + (isHandle) ? (
{isHandle && (
- {taskName}({operationRecords.length}人处理中 · {NoOperationValue[taskType]}) + {taskName} {isFill ? '(处理中)' : renderNumUser()}
) }
@@ -85,7 +95,9 @@ export default function Approval({ workData, clickHandle }: Props): JSX.Element } { (!isSingle || (isSingle && isHandle) || (status === 'AUTO_REVIEW')) && operationRecords && ( - + ) } { diff --git a/clients/home/pages/approvals/detail/dynamic/index.tsx b/clients/home/pages/approvals/detail/dynamic/index.tsx index 744b9a531..46058acc6 100644 --- a/clients/home/pages/approvals/detail/dynamic/index.tsx +++ b/clients/home/pages/approvals/detail/dynamic/index.tsx @@ -51,7 +51,7 @@ export default function ProcessHistory(props: Props) { function handleContent(flow: FlowItem): JSX.Element { const { taskType } = flow; - if (['OR_APPROVAL', 'AND_APPROVAL'].includes(taskType)) { + if (['OR_APPROVAL', 'AND_APPROVAL', 'FILL'].includes(taskType)) { return ; } diff --git a/clients/home/pages/approvals/detail/index.scss b/clients/home/pages/approvals/detail/index.scss index 4b8ca7f8e..c223c7465 100644 --- a/clients/home/pages/approvals/detail/index.scss +++ b/clients/home/pages/approvals/detail/index.scss @@ -32,6 +32,15 @@ &.btn-item-done { background: #16A34A; } + + &.btn-item-submit { + color: #ddd; + background: var(--blue-700); + &:hover{ + color: #fff; + } + } + } } } diff --git a/clients/home/pages/approvals/detail/index.tsx b/clients/home/pages/approvals/detail/index.tsx index 6849a6c53..28a91988b 100644 --- a/clients/home/pages/approvals/detail/index.tsx +++ b/clients/home/pages/approvals/detail/index.tsx @@ -1,9 +1,12 @@ +/* eslint-disable no-empty */ +/* eslint-disable guard-for-in */ +/* eslint-disable max-len */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ import React, { useState, useEffect, useMemo, useRef } from 'react'; import { useParams, useHistory } from 'react-router'; import { useQuery } from 'react-query'; import { observer } from 'mobx-react'; -import { pick, get } from 'lodash'; +import { pick, get, isNumber } from 'lodash'; import Breadcrumb from '@c/breadcrumb'; import RadioButtonGroup from '@c/radio/radio-button-group'; @@ -22,11 +25,12 @@ import Toolbar from './toolbar'; import Dynamic from './dynamic'; import Discuss from './discuss'; import ActionModals from './action-modals'; -import { getTaskFormById } from '../api'; +import { getFillInDetail, getTaskFormById } from '../api'; import store from './store'; import './index.scss'; import Button from '@c/button'; +import { FILL_IN } from '../constant'; const globalActionKeys = [ 'canMsg', 'canViewStatusAndMsg', 'hasCancelBtn', @@ -41,16 +45,20 @@ function ApprovalDetail(): JSX.Element { const [showSwitch, setShowSwitch] = useState(false); const [taskEnd, setTaskEnd] = useState(false); const [count, setCount] = useState(0); + const [fillTask, setFillTask] = useState({}); const [validate, setValidate] = useState(false); const [actionParams, setActionParams] = useState({}); const submitRef = useRef(); const listType = search.get('list') || 'todo'; - const { processInstanceID, type } = useParams<{ + const { processInstanceID, type, taskID, taskType } = useParams<{ processInstanceID: string; - type: string + taskID: string; + type: string; + taskType: string; }>(); + const history = useHistory(); const queryRelationKey = showSwitch ? [processInstanceID, type, currentTaskId] : [processInstanceID, type]; @@ -58,28 +66,35 @@ function ApprovalDetail(): JSX.Element { isLoading, data, isError, error, } = useQuery( queryRelationKey, - () => getTaskFormById(processInstanceID, { type, taskId: currentTaskId }).then((res) => { - if (!currentTaskId) { - setCurrentTaskId(get(res, 'taskDetailModels[0].taskId', '').toString()); + ()=>{ + if (taskType === FILL_IN) { + return getFillIn(); } + return getApprovel(); + }, + ); - if (type === 'HANDLED_PAGE') { - const taskDetailModels = get(res, 'taskDetailModels', []); - if (taskDetailModels.length > 1) { - setShowSwitch(true); - const status = taskDetailModels.map(({ taskName, taskId }: Record) => { - return { - label: taskName, - value: taskId, - }; - }); - setStatus(status); - } + const getApprovel = () => getTaskFormById(processInstanceID, { type, taskId: currentTaskId }).then((res) => { + if (!currentTaskId) { + setCurrentTaskId(get(res, 'taskDetailModels[0].taskId', '').toString()); + } + + if (type === 'HANDLED_PAGE') { + const taskDetailModels = get(res, 'taskDetailModels', []); + if (taskDetailModels.length > 1) { + setShowSwitch(true); + const status = taskDetailModels.map(({ taskName, taskId }: Record) => { + return { + label: taskName, + value: taskId, + }; + }); + setStatus(status); } + } - return res; - }), - ); + return res; + }); const task = useMemo(() => { const taskDetailData = get(data, 'taskDetailModels', []).find( @@ -96,7 +111,6 @@ function ApprovalDetail(): JSX.Element { if (!currentTaskId || !task?.formSchema) { return Promise.resolve({}); } - return getFlowFormData( processInstanceID, currentTaskId, @@ -107,6 +121,54 @@ function ApprovalDetail(): JSX.Element { }, ); + const getFillIn = () => { + return getFillInDetail(type, taskID, { ref: buildQueryRef(task?.formSchema) }).then((res) => { + if (res?.taskType && res.taskType === 'Pending') { + res.operatorPermission = { + custom: null, + system: [ + { + enabled: true, + changeable: false, + name: '提交', + text: '提交', + value: 'FILL_IN', + only: 'filIn', + }, + ], + }; + } + + res.taskDetailModels = [JSON.parse(JSON.stringify(res))]; + !res?.flowName && (res.flowName = sessionStorage.getItem('fillInTaskCardName')); + if (!currentTaskId) { + setCurrentTaskId(get(res, 'taskDetailModels[0].taskId', '').toString()); + } + + if (type === 'HANDLED_PAGE') { + const taskDetailModels = get(res, 'taskDetailModels', []); + if (taskDetailModels.length > 1) { + setShowSwitch(true); + const status = taskDetailModels.map(({ taskName, taskId }: Record) => { + return { + label: taskName, + value: taskId, + }; + }); + setStatus(status); + } + } + setFillTask(res); + return res; + }); + }; + + useEffect(()=>{ + if (task.formSchema) { + getFillIn(); + } + }, [JSON.stringify(buildQueryRef(task.formSchema))]); + useEffect(() => { setFormValues(formData); }, [formData]); @@ -127,29 +189,44 @@ function ApprovalDetail(): JSX.Element { } }, [count]); - const formatProperties = (data: any)=>{ + const formatProperties = (data: any, fieldPermission?: any)=>{ for (const key in data) { if (data[key].type === 'object') { formatProperties(data[key].properties); } else { data[key]?.description && (data[key].description = ''); + try { + if (fieldPermission && taskType === FILL_IN) { + if (isNumber(fieldPermission[key])) { + data[key]['x-internal'].permission = fieldPermission[key]; + } else { + fieldPermission?.[key]?.['x-internal']?.permission && (data[key]['x-internal'].permission = fieldPermission[key]['x-internal'].permission); + } + } + } catch (error) { + console.log(error); + } } } }; - const formatFormSchema = (formSchema: any)=>{ - formSchema && formatProperties(formSchema.properties); + const formatFormSchema = (formSchema: any, fieldPermission?: any)=>{ + formSchema && formatProperties(formSchema.properties, fieldPermission); return formSchema; }; const renderSchemaForm = (task: any): JSX.Element | null => { + let _formData = formData; + if (taskType === FILL_IN) { + _formData = fillTask?.FormData; + } return (
{ setValidate(value); @@ -172,6 +249,8 @@ function ApprovalDetail(): JSX.Element { } const appID = get(data, 'appId'); const tableID = get(data, 'tableId'); + + const listText = taskType === FILL_IN ? '填写列表' : '审批列表'; return ( <> ), }, - { key: 'list', text: '审批列表', path: `/approvals?list=${listType}` }, + // { key: 'list', text: listText, path: `/approvals?list=${listType}` }, { key: 'current', text: data?.flowName }, ]} className="px-24 py-10" @@ -212,6 +291,7 @@ function ApprovalDetail(): JSX.Element { schema={task?.formSchema} formData={formValues} onSubmitClick={onSubmitClick} + taskType = {taskType} />
{data?.flowName}
{renderSchemaForm(task)} @@ -220,6 +300,7 @@ function ApprovalDetail(): JSX.Element { { + // taskType !== FILL_IN && data.canViewStatusAndMsg && ( <>
审批详情
@@ -244,7 +325,7 @@ function ApprovalDetail(): JSX.Element { ) }
- {appID && ( + {(appID || taskType === FILL_IN) && ( ; + taskType?: string; } const moreActions = [ @@ -36,7 +38,7 @@ const getIconByAction = (action: string): string => { }; function Toolbar({ - currTask, permission, onClickAction, globalActions, workFlowType, schema, formData, + currTask, permission, onClickAction, globalActions, workFlowType, schema, formData, taskType, onSubmitClick, }: Props): JSX.Element { const { processInstanceID, taskID } = useParams<{ processInstanceID: string; taskID: string }>(); @@ -116,7 +118,8 @@ function Toolbar({