提交 288f8303 编辑于 作者: wenxiangdong's avatar wenxiangdong
浏览文件

识别算法

上级 d2ef6a5e
......@@ -37,6 +37,7 @@
.state-item {
margin: 5px auto;
cursor: pointer;
}
.state-item:hover {
color: #19be6b;
......
......@@ -2,27 +2,34 @@
Object.defineProperty(exports, "__esModule", { value: true });
var logger_1 = require("../utils/logger");
var panel_state_manager_1 = require("../panel-state-manager/panel-state-manager");
var shape_recognition_tool_1 = require("../recogonition/shape-recognition-tool");
var PanelStore = /** @class */ (function () {
function PanelStore(states) {
this.states = states;
}
return PanelStore;
}());
exports.PanelStore = PanelStore;
var shape_recognition_util_1 = require("../recogonition/shape-recognition-util");
var message_1 = require("../utils/message");
var DrawingPanel = /** @class */ (function () {
function DrawingPanel(containerID, options) {
var _this = this;
this.onDrawingEnd = function (shape) {
/**
* 画完一次的 回调函数
* @param {Shape} shape
* @param {PanelState} lastState 之前画面状态
*/
this.onDrawingEnd = function (shape, lastState) {
logger_1.default.info(DrawingPanel.TAG, '画完了', shape);
var type = shape_recognition_tool_1.ShapeRecognitionTool.test(shape.coordinates);
shape.label = type;
var ctx = _this.canvas.getContext('2d');
ctx.save();
ctx.fillStyle = DrawingPanel.labelColor;
ctx.font = DrawingPanel.labelFont;
ctx.fillText(shape.label, shape.startPoint.x, shape.startPoint.y);
ctx.restore();
var recognizedShape = shape_recognition_util_1.ShapeRecognitionUtil.test(shape.coordinates);
var label;
if (!recognizedShape) {
// 没有识别结果
label = prompt('未识别出结果,请手动填写');
}
else {
if (confirm("\u7CFB\u7EDF\u8BC6\u522B\u7ED3\u679C\u4E3A\uFF1A" + recognizedShape.label + "\uFF0C\u662F\u5426\u81EA\u52A8\u6821\u6B63\u56FE\u5F62\uFF1F")) {
_this.restoreCanvas(lastState);
recognizedShape.draw(_this.canvas.getContext('2d'));
label = recognizedShape.label;
}
}
if (label) {
_this.drawText(label, shape.coordinates[0]);
}
};
this.drawing = false;
// 准备options
......@@ -43,22 +50,40 @@ var DrawingPanel = /** @class */ (function () {
this.drawingTool = tool;
this.drawingTool.init(this.onDrawingEnd);
};
// 设置管理器
DrawingPanel.prototype.setStateManager = function (stateManager) {
this.stateManager = stateManager;
};
DrawingPanel.prototype.getCanvas = function () {
return this.canvas;
};
/**
* 得到画板状态的 列表
* @return {PanelState[]}
*/
DrawingPanel.prototype.getPanelStates = function () {
if (!this.stateManager)
return [];
var res = [];
this.stateManager.forEach(function (item) {
res.push(item);
});
return res;
};
/**
* 保存当前画面
* @return {PanelState[]} 目前状态列表
*/
DrawingPanel.prototype.saveCanvas = function () {
var ctx = this.canvas.getContext('2d');
var data = this.canvas.toDataURL();
var id = new Date().getTime().toString() + 'state';
var id = "state" + new Date().getTime().toString();
var state = new panel_state_manager_1.PanelState(id, data);
this.stateManager.save(state);
if (!this.stateManager) {
return [];
}
this.stateManager.save(state).then(function (res) {
message_1.Message.show('保存成功');
});
var stateList = [];
this.stateManager.forEach(function (item) {
stateList.push(item);
......@@ -71,19 +96,16 @@ var DrawingPanel = /** @class */ (function () {
*/
DrawingPanel.prototype.restoreCanvas = function (state) {
this.resetCanvas();
if (!state) {
return false;
}
var ctx = this.canvas.getContext('2d');
var pic = new Image();
pic.src = state.data.toString();
pic.onload = function () {
ctx.drawImage(pic, 0, 0);
};
};
DrawingPanel.prototype.getPanelStates = function () {
var res = [];
this.stateManager.forEach(function (item) {
res.push(item);
});
return res;
return true;
};
/**
* 新一个canvas
......@@ -96,6 +118,14 @@ var DrawingPanel = /** @class */ (function () {
var ctx = this.canvas.getContext('2d');
ctx.clearRect(0, 0, this.options.width, this.options.height);
};
DrawingPanel.prototype.drawText = function (text, point) {
var ctx = this.canvas.getContext('2d');
ctx.save();
ctx.fillStyle = DrawingPanel.labelColor;
ctx.font = DrawingPanel.labelFont;
ctx.fillText(text, point.x, point.y);
ctx.restore();
};
DrawingPanel.prototype.initCanvas = function (options) {
var canvas = this.canvas;
canvas.width = options.width;
......
{"version":3,"file":"drawing-panel.js","sourceRoot":"","sources":["drawing-panel.ts"],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Tool } from './drawing-tool';
import { Shape } from './shape';
import { Point, Shape } from '../shape/shape';
import {
IPanelStateManager,
PanelState
} from '../panel-state-manager/panel-state-manager';
import { ShapeRecognitionTool } from '../recogonition/shape-recognition-tool';
import { ShapeRecognitionUtil } from '../recogonition/shape-recognition-util';
import { Message } from '../utils/message';
/**
* 画板构造选项
*/
export interface DrawingPanelOptions {
width: number;
height: number;
......@@ -16,14 +20,6 @@ export interface DrawingPanelOptions {
};
}
export class PanelStore {
constructor(
public states: PanelState[]
) {}
}
export class DrawingPanel {
private static TAG = 'DrawingPanel';
private static defaultOptions: DrawingPanelOptions = {width: 500, height: 500, style: {backgroundColor: 'white', border:'1px solid #dcdee2'}};
......@@ -33,13 +29,11 @@ export class DrawingPanel {
private drawingTool: DrawingTool;
private drawing: boolean;
private options: DrawingPanelOptions;
stateManager: IPanelStateManager;
private stateManager: IPanelStateManager;
constructor(
containerID: string,
options?: DrawingPanelOptions) {
constructor(containerID: string, options?: DrawingPanelOptions) {
this.drawing = false;
// 准备options
options = options || <DrawingPanelOptions>{};
......@@ -61,6 +55,7 @@ export class DrawingPanel {
this.drawingTool.init(this.onDrawingEnd);
}
// 设置管理器
public setStateManager(stateManager: IPanelStateManager) {
this.stateManager = stateManager;
}
......@@ -69,16 +64,35 @@ export class DrawingPanel {
return this.canvas;
}
/**
* 得到画板状态的 列表
* @return {PanelState[]}
*/
public getPanelStates(): PanelState[] {
if (!this.stateManager) return [];
let res = [];
this.stateManager.forEach(item => {
res.push(item);
});
return res;
}
/**
* 保存当前画面
* @return {PanelState[]} 目前状态列表
*/
public saveCanvas(): PanelState[] {
const ctx = this.canvas.getContext('2d');
let data = this.canvas.toDataURL();
const id = new Date().getTime().toString() + 'state';
const id = `state${new Date().getTime().toString()}`;
let state = new PanelState(id, data);
this.stateManager.save(state);
if (!this.stateManager) {
return [];
}
this.stateManager.save(state).then(
res => {
Message.show('保存成功');
}
);
let stateList: PanelState[] = [];
this.stateManager.forEach((item) => {
stateList.push(item);
......@@ -90,22 +104,18 @@ export class DrawingPanel {
* 恢复某个画面
* @param {PanelState} state
*/
public restoreCanvas(state: PanelState) {
public restoreCanvas(state: PanelState): boolean {
this.resetCanvas();
if (!state) {
return false;
}
const ctx = this.canvas.getContext('2d');
const pic = new Image();
pic.src = state.data.toString();
pic.onload = () => {
ctx.drawImage(pic, 0, 0);
};
}
public getPanelStates(): PanelState[] {
let res = [];
this.stateManager.forEach(item => {
res.push(item);
});
return res;
return true;
}
/**
......@@ -120,17 +130,38 @@ export class DrawingPanel {
ctx.clearRect(0, 0, this.options.width, this.options.height);
}
private onDrawingEnd = (shape: Shape) => {
/**
* 画完一次的 回调函数
* @param {Shape} shape
* @param {PanelState} lastState 之前画面状态
*/
private onDrawingEnd = (shape: Shape, lastState: PanelState) => {
logger.info(DrawingPanel.TAG, '画完了', shape);
let type = ShapeRecognitionTool.test(shape.coordinates);
shape.label = type;
let recognizedShape = ShapeRecognitionUtil.test(shape.coordinates);
let label;
if (!recognizedShape) {
// 没有识别结果
label = prompt('未识别出结果,请手动填写');
} else {
if (confirm(`系统识别结果为:${recognizedShape.label},是否自动校正图形?`)) {
this.restoreCanvas(lastState);
recognizedShape.draw(this.canvas.getContext('2d'));
label = recognizedShape.label;
}
}
if (label) {
this.drawText(label, shape.coordinates[0]);
}
};
private drawText(text: string, point: Point) {
const ctx = this.canvas.getContext('2d');
ctx.save();
ctx.fillStyle = DrawingPanel.labelColor;
ctx.font = DrawingPanel.labelFont;
ctx.fillText(shape.label, shape.startPoint.x, shape.startPoint.y);
ctx.fillText(text, point.x, point.y);
ctx.restore();
};
}
private initCanvas(options: DrawingPanelOptions) {
const canvas = this.canvas;
......@@ -152,5 +183,4 @@ export class DrawingPanel {
this.initCanvas(options);
}
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var logger_1 = require("../utils/logger");
var panel_state_manager_1 = require("../panel-state-manager/panel-state-manager");
var DrawingToolCustom = /** @class */ (function () {
function DrawingToolCustom(canvas) {
this.canvas = canvas;
......@@ -13,6 +14,7 @@ var DrawingToolCustom = /** @class */ (function () {
// 监听事件
canvas.onmousedown = function (e) {
logger_1.default.info(DrawingToolCustom.tag, '开始画');
var lastState = _this.canvas.toDataURL();
if (_this.drawing) {
return;
}
......@@ -24,7 +26,7 @@ var DrawingToolCustom = /** @class */ (function () {
ctx.beginPath();
ctx.moveTo(x, y);
// shape保存图形
var shape = { id: '', coordinates: [], label: '未识别', startPoint: { x: x, y: y } };
var shape = { id: '', coordinates: [{ x: x, y: y }], label: '未识别' };
// 鼠标移动,边动边画
canvas.onmousemove = function (e) {
var x = e.clientX - canvas.offsetLeft;
......@@ -40,7 +42,7 @@ var DrawingToolCustom = /** @class */ (function () {
shape.id = DrawingToolCustom.tag + DrawingToolCustom.counter;
DrawingToolCustom.counter++;
_this.drawing = false;
onDrawingEnd(shape);
onDrawingEnd(shape, new panel_state_manager_1.PanelState('auto', lastState));
}
};
};
......
{"version":3,"file":"drawing-tool-custom.js","sourceRoot":"","sources":["drawing-tool-custom.ts"],"names":[],"mappings":";;AAEA,0CAAqC;AAErC;IAOE,2BAAY,MAAyB;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,gCAAI,GAAJ,UAAK,YAAqC;QAA1C,iBAqCC;QApCC,IAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACzC,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,OAAO;QACP,MAAM,CAAC,WAAW,GAAG,UAAC,CAAC;YACrB,gBAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC1C,IAAI,KAAI,CAAC,OAAO,EAAE;gBAChB,OAAO;aACR;YACD,KAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,OAAO;YACP,IAAM,CAAC,GAA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AAC,CAAC,GAAA,EAAE,CAAC,GAAA,EAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAC,CAAC;YACjE,YAAY;YACZ,MAAM,CAAC,WAAW,GAAG,UAAA,CAAC;gBACpB,IAAM,CAAC,GAAG,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC;gBACxC,IAAM,CAAC,GAAG,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC;gBACvC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBACjB,GAAG,CAAC,MAAM,EAAE,CAAC;gBACb,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,EAAC,CAAC,GAAA,EAAE,CAAC,GAAA,EAAC,CAAC,CAAC;YACjC,CAAC,CAAC;YACF,MAAM,CAAC,SAAS,GAAG,UAAA,CAAC;gBAClB,OAAO;gBACP,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;gBAC1B,IAAI,YAAY,EAAE;oBAChB,KAAK,CAAC,EAAE,GAAG,iBAAiB,CAAC,GAAG,GAAG,iBAAiB,CAAC,OAAO,CAAC;oBAC7D,iBAAiB,CAAC,OAAO,EAAE,CAAC;oBAC5B,KAAI,CAAC,OAAO,GAAG,KAAK,CAAC;oBACrB,YAAY,CAAC,KAAK,EAAE,IAAI,gCAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;iBACxD;YACH,CAAC,CAAC;QACJ,CAAC,CAAA;IACH,CAAC;IAED,gCAAI,GAAJ;QACE,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;IACjC,CAAC;IApDM,yBAAO,GAAW,CAAC,CAAC;IACpB,qBAAG,GAAG,QAAQ,CAAC;IAoDxB,wBAAC;CAAA,AAxDD,IAwDC;AAxDY,8CAAiB"}
\ No newline at end of file
import { DrawingTool } from './drawing-tool';
import { Shape } from './shape';
import { Shape } from '../shape/shape';
import logger from '../utils/logger';
import { PanelState } from '../panel-state-manager/panel-state-manager';
export class DrawingToolCustom implements DrawingTool{
......@@ -14,12 +15,14 @@ export class DrawingToolCustom implements DrawingTool{
this.drawing = false;
}
init(onDrawingEnd?: (shape: Shape) => void): void {
init(onDrawingEnd?: (shape: Shape, lastState: PanelState) => void): void {
const ctx = this.canvas.getContext('2d');
const canvas = this.canvas;
// 监听事件
canvas.onmousedown = (e) => {
logger.info(DrawingToolCustom.tag, '开始画');
const lastState = this.canvas.toDataURL();
if (this.drawing) {
return;
}
......@@ -31,7 +34,7 @@ export class DrawingToolCustom implements DrawingTool{
ctx.beginPath();
ctx.moveTo(x, y);
// shape保存图形
let shape: Shape = {id: '', coordinates: [], label: '未识别', startPoint: {x, y}};
let shape = <Shape>{id: '', coordinates: [{x, y}], label: '未识别'};
// 鼠标移动,边动边画
canvas.onmousemove = e => {
const x = e.clientX - canvas.offsetLeft;
......@@ -47,7 +50,7 @@ export class DrawingToolCustom implements DrawingTool{
shape.id = DrawingToolCustom.tag + DrawingToolCustom.counter;
DrawingToolCustom.counter++;
this.drawing = false;
onDrawingEnd(shape);
onDrawingEnd(shape, new PanelState('auto', lastState));
}
};
}
......
import { Shape } from './shape';
import { Shape } from '../shape/shape';
import { PanelState } from '../panel-state-manager/panel-state-manager';
export interface DrawingTool {
canvas: HTMLCanvasElement;
drawing: boolean;
init(onDrawingEnd?: (shape: Shape) => void): void;
init(onDrawingEnd?: (shape: Shape, lastState: PanelState) => void): void;
/**
* 停止画图服务,主要是off 事件
*/
stop();
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ var drawing_tool_custom_1 = require("./drawing/drawing-tool-custom");
var $ = require("jquery");
var logger_1 = require("./utils/logger");
var panel_state_manager_1 = require("./panel-state-manager/panel-state-manager");
var message_1 = require("./utils/message");
var tool;
var panel;
var states = [];
......@@ -21,12 +22,15 @@ window.onload = function (e) {
// 初始列表
states = panel.getPanelStates();
refreshList();
// 绑定按钮事件
var saveBtn = document.getElementById(SAVE_BTN_ID);
if (saveBtn) {
saveBtn.onclick = handleSave;
}
var newBtn = document.getElementById(NEW_BTN_ID);
newBtn.onclick = handleNew;
if (newBtn) {
newBtn.onclick = handleNew;
}
};
var handleSave = function () {
states = panel.saveCanvas();
......@@ -34,6 +38,7 @@ var handleSave = function () {
};
var handleNew = function () {
panel.resetCanvas();
message_1.Message.show('新建成功');
};
var refreshList = function () {
logger_1.default.info(TAG, 'states', states);
......
{"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";;AAAA,yDAAuD;AACvD,qEAAkE;AAClE,0BAA4B;AAC5B,yCAAoC;AACpC,iFAAwG;AAExG,IAAI,IAAI,CAAC;AACT,IAAI,KAAmB,CAAC;AACxB,IAAI,MAAM,GAAiB,EAAE,CAAC;AAE9B,IAAM,WAAW,GAAG,UAAU,CAAC;AAC/B,IAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,IAAM,aAAa,GAAG,YAAY,CAAC;AACnC,IAAM,GAAG,GAAG,SAAS,CAAC;AACtB,IAAM,YAAY,GAAG,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,GAAG,UAAC,CAAC;IAChB,KAAK,GAAG,IAAI,4BAAY,CAAC,YAAY,EAAE,EAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAC,CAAC,CAAC;IAClE,IAAI,GAAG,IAAI,uCAAiB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAChD,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC3B,KAAK,CAAC,eAAe,CAAC,IAAI,qDAA+B,EAAE,CAAC,CAAC;IAE7D,OAAO;IACP,MAAM,GAAG,KAAK,CAAC,cAAc,EAAE,CAAC;IAChC,WAAW,EAAE,CAAC;IAEd,IAAI,OAAO,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IACnD,IAAI,OAAO,EAAE;QACX,OAAO,CAAC,OAAO,GAAG,UAAU,CAAC;KAC9B;IAED,IAAI,MAAM,G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AC;IACpB,iBAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF,IAAM,WAAW,GAAG;IAClB,gBAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACnC,IAAM,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,aAAa,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,EAAE,CAAC;IACb,gBAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;4BACtB,KAAK;QACZ,IAAI,EAAE,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC;QACxB,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClB,gBAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9B,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,UAAC,CAAC;YACf,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;IATD,KAAkB,UAAM,EAAN,iBAAM,EAAN,oBAAM,EAAN,IAAM;QAAnB,IAAI,KAAK,eAAA;gBAAL,KAAK;KASb;AACH,CAAC,CAAA"}
\ No newline at end of file
......@@ -3,6 +3,7 @@ import { DrawingToolCustom } from './drawing/drawing-tool-custom';
import * as $ from 'jquery';
import logger from './utils/logger';
import { PanelState, PanelStateManagerByLocalStorage } from './panel-state-manager/panel-state-manager';
import { Message } from './utils/message';
var tool;
var panel: DrawingPanel;
......@@ -24,13 +25,15 @@ window.onload = (e) => {
states = panel.getPanelStates();
refreshList();
// 绑定按钮事件
let saveBtn = document.getElementById(SAVE_BTN_ID);
if (saveBtn) {
saveBtn.onclick = handleSave;
}
let newBtn = document.getElementById(NEW_BTN_ID);
newBtn.onclick = handleNew;
if (newBtn) {
newBtn.onclick = handleNew;
}
}
......@@ -40,9 +43,8 @@ const handleSave = () => {
};
const handleNew = () => {
panel.resetCanvas();
}
Message.show('新建成功');
};
const refreshList = () => {
logger.info(TAG, 'states', states);
......
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var logger_1 = require("../utils/logger");
var PanelState = /** @class */ (function () {
......@@ -27,14 +62,27 @@ var PanelStateManagerByLocalStorage = /** @class */ (function () {
this.states.forEach(fn);
};
PanelStateManagerByLocalStorage.prototype.save = function (state) {
logger_1.default.info(PanelStateManagerByLocalStorage.TAG, '保存', state);
this.states.push(state);
window.localStorage.setItem(PanelStateManagerByLocalStorage.KEY, JSON.stringify(this.states));
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
logger_1.default.info(PanelStateManagerByLocalStorage.TAG, '保存', state);
this.states.push(state);
window.localStorage.setItem(PanelStateManagerByLocalStorage.KEY, JSON.stringify(this.states));
return [2 /*return*/];
});
});
};
PanelStateManagerByLocalStorage.prototype.clearAll = function () {
logger_1.default.info(PanelStateManagerByLocalStorage.TAG, '清除所有');
this.states = [];
window.localStorage.removeItem(PanelStateManagerByLocalStorage.KEY);
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
logger_1.default.info(PanelStateManagerByLocalStorage.TAG, '清除所有');
this.states = [];
window.localStorage.removeItem(PanelStateManagerByLocalStorage.KEY);
return [2 /*return*/];
});
});
};
PanelStateManagerByLocalStorage.prototype.restore = function () {
return this.states.pop();
};
PanelStateManagerByLocalStorage.TAG = 'PanelStateManagerByLocalStorage';
PanelStateManagerByLocalStorage.KEY = 'panel-states';
......
{"version":3,"file":"panel-state-manager.js","sourceRoot":"","sources":["panel-state-manager.ts"],"names":[],"mappings":";;AAAA,0CAAqC;AAErC;IACE,oBACS,EAAU,EACV,IAAY;QADZ,OAAE,GAAF,EAAE,CAAQ;QACV,SAAI,GAAJ,IAAI,CAAQ;IAClB,CAAC;IACN,iBAAC;AAAD,CAAC,AALD,IAKC;AALY,gCAAU;AAgBvB;;GAEG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