From f8bdc94ddc0876db032b6cbcf43936edf85e966d Mon Sep 17 00:00:00 2001 From: ZoeLeeFZ Date: Fri, 19 Feb 2021 14:19:33 +0800 Subject: [PATCH] =?UTF-8?q?!1412=20=E4=BC=98=E5=8C=96:=E6=B3=A8=E9=94=80?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=9B=BE=E7=BA=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UI/Components/MainContent/Login.tsx | 25 ++++++++++++++++++++++++- src/UI/Components/Panel.tsx | 9 ++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/UI/Components/MainContent/Login.tsx b/src/UI/Components/MainContent/Login.tsx index 9fb9cb99f..e1702aa10 100644 --- a/src/UI/Components/MainContent/Login.tsx +++ b/src/UI/Components/MainContent/Login.tsx @@ -12,6 +12,8 @@ import { appCache } from '../../../Common/AppCache'; import { userConfig } from '../../../Editor/UserConfig'; import { app } from '../../../ApplicationServices/Application'; import { AppToaster } from '../Toaster'; +import { AppConfirm } from '../Common/Confirm'; +import { FileServer } from '../../../DatabaseServices/FileServer'; interface ILoginState { @@ -53,7 +55,8 @@ export default class Login extends React.Component<{ store?: TopPanelStore; }, I handleLogin = async () => { if (this.isLoginIng) return; - if (!this.state.user_name.trim() || !this.state.pass_word.trim()) + let userName = this.state.user_name.trim(); + if (!userName || !this.state.pass_word.trim()) { AppToaster.show({ message: "用户名和密码不能为空", @@ -63,6 +66,26 @@ export default class Login extends React.Component<{ store?: TopPanelStore; }, I return; } + let oldName = localStorage.getItem(StoreageKeys.UserName); + let oldPhone = localStorage.getItem(StoreageKeys.UserPhone); + if (oldName !== userName && oldPhone !== userName) + { + // 切换账号 + if (!app.Saved) + { + let status = await AppConfirm.show({ + message: "图纸还未保存,切换账号将清空图纸,确定切换?" + }); + if (status) + { + app.Saved = true; + let server = FileServer.GetInstance() as FileServer; + await server.AddNewFile(); + } + else return; + } + } + this.isLoginIng = true; let data = await PostJson(SignUrl.login, this.state); if (data.err_code === RequestStatus.Ok) diff --git a/src/UI/Components/Panel.tsx b/src/UI/Components/Panel.tsx index 1e1b20819..19e4a320e 100644 --- a/src/UI/Components/Panel.tsx +++ b/src/UI/Components/Panel.tsx @@ -4,7 +4,6 @@ import * as React from 'react'; import { app } from '../../ApplicationServices/Application'; import { SignUrl } from '../../Common/HostUrl'; import { Post, RequestStatus } from '../../Common/Request'; -import { FileServer } from '../../DatabaseServices/FileServer'; import { commandMachine } from '../../Editor/CommandMachine'; import { CommandState } from '../../Editor/CommandState'; import { SnapMenuFixed } from '../../Editor/SnapMenuFixed'; @@ -18,6 +17,7 @@ import { userConfigStore } from '../Store/UserConfigStore'; import { TempEditor } from '../../Editor/TempEditor'; import { Log } from '../../Common/Log'; import { Entity } from '../../DatabaseServices/Entity/Entity'; +import { AppConfirm } from './Common/Confirm'; interface TopPanelState { @@ -76,8 +76,11 @@ export class TopPanel extends React.Component<{ store?: TopPanelStore; }, {}> }; handleLoginOut = async () => { - if (!FileServer.GetInstance().isSave && !confirm("您当前图纸还未保存,是否继续")) - return; + if (!app.Saved) + { + let status = await AppConfirm.show({ message: "您当前图纸还未保存,是否继续?" }); + if (!status) return; + } this.props.store.isLogin = false; let data = await Post(SignUrl.loginOut); if (data.err_code === RequestStatus.Ok)