From a1a72e2472d92162e818f185d137c18f1bd4ffaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E5=B7=9E?= Date: Fri, 16 Jul 2021 16:55:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=90=8C=E6=AD=A5=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=BC=B9=E7=AA=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AppHeader/AppHeader.tsx | 45 +++++++++++++++++++---- src/components/AppHeader/index.less | 5 +++ src/components/SyncModal/SyncModal.tsx | 50 ++++++++++++++++++++------ src/pages/sync/index.tsx | 1 - 4 files changed, 83 insertions(+), 18 deletions(-) diff --git a/src/components/AppHeader/AppHeader.tsx b/src/components/AppHeader/AppHeader.tsx index 4b352ce..be439b4 100644 --- a/src/components/AppHeader/AppHeader.tsx +++ b/src/components/AppHeader/AppHeader.tsx @@ -10,23 +10,49 @@ import UserCenter from './components/userCenter'; import system, { isClient } from '@/services/system'; import SvgIcon from '../SvgIcon'; import classNames from 'classnames'; +import { CloudDownloadOutlined } from '@ant-design/icons'; +import ATooltip from '../Tooltip'; +import SyncModal from '../SyncModal'; +import { useState } from 'react'; +import storage from '@/utils/storage'; export default function AppHeader(props) { const { className, style } = props; const { initialState: { isLogin } = { isLogin: false } } = useModel('@@initialState'); + const [modalVisible, setModalVisible] = useState(() => { + const flag = storage.get('isNotFirstLogin'); + if (!flag) { + storage.set('isNotFirstLogin', 'true', true); + } + return !flag; + }); + return (
-
system.openUrl('https://www.locking.cn')} - > - -
+ {isLogin ? ( + +
setModalVisible(true)} + > + +
+
+ ) : null} + +
system.openUrl('https://www.locking.cn')} + > + +
+
+ {isLogin ? ( <> @@ -44,6 +70,13 @@ export default function AppHeader(props) { ) : null}
+ {isLogin ? ( + setModalVisible(false)} + onOk={() => setModalVisible(false)} + /> + ) : null}
); } diff --git a/src/components/AppHeader/index.less b/src/components/AppHeader/index.less index 3c2459f..5c0a454 100644 --- a/src/components/AppHeader/index.less +++ b/src/components/AppHeader/index.less @@ -45,3 +45,8 @@ color: @primary-color; } } + +.import { + .monitor(); + font-size: 20px; +} diff --git a/src/components/SyncModal/SyncModal.tsx b/src/components/SyncModal/SyncModal.tsx index 0041223..3a34317 100644 --- a/src/components/SyncModal/SyncModal.tsx +++ b/src/components/SyncModal/SyncModal.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Modal, Table } from 'antd'; +import { Modal, ModalProps, Table } from 'antd'; import { useModel, useRequest } from 'umi'; import { useState } from 'react'; import styles from './SyncModal.less'; @@ -8,6 +8,7 @@ import { fetchApi } from '@/utils/request'; import { firstCharToLowerCase, handleRequest } from '@/utils/tool'; import { useCallback } from 'react'; import system from '@/services/system'; +import { useEffect } from 'react'; const columns = [ { @@ -43,10 +44,13 @@ interface DataType { address: string; } -export default function SyncModal() { +interface SyncModalProps extends ModalProps {} + +export default function SyncModal(props: SyncModalProps) { + const { onOk: propsOnOk, onCancel: propsOnCancel, ...restProps } = props; const { initialState: { currentUser } = {} } = useModel('@@initialState'); const [btnLoading, setBtnLoading] = useState(false); - const [modalVisible, setModalVisible] = useState(true); + const [modalVisible, setModalVisible] = useState(restProps.visible || false); const [selectedKeys, setSelectedKeys] = useState([]); const { loading, data } = useRequest(async () => { return await fetchApi('project/queryProjectListByUserId', { @@ -54,14 +58,36 @@ export default function SyncModal() { }); }); - const onOk = useCallback(async () => { - setBtnLoading(true); - const res = await system.syncProjects(selectedKeys); - setBtnLoading(false); - handleRequest(res!).success(() => { + const onOk = useCallback( + async (e) => { + setBtnLoading(true); + const res = await system.syncProjects(selectedKeys); + setBtnLoading(false); + handleRequest(res!).success(() => { + setModalVisible(false); + if (propsOnOk) { + propsOnOk(e); + } + }); + }, + [selectedKeys, propsOnOk], + ); + + const onCancel = useCallback( + (e) => { + if (propsOnCancel) { + propsOnCancel(e); + } setModalVisible(false); - }); - }, [selectedKeys]); + }, + [propsOnCancel], + ); + + useEffect(() => { + if (modalVisible || restProps.visible) { + setSelectedKeys([]); + } + }, [modalVisible, restProps.visible]); return ( setModalVisible(false)} + onCancel={onCancel} okButtonProps={{ disabled: selectedKeys.length === 0, loading: btnLoading, }} onOk={onOk} + {...restProps} >
选择「与我有关的文件夹」,并同步到「我的电脑/工作空间」中 @@ -99,6 +126,7 @@ export default function SyncModal() { ); setSelectedKeys(selectedRowKeys as string[]); }, + selectedRowKeys: selectedKeys, // getCheckboxProps: (record: DataType) => ({ // disabled: record.name === 'Disabled User', // Column configuration not to be checked // name: record.name, diff --git a/src/pages/sync/index.tsx b/src/pages/sync/index.tsx index 9e24056..6499184 100644 --- a/src/pages/sync/index.tsx +++ b/src/pages/sync/index.tsx @@ -96,7 +96,6 @@ export default function SyncView() { ))}
- ); }