extrafile2
This commit is contained in:
parent
5ce7619b3e
commit
7daedef769
|
|
@ -6,5 +6,6 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps<
|
|||
block: boolean;
|
||||
type: string;
|
||||
executeText: string;
|
||||
buttonProps: {};
|
||||
}>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
||||
export default _default;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export default OakComponent({
|
|||
block: false,
|
||||
type: 'primary',
|
||||
executeText: '',
|
||||
buttonProps: {},
|
||||
},
|
||||
methods: {
|
||||
getEfIds() {
|
||||
|
|
@ -32,7 +33,7 @@ export default OakComponent({
|
|||
assert(efPaths);
|
||||
if (oakFullpath) {
|
||||
const ids = efPaths.map((path) => {
|
||||
const path2 = path ? `${oakFullpath}.path` : oakFullpath;
|
||||
const path2 = path ? `${oakFullpath}.${path}` : oakFullpath;
|
||||
const data = this.features.runningTree.getFreshValue(path2);
|
||||
if (data) {
|
||||
return data.map(ele => ele.id);
|
||||
|
|
@ -42,7 +43,22 @@ export default OakComponent({
|
|||
}
|
||||
return [];
|
||||
},
|
||||
upload() {
|
||||
async upload() {
|
||||
const ids = this.getEfIds();
|
||||
const promises = [];
|
||||
ids.forEach((id) => {
|
||||
const fileState = this.features.extraFile2.getFileState(id);
|
||||
if (fileState) {
|
||||
const { state } = fileState;
|
||||
if (['local', 'failed'].includes(state)) {
|
||||
promises.push(this.features.extraFile2.upload(id));
|
||||
}
|
||||
}
|
||||
});
|
||||
if (promises.length > 0) {
|
||||
await Promise.all(promises);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
features: ['extraFile2'],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
|
|||
block?: ButtonProps['block'];
|
||||
type?: ButtonProps['type'];
|
||||
executeText?: string;
|
||||
buttonProps?: ButtonProps;
|
||||
}, {
|
||||
upload: () => Promise<void>;
|
||||
}>): import("react/jsx-runtime").JSX.Element;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { Button } from 'antd-mobile';
|
||||
export default function render(props) {
|
||||
const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText } = props.data;
|
||||
const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps } = props.data;
|
||||
const { t, upload, execute } = props.methods;
|
||||
const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable === false && ['uploaded'].includes(state));
|
||||
let text = executeText || t('common::action.confirm');
|
||||
|
|
@ -24,5 +24,5 @@ export default function render(props) {
|
|||
else {
|
||||
await upload();
|
||||
}
|
||||
}, children: text }));
|
||||
}, ...buttonProps, children: text }));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
|
|||
block?: ButtonProps['block'];
|
||||
type?: ButtonProps['type'];
|
||||
executeText?: string;
|
||||
buttonProps?: ButtonProps;
|
||||
}, {
|
||||
upload: () => Promise<void>;
|
||||
}>): import("react/jsx-runtime").JSX.Element;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { Button } from 'antd';
|
||||
export default function render(props) {
|
||||
const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText } = props.data;
|
||||
const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps = {} } = props.data;
|
||||
const { t, upload, execute } = props.methods;
|
||||
const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable !== true && ['uploaded'].includes(state));
|
||||
let text = executeText || t('common::action.confirm');
|
||||
|
|
@ -24,5 +24,5 @@ export default function render(props) {
|
|||
else {
|
||||
await upload();
|
||||
}
|
||||
}, children: text }));
|
||||
}, ...buttonProps, children: text }));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { bytesToSize, getFileURL } from '../utils/extraFile';
|
|||
import { assert } from 'oak-domain/lib/utils/assert';
|
||||
import { getCos } from '../utils/cos';
|
||||
import { unset } from 'oak-domain/lib/utils/lodash';
|
||||
import { generateNewIdAsync } from 'oak-domain';
|
||||
export class ExtraFile2 extends Feature {
|
||||
cache;
|
||||
application;
|
||||
|
|
@ -62,9 +63,19 @@ export class ExtraFile2 extends Feature {
|
|||
item.state = 'uploading';
|
||||
item.percentage = 0;
|
||||
const up = new Upload();
|
||||
const cos = getCos(origin);
|
||||
try {
|
||||
const cos = getCos(extraFile.origin);
|
||||
await cos.upload(extraFile, up.uploadFile, file);
|
||||
await this.cache.exec('operate', {
|
||||
entity: 'extraFile',
|
||||
operation: {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'update',
|
||||
data: {
|
||||
uploadState: 'success',
|
||||
},
|
||||
},
|
||||
});
|
||||
item.state = 'uploaded';
|
||||
item.percentage = undefined;
|
||||
this.publish();
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps<
|
|||
block: boolean;
|
||||
type: string;
|
||||
executeText: string;
|
||||
buttonProps: {};
|
||||
}>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
||||
export default _default;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ exports.default = OakComponent({
|
|||
block: false,
|
||||
type: 'primary',
|
||||
executeText: '',
|
||||
buttonProps: {},
|
||||
},
|
||||
methods: {
|
||||
getEfIds() {
|
||||
|
|
@ -35,7 +36,7 @@ exports.default = OakComponent({
|
|||
(0, assert_1.default)(efPaths);
|
||||
if (oakFullpath) {
|
||||
const ids = efPaths.map((path) => {
|
||||
const path2 = path ? `${oakFullpath}.path` : oakFullpath;
|
||||
const path2 = path ? `${oakFullpath}.${path}` : oakFullpath;
|
||||
const data = this.features.runningTree.getFreshValue(path2);
|
||||
if (data) {
|
||||
return data.map(ele => ele.id);
|
||||
|
|
@ -45,7 +46,22 @@ exports.default = OakComponent({
|
|||
}
|
||||
return [];
|
||||
},
|
||||
upload() {
|
||||
async upload() {
|
||||
const ids = this.getEfIds();
|
||||
const promises = [];
|
||||
ids.forEach((id) => {
|
||||
const fileState = this.features.extraFile2.getFileState(id);
|
||||
if (fileState) {
|
||||
const { state } = fileState;
|
||||
if (['local', 'failed'].includes(state)) {
|
||||
promises.push(this.features.extraFile2.upload(id));
|
||||
}
|
||||
}
|
||||
});
|
||||
if (promises.length > 0) {
|
||||
await Promise.all(promises);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
features: ['extraFile2'],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
|
|||
block?: ButtonProps['block'];
|
||||
type?: ButtonProps['type'];
|
||||
executeText?: string;
|
||||
buttonProps?: ButtonProps;
|
||||
}, {
|
||||
upload: () => Promise<void>;
|
||||
}>): import("react/jsx-runtime").JSX.Element;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
const jsx_runtime_1 = require("react/jsx-runtime");
|
||||
const antd_mobile_1 = require("antd-mobile");
|
||||
function render(props) {
|
||||
const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText } = props.data;
|
||||
const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps } = props.data;
|
||||
const { t, upload, execute } = props.methods;
|
||||
const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable === false && ['uploaded'].includes(state));
|
||||
let text = executeText || t('common::action.confirm');
|
||||
|
|
@ -26,6 +26,6 @@ function render(props) {
|
|||
else {
|
||||
await upload();
|
||||
}
|
||||
}, children: text }));
|
||||
}, ...buttonProps, children: text }));
|
||||
}
|
||||
exports.default = render;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
|
|||
block?: ButtonProps['block'];
|
||||
type?: ButtonProps['type'];
|
||||
executeText?: string;
|
||||
buttonProps?: ButtonProps;
|
||||
}, {
|
||||
upload: () => Promise<void>;
|
||||
}>): import("react/jsx-runtime").JSX.Element;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
const jsx_runtime_1 = require("react/jsx-runtime");
|
||||
const antd_1 = require("antd");
|
||||
function render(props) {
|
||||
const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText } = props.data;
|
||||
const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps = {} } = props.data;
|
||||
const { t, upload, execute } = props.methods;
|
||||
const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable !== true && ['uploaded'].includes(state));
|
||||
let text = executeText || t('common::action.confirm');
|
||||
|
|
@ -26,6 +26,6 @@ function render(props) {
|
|||
else {
|
||||
await upload();
|
||||
}
|
||||
}, children: text }));
|
||||
}, ...buttonProps, children: text }));
|
||||
}
|
||||
exports.default = render;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ const extraFile_1 = require("../utils/extraFile");
|
|||
const assert_1 = require("oak-domain/lib/utils/assert");
|
||||
const cos_1 = require("../utils/cos");
|
||||
const lodash_1 = require("oak-domain/lib/utils/lodash");
|
||||
const oak_domain_1 = require("oak-domain");
|
||||
class ExtraFile2 extends oak_frontend_base_1.Feature {
|
||||
cache;
|
||||
application;
|
||||
|
|
@ -65,9 +66,19 @@ class ExtraFile2 extends oak_frontend_base_1.Feature {
|
|||
item.state = 'uploading';
|
||||
item.percentage = 0;
|
||||
const up = new upload_1.Upload();
|
||||
const cos = (0, cos_1.getCos)(origin);
|
||||
try {
|
||||
const cos = (0, cos_1.getCos)(extraFile.origin);
|
||||
await cos.upload(extraFile, up.uploadFile, file);
|
||||
await this.cache.exec('operate', {
|
||||
entity: 'extraFile',
|
||||
operation: {
|
||||
id: await (0, oak_domain_1.generateNewIdAsync)(),
|
||||
action: 'update',
|
||||
data: {
|
||||
uploadState: 'success',
|
||||
},
|
||||
},
|
||||
});
|
||||
item.state = 'uploaded';
|
||||
item.percentage = undefined;
|
||||
this.publish();
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ export default OakComponent({
|
|||
block: false,
|
||||
type: 'primary',
|
||||
executeText: '',
|
||||
buttonProps: {},
|
||||
},
|
||||
methods: {
|
||||
getEfIds() {
|
||||
|
|
@ -40,7 +41,7 @@ export default OakComponent({
|
|||
if (oakFullpath) {
|
||||
const ids = efPaths.map(
|
||||
(path) => {
|
||||
const path2 = path ? `${oakFullpath}.path` : oakFullpath;
|
||||
const path2 = path ? `${oakFullpath}.${path}` : oakFullpath;
|
||||
const data = this.features.runningTree.getFreshValue(path2);
|
||||
if (data) {
|
||||
return (data as EntityDict['extraFile']['OpSchema'][]).map(
|
||||
|
|
@ -55,8 +56,26 @@ export default OakComponent({
|
|||
}
|
||||
return [];
|
||||
},
|
||||
upload() {
|
||||
async upload() {
|
||||
const ids = this.getEfIds();
|
||||
|
||||
const promises: Promise<void>[] = [];
|
||||
ids.forEach(
|
||||
(id) => {
|
||||
const fileState = this.features.extraFile2.getFileState(id);
|
||||
if (fileState) {
|
||||
const { state } = fileState;
|
||||
if (['local', 'failed'].includes(state)) {
|
||||
promises.push(this.features.extraFile2.upload(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (promises.length > 0) {
|
||||
await Promise.all(promises);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
features: ['extraFile2'],
|
||||
});
|
||||
|
|
@ -10,11 +10,12 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
|
|||
block?: ButtonProps['block'];
|
||||
type?: ButtonProps['type'];
|
||||
executeText?: string;
|
||||
buttonProps?: ButtonProps;
|
||||
}, {
|
||||
upload: () => Promise<void>
|
||||
}>) {
|
||||
const { state, oakExecutable, oakExecuting, oakDirty,
|
||||
size, block, type, executeText } = props.data;
|
||||
size, block, type, executeText, buttonProps = {} } = props.data;
|
||||
const { t, upload, execute } = props.methods;
|
||||
|
||||
const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable !== true && ['uploaded'].includes(state));
|
||||
|
|
@ -46,6 +47,7 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
|
|||
await upload();
|
||||
}
|
||||
}}
|
||||
{...buttonProps}
|
||||
>
|
||||
{text}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -10,11 +10,12 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
|
|||
block?: ButtonProps['block'];
|
||||
type?: ButtonProps['type'];
|
||||
executeText?: string;
|
||||
buttonProps?: ButtonProps;
|
||||
}, {
|
||||
upload: () => Promise<void>
|
||||
}>) {
|
||||
const { state, oakExecutable, oakExecuting, oakDirty,
|
||||
size, block, type, executeText } = props.data;
|
||||
size, block, type, executeText, buttonProps } = props.data;
|
||||
const { t, upload, execute } = props.methods;
|
||||
|
||||
const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable === false && ['uploaded'].includes(state));
|
||||
|
|
@ -46,6 +47,7 @@ export default function render(props: WebComponentProps<EntityDict, any, true, {
|
|||
await upload();
|
||||
}
|
||||
}}
|
||||
{...buttonProps}
|
||||
>
|
||||
{text}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import { assert } from 'oak-domain/lib/utils/assert';
|
|||
import { getCos } from '../utils/cos';
|
||||
import { OpSchema } from '../oak-app-domain/ExtraFile/Schema';
|
||||
import { unset } from 'oak-domain/lib/utils/lodash';
|
||||
import { generateNewIdAsync } from 'oak-domain';
|
||||
|
||||
export type FileState = 'local' | 'uploading' | 'uploaded' | 'failed';
|
||||
|
||||
|
|
@ -94,13 +95,23 @@ export class ExtraFile2<
|
|||
item.percentage = 0;
|
||||
|
||||
const up = new Upload();
|
||||
const cos = getCos<ED, Cxt, FrontCxt>(origin);
|
||||
try {
|
||||
const cos = getCos<ED, Cxt, FrontCxt>(extraFile.origin!);
|
||||
await cos.upload(
|
||||
extraFile as OpSchema,
|
||||
up.uploadFile,
|
||||
file
|
||||
);
|
||||
await this.cache.exec('operate', {
|
||||
entity: 'extraFile',
|
||||
operation: {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'update',
|
||||
data: {
|
||||
uploadState: 'success',
|
||||
},
|
||||
} as ED['extraFile']['Operation'],
|
||||
});
|
||||
item.state = 'uploaded';
|
||||
item.percentage = undefined;
|
||||
this.publish();
|
||||
|
|
|
|||
Loading…
Reference in New Issue