Browse Source

feature:
1.控制导出权限(包含 Dashboard/ShareDashboard)

WanRuixiang 9 months ago
parent
commit
1358b5e3d4

+ 23 - 1
src/app/components/ChartIFrameContainer/ChartIFrameLifecycleAdapter.tsx

@@ -37,6 +37,9 @@ import styled from 'styled-components/macro';
 import { uuidv4 } from 'utils/utils';
 import ChartIFrameEventBroker from './ChartIFrameEventBroker';
 import ChartIFrameResourceLoader from './ChartIFrameResourceLoader';
+import { useDispatch, useSelector } from 'react-redux';
+import { useScheduleSlice } from '../../pages/MainPage/pages/SchedulePage/slice';
+import { selectSelectedTab } from '../../pages/MainPage/pages/VizPage/slice/selectors';
 
 enum ContainerStatus {
   INIT,
@@ -72,6 +75,9 @@ const ChartIFrameLifecycleAdapter: FC<{
   const { document, window } = useFrame();
   const [containerId] = useState(() => `datart-${uuidv4()}`);
   const translator = usePrefixI18N();
+  const dispatch = useDispatch();
+  const { actions } = useScheduleSlice();
+  const currentTab = useSelector(selectSelectedTab);
 
   const buildBrokerOption = useCallback(() => {
     return {
@@ -132,6 +138,21 @@ const ChartIFrameLifecycleAdapter: FC<{
           );
           eventBrokerRef.current = newBrokerRef;
           setContainerStatus(ContainerStatus.SUCCESS);
+          if (chart?.meta?.id==='piovt-sheet'){
+            setTimeout(()=>{
+              // @ts-ignore
+              if (chart?.chart){
+                if (currentTab){
+                  // @ts-ignore
+                  dispatch(actions.updateExportBase({tabId:currentTab?.id,value:{chartId:containerId,chart:chart?.chart}}))
+                }else {
+                  // @ts-ignore
+                  dispatch(actions.updateExportBase({chart:chart?.chart}))
+                }
+              }
+            },2000)
+          }
+
         })
         .catch(_ => {
           setContainerStatus(ContainerStatus.FAILED);
@@ -146,9 +167,10 @@ const ChartIFrameLifecycleAdapter: FC<{
         buildBrokerContext(),
       );
       eventBrokerRef?.current?.dispose();
+      dispatch(actions.clearExportBase(currentTab))
     };
     // eslint-disable-next-line react-hooks/exhaustive-deps
-  }, [chart?.meta?.id, isShown]);
+  }, [chart?.meta?.id, isShown,currentTab]);
 
   /**
    * Chart Resize Event

+ 36 - 14
src/app/pages/DashBoardPage/components/ActionProvider/BoardActionProvider.tsx

@@ -28,8 +28,15 @@ import { clearEditBoardState } from '../../pages/BoardEditor/slice/actions/actio
 import { toUpdateDashboard } from '../../pages/BoardEditor/slice/thunk';
 import { StorageKeys } from '../../../../../globalConstants';
 import { selectNeedVerify, selectShareExecuteTokenMap, selectSharePassword } from '../../../SharePage/slice/selectors';
-import { selectShareBoard } from '../../pages/Board/slice/selector';
+import {
+  selectBoardDataChart,
+  selectShareBoard,
+} from '../../pages/Board/slice/selector';
 import { useRouteMatch } from 'react-router-dom';
+import { BoardState } from '../../pages/Board/slice/types';
+import { selectScheduleExportBase } from '../../../MainPage/pages/SchedulePage/slice/selectors';
+import { selectSelectedTab } from '../../../MainPage/pages/VizPage/slice/selectors';
+import { copyData, download } from '@antv/s2';
 
 export interface BoardActionContextProps {
   // read
@@ -68,6 +75,11 @@ export const BoardActionProvider: FC<{
   const executeTokenMap = useSelector(selectShareExecuteTokenMap);
   const routerParams: { params: { token: string } } = useRouteMatch();
   const sharePassword = useSelector(selectSharePassword);
+  const dataChart = useSelector((state: { board: BoardState }) =>
+    selectBoardDataChart(state, boardId),
+  );
+  const exportBase = useSelector(selectScheduleExportBase);
+  const currentTab = useSelector(selectSelectedTab);
 
   const actions = useMemo(() => {
     const actionObj: BoardActionContextProps = {
@@ -94,18 +106,28 @@ export const BoardActionProvider: FC<{
         return result;
       },
       onBoardToDownLoad: (downloadType) => {
-        dispatch(
-          boardDownLoadAction({
-            boardId,
-            downloadType,
-            clientId,
-            needVerify,
-            shareBoard,
-            executeTokenMap,
-            routerParams,
-            sharePassword
-          }),
-        );
+        if (downloadType===DownloadFileType.Excel){
+          if (currentTab?.id){
+            const tabExport = exportBase[currentTab?.id];
+            Object.keys(tabExport).reduce((acc, key) => {
+              download(copyData(tabExport[key], ',', false), key)
+              return acc;
+            }, 0)
+          }
+        }else {
+          dispatch(
+            boardDownLoadAction({
+              boardId,
+              downloadType,
+              clientId,
+              needVerify,
+              shareBoard,
+              executeTokenMap,
+              routerParams,
+              sharePassword
+            }),
+          );
+        }
       },
       onCloseBoardEditor: (boardId: string) => {
         const pathName = history.location.pathname;
@@ -123,7 +145,7 @@ export const BoardActionProvider: FC<{
       },
     };
     return actionObj;
-  }, [boardId, dispatch, history]);
+  }, [boardId, dispatch, history,dataChart,exportBase,currentTab]);
   return (
     <BoardActionContext.Provider value={actions}>
       {children}

+ 4 - 1
src/app/pages/DashBoardPage/pages/Board/slice/asyncActions.ts

@@ -167,7 +167,10 @@ export const getBoardStateAction =
     };
   };
 export const boardDownLoadAction =
-  (params: { boardId: string; downloadType: DownloadFileType, clientId:any,
+  (params: {
+    boardId: string;
+    downloadType: DownloadFileType,
+    clientId:any,
     needVerify:any,
     shareBoard:any,
     executeTokenMap:any,

+ 9 - 0
src/app/pages/DashBoardPage/pages/Board/slice/selector.ts

@@ -150,6 +150,15 @@ export const selectDataChartById = createSelector(
     dataChartMap[dashboardId]?.[datachartId],
 );
 
+export const selectBoardDataChart = createSelector(
+  [
+    selectDataChartMap,
+    (_, dashboardId: string) => dashboardId,
+  ],
+  (dataChartMap, dashboardId) =>
+    dataChartMap[dashboardId],
+);
+
 export const selectViewMap = createSelector(
   [boardState],
   state => state.viewMap,

+ 20 - 0
src/app/pages/MainPage/pages/SchedulePage/slice/index.ts

@@ -26,6 +26,8 @@ export const initialState: ScheduleState = {
   logs: [],
   logsLoading: false,
   updateLoading: false,
+  exportBase:{},
+  shareExportBase:[]
 };
 
 const slice = createSlice({
@@ -43,6 +45,24 @@ const slice = createSlice({
     clearLogs(state) {
       state.logs = [];
     },
+    updateExportBase(state, { payload: active }){
+      if (active?.tabId){
+        state.exportBase = {
+          [active?.tabId]:{
+            ...state.exportBase[active?.tabId],
+            [active?.value?.chartId]:active?.value?.chart
+          }
+        }
+      }else {
+        state.shareExportBase = [
+          ...state.shareExportBase,
+          active?.chart
+        ]
+      }
+    },
+    clearExportBase(state, { payload: active }){
+      delete state.exportBase[active?.id]
+    }
   },
   extraReducers: builder => {
     // getSchedules

+ 8 - 0
src/app/pages/MainPage/pages/SchedulePage/slice/selectors.ts

@@ -93,3 +93,11 @@ export const selectScheduleLogsLoading = createSelector(
   [selectDomain],
   scheduleState => scheduleState.logsLoading,
 );
+export const selectScheduleExportBase = createSelector(
+  [selectDomain],
+  scheduleState => scheduleState.exportBase,
+);
+export const selectScheduleShareExportBase = createSelector(
+  [selectDomain],
+  scheduleState => scheduleState.shareExportBase,
+);

+ 2 - 0
src/app/pages/MainPage/pages/SchedulePage/slice/types.ts

@@ -35,6 +35,8 @@ export interface ScheduleState {
   logs: ErrorLog[];
   logsLoading: boolean;
   updateLoading: boolean;
+  exportBase:object;
+  shareExportBase:any;
 }
 
 export interface SelectScheduleTreeProps {

+ 12 - 2
src/app/pages/SharePage/Dashboard/DashboardForShare.tsx

@@ -39,6 +39,8 @@ import { DownloadTask } from '../../MainPage/slice/types';
 import { DownloadTaskContainer } from '../components/DownloadTaskContainer';
 import { HeadlessBrowserIdentifier } from '../components/HeadlessBrowserIdentifier';
 import TitleForShare from '../components/TitleForShare';
+import { selectScheduleShareExportBase} from '../../MainPage/pages/SchedulePage/slice/selectors';
+import { copyData, download } from '@antv/s2';
 const TitleHeight = 60;
 
 export interface ShareBoardProps {
@@ -112,9 +114,17 @@ export const DashboardForShare: React.FC<ShareBoardProps> = memo(
       [onMakeShareDownloadDataTask],
     );
 
+    const exportBase = useSelector(selectScheduleShareExportBase);
+
     const onShareDownloadData = useCallback(() => {
-      dispatch(boardDownLoadAction({ boardId: dashboard.id }));
-    }, [boardDownLoadAction, dashboard.id, dispatch]);
+      exportBase.reduce((acc, key) => {
+          acc = acc + 1
+          download(copyData(key, ',', false), acc)
+          return acc;
+        }, 0)
+      //download(copyData(tabExport[key], ',', false), key)
+      // dispatch(boardDownLoadAction({ boardId: dashboard.id }));
+    }, [boardDownLoadAction, dashboard.id, dispatch,exportBase]);
 
     const viewBoard = useMemo(() => {
       let boardType = dashboard?.config?.type;