From 050219aae03c82c819c0f73f9cc609fee14a43e0 Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Tue, 27 Feb 2024 21:50:34 +0800 Subject: [PATCH] =?UTF-8?q?usefulFn=E4=B8=AD=E8=BF=87=E5=8E=BB=E5=87=A0?= =?UTF-8?q?=E4=B8=AA=E6=B2=A1=E6=9C=89=E5=A4=84=E7=90=86=E7=9A=84exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/utils/usefulFn.js | 59 ++++++++++++++++++------------------------- lib/utils/usefulFn.js | 59 ++++++++++++++++++------------------------- src/utils/usefulFn.ts | 58 ++++++++++++++++++------------------------ 3 files changed, 75 insertions(+), 101 deletions(-) diff --git a/es/utils/usefulFn.js b/es/utils/usefulFn.js index 42bd3f6c..eff1548b 100644 --- a/es/utils/usefulFn.js +++ b/es/utils/usefulFn.js @@ -45,44 +45,31 @@ export function resolvePath(dataSchema, entity, path) { idx++; continue; } - try { - const relation = judgeRelation(dataSchema, _entity, attr); - if (relation === 1) { - const attributes = getAttributes(dataSchema[_entity].attributes); - attribute = attributes[attr]; - attrType = attribute.type; - if (attr === 'id') { - attrType = 'ref'; - } - else { - if (attrType === 'ref') { - attr = attribute.ref; - } + const relation = judgeRelation(dataSchema, _entity, attr, true); + if (relation === 1) { + const attributes = getAttributes(dataSchema[_entity].attributes); + attribute = attributes[attr]; + attrType = attribute.type; + if (attr === 'id') { + attrType = 'ref'; + } + else { + if (attrType === 'ref') { + attr = attribute.ref; } } - else if (relation === 2) { - // entity entityId - if (attr === 'entityId') { - attrType = 'ref'; - } - _entity = attr; - } - else if (typeof relation === 'string') { - _entity = relation; - } - idx++; } - catch (err) { - if (process.env.NODE_ENV === 'development') { - console.warn(`存在非「${_entity}」schema属性: ${path}`); + else if (relation === 2) { + // entity entityId + if (attr === 'entityId') { + attrType = 'ref'; } - return { - entity: 'notExist', - attr: path, - attrType: undefined, - attribute, - }; + _entity = attr; } + else if (typeof relation === 'string') { + _entity = relation; + } + idx++; } return { entity: _entity, @@ -123,11 +110,15 @@ export function getLabel(attribute, entity, attr, t) { } if (attr === '$$createAt$$' || attr === '$$updateAt$$' || - attr === '$$deleteAt$$') { + attr === '$$deleteAt$$' || + attr === '$$seq$$') { return t(`common::${attr}`, { '#oakModule': 'oak-frontend-base', }); } + if (attr === 'id') { + return 'id'; + } return t(`${entity}:attr.${attr}`, {}); } // 目前width属性可以是undefined,只有特殊type或用户自定义才有值,这样其余attr属性可以自适应 diff --git a/lib/utils/usefulFn.js b/lib/utils/usefulFn.js index f4424278..f4c612a8 100644 --- a/lib/utils/usefulFn.js +++ b/lib/utils/usefulFn.js @@ -50,44 +50,31 @@ function resolvePath(dataSchema, entity, path) { idx++; continue; } - try { - const relation = (0, relation_1.judgeRelation)(dataSchema, _entity, attr); - if (relation === 1) { - const attributes = getAttributes(dataSchema[_entity].attributes); - attribute = attributes[attr]; - attrType = attribute.type; - if (attr === 'id') { - attrType = 'ref'; - } - else { - if (attrType === 'ref') { - attr = attribute.ref; - } + const relation = (0, relation_1.judgeRelation)(dataSchema, _entity, attr, true); + if (relation === 1) { + const attributes = getAttributes(dataSchema[_entity].attributes); + attribute = attributes[attr]; + attrType = attribute.type; + if (attr === 'id') { + attrType = 'ref'; + } + else { + if (attrType === 'ref') { + attr = attribute.ref; } } - else if (relation === 2) { - // entity entityId - if (attr === 'entityId') { - attrType = 'ref'; - } - _entity = attr; - } - else if (typeof relation === 'string') { - _entity = relation; - } - idx++; } - catch (err) { - if (process.env.NODE_ENV === 'development') { - console.warn(`存在非「${_entity}」schema属性: ${path}`); + else if (relation === 2) { + // entity entityId + if (attr === 'entityId') { + attrType = 'ref'; } - return { - entity: 'notExist', - attr: path, - attrType: undefined, - attribute, - }; + _entity = attr; } + else if (typeof relation === 'string') { + _entity = relation; + } + idx++; } return { entity: _entity, @@ -131,11 +118,15 @@ function getLabel(attribute, entity, attr, t) { } if (attr === '$$createAt$$' || attr === '$$updateAt$$' || - attr === '$$deleteAt$$') { + attr === '$$deleteAt$$' || + attr === '$$seq$$') { return t(`common::${attr}`, { '#oakModule': 'oak-frontend-base', }); } + if (attr === 'id') { + return 'id'; + } return t(`${entity}:attr.${attr}`, {}); } exports.getLabel = getLabel; diff --git a/src/utils/usefulFn.ts b/src/utils/usefulFn.ts index 4d88f6d1..420873b8 100644 --- a/src/utils/usefulFn.ts +++ b/src/utils/usefulFn.ts @@ -85,42 +85,30 @@ export function resolvePath( idx++; continue; } - try { - const relation = judgeRelation(dataSchema, _entity, attr); - if (relation === 1) { - const attributes = getAttributes( - dataSchema[_entity].attributes - ); - attribute = attributes[attr]; - attrType = attribute.type; - if (attr === 'id') { - attrType = 'ref'; - } else { - if (attrType === 'ref') { - attr = attribute.ref as string; - } + const relation = judgeRelation(dataSchema, _entity, attr, true); + if (relation === 1) { + const attributes = getAttributes( + dataSchema[_entity].attributes + ); + attribute = attributes[attr]; + attrType = attribute.type; + if (attr === 'id') { + attrType = 'ref'; + } else { + if (attrType === 'ref') { + attr = attribute.ref as string; } - } else if (relation === 2) { - // entity entityId - if (attr === 'entityId') { - attrType = 'ref'; - } - _entity = attr as keyof ED; - } else if (typeof relation === 'string') { - _entity = relation as keyof ED; } - idx++; - } catch (err) { - if (process.env.NODE_ENV === 'development') { - console.warn(`存在非「${_entity as string}」schema属性: ${path}`); + } else if (relation === 2) { + // entity entityId + if (attr === 'entityId') { + attrType = 'ref'; } - return { - entity: 'notExist', - attr: path, - attrType: undefined, - attribute, - }; + _entity = attr as keyof ED; + } else if (typeof relation === 'string') { + _entity = relation as keyof ED; } + idx++; } return { entity: _entity, @@ -174,12 +162,16 @@ export function getLabel( if ( attr === '$$createAt$$' || attr === '$$updateAt$$' || - attr === '$$deleteAt$$' + attr === '$$deleteAt$$' || + attr === '$$seq$$' ) { return t(`common::${attr}`, { '#oakModule': 'oak-frontend-base', }); } + if (attr === 'id') { + return 'id'; + } return t(`${entity as string}:attr.${attr}`, {}); }