From 5be2539d489602a191a42cd022f08720e8d3a5aa Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Thu, 26 Oct 2023 16:48:43 +0800 Subject: [PATCH] extraFile2 --- lib/components/extraFile/commit/index.d.ts | 1 - lib/components/extraFile/commit/index.js | 67 ++++++++++++++-------- lib/components/extraFile/commit/web.pc.js | 2 +- lib/features/extraFile2.js | 8 +-- src/features/extraFile2.ts | 1 + 5 files changed, 50 insertions(+), 29 deletions(-) diff --git a/lib/components/extraFile/commit/index.d.ts b/lib/components/extraFile/commit/index.d.ts index 6b034c848..c9cabbb91 100644 --- a/lib/components/extraFile/commit/index.d.ts +++ b/lib/components/extraFile/commit/index.d.ts @@ -2,7 +2,6 @@ import { EntityDict } from '../../../oak-app-domain'; declare const _default: (props: import("oak-frontend-base").ReactComponentProps true), }, methods: { - getEfIds(strict) { - const { efPaths } = this.props; - const { oakFullpath } = this.state; - (0, assert_1.default)(efPaths && efPaths.length > 0); - if (oakFullpath) { - const ids = efPaths - .map((path) => { - const path2 = path - ? `${oakFullpath}.${path}` - : oakFullpath; - const data = this.features.runningTree.getFreshValue(path2); - if (strict) { - (0, assert_1.default)(data, `efPath为${path}的路径上取不到extraFile数据,请设置正确的相对路径`); + getEfIds() { + const entity = this.features.runningTree.getEntity(this.state.oakFullpath); + const value = this.features.runningTree.getFreshValue(this.state.oakFullpath); + const efIds = []; + const getRecursive = (e, v) => { + for (const attr in v) { + const rel = this.features.cache.judgeRelation(e, attr); + if (rel === 2) { + (0, assert_1.default)(typeof v[attr] === 'object'); + if (attr === 'extraFile') { + (0, assert_1.default)(v[attr].id); + efIds.push(v[attr].id); + } + else { + getRecursive(attr, v[attr]); + } } - return data?.map((ele) => ele.id); - }) - .flat() - .filter((ele) => !!ele); - return ids; + else if (typeof rel === 'string') { + (0, assert_1.default)(typeof v[attr] === 'object'); + if (rel === 'extraFile') { + (0, assert_1.default)(v[attr].id); + efIds.push(v[attr].id); + } + else { + getRecursive(rel, v[attr]); + } + } + else if (rel instanceof Array) { + (0, assert_1.default)(v[attr] instanceof Array); + const [e2, fk2] = rel; + if (e2 === 'extraFile') { + efIds.push(...(v[attr].map((ele) => ele.id))); + } + else { + v[attr].forEach((ele) => getRecursive(rel, ele)); + } + } + } + }; + if (value instanceof Array) { + value.forEach(ele => getRecursive(entity, ele)); } - return []; + getRecursive(entity, value); + return efIds; }, async upload() { - const ids = this.getEfIds(true); + const ids = this.getEfIds(); if (ids.length === 0) { return; } @@ -77,7 +99,6 @@ exports.default = OakComponent({ async onSubmit() { const { oakExecutable } = this.state; const { beforeCommit, afterCommit, action } = this.props; - console.log(beforeCommit, afterCommit, action); if (oakExecutable) { if (beforeCommit) { const beforeCommitResult = await beforeCommit(); diff --git a/lib/components/extraFile/commit/web.pc.js b/lib/components/extraFile/commit/web.pc.js index cc55543c1..b60802aa1 100644 --- a/lib/components/extraFile/commit/web.pc.js +++ b/lib/components/extraFile/commit/web.pc.js @@ -8,7 +8,7 @@ function render(props) { const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable !== true && ['uploaded'].includes(state)); - let text = executeText || t('common:submit'); + let text = executeText || t('common::submit'); if (oakExecuting) { text = t('executing', { text }); } diff --git a/lib/features/extraFile2.js b/lib/features/extraFile2.js index 6056f1189..dc48f3a39 100644 --- a/lib/features/extraFile2.js +++ b/lib/features/extraFile2.js @@ -54,16 +54,16 @@ class ExtraFile2 extends oak_frontend_base_1.Feature { const cos = (0, cos_1.getCos)(extraFile.origin); await cos.upload(extraFile, up.uploadFile, file, this.uploadToAspect.bind(this)); if (!cos.autoInform()) { - /* await this.cache.exec('operate', { + await this.cache.exec('operate', { entity: 'extraFile', operation: { - id: await generateNewIdAsync(), + id: await (0, oak_domain_1.generateNewIdAsync)(), action: 'update', data: { uploadState: 'success', }, - } as ED['extraFile']['Operation'], - }); */ + }, + }); } item.state = 'uploaded'; item.percentage = undefined; diff --git a/src/features/extraFile2.ts b/src/features/extraFile2.ts index 126f1d1f9..b3a6e5dfa 100644 --- a/src/features/extraFile2.ts +++ b/src/features/extraFile2.ts @@ -113,6 +113,7 @@ export class ExtraFile2< } async uploadCommit(efPaths: string[], oakFullpath: string) { + assert(false, '方法已经废弃'); assert(efPaths && efPaths.length > 0); let ids = [] as string[]; if (oakFullpath) {