@lcap/asl
Version:
NetEase Application Specific Language
263 lines • 10.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.genGridViewCardBlock = exports.genGridViewBlock = exports.genGridViewRemoveLogic = exports.genGridViewLoadLogic = exports.genGridViewTemplate = exports.genGridViewCardTemplate = void 0;
const __1 = require("../..");
const _1 = require(".");
/**
* 根据实体属性生成表格列模板
* @param property 实体属性
*/
function genGridViewCardTemplate(property) {
const lowerEntityName = __1.utils.firstLowerCase(property.root.name);
let expression = `scope.item.${lowerEntityName}.${property.name}`;
const title = property.label || property.name;
if (__1.dataTypesMap[property.typeKey].type === 'enum')
expression = _1.getExpression(property, `scope.item.${lowerEntityName}.${property.name}`);
else if (property.$relationEntity) { // 有外键关联
const relationEntity = __1.vertexsMap.get(property.$relationEntity);
if (relationEntity) {
const displayedProperty = _1.getFirstDisplayedProperty(relationEntity);
if (displayedProperty) {
expression = _1.getExpression(property, `scope.item.${__1.utils.firstLowerCase(relationEntity.name)}.${displayedProperty.name}`);
}
else
return '';
}
else
return '';
}
else
expression = _1.getExpression(property, `scope.item.${lowerEntityName}.${property.name}`);
return `<u-linear-layout gap="small">
<u-text text="${title}:"></u-text><u-text :text="${expression}"></u-text>
</u-linear-layout>`;
}
exports.genGridViewCardTemplate = genGridViewCardTemplate;
/**
* 生成表格模板
* @param entity 实体
* @param nameGroup 命名组
*/
function genGridViewTemplate(entity, nameGroup) {
const propertyList = entity.propertyList
.filter(_1.filterProperty('inTable'));
return `<u-grid-view ref="gridView" :data-source="${nameGroup.load}" data-schema="${nameGroup.structure}"
value-field="${nameGroup.lowerEntity}.id"
:page-size="20"
:pageable="true"
:remote-paging="true"
:show-sizer="true"
:repeat="4"
:border="false"
:readonly="true"
:show-foot="true"
style="height:auto">
<template #item="scope">
<u-card title="">
<u-linear-layout direction="vertical" gap="small">
${propertyList.map((property) => genGridViewCardTemplate(property) + '\n').join('')}
<u-linear-layout gap="small">
<u-link @click="${nameGroup.modify || 'modify'}($event, scope)">修改</u-link>
<u-link @click="${nameGroup.remove}($event, scope)">删除</u-link>
</u-linear-layout>
</u-linear-layout>
</u-card>
</template>
</u-grid-view>
`;
}
exports.genGridViewTemplate = genGridViewTemplate;
/**
* 生成表格 load 逻辑
* @param entity 实体
*/
function genGridViewLoadLogic(entity, nameGroup, newStructures, newInterfaces, supportFilter) {
const paramsSchema = {
$ref: '#/systemTypes/DataSourceParams',
};
const resultSchema = _1.genGenericTypeSchema('PageOf', { T: { $ref: nameGroup.structure } });
const params = [
_1.genInterParam(`${newInterfaces[0].name}.${newInterfaces[0].logic.params[0].name}`, 'params.page', [undefined, undefined]),
_1.genInterParam(`${newInterfaces[0].name}.${newInterfaces[0].logic.params[1].name}`, 'params.size', [undefined, undefined]),
_1.genInterParam(`${newInterfaces[0].name}.${newInterfaces[0].logic.params[2].name}`, 'params.sort', [undefined, undefined]),
_1.genInterParam(`${newInterfaces[0].name}.${newInterfaces[0].logic.params[3].name}`, 'params.order', [undefined, undefined]),
];
if (supportFilter)
params.push(_1.genInterParam(`${newInterfaces[0].name}.${newInterfaces[0].logic.params[4].name}`, 'filter', [undefined]));
return {
level: 'logic',
name: nameGroup.load,
params: [
{
level: 'param',
type: 'Identifier',
name: 'params',
schema: paramsSchema,
},
],
returns: [
_1.genVariable('result', resultSchema, __1.LEVEL_ENUM.return),
],
variables: [],
body: [
{
level: 'logicNode',
type: 'Start',
label: '开始',
},
{
level: 'logicNode',
type: 'AssignmentExpression',
label: '赋值',
operator: '=',
left: {
level: 'expressionNode',
type: 'Identifier',
name: 'result',
},
right: _1.genCallInterfaceFromTempInterface(newInterfaces[0], params),
},
{
level: 'logicNode',
type: 'End',
label: '结束',
},
],
};
}
exports.genGridViewLoadLogic = genGridViewLoadLogic;
/**
* 生成表格 remove 逻辑
* @param entity 实体
*/
function genGridViewRemoveLogic(entity, nameGroup) {
const scopeStructureSchema = _1.genGenericTypeSchema('ScopeOf', { T: { $ref: nameGroup.structure } });
const deleteResolver = entity.resolvers.find((resolver) => resolver.name === 'delete');
const deleteInterface = deleteResolver.interface;
const idParam = _1.getParamFromResolver(deleteResolver, 'id');
const idProperty = entity.propertyList.find((property) => property.primaryKey || property.name === 'id');
return {
level: 'logic',
name: nameGroup.remove,
params: [{
level: 'param',
type: 'Identifier',
name: 'event',
schema: { $ref: '#/basicTypes/String' },
}, {
level: 'param',
name: 'scope',
schema: scopeStructureSchema,
}],
returns: [],
variables: [],
body: [{
level: 'logicNode',
type: 'Start',
label: '开始',
},
_1.genCallInterface(deleteInterface, [
_1.genInterParam(idParam.id, `scope.item.${nameGroup.lowerEntity}.id`, ['', '', `${nameGroup.structure}.${nameGroup.lowerEntity}`, idProperty.id]),
]),
_1.genCallComponentLogic('gridView', 'reload'),
{
level: 'logicNode',
label: '结束',
type: 'End',
}],
};
}
exports.genGridViewRemoveLogic = genGridViewRemoveLogic;
/**
* 生成表格区块
* @param entity 实体
* @param view 所插入的页面,用于生成逻辑名字,去重等
* @notice 目前 logic 名去重做成前置处理了,与 mergeBlock 的后置处理不冲突
* (页面 load 名) -产生-> (interface 名) -产生-> (structure 名)
* load -> load_someView_tableView
* load_select_student -> load_someView_select_student
*/
function genGridViewBlock(entity, view) {
const existingNameSets = {
viewLogic: new Set(view.$def.logics.map((logic) => logic.name)),
interface: new Set(entity.dataNode.service.interfaces.map((itface) => itface.name)),
structure: new Set(entity.dataNode.structures.map((structure) => structure.name)),
};
const nameGroup = _1.genUniqueQueryNameGroup(existingNameSets, view.name, 'gridView');
nameGroup.remove = __1.utils.unique('remove', existingNameSets.viewLogic);
nameGroup.lowerEntity = __1.utils.firstLowerCase(entity.name);
// 收集所有和本实体关联的实体
const allEntities = [entity];
entity.propertyList.forEach((property) => {
if (property.$relationEntity) { // 有外键关联
const relationEntity = __1.vertexsMap.get(property.$relationEntity);
if (relationEntity) {
const displayedProperty = _1.getFirstDisplayedProperty(relationEntity);
if (displayedProperty)
allEntities.push(relationEntity);
}
}
});
const newStructures = [_1.genQueryStructure(allEntities, nameGroup)];
const newInterfaces = [_1.genQueryInterface(allEntities, nameGroup, false, true)];
return `
<template>
${genGridViewTemplate(entity, nameGroup)}
</template>
<definition>
{
"logics": [
${JSON.stringify(genGridViewLoadLogic(entity, nameGroup, newStructures, newInterfaces, false))},
${JSON.stringify(genGridViewRemoveLogic(entity, nameGroup))}
],
"interfaces": ${JSON.stringify(newInterfaces)},
"structures": ${JSON.stringify(newStructures)}
}
</definition>
`;
}
exports.genGridViewBlock = genGridViewBlock;
function genGridViewCardBlock(property, view) {
const entity = property.root;
const existingNameSets = {
viewLogic: new Set(view.$def.logics.map((logic) => logic.name)),
interface: new Set(entity.dataNode.service.interfaces.map((itface) => itface.name)),
structure: new Set(entity.dataNode.structures.map((structure) => structure.name)),
};
const nameGroup = _1.genUniqueQueryNameGroup(existingNameSets, view.name, 'gridView');
nameGroup.remove = __1.utils.unique('remove', existingNameSets.viewLogic);
nameGroup.lowerEntity = __1.utils.firstLowerCase(entity.name);
// 收集所有和本实体关联的实体
const allEntities = [entity];
const propertyList = [property];
propertyList.forEach((property) => {
if (property.$relationEntity) { // 有外键关联
const relationEntity = __1.vertexsMap.get(property.$relationEntity);
if (relationEntity) {
const displayedProperty = _1.getFirstDisplayedProperty(relationEntity);
if (displayedProperty)
allEntities.push(relationEntity);
}
}
});
const newStructures = [_1.genQueryStructure(allEntities, nameGroup)];
const newInterfaces = [_1.genQueryInterface(allEntities, nameGroup, false, true)];
return `
<template>
${genGridViewTemplate(entity, nameGroup)}
</template>
<definition>
{
"logics": [
${JSON.stringify(genGridViewLoadLogic(entity, nameGroup, newStructures, newInterfaces, false))},
${JSON.stringify(genGridViewRemoveLogic(entity, nameGroup))}
],
"interfaces": ${JSON.stringify(newInterfaces)},
"structures": ${JSON.stringify(newStructures)}
}
</definition>
`;
}
exports.genGridViewCardBlock = genGridViewCardBlock;
exports.default = genGridViewBlock;
//# sourceMappingURL=genGridViewBlock.js.map