mirror of https://gitee.com/cf-fz/WebCAD.git
!1596 优化:<历史操作日志>打开文件时弹出历史窗口,可以在用户配置中设置开关
parent
2e43bf8696
commit
87647ec5e3
@ -0,0 +1,207 @@
|
||||
import { Button, Checkbox, HTMLTable } from "@blueprintjs/core";
|
||||
import { observable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { userConfig } from "../../Editor/UserConfig";
|
||||
import { ModalState } from "../../UI/Components/Modal/ModalInterface";
|
||||
import { HistoryProp } from "./OperLogsModal";
|
||||
|
||||
@observer
|
||||
export class OpenHistoryBody extends React.Component<HistoryProp, {}>
|
||||
{
|
||||
@observable time = this.props.time / 1000;
|
||||
timer: NodeJS.Timeout;
|
||||
isOnHover = false;
|
||||
|
||||
componentDidMount()
|
||||
{
|
||||
let el = document.getElementById("HistoryFile");
|
||||
el.onmousemove = () => { this.isOnHover = true; };
|
||||
el.onmouseleave = () => { this.isOnHover = false; };
|
||||
|
||||
if (!this.timer)
|
||||
this.timer = setInterval(() =>
|
||||
{
|
||||
if (!this.isOnHover)
|
||||
this.time--;
|
||||
if (this.time <= 0)
|
||||
{
|
||||
clearInterval(this.timer);
|
||||
this.timer = undefined;
|
||||
this.props.Toaster.clear();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
componentWillUnmount()
|
||||
{
|
||||
this.time = undefined;
|
||||
this.timer = undefined;
|
||||
}
|
||||
|
||||
render()
|
||||
{
|
||||
return (
|
||||
<div>
|
||||
<div id="HistoryFile">
|
||||
<div><h3 style={{ margin: "0 0 5px 0" }}>历史编辑</h3></div>
|
||||
<div style={{ overflow: "auto", maxHeight: "290px" }}>
|
||||
<OpenHistoryList
|
||||
fileId={this.props.fileId}
|
||||
userName={this.props.userName}
|
||||
files={this.props.files}
|
||||
data={this.props.data}
|
||||
OnClickOpenFile={this.props.OnClickOpenFile}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{
|
||||
<div style={{ float: "left", margin: "15px 0px 0px 0px" }}>
|
||||
可以使用OpenHistory命令打开历史记录
|
||||
</div>
|
||||
}
|
||||
{
|
||||
this.props.isOpenFile ? <div>
|
||||
<Checkbox
|
||||
style={{ margin: "15px 0px 0px 0px", float: "left", left: "18%" }}
|
||||
label="下次不再显示"
|
||||
onClick={() => userConfig.openHistoryList = !userConfig.openHistoryList}
|
||||
/>
|
||||
</div> : undefined
|
||||
}
|
||||
<div style={{ margin: "15px 0px 0px 0px", float: "right", right: "0%" }}>
|
||||
{this.time} 秒后关闭
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@observer
|
||||
export class OpenHistoryList extends React.Component<HistoryProp, {}>
|
||||
{
|
||||
_Index = 0;
|
||||
_LastOper = "";
|
||||
_Data = this.props.data;
|
||||
@observable _CanOpen: boolean = false;
|
||||
|
||||
render()
|
||||
{
|
||||
return (
|
||||
<HTMLTable bordered={true} interactive={true} style={{ lineHeight: 0.5, width: "100%", padding: "5px 5px 0px 5px", border: "1px solid #DBDCDD" }}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>操作</th>
|
||||
<th style={{ width: "120px" }}>用户名</th>
|
||||
<th>日期
|
||||
<Checkbox
|
||||
label="只显示能还原记录"
|
||||
style={{ position: 'absolute', right: "10px", fontSize: "smaller", top: "15px" }}
|
||||
checked={this._CanOpen}
|
||||
onClick={(e) => { this._Index = 0, this._LastOper = "", this._CanOpen = !this._CanOpen; e.currentTarget.blur(); }}
|
||||
/>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{
|
||||
this._CanOpen ? this._CanOpenDataList() : this._AllDataList()
|
||||
}
|
||||
</tbody>
|
||||
</HTMLTable>
|
||||
);
|
||||
}
|
||||
|
||||
_AllDataList = () =>
|
||||
{
|
||||
return (
|
||||
<>
|
||||
{
|
||||
this._Data.map(d =>
|
||||
{
|
||||
if (d.oper_type_name === "打开")
|
||||
if (this._LastOper === "打开")
|
||||
return;
|
||||
this._LastOper = d.oper_type_name;
|
||||
return <tr>
|
||||
<td>{d.oper_type_name}</td>
|
||||
<td>{d.oper_user}</td>
|
||||
<td>
|
||||
{d.oper_date}
|
||||
{this._ButtonEl(d.oper_type_name, d.oper_date, this.props.files[this._Index])}
|
||||
</td>
|
||||
</tr>;
|
||||
})
|
||||
}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
_CanOpenDataList = () =>
|
||||
{
|
||||
return (
|
||||
<>
|
||||
{
|
||||
this._Data.map(d =>
|
||||
{
|
||||
if (d.oper_type_name !== "新建" && d.oper_type_name !== "修改") return;
|
||||
if (!this._HasHistoryFile(d.oper_type_name, d.oper_date, this.props.files[this._Index])) return;
|
||||
return <tr>
|
||||
<td>{d.oper_type_name}</td>
|
||||
<td>{d.oper_user}</td>
|
||||
<td>
|
||||
{d.oper_date}
|
||||
<Button
|
||||
className="button"
|
||||
value={this._Index++}
|
||||
text="打开"
|
||||
onClick={(e) =>
|
||||
{
|
||||
this.props.OnClickOpenFile(this.props.userName, this.props.fileId, this.props.files, e.currentTarget.value);
|
||||
if (this.props.isNotToaster)
|
||||
app.Editor.ModalManage.m_PromisRes({ Status: ModalState.Ok });
|
||||
app.Editor.ModalManage.Destory();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>;
|
||||
})
|
||||
}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
_ButtonEl(name: string, oper_date: string, file_date: string): React.ReactElement<any>
|
||||
{
|
||||
if (!this._HasHistoryFile(name, oper_date, file_date)) return;
|
||||
return (
|
||||
<Button
|
||||
className="button"
|
||||
value={this._Index++}
|
||||
text="打开"
|
||||
onClick={(e) =>
|
||||
{
|
||||
this.props.OnClickOpenFile(this.props.userName, this.props.fileId, this.props.files, e.currentTarget.value);
|
||||
if (this.props.isNotToaster)
|
||||
app.Editor.ModalManage.m_PromisRes({ Status: ModalState.Ok });
|
||||
app.Editor.ModalManage.Destory();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
//验证是否有可以打开的历史文件
|
||||
_HasHistoryFile(name: string, oper_date: string, file_date: string)
|
||||
{
|
||||
if (this._Index >= this.props.files.length) return;
|
||||
if (name !== "修改" && name !== "新建") return;
|
||||
let date = new Date(oper_date);
|
||||
let operDate = date.getHours() * 60 * 60 + date.getMinutes() * 60 + date.getSeconds(); //时分秒转换number 好比较
|
||||
let fileDateStr = file_date.split("-");
|
||||
let fileDate = parseInt(fileDateStr[fileDateStr.length - 3]) * 60 * 60 + parseInt(fileDateStr[fileDateStr.length - 2]) * 60 + parseInt(fileDateStr[fileDateStr.length - 1]); //时分秒转换number 好比较
|
||||
if (!(operDate - 3 <= fileDate && fileDate <= operDate + 3)) return false; //误差±3秒
|
||||
else return true;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue