@lcap/nasl
Version:
NetEase Application Specific Language
151 lines (149 loc) • 6.53 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.genListViewBlock = exports.genLoadListViewLogic = exports.genH5ListViewTemplate = exports.genListViewTemplate = void 0;
const config_1 = require("../config");
const utils = __importStar(require("../utils"));
const _1 = require(".");
const utils_1 = require("./utils");
function genListViewTemplate(property, nameGroup, newLogic) {
const { entity } = property;
const lowerEntityName = utils.firstLowerCase(entity.name);
const currentName = nameGroup.currentName || 'current';
const valueExpression = `${currentName}.item.${lowerEntityName}.${property.name}`;
let dataSourceValue = `(params) => ${newLogic.name}(elements.$ce.page, elements.$ce.size)`;
return `<u-list-view ref="${nameGroup.viewElementMainView}" :dataSource="${dataSourceValue}" dataSchema="${nameGroup.structure}"
:pageSize="50"
:pageNumber="1"
textField="${lowerEntityName}.${property.name}"
valueField="${lowerEntityName}.${entity.properties.find((p) => p.primaryKey)?.name || 'id'}"
:pageable="true" :remotePaging="true">
<template #item="current">
<u-linear-layout>
<u-text :text="${valueExpression}"></u-text>
</u-linear-layout>
</template>
</u-list-view>`;
}
exports.genListViewTemplate = genListViewTemplate;
function genH5ListViewTemplate(property, nameGroup, newLogic) {
const { entity } = property;
const lowerEntityName = utils.firstLowerCase(entity.name);
const currentName = nameGroup.currentName || 'current';
const valueExpression = `${currentName}.item.${lowerEntityName}.${property.name}`;
let dataSourceValue = `(params) => ${newLogic.name}(elements.$ce.page, elements.$ce.size)`;
return `<van-list-view ref="${nameGroup.viewElementMainView}" :dataSource="${dataSourceValue}" dataSchema="${nameGroup.structure}"
:pageSize="50"
:pageNumber="1"
textField="${lowerEntityName}.${property.name}"
valueField="${lowerEntityName}.${entity.properties.find((p) => p.primaryKey)?.name || 'id'}"
pageable="auto-more" :remotePaging="true">
<template #item="current">
<van-cell :value="${valueExpression}" isLink>
<template #title>{{ ${valueExpression} }}</template>
</van-cell>
</template>
<template #prev>
上一页
</template>
<template #next>
下一页
</template>
</van-list-view>`;
}
exports.genH5ListViewTemplate = genH5ListViewTemplate;
function genLoadListViewLogic(entity, nameGroup, newLogics) {
const parentNode = entity.parentNode;
const moduleNode = entity.app;
const moduleNamespace = moduleNode?.getNamespace();
// Select 和 table 不一样,直接在内部产生了
const entityLogic = (0, _1.genQueryLogic)([entity], nameGroup, false, false, parentNode);
newLogics.push(entityLogic);
return utils_1.NaslNode.Logic({
name: nameGroup.viewLogicLoad,
params: [
utils_1.NaslNode.Param({
name: 'params',
typeAnnotation: utils_1.NaslUITypeAnnotation.DataSourceParams,
}),
],
returns: [
utils_1.NaslNode.Return({
name: 'result',
typeAnnotation: null,
}),
],
variables: [],
body: [
utils_1.NaslLogicItem.Start,
utils_1.NaslLogicItem.Assignment({
left: utils_1.NaslLogicItem.Identifier({
name: 'result',
}),
right: utils_1.NaslLogicItem.CallLogic({
calleeNamespace: `${moduleNamespace}.logics`,
calleeName: entityLogic.name,
arguments: [(0, _1.genLogicParam)(`${entityLogic.params[0].name}`, 'params.page'), (0, _1.genLogicParam)(`${entityLogic.params[1].name}`, 'params.size')],
}),
}),
utils_1.NaslLogicItem.End,
],
});
}
exports.genLoadListViewLogic = genLoadListViewLogic;
/**
* 生成实体选择框区块
*/
function genListViewBlock(entity, oldNode, property, genListTemplate) {
const likeComponent = oldNode?.likeComponent;
const dataSource = entity.parentNode;
const module = dataSource.app;
const viewElementMainView = likeComponent.getViewElementUniqueName('listView');
const nameGroup = (0, _1.genUniqueQueryNameGroup)(module, likeComponent, viewElementMainView, false);
nameGroup.viewElementMainView = viewElementMainView;
nameGroup.viewVariableEntity = likeComponent.getVariableUniqueName(utils.firstLowerCase(entity.name));
// 当前节点的currentName
nameGroup.currentName = oldNode.getCurrentName();
const displayedProperty = property || (0, _1.getFirstDisplayedProperty)(entity);
const newLogics = [];
const parentNode = entity.parentNode;
const entityLogic = (0, _1.genQueryLogic)([entity], nameGroup, false, false, parentNode);
const genTemplate = genListTemplate ? genListTemplate : (config_1.config.scope === 'h5' ? genH5ListViewTemplate : genListViewTemplate);
return `<template>
${genTemplate(displayedProperty, nameGroup, entityLogic)}
</template>
<definition>
{
"viewLogics": [
${JSON.stringify(genLoadListViewLogic(entity, nameGroup, newLogics))}
],
"logics": ${JSON.stringify(newLogics)}
}
</definition>
`;
}
exports.genListViewBlock = genListViewBlock;
exports.default = genListViewBlock;
//# sourceMappingURL=genListViewBlock.js.map