extraFile upload

This commit is contained in:
Wang Kejun 2023-10-25 12:37:10 +08:00
parent a7848d5273
commit 60a6677191
6 changed files with 43 additions and 67 deletions

View File

@ -0,0 +1,5 @@
/** index.wxss **/
.btn {
display: flex;
}

View File

@ -22,7 +22,7 @@ export default OakComponent({
};
},
properties: {
action: '' as (string | undefined),
action: '' as string | undefined,
efPaths: [] as string[],
size: 'middle',
block: false,
@ -30,7 +30,10 @@ export default OakComponent({
executeText: '',
buttonProps: {},
afterCommit: () => {},
beforeCommit: (() => true) as () => boolean | undefined | Promise<boolean | undefined>,
beforeCommit: (() => true) as () =>
| boolean
| undefined
| Promise<boolean | undefined>,
},
methods: {
getEfIds() {
@ -78,6 +81,28 @@ export default OakComponent({
await Promise.all(promises);
}
},
async onSubmit() {
const { oakExecutable } = this.state;
const { beforeCommit, afterCommit, action } = this.props;
if (oakExecutable) {
if (beforeCommit) {
const beforeCommitResult = await beforeCommit();
if (beforeCommitResult === false) {
return;
}
}
await this.execute(action || undefined);
await this.upload();
if (afterCommit) {
afterCommit();
}
} else {
await this.upload();
if (afterCommit) {
afterCommit();
}
}
},
},
features: ['extraFile2'],
});

View File

@ -0,0 +1,4 @@
<!-- index.wxml -->
<l-button size="long" disabled="{{disabled}}" type="default" bind:lintap="onSubmit">
{{ executeText || t('common:submit') }}
</l-button>

View File

@ -17,11 +17,9 @@ export default function render(
executeText?: string;
action?: string;
buttonProps?: ButtonProps;
afterCommit?: () => void;
beforeCommit?: () => Promise<boolean> | boolean;
},
{
upload: () => Promise<void>;
onSubmit: () => Promise<void>;
}
>
) {
@ -34,11 +32,8 @@ export default function render(
type,
executeText,
buttonProps = {},
action,
afterCommit,
beforeCommit,
} = props.data;
const { t, upload, execute } = props.methods;
const { t, onSubmit } = props.methods;
const disabled =
oakExecuting ||
@ -61,26 +56,7 @@ export default function render(
size={size}
block={block}
disabled={disabled}
onClick={async () => {
if (oakExecutable) {
if (beforeCommit) {
const beforeCommitResult = await beforeCommit();
if (beforeCommitResult === false) {
return;
}
}
await execute(action || undefined);
await upload();
if (afterCommit) {
afterCommit();
}
} else {
await upload();
if (afterCommit) {
afterCommit();
}
}
}}
onClick={onSubmit}
{...buttonProps}
>
{text}

View File

@ -17,14 +17,9 @@ export default function render(
executeText?: string;
action?: string;
buttonProps?: ButtonProps;
beforeCommit?: () =>
| Promise<boolean | undefined>
| boolean
| undefined;
afterCommit?: () => void;
},
{
upload: () => Promise<void>;
onSubmit: () => Promise<void>;
}
>
) {
@ -38,11 +33,8 @@ export default function render(
type,
executeText,
buttonProps,
action,
beforeCommit,
afterCommit,
} = props.data;
const { t, upload, execute } = props.methods;
const { t, onSubmit } = props.methods;
const disabled =
oakExecuting ||
@ -65,26 +57,7 @@ export default function render(
size={size}
block={block}
disabled={disabled}
onClick={async () => {
if (oakExecutable) {
if (beforeCommit) {
const beforeCommitResult = await beforeCommit();
if (beforeCommitResult === false) {
return;
}
}
await execute(action || undefined);
await upload();
if (afterCommit) {
afterCommit();
}
} else {
await upload();
if (afterCommit) {
afterCommit();
}
}
}}
onClick={onSubmit}
{...buttonProps}
>
{text}

View File

@ -280,7 +280,7 @@ export default OakComponent({
const { errMsg, tempFiles } = await wx.chooseMessageFile({
count: selectCount!,
type: 'all',
extension,
...(extension && extension.length > 0 ? { extension } : {}),
});
if (errMsg !== 'chooseMessageFile:ok') {
this.triggerEvent('onError', {
@ -329,19 +329,12 @@ export default OakComponent({
const imageUrl = files[index].url;
const urls = files?.filter((ele) => !!ele).map((ele) => ele.url);
const detail = {
all: files,
index,
urls,
current: imageUrl,
};
// 预览图片
if (!this.props.disablePreview) {
const result = await wx.previewImage({
urls: urls,
current: imageUrl,
});
this.triggerEvent('onPreview', detail);
}
},
getSort(index: number = 0) {