diff --git a/es/components/extraFile/commit/index.d.ts b/es/components/extraFile/commit/index.d.ts index 8578987c0..e12d2cdfa 100644 --- a/es/components/extraFile/commit/index.d.ts +++ b/es/components/extraFile/commit/index.d.ts @@ -4,6 +4,8 @@ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; import { ReactComponentProps } from 'oak-frontend-base/lib/types/Page'; import { ButtonProps } from 'antd'; import { ButtonProps as AmButtonProps } from 'antd-mobile'; +type AfterCommit = (() => void) | undefined; +type BeforeCommit = (() => boolean | undefined | Promise) | undefined; declare const _default: (props: ReactComponentProps>) | undefined; tabIndex?: number | undefined; } & import("react").AriaAttributes) | undefined; - afterCommit?: (() => any) | undefined; - beforeCommit?: (() => boolean | undefined | Promise) | undefined; + afterCommit?: AfterCommit; + beforeCommit?: BeforeCommit; + fnSetMp?: { + afterCommit?: AfterCommit; + beforeCommit?: BeforeCommit; + } | undefined; }>) => React.ReactElement; export default _default; diff --git a/es/components/extraFile/commit/index.js b/es/components/extraFile/commit/index.js index 46f05fafb..edae76edf 100644 --- a/es/components/extraFile/commit/index.js +++ b/es/components/extraFile/commit/index.js @@ -25,8 +25,12 @@ export default OakComponent({ type: 'primary', executeText: '', buttonProps: {}, - afterCommit: () => { }, - beforeCommit: (() => true), + afterCommit: undefined, + beforeCommit: undefined, + fnSet: { + afterCommit: undefined, + beforeCommit: undefined, + }, //小程序传递函数 需要以对象形式传入组件 }, data: { failureIds: undefined, @@ -103,41 +107,52 @@ export default OakComponent({ }); if (promises.length > 0) { await Promise.all(promises); - if (failureIds.length > 0) { - this.setState({ - failureIds, - }); - } - else { - this.setState({ - failureIds: undefined, - }); - } } + return failureIds; }, - async onSubmit() { + async onSubmit(e) { const { oakExecutable } = this.state; - const { beforeCommit, afterCommit, action } = this.props; + const { beforeCommit, afterCommit, action, fnSet } = this.props; const ids = this.getEfIds(); + const beforeCommit2 = fnSet?.beforeCommit || beforeCommit; + const afterCommit2 = fnSet?.afterCommit || afterCommit; if (oakExecutable) { - if (beforeCommit) { - const beforeCommitResult = await beforeCommit(); + if (typeof beforeCommit2 === 'function') { + const beforeCommitResult = await beforeCommit2(); if (beforeCommitResult === false) { return; } } await this.execute(action || undefined); - await this.upload(ids); - if (afterCommit) { - afterCommit(); + const failureIds = await this.upload(ids); + if (failureIds && failureIds.length > 0) { + this.setState({ + failureIds, + }); + return; + } + this.setState({ + failureIds: undefined, + }); + if (typeof afterCommit2 === 'function') { + afterCommit2(); } } else { const { failureIds } = this.state; assert(failureIds && failureIds.length > 0); - await this.upload(failureIds); - if (afterCommit) { - afterCommit(); + const failureIds2 = await this.upload(failureIds); + if (failureIds2 && failureIds2.length > 0) { + this.setState({ + failureIds: failureIds2, + }); + return; + } + this.setState({ + failureIds: undefined, + }); + if (typeof afterCommit2 === 'function') { + afterCommit2(); } } }, diff --git a/es/components/extraFile/commit/index.xml b/es/components/extraFile/commit/index.xml index 88b9b09c9..39ae6cb44 100644 --- a/es/components/extraFile/commit/index.xml +++ b/es/components/extraFile/commit/index.xml @@ -1,4 +1,4 @@ - - {{ executeText || t('common:submit') }} + + {{ executeText || t('common::submit')}} \ No newline at end of file diff --git a/es/components/extraFile/commit/web.pc.d.ts b/es/components/extraFile/commit/web.pc.d.ts index 6f0da0377..defcb16f0 100644 --- a/es/components/extraFile/commit/web.pc.d.ts +++ b/es/components/extraFile/commit/web.pc.d.ts @@ -1,5 +1,5 @@ -import { WebComponentProps } from 'oak-frontend-base'; import { ButtonProps } from 'antd'; +import { WebComponentProps } from 'oak-frontend-base'; import { EntityDict } from '../../../oak-app-domain'; import { FileState } from '../../../features/extraFile'; export default function render(props: WebComponentProps; - uploadCommit(efPaths: string[], oakFullpath: string): Promise; getUrl(extraFile?: EntityDict['extraFile']['OpSchema'] | EntityDict['extraFile']['Schema'] | null, style?: string): string; getFileState(id: string): { state: FileState; diff --git a/es/features/extraFile.js b/es/features/extraFile.js index 69c72d061..5882a9184 100644 --- a/es/features/extraFile.js +++ b/es/features/extraFile.js @@ -70,36 +70,7 @@ export class ExtraFile extends Feature { item.state = 'failed'; item.percentage = undefined; this.publish(); - } - } - async uploadCommit(efPaths, oakFullpath) { - assert(false, '方法已经废弃'); - assert(efPaths && efPaths.length > 0); - let ids = []; - if (oakFullpath) { - ids = efPaths - .map((path) => { - const path2 = path ? `${oakFullpath}.${path}` : oakFullpath; - const data = this.runningTree.getFreshValue(path2); - assert(data, `efPath为${path}的路径上取不到extraFile数据,请设置正确的相对路径`); - return data.map((ele) => ele.id); - }) - .flat() - .filter((ele) => !!ele); - } - assert(ids.length > 0); - const promises = []; - ids.forEach((id) => { - const fileState = this.getFileState(id); - if (fileState) { - const { state } = fileState; - if (['local', 'failed'].includes(state)) { - promises.push(this.upload(id)); - } - } - }); - if (promises.length > 0) { - await Promise.all(promises); + throw err; } } getUrl(extraFile, style) { diff --git a/lib/features/extraFile.d.ts b/lib/features/extraFile.d.ts index 37c785f7f..7ee428f3a 100644 --- a/lib/features/extraFile.d.ts +++ b/lib/features/extraFile.d.ts @@ -19,7 +19,6 @@ export declare class ExtraFile; - uploadCommit(efPaths: string[], oakFullpath: string): Promise; getUrl(extraFile?: EntityDict['extraFile']['OpSchema'] | EntityDict['extraFile']['Schema'] | null, style?: string): string; getFileState(id: string): { state: FileState; diff --git a/lib/features/extraFile.js b/lib/features/extraFile.js index 0038a5850..ea15b2c12 100644 --- a/lib/features/extraFile.js +++ b/lib/features/extraFile.js @@ -73,36 +73,7 @@ class ExtraFile extends oak_frontend_base_1.Feature { item.state = 'failed'; item.percentage = undefined; this.publish(); - } - } - async uploadCommit(efPaths, oakFullpath) { - (0, assert_1.assert)(false, '方法已经废弃'); - (0, assert_1.assert)(efPaths && efPaths.length > 0); - let ids = []; - if (oakFullpath) { - ids = efPaths - .map((path) => { - const path2 = path ? `${oakFullpath}.${path}` : oakFullpath; - const data = this.runningTree.getFreshValue(path2); - (0, assert_1.assert)(data, `efPath为${path}的路径上取不到extraFile数据,请设置正确的相对路径`); - return data.map((ele) => ele.id); - }) - .flat() - .filter((ele) => !!ele); - } - (0, assert_1.assert)(ids.length > 0); - const promises = []; - ids.forEach((id) => { - const fileState = this.getFileState(id); - if (fileState) { - const { state } = fileState; - if (['local', 'failed'].includes(state)) { - promises.push(this.upload(id)); - } - } - }); - if (promises.length > 0) { - await Promise.all(promises); + throw err; } } getUrl(extraFile, style) { diff --git a/package.json b/package.json index b2296bc46..9b6646be1 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "make:locale": "ts-node ./scripts/buildLocale.ts", "make:domain": "ts-node ./scripts/make.ts", "clean": "rimraf lib/* && rimraf es/*", - "copy-js": "copyfiles -u 1 src/**/*.js lib/ & copyfiles -u 1 src/**/*.js es/", + "copy-js": "copyfiles -u 1 src/**/*.js es/", "copy-svg": "copyfiles -u 1 src/**/*.svg es/ & copyfiles -u 1 src/**/*.png es/", "copy-less": "copyfiles -u 1 src/**/*.less es/ & copyfiles -u 1 src/**/*.wxss es/ & copyfiles -u 1 src/**/*.css es/", "copy-wxs": "copyfiles -u 1 src/**/*.wxs es/", diff --git a/src/components/extraFile/commit/index.ts b/src/components/extraFile/commit/index.ts index 0487d0350..0c779b561 100644 --- a/src/components/extraFile/commit/index.ts +++ b/src/components/extraFile/commit/index.ts @@ -6,6 +6,11 @@ import { ReactComponentProps } from 'oak-frontend-base/lib/types/Page'; import { ButtonProps } from 'antd'; import { ButtonProps as AmButtonProps } from 'antd-mobile'; +type AfterCommit = (() => void) | undefined; +type BeforeCommit = + | (() => boolean | undefined | Promise) + | undefined; + export default OakComponent({ formData({ features }) { const ids: string[] = this.getEfIds(); @@ -31,11 +36,17 @@ export default OakComponent({ type: 'primary', executeText: '', buttonProps: {}, - afterCommit: () => {}, - beforeCommit: (() => true) as () => - | boolean - | undefined - | Promise, + afterCommit: undefined as AfterCommit, + beforeCommit: undefined as BeforeCommit, + fnSetMp: { + afterCommit: undefined, + beforeCommit: undefined, + } as + | { + afterCommit?: AfterCommit; + beforeCommit?: BeforeCommit; + } + | undefined, //小程序传递函数 需要以对象形式传入组件 }, data: { failureIds: undefined as string[] | undefined, @@ -101,7 +112,7 @@ export default OakComponent({ } const promises: Promise[] = []; - const failureIds = [] as string[]; + const failureIds = [] as string[]; ids.forEach((id) => { const fileState = this.features.extraFile.getFileState(id); if (fileState) { @@ -111,8 +122,7 @@ export default OakComponent({ (async () => { try { await this.features.extraFile.upload(id); - } - catch (err) { + } catch (err) { failureIds.push(id); } })() @@ -121,44 +131,56 @@ export default OakComponent({ } }); - if (promises.length > 0) { + if (promises.length > 0) { await Promise.all(promises); - if (failureIds.length > 0) { - this.setState({ - failureIds, - }); - } - else { - this.setState({ - failureIds: undefined, - }); - } } + return failureIds; }, - async onSubmit() { + async onSubmit(e: any) { const { oakExecutable } = this.state; - const { beforeCommit, afterCommit, action } = this.props; + const { beforeCommit, afterCommit, action, fnSet } = this.props; const ids = this.getEfIds(); + const beforeCommit2 = fnSet?.beforeCommit || beforeCommit; + const afterCommit2 = fnSet?.afterCommit || afterCommit; + if (oakExecutable) { - if (beforeCommit) { - const beforeCommitResult = await beforeCommit(); + if (typeof beforeCommit2 === 'function') { + const beforeCommitResult = await beforeCommit2(); if (beforeCommitResult === false) { return; } } await this.execute(action || undefined); - await this.upload(ids); - if (afterCommit) { - afterCommit(); + const failureIds = await this.upload(ids); + if (failureIds && failureIds.length > 0) { + this.setState({ + failureIds, + }); + return; + } + this.setState({ + failureIds: undefined, + }); + if (typeof afterCommit2 === 'function') { + afterCommit2(); } } else { const { failureIds } = this.state; assert(failureIds && failureIds.length > 0); - await this.upload(failureIds); - if (afterCommit) { - afterCommit(); + const failureIds2 = await this.upload(failureIds); + if (failureIds2 && failureIds2.length > 0) { + this.setState({ + failureIds: failureIds2, + }); + return; + } + this.setState({ + failureIds: undefined, + }); + if (typeof afterCommit2 === 'function') { + afterCommit2(); } } }, @@ -176,11 +198,13 @@ export default OakComponent({ type?: ButtonProps['type'] | AmButtonProps['type']; executeText?: string; buttonProps?: ButtonProps & AmButtonProps; - afterCommit?: () => any; - beforeCommit?: () => - | boolean - | undefined - | Promise; + afterCommit?: AfterCommit; + beforeCommit?: BeforeCommit; + fnSetMp?: { + //小程序传递函数 需要以对象形式传入组件 + afterCommit?: AfterCommit; + beforeCommit?: BeforeCommit; + }; } > ) => React.ReactElement; \ No newline at end of file diff --git a/src/components/extraFile/commit/index.xml b/src/components/extraFile/commit/index.xml index 88b9b09c9..39ae6cb44 100644 --- a/src/components/extraFile/commit/index.xml +++ b/src/components/extraFile/commit/index.xml @@ -1,4 +1,4 @@ - - {{ executeText || t('common:submit') }} + + {{ executeText || t('common::submit')}} \ No newline at end of file diff --git a/src/components/extraFile/commit/web.pc.tsx b/src/components/extraFile/commit/web.pc.tsx index a7552ce1c..4d313d0ac 100644 --- a/src/components/extraFile/commit/web.pc.tsx +++ b/src/components/extraFile/commit/web.pc.tsx @@ -1,6 +1,6 @@ -import { WebComponentProps } from 'oak-frontend-base'; import React from 'react'; import { Button, ButtonProps } from 'antd'; +import { WebComponentProps } from 'oak-frontend-base'; import { EntityDict } from '../../../oak-app-domain'; import { FileState } from '../../../features/extraFile'; diff --git a/src/features/extraFile.ts b/src/features/extraFile.ts index 855d5b4fd..388dc99f2 100644 --- a/src/features/extraFile.ts +++ b/src/features/extraFile.ts @@ -109,44 +109,7 @@ export class ExtraFile< item.state = 'failed'; item.percentage = undefined; this.publish(); - } - } - - async uploadCommit(efPaths: string[], oakFullpath: string) { - assert(false, '方法已经废弃'); - assert(efPaths && efPaths.length > 0); - let ids = [] as string[]; - if (oakFullpath) { - ids = efPaths - .map((path) => { - const path2 = path ? `${oakFullpath}.${path}` : oakFullpath; - const data = this.runningTree.getFreshValue(path2); - assert( - data, - `efPath为${path}的路径上取不到extraFile数据,请设置正确的相对路径` - ); - return ( - data as Partial[] - ).map((ele) => ele.id); - }) - .flat() - .filter((ele) => !!ele) as string[]; - } - assert(ids.length > 0); - - const promises: Promise[] = []; - ids.forEach((id) => { - const fileState = this.getFileState(id); - if (fileState) { - const { state } = fileState; - if (['local', 'failed'].includes(state)) { - promises.push(this.upload(id)); - } - } - }); - - if (promises.length > 0) { - await Promise.all(promises); + throw err; } }