From d19e7c59a9f515a18e9dae1ae73b7542eadc263a Mon Sep 17 00:00:00 2001 From: Xc Date: Fri, 16 May 2025 16:51:06 +0800 Subject: [PATCH] =?UTF-8?q?relation/path/list=E7=9A=84=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/components/relation/path/list/index.js | 18 ++++++++++++++++++ .../relation/path/list/locales/zh_CN.json | 5 ++++- es/components/relation/path/list/web.pc.d.ts | 2 ++ es/components/relation/path/list/web.pc.js | 7 +++++-- es/components/relation/path/upsert/index.js | 17 ++--------------- .../relation/path/upsert/locales/zh-CN.json | 3 --- es/features/cache.js | 4 +++- lib/features/cache.js | 4 +++- src/components/relation/path/list/index.ts | 18 ++++++++++++++++++ .../relation/path/list/locales/zh_CN.json | 5 ++++- src/components/relation/path/list/web.pc.tsx | 9 ++++++++- src/components/relation/path/upsert/index.ts | 16 ++-------------- .../relation/path/upsert/locales/zh-CN.json | 3 --- 13 files changed, 69 insertions(+), 42 deletions(-) diff --git a/es/components/relation/path/list/index.js b/es/components/relation/path/list/index.js index 618699cc..3c024351 100644 --- a/es/components/relation/path/list/index.js +++ b/es/components/relation/path/list/index.js @@ -1,3 +1,4 @@ +import { OakUniqueViolationException } from 'oak-domain/lib/types/Exception'; import { difference } from 'oak-domain/lib/utils/lodash'; export default OakComponent({ entity: 'path', @@ -55,5 +56,22 @@ export default OakComponent({ }, properties: { entity: '', + }, + methods: { + async onConfirmed() { + try { + await this.execute(); + } + catch (err) { + if (err instanceof OakUniqueViolationException) { + this.setMessage({ + type: 'error', + content: this.t('error.existed'), + }); + return; + } + throw err; + } + } } }); diff --git a/es/components/relation/path/list/locales/zh_CN.json b/es/components/relation/path/list/locales/zh_CN.json index b831e46c..f861603c 100644 --- a/es/components/relation/path/list/locales/zh_CN.json +++ b/es/components/relation/path/list/locales/zh_CN.json @@ -1,3 +1,6 @@ { - "addPath": "新增路径" + "addPath": "新增路径", + "error": { + "existed": "本条关系路径已经存在" + } } \ No newline at end of file diff --git a/es/components/relation/path/list/web.pc.d.ts b/es/components/relation/path/list/web.pc.d.ts index 66ca3302..ba1fe00a 100644 --- a/es/components/relation/path/list/web.pc.d.ts +++ b/es/components/relation/path/list/web.pc.d.ts @@ -6,4 +6,6 @@ export default function render(props: WebComponentProps Promise; }>): React.JSX.Element | null; diff --git a/es/components/relation/path/list/web.pc.js b/es/components/relation/path/list/web.pc.js index 462eebdf..4116db15 100644 --- a/es/components/relation/path/list/web.pc.js +++ b/es/components/relation/path/list/web.pc.js @@ -5,7 +5,7 @@ import PathDetail from '../detail'; const { Title } = Typography; export default function render(props) { const { paths, oakPagination, oakFullpath, allowCreate, actions, entity } = props.data; - const { t, execute, addItem, clean, navigateTo } = props.methods; + const { t, execute, addItem, clean, onConfirmed } = props.methods; if (oakFullpath) { const [upsertId, setUpsertId] = useState(''); const isCreate = upsertId && paths.find(ele => ele.id === upsertId)?.$$createAt$$ === 1; @@ -35,7 +35,10 @@ export default function render(props) { clean(); setUpsertId(''); }} closeIcon={null} footer={null}> - + { + await onConfirmed(); + setUpsertId(''); + }}/> ); } diff --git a/es/components/relation/path/upsert/index.js b/es/components/relation/path/upsert/index.js index ed998dae..0caf479e 100644 --- a/es/components/relation/path/upsert/index.js +++ b/es/components/relation/path/upsert/index.js @@ -1,6 +1,5 @@ import assert from 'assert'; import { unset } from 'oak-domain/lib/utils/lodash'; -import { OakUniqueViolationException } from 'oak-domain/lib/types/Exception'; const SystemEntities = [ 'modi', 'modiEntity', @@ -187,21 +186,9 @@ export default OakComponent({ value, }); } - try { - await this.execute(); - } - catch (err) { - if (err instanceof OakUniqueViolationException) { - this.setMessage({ - type: 'error', - content: this.t('error.existed'), - }); - return; - } - throw err; - } const { onConfirmed } = this.props; - onConfirmed && onConfirmed(); + assert(onConfirmed); + onConfirmed(); } } }); diff --git a/es/components/relation/path/upsert/locales/zh-CN.json b/es/components/relation/path/upsert/locales/zh-CN.json index 4e477bf9..93b25c18 100644 --- a/es/components/relation/path/upsert/locales/zh-CN.json +++ b/es/components/relation/path/upsert/locales/zh-CN.json @@ -4,8 +4,5 @@ "sourceEntity": "源对象必须指向user,或者存在Relation关系", "desc": "请用自然语言准确描述两者之间的关系,以便用户理解", "value": "选择路径上的下一级对象" - }, - "error": { - "existed": "本条关系路径已经存在" } } \ No newline at end of file diff --git a/es/features/cache.js b/es/features/cache.js index d6b9087d..b5d69ffb 100644 --- a/es/features/cache.js +++ b/es/features/cache.js @@ -358,7 +358,9 @@ export class Cache extends Feature { } const filter2 = typeof filter === 'function' ? filter({ action, - data: {}, + data: { + [attr]: 'void', // 这里里面应该不会用到更新的值,这样写不要紧…… + }, filter: { id } }, this.context) : filter; if (!filter2 || this.checkFilterContains(entity, filter2, { id }, true)) { diff --git a/lib/features/cache.js b/lib/features/cache.js index c3319b8f..a50c0c20 100644 --- a/lib/features/cache.js +++ b/lib/features/cache.js @@ -361,7 +361,9 @@ class Cache extends Feature_1.Feature { } const filter2 = typeof filter === 'function' ? filter({ action, - data: {}, + data: { + [attr]: 'void', // 这里里面应该不会用到更新的值,这样写不要紧…… + }, filter: { id } }, this.context) : filter; if (!filter2 || this.checkFilterContains(entity, filter2, { id }, true)) { diff --git a/src/components/relation/path/list/index.ts b/src/components/relation/path/list/index.ts index 7b0fb081..6bfb53cc 100644 --- a/src/components/relation/path/list/index.ts +++ b/src/components/relation/path/list/index.ts @@ -1,4 +1,5 @@ import { EntityDict } from 'oak-domain/lib/base-app-domain'; +import { OakUniqueViolationException } from 'oak-domain/lib/types/Exception'; import { difference } from 'oak-domain/lib/utils/lodash'; export default OakComponent({ @@ -59,5 +60,22 @@ export default OakComponent({ }, properties: { entity: '', + }, + methods: { + async onConfirmed() { + try { + await this.execute(); + } + catch (err) { + if (err instanceof OakUniqueViolationException) { + this.setMessage({ + type: 'error', + content: this.t('error.existed'), + }); + return; + } + throw err; + } + } } }); diff --git a/src/components/relation/path/list/locales/zh_CN.json b/src/components/relation/path/list/locales/zh_CN.json index b831e46c..f861603c 100644 --- a/src/components/relation/path/list/locales/zh_CN.json +++ b/src/components/relation/path/list/locales/zh_CN.json @@ -1,3 +1,6 @@ { - "addPath": "新增路径" + "addPath": "新增路径", + "error": { + "existed": "本条关系路径已经存在" + } } \ No newline at end of file diff --git a/src/components/relation/path/list/web.pc.tsx b/src/components/relation/path/list/web.pc.tsx index fd9e8911..005b16f0 100644 --- a/src/components/relation/path/list/web.pc.tsx +++ b/src/components/relation/path/list/web.pc.tsx @@ -26,11 +26,14 @@ export default function render( actions: string[]; // relations: string[]; entity: string; + }, + { + onConfirmed: () => Promise; } > ) { const { paths, oakPagination, oakFullpath, allowCreate, actions, entity } = props.data; - const { t, execute, addItem, clean, navigateTo } = props.methods; + const { t, execute, addItem, clean, onConfirmed } = props.methods; if (oakFullpath) { const [upsertId, setUpsertId] = useState(''); @@ -83,6 +86,10 @@ export default function render( { + await onConfirmed(); + setUpsertId(''); + }} /> diff --git a/src/components/relation/path/upsert/index.ts b/src/components/relation/path/upsert/index.ts index 0695a15a..b566ac93 100644 --- a/src/components/relation/path/upsert/index.ts +++ b/src/components/relation/path/upsert/index.ts @@ -215,22 +215,10 @@ export default OakComponent({ value, }); } - try { - await this.execute(); - } - catch (err) { - if (err instanceof OakUniqueViolationException) { - this.setMessage({ - type: 'error', - content: this.t('error.existed'), - }); - return; - } - throw err; - } const { onConfirmed } = this.props; - onConfirmed && onConfirmed(); + assert(onConfirmed); + onConfirmed(); } } }); \ No newline at end of file diff --git a/src/components/relation/path/upsert/locales/zh-CN.json b/src/components/relation/path/upsert/locales/zh-CN.json index 4e477bf9..93b25c18 100644 --- a/src/components/relation/path/upsert/locales/zh-CN.json +++ b/src/components/relation/path/upsert/locales/zh-CN.json @@ -4,8 +4,5 @@ "sourceEntity": "源对象必须指向user,或者存在Relation关系", "desc": "请用自然语言准确描述两者之间的关系,以便用户理解", "value": "选择路径上的下一级对象" - }, - "error": { - "existed": "本条关系路径已经存在" } } \ No newline at end of file