@lcap/asl
Version:
NetEase Application Specific Language
106 lines (105 loc) • 4.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.genSelectBlock = exports.genLoadSelectLogic = exports.genH5SelectTemplate = exports.genSelectTemplate = void 0;
const __1 = require("../..");
const _1 = require(".");
function genSelectTemplate(property, nameGroup) {
return `<u-select clearable placeholder="请选择" ref="select" :data-source="${nameGroup.load}" data-schema="${nameGroup.structure}"
text-field="${nameGroup.lowerEntity}.${property.name}"
value-field="${nameGroup.lowerEntity}.id" pageable remote-paging>
</u-select>`;
}
exports.genSelectTemplate = genSelectTemplate;
function genH5SelectTemplate(property, nameGroup) {
return `<van-cascader title="请选择" placeholder="请选择" ref="select" :data-source="${nameGroup.load}" data-schema="${nameGroup.structure}"
text-field="${nameGroup.lowerEntity}.${property.name}"
value-field="${nameGroup.lowerEntity}.id" pageable remote-paging>
</van-cascader>`;
}
exports.genH5SelectTemplate = genH5SelectTemplate;
function genLoadSelectLogic(entity, nameGroup, newStructures, newInterfaces) {
const paramsSchema = {
$ref: '#/systemTypes/DataSourceParams',
};
// Select 和 table 不一样,直接在内部产生了
const newStructure = _1.genQueryStructure([entity], nameGroup);
const newInterface = _1.genQueryInterface([entity], nameGroup, false, false);
newStructures.push(newStructure);
newInterfaces.push(newInterface);
const resultSchema = _1.genGenericTypeSchema('PageOf', { T: { $ref: nameGroup.structure } });
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(newInterface, [
_1.genInterParam(`${newInterface.name}.${newInterface.logic.params[0].name}`, 'params.page', [undefined, undefined]),
_1.genInterParam(`${newInterface.name}.${newInterface.logic.params[1].name}`, 'params.size', [undefined, undefined]),
]),
},
{
level: 'logicNode',
type: 'End',
label: '结束',
},
],
};
}
exports.genLoadSelectLogic = genLoadSelectLogic;
/**
* 生成实体选择框区块
*/
function genSelectBlock(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, 'select', false);
nameGroup.lowerEntity = __1.utils.firstLowerCase(entity.name);
const displayedProperty = _1.getFirstDisplayedProperty(entity, 'inDetail');
const newStructures = [];
const newInterfaces = [];
return `<template>
${__1.config.scope === 'h5' ? genH5SelectTemplate(displayedProperty, nameGroup) : genSelectTemplate(displayedProperty, nameGroup)}
</template>
<definition>
{
"logics": [
${JSON.stringify(genLoadSelectLogic(entity, nameGroup, newStructures, newInterfaces))}
],
"interfaces": ${JSON.stringify(newInterfaces)},
"structures": ${JSON.stringify(newStructures)}
}
</definition>
`;
}
exports.genSelectBlock = genSelectBlock;
exports.default = genSelectBlock;
//# sourceMappingURL=genSelectBlock.js.map