/* eslint-disable react-hooks/exhaustive-deps */ import { Button, Checkbox, DatePicker, message, Popconfirm, Space, Spin } from 'antd'; import moment from 'moment'; import { useCallback, useEffect, useRef, useState } from 'react'; import { useIntl, useModel, useRequest } from 'umi'; import AutoEmpty from '../Empty'; import RenewalModel from '../RenewalModel'; import UserSuperior from '../UserSuperior'; import { formatUserRender } from '../utils'; import publicConst from '../utils/const'; import useAppDetail, { AppDetailContext } from '../utils/hooks'; import { detailList, requestBatchUnbind } from './api'; import CityListTable from './components/city'; import FeatureTable from './components/feature'; import OptionListTable from './components/option'; import PolicyListTable from './components/policy'; import RoleListTable from './components/role'; import { emptyMarginTop, emptyRowSelected, filterCity, filterFeature, filterOption, filterPolicy, filterRole, } from './util'; export interface AppDetailViewProps { /** * @description appId */ appId: number; /** * @description 是否显示操作功能 */ isOptShow?: boolean; /** * @description 离职用户id */ userId?: number; } const AppDetailView = (props: AppDetailViewProps) => { const { appId, isOptShow = false, userId } = props; const { formatMessage } = useIntl(); const [expandedAll, setExpandedAll] = useState({ optionListKey: true, featureTreeKey: true, }); const { DataSensitiveMap, DataSensitiveLevelMap } = publicConst(formatMessage); // 存储批量参数 const [batchParams, setBatchParams] = useState(); const [openObj, setOpenObj] = useState(); const [renewalParams, setRenewalParams] = useState(); const [params, setParams] = useState({}); const { initialState } = useModel('@@initialState'); const { currentUser } = initialState || {}; const expandedData = useRef({}); const [permission, setPermission] = useState({}); const appDetail = useAppDetail(appId); const { loading, data, run } = useRequest( () => { const param = userId ? { userId, appId } : { appId }; return detailList(param); }, { ready: !!appId, refreshDeps: [appId, userId], }, ); useEffect(() => { expandedData.current = { featureTree: data?.featureIds, optionList: data?.optionIds }; setExpandedAll({ featureTree: data?.featureTree, optionList: data?.optionList, featureTreeKey: true, optionListKey: true, }); setBatchParams(() => { return {}; }); }, [loading]); const renderExtraFooter = useCallback(() => { const timestamp = moment().startOf('day').valueOf(); return ( ); }, []); useEffect(() => { if (expandedAll?.featureTreeKey) { setExpandedAll({ ...expandedAll, featureTree: expandedData?.current?.featureTree }); } else { setExpandedAll({ ...expandedAll, featureTree: [] }); } }, [expandedAll?.featureTreeKey]); useEffect(() => { if (expandedAll?.optionListKey) { setExpandedAll({ ...expandedAll, optionList: expandedData?.current?.optionList }); } else { setExpandedAll({ ...expandedAll, optionList: [] }); } }, [expandedAll?.optionListKey]); useEffect(() => { setExpandedAll({ optionList: expandedData?.current?.optionList, optionListKey: true, featureTree: expandedData?.current?.featureTree, featureTreeKey: true, }); }, [loading]); useEffect(() => { if (openObj?.reload) setBatchParams({}); }, [openObj?.reload]); useEffect(() => { setPermission((value) => { return { ...value, featureTree: filterFeature(data, params) }; }); }, [params?.featureTree, params?.expired]); useEffect(() => { setPermission((value) => { return { ...value, optionList: filterOption(data, params) }; }); }, [params?.optionList, params?.expired]); useEffect(() => { setPermission((value) => { return { ...value, policyList: filterPolicy(data, params) }; }); }, [params?.policyList, params?.expired]); useEffect(() => { setPermission((value) => { return { ...value, roleList: filterRole(data, params) }; }); }, [params?.roleList, params?.expired]); useEffect(() => { setPermission((value) => { return { ...value, userCityList: filterCity(data, params) }; }); }, [params?.userCityList, params?.expired]); const buttonDisabled = emptyRowSelected(batchParams); const [checked, setChecked] = useState(true); return ( {Boolean(isOptShow) && (
{!userId && (

{formatMessage({ id: 'component.ApplyDetail.nav.title.current.user' })}

{formatUserRender({ nameZh: currentUser?.nameZh, account: currentUser?.account, state: currentUser?.state, })}

{formatMessage({ id: 'component.ApplyDetail.nav.title.other.user' })}

)}

{formatMessage({ id: 'component.user.add.user.expires' })}

{ setParams({ ...params, expired: moment(dateString).valueOf() / 1000 }); }} />
{ const allSettledPromise = requestBatchUnbind( batchParams, currentUser, appId, formatMessage, ); if (allSettledPromise) { allSettledPromise.then(() => { run(); }); } }} >
)} { return ( setChecked(e.target.checked)} style={{ marginBottom: 20 }} > {formatMessage({ id: 'component.AppDetail.permissions.showSelected' })} ); } } >
); }; export default AppDetailView;