!1022 优化:按时间自动保存

pull/1022/MERGE
ZoeLeeFZ 4 years ago committed by ChenX
parent 40e16a554f
commit 578020fd55

@ -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();
}
}
}

@ -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, () =>
{

@ -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));
}
}

@ -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);
}
}
}

@ -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<AnyObject>;
isDisabled?: boolean;
placeHolder?: string;
onChange?: (e, ...arg) => void;

@ -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%;
}

@ -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);
};
}

@ -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<ISystemConfig>;
private cursorUiData: IUiOption<ICursorConfig>;
private saveUiData: IUiOption<any>;
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
<Radio inline label="Ctrl" value="ctrl" />
<Radio inline label="Shift" value="shift" />
</RadioGroup>
<Label className={Classes.INLINE}>
<Checkbox
label="自动保存"
inline
checked={userConfig.autoSaveConfig.enable}
onChange={() => userConfig.autoSaveConfig.enable = !userConfig.autoSaveConfig.enable}
/>
<ToasterInput
optKey="time"
inputClassName="time-config"
option={userConfig.autoSaveConfig}
uiOption={this.saveUiData}
type={CheckObjectType.GT0Num}
/>
<span style={{ marginLeft: 10 }}>mins</span>
</Label>
</Card>
);
}

@ -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
{

Loading…
Cancel
Save