diff --git a/src/Add-on/Save.ts b/src/Add-on/Save.ts index de687cb90..65235ee1c 100644 --- a/src/Add-on/Save.ts +++ b/src/Add-on/Save.ts @@ -102,8 +102,7 @@ export class Save implements Command } } - const store = await IndexedDbStore.CADStore(); - store.Delete(StoreName.FileCache, localStorage.getItem(StoreageKeys.Uid)); + await app.AutoSaveServer.Clear(); app.Editor.Prompt("文件缓存已清理!"); app.Saved = true; @@ -152,6 +151,7 @@ export class SaveAs implements Command message: "文件另存为成功", timeout: 2000 }); + await app.AutoSaveServer.Clear(); } } } diff --git a/src/ApplicationServices/Application.ts b/src/ApplicationServices/Application.ts index 41468a7b9..2e051ea69 100644 --- a/src/ApplicationServices/Application.ts +++ b/src/ApplicationServices/Application.ts @@ -140,6 +140,7 @@ export class ApplicationService this.Editor.Prompt("撤销:" + cmdName); this.Saved = false; + this.AutoSaveServer.isCached = false; }); end(this.Database.hm, this.Database.hm.RedoEvent, (cmdName: string) => { @@ -147,6 +148,7 @@ export class ApplicationService this.Editor.Prompt("重做:" + cmdName); this.Saved = false; + this.AutoSaveServer.isCached = false; }); end(this.Database, this.Database.FileRead, () => { diff --git a/src/Editor/AutoSave.ts b/src/Editor/AutoSave.ts index e038c45af..fdde926ae 100644 --- a/src/Editor/AutoSave.ts +++ b/src/Editor/AutoSave.ts @@ -4,20 +4,30 @@ import { arrayRemoveIf } from "../Common/ArrayExt"; import { IndexedDbStore, StoreName } from "../IndexedDb/IndexedDbStore"; import { Log } from "../Common/Log"; import { StoreageKeys } from "../Common/StoreageKeys"; +import { TopPanelStore } from "../UI/Store/TopPanelStore"; +import { userConfig } from "./UserConfig"; export class AutoSaveServer { private indexDbStore: IndexedDbStore; + //缓存过了 + isCached = false; + private timeId: NodeJS.Timeout; constructor() { app.CommandReactor.OnCommandEnd(async (cmdName: string, changeObjects, createObjects) => { - if (app.Saved) return; - - if (changeObjects.length === 0 && createObjects.length === 0) return; - - let searchParams = new URLSearchParams(location.search); - if (!searchParams.has("autosave")) return; + if (changeObjects.length > 0 || createObjects.length > 0) + this.isCached = false; + }); + } + Start() + { + this.Stop(); + const topStore = TopPanelStore.GetInstance() as TopPanelStore; + this.timeId = setInterval(async () => + { + if (app.Saved || !topStore.editoring || this.isCached) return; let f = app.Database.FileWrite(); if (false) @@ -34,7 +44,15 @@ export class AutoSaveServer } //异步不等待 this.SavaData(f.Data); - }); + }, userConfig.autoSaveConfig.time * 60 * 1000); + } + Stop() + { + if (this.timeId) + { + clearInterval(this.timeId); + this.timeId = null; + } } async SavaData(data: any[]) { @@ -42,5 +60,11 @@ export class AutoSaveServer this.indexDbStore = await IndexedDbStore.CADStore(); this.indexDbStore.Put(StoreName.FileCache, localStorage.getItem(StoreageKeys.Uid), { time: new Date().toLocaleString(), data }); Log("文件缓存成功!"); + this.isCached = true; + } + async Clear() + { + const store = await IndexedDbStore.CADStore(); + store.Delete(StoreName.FileCache, localStorage.getItem(StoreageKeys.Uid)); } } diff --git a/src/Editor/UserConfig.ts b/src/Editor/UserConfig.ts index 67b355c84..051321529 100644 --- a/src/Editor/UserConfig.ts +++ b/src/Editor/UserConfig.ts @@ -29,7 +29,7 @@ export interface ICursorConfig extends IBaseOption export class UserConfig implements IConfigStore { - private readonly _version = 4; + private readonly _version = 5; _renderType: RenderType = RenderType.Wireframe; @observable maxSize: IMaxSizeProps = { height: 2440, @@ -60,6 +60,10 @@ export class UserConfig implements IConfigStore D2: 1000, D3: 100, }; + @observable autoSaveConfig = { + enable: true, + time: 1, + }; constructor() { this.Init(); @@ -125,6 +129,7 @@ export class UserConfig implements IConfigStore viewDirType: this.viewDirType, useCtrlRotate: this.useCtrlRotate, cursorSize: toJS(this.cursorSize), + autoSaveConfig: toJS(this.autoSaveConfig), } }; } @@ -149,6 +154,10 @@ export class UserConfig implements IConfigStore { Object.assign(this.cursorSize, config.option.cursorSize); } + if (config.option.version > 4) + { + Object.assign(this.autoSaveConfig, config.option.autoSaveConfig); + } } } diff --git a/src/UI/Components/Board/BoardCommon.tsx b/src/UI/Components/Board/BoardCommon.tsx index f4948cbb6..ef4800010 100644 --- a/src/UI/Components/Board/BoardCommon.tsx +++ b/src/UI/Components/Board/BoardCommon.tsx @@ -4,7 +4,7 @@ import * as React from 'react'; import { app } from '../../../ApplicationServices/Application'; import { CheckObjectType } from '../../../Common/CheckoutVaildValue'; import { Board } from '../../../DatabaseServices/Entity/Board'; -import { BoardConfigOption, IBaseOption, BoardProcessOption, BrRelativePos, TBBoardOption, DrillType, IHightDrillOption, BoardType, IDrawBoardAutoCutOption } from '../../Store/BoardInterface'; +import { BoardConfigOption, IBaseOption, BoardProcessOption, BrRelativePos, TBBoardOption, DrillType, IHightDrillOption, BoardType, AnyObject, IUiOption, IDrawBoardAutoCutOption } from '../../Store/BoardInterface'; import { DrillingOption } from '../../Store/drillInterface'; import { RightPanelStore } from '../../Store/RightPanelStore/RightPanelStore'; import { RightTabId } from '../RightPanel/RightPanel'; @@ -18,9 +18,9 @@ export interface ISetItemOption type: CheckObjectType; optKey: string; title?: string; - option: IBaseOption; + option: AnyObject; /**不传将默认属性允许为字符串类型 */ - uiOption?: Object; + uiOption?: IUiOption; isDisabled?: boolean; placeHolder?: string; onChange?: (e, ...arg) => void; diff --git a/src/UI/Components/Modal/ModalStyle/OptionModal.less b/src/UI/Components/Modal/ModalStyle/OptionModal.less index cbcf79f58..7a6fd39de 100644 --- a/src/UI/Components/Modal/ModalStyle/OptionModal.less +++ b/src/UI/Components/Modal/ModalStyle/OptionModal.less @@ -1,38 +1,44 @@ -#optionModal -{ +#optionModal { min-width: 350px; min-height: 360px; } -#optionModal .bp3-dialog{ + +#optionModal .bp3-dialog { position: absolute; height: 100%; } -#optionModal .bp3-dialog-body -{ + +#optionModal .bp3-dialog-body { display: flex; flex-direction: column; padding: 10px; overflow: hidden; - &>.bp3-card - { + + &>.bp3-card { padding: 10px; } - &>.bp3-tabs - { + + &>.bp3-tabs { flex: 1 1 auto; overflow: hidden; - .bp3-tab-panel{ + + .bp3-tab-panel { margin: 0; padding: 1px; height: 85%; - &>.bp3-card{ + + &>.bp3-card { height: 100%; overflow: auto; } } } } -#optionModal .bp3-dialog-footer -{ + +#optionModal .bp3-dialog-footer { justify-content: flex-end; } + +#optionModal .time-config { + width: 100%; +} diff --git a/src/UI/Components/Modal/OptionModal/ConfigDialog.tsx b/src/UI/Components/Modal/OptionModal/ConfigDialog.tsx index ae199e864..b5da51f1c 100644 --- a/src/UI/Components/Modal/OptionModal/ConfigDialog.tsx +++ b/src/UI/Components/Modal/OptionModal/ConfigDialog.tsx @@ -54,6 +54,10 @@ export class ConfigStore extends Singleton app.Viewer.PreViewer.Cursor.LineLength2D = userConfig.cursorSize.D2; app.Viewer.PreViewer.Cursor.LineLength3D = userConfig.cursorSize.D3; + if (!userConfig.autoSaveConfig.enable) + app.AutoSaveServer.Stop(); + else + app.AutoSaveServer.Start(); await userConfigStore.SaveConfig(BoardModalType.UserConfig, userConfig); }; } diff --git a/src/UI/Components/Modal/SystemConfig.tsx b/src/UI/Components/Modal/SystemConfig.tsx index 047072ad3..1eeccdfe0 100644 --- a/src/UI/Components/Modal/SystemConfig.tsx +++ b/src/UI/Components/Modal/SystemConfig.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Card, Label, Classes, RadioGroup, Radio } from "@blueprintjs/core"; +import { Card, Label, Classes, RadioGroup, Radio, Checkbox } from "@blueprintjs/core"; import { observer } from "mobx-react"; import { userConfig, ISystemConfig, ICursorConfig } from "../../../Editor/UserConfig"; import { safeEval } from "../../../Common/eval"; @@ -13,10 +13,12 @@ export class SystemConfigPanel extends React.Component { private systemUiData: IUiOption; private cursorUiData: IUiOption; + private saveUiData: IUiOption; UNSAFE_componentWillMount() { this.systemUiData = DataAdapter.ConvertUIData(userConfig.SystemConfig); this.cursorUiData = DataAdapter.ConvertUIData(userConfig.cursorSize); + this.saveUiData = DataAdapter.ConvertUIData(userConfig.autoSaveConfig); } render() { @@ -81,6 +83,22 @@ export class SystemConfigPanel extends React.Component + ); } diff --git a/src/UI/Store/UserConfigStore.ts b/src/UI/Store/UserConfigStore.ts index bc1e1cfdd..e31db2d4b 100644 --- a/src/UI/Store/UserConfigStore.ts +++ b/src/UI/Store/UserConfigStore.ts @@ -144,6 +144,10 @@ export class UserConfigStore extends Singleton app.Viewer.PreViewer.Cursor.LineLength2D = userConfig.cursorSize.D2; app.Viewer.PreViewer.Cursor.LineLength3D = userConfig.cursorSize.D3; app.Viewer.InitViewDir(); + + //自动保存配置 + if (userConfig.autoSaveConfig.enable) + app.AutoSaveServer.Start(); } else {