@lcap/asl
Version:
NetEase Application Specific Language
192 lines • 6.31 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Lifecycle = void 0;
// import stringify = require('json-stringify-safe');
const decorators_1 = require("../decorators");
const __1 = require("..");
const page_1 = require("../../service/page");
/**
* 前端页面事件
*/
class Lifecycle extends __1.Vertex {
/**
* @param source 需要合并的部分参数
*/
constructor(source) {
super();
/**
* 概念类型
*/
this.level = __1.LEVEL_ENUM.lifecycle;
/**
* 页面事件 Id
*/
this.id = undefined;
/**
* 页面事件名
*/
this.name = undefined;
/**
* 页面事件逻辑 Id
*/
this.logicId = undefined;
/**
* 所属页面 Id
*/
this.viewId = undefined;
/**
* 所属页面
*/
this.view = undefined;
source && this.assign(source);
}
/**
* 添加页面事件
*/
async create(none, actionOptions) {
__1.config.defaultApp?.emit('saving');
if (actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo) {
const body = this.toJSON();
__1.utils.logger.debug('添加页面事件', body);
const result = await page_1.lifecycleService.create({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'Lifecycle.create',
operationDesc: actionOptions?.actionDesc,
},
body,
});
this.assign({ id: result.id });
}
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
return this;
}
/**
* 修改页面事件
*/
async update(data, actionOptions) {
__1.config.defaultApp?.emit('saving');
data && this.assign(data);
if (actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo) {
const body = this.toJSON();
__1.utils.logger.debug('修改页面事件', body);
await page_1.lifecycleService.update({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'Lifecycle.update',
operationDesc: actionOptions?.actionDesc,
},
body,
});
}
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
return this;
}
/**
* 保存
* createOrUpdate 创建或更新
*/
save() {
return !this.id ? this.create() : this.update();
}
/**
* 删除页面事件
*/
async delete(none, actionOptions) {
__1.config.defaultApp?.emit('saving');
if (actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo) {
if (this.id) {
try {
await page_1.lifecycleService.delete({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'Lifecycle.delete',
operationDesc: actionOptions?.actionDesc,
},
query: {
id: this.id,
},
});
}
catch (err) {
await __1.config.defaultApp?.history.load();
throw err;
}
}
}
const index = this.view.$def.lifecycles.indexOf(this);
~index && this.view.$def.lifecycles.splice(index, 1);
this.destroy();
if (this.id) {
if (this.view) {
this.view.page.service.emit('pageTreeChange');
this.view.emit('change');
}
}
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
}
selectName(name) {
this.assign({ name });
this.save();
if (this.view) {
this.view.page.service.emit('pageTreeChange');
this.view.emit('change');
}
}
selectLogic(logicId) {
this.assign({ logicId });
this.save();
if (this.view) {
this.view.page.service.emit('pageTreeChange');
this.view.emit('change');
}
}
/**
* 从后端 JSON 生成规范的 Lifecycle 对象
*/
static from(source, view) {
const lifecyle = new Lifecycle(source);
lifecyle.assign({ view });
return lifecyle;
}
}
__decorate([
decorators_1.immutable()
], Lifecycle.prototype, "level", void 0);
__decorate([
decorators_1.immutable()
], Lifecycle.prototype, "id", void 0);
__decorate([
decorators_1.immutable()
], Lifecycle.prototype, "name", void 0);
__decorate([
decorators_1.immutable()
], Lifecycle.prototype, "logicId", void 0);
__decorate([
decorators_1.immutable()
], Lifecycle.prototype, "viewId", void 0);
__decorate([
decorators_1.circular(),
decorators_1.immutable()
], Lifecycle.prototype, "view", void 0);
__decorate([
decorators_1.action('删除页面事件')
], Lifecycle.prototype, "delete", null);
__decorate([
decorators_1.action('选择页面事件名')
], Lifecycle.prototype, "selectName", null);
__decorate([
decorators_1.action('选择页面事件逻辑')
], Lifecycle.prototype, "selectLogic", null);
exports.Lifecycle = Lifecycle;
exports.default = Lifecycle;
//# sourceMappingURL=Lifecycle.js.map