extraFile2

This commit is contained in:
Xu Chang 2023-10-26 16:48:43 +08:00
parent 1d3d0d3842
commit 5be2539d48
5 changed files with 50 additions and 29 deletions

View File

@ -2,7 +2,6 @@
import { EntityDict } from '../../../oak-app-domain';
declare const _default: (props: import("oak-frontend-base").ReactComponentProps<EntityDict, keyof EntityDict, boolean, {
action: string | undefined;
efPaths: string[];
size: string;
block: boolean;
type: string;

View File

@ -22,8 +22,7 @@ exports.default = OakComponent({
};
},
properties: {
action: '',
efPaths: [],
action: undefined,
size: 'middle',
block: false,
type: 'primary',
@ -33,30 +32,53 @@ exports.default = OakComponent({
beforeCommit: (() => 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();

View File

@ -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 });
}

View File

@ -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;

View File

@ -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) {