diff --git a/src/Add-on/File/operLog.tsx b/src/Add-on/File/operLog.tsx deleted file mode 100644 index 084a66527..000000000 --- a/src/Add-on/File/operLog.tsx +++ /dev/null @@ -1,149 +0,0 @@ -import { Intent, Toaster } from "@blueprintjs/core"; -import React from "react"; -import { app } from "../../ApplicationServices/Application"; -import { FileHistoryFilesUrl, FileHistoryUrl, SignUrl } from "../../Common/HostUrl"; -import { inflateBase64 } from "../../Common/inflate"; -import { PostJson, RequestStatus } from "../../Common/Request"; -import { StoreageKeys } from "../../Common/StoreageKeys"; -import { CADFiler } from "../../DatabaseServices/CADFiler"; -import { FileServer } from "../../DatabaseServices/FileServer"; -import { Command } from "../../Editor/CommandMachine"; -import { ModalState } from "../../UI/Components/Modal/ModalInterface"; -import { AppToaster } from "../../UI/Components/Toaster"; -import { OpenHistoryBody } from "./OpenHistoryBody"; -import { OperLogsModal } from "./OperLogsModal"; - -const ADDSTRS = ["秒", "分", "时", "号", "月"]; - -export const HistoryToaster = Toaster.create({ - className: "historyToaster", - canEscapeKeyClear: true, - position: "top-right" -}); - -export class OperLogs implements Command -{ - constructor(private _IsOpenFile: boolean = true) { } - - async exec() - { - let fid = FileServer.GetInstance().m_CurFileId; - if (!fid) - { - AppToaster.show({ - message: "该文件为新键文件,未保存", - timeout: 2000, - intent: Intent.PRIMARY - }); - return; - } - - let userName = localStorage.getItem(StoreageKeys.UserName); - let curUserFileHistoryRes: Response;//当前用户操作历史(备份服务器) - try - { - curUserFileHistoryRes = await fetch(`${FileHistoryUrl}?user=${userName}&fileId=${fid}`); - if (curUserFileHistoryRes.status !== 200) return; - } catch (error) - { - AppToaster.show({ - message: "文件历史记录请求失败!(可能历史备份服务器暂时无法使用,请注意保存图纸!)", - timeout: 4000, - intent: Intent.WARNING, - }); - return; - } - - let allFiles = await curUserFileHistoryRes.json() as string[]; - - let operLogsRes = await PostJson(SignUrl.operLogs, { obj_type: 1, obj_value: fid });//服务端操作历史 - if (operLogsRes.err_code !== RequestStatus.Ok) return; - - let userNames: Set = new Set; - for (let date of operLogsRes.data) - { - let user = date.oper_user as string; - if (user === userName || userNames.has(user)) continue; - - userNames.add(date.oper_user); - let res = await fetch(`${FileHistoryUrl}?user=${date.oper_user}&fileId=${fid}`); - if (res.status !== 200) continue; - - let files = await res.json() as string[]; - allFiles.concat(files); - } - - allFiles.sort((f1, f2) => - { - return this.ParseTime(f2) - this.ParseTime(f1); - }); - - const data = operLogsRes.data.reverse(); - if (!this._IsOpenFile) - { - app.Editor.ModalManage.RenderModal(OperLogsModal, { - fileId: fid, - userName: userName, - files: allFiles, - data: data, - OnClickOpenFile: this.OnClickOpenFile, - isNotToaster: true, - }); - let Rm = await app.Editor.ModalManage.Wait(); - if (Rm.Status !== ModalState.Ok) return; - } - - let time = allFiles.length === 0 ? 5000 : 10000; //窗口持续时间 - - if (HistoryToaster) - HistoryToaster.clear(); - HistoryToaster.show({ - message: - , - timeout: time + 500, - intent: Intent.NONE, - }); - } - - //打开历史保存的文件图纸 - private async OnClickOpenFile(userName: string, fileId: string, files: string[], number: number) - { - let fileName = files[number]; - let url = FileHistoryFilesUrl + encodeURIComponent(userName + "//" + fileId + "//" + fileName); - let cadf = await FetchFile1(url + ".cad"); - app.OpenFile(cadf); - } - - private ParseTime(f1: string) - { - let time = f1.split("-"); - time.shift(); - let sum = 0; - for (let i = 0; i < ADDSTRS.length; i++) - { - sum += parseInt(time[time.length - 1 - i]) * Math.pow(60, i); - } - return sum; - } -} - -async function FetchFile1(url: string): Promise -{ - let res = await fetch(url); - let binaryData = await res.text(); - - let jsonString = inflateBase64(binaryData); - let jsonObject = JSON.parse(jsonString); - - let cadfiler = new CADFiler(jsonObject); - return cadfiler; -}