Skip to content

Commit

Permalink
fix(upload): fileListDisplay and remove params (#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn authored Aug 24, 2022
1 parent a211567 commit 195df43
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/_common
25 changes: 14 additions & 11 deletions src/upload/dragger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
},
cancel: Function as PropType<(e: MouseEvent) => void>,
trigger: Function as PropType<(e: MouseEvent) => void>,
remove: Function as PropType<(e: MouseEvent) => void>,
remove: Function as PropType<({ e, file }: { e: MouseEvent; file: UploadFile }) => void>,
upload: Function as PropType<(file: UploadFile, e: MouseEvent) => void>,
autoUpload: Boolean,
locale: props.locale,
},

data() {
Expand Down Expand Up @@ -106,11 +107,13 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
renderDefaultDragElement(): VNode {
const unActiveElement = (
<div>
<span class={`${this.componentName}--highlight`}>{this.global.triggerUploadText.normal}</span>
<span>&nbsp;&nbsp;/&nbsp;&nbsp;{this.global.dragger.draggingText}</span>
<span class={`${this.componentName}--highlight`}>
{this.locale?.triggerUploadText?.normal || this.global.triggerUploadText.normal}
</span>
<span>&nbsp;&nbsp;/&nbsp;&nbsp;{this.locale?.dragger?.draggingText || this.global.dragger.draggingText}</span>
</div>
);
const activeElement = <div>{this.global.dragger.dragDropText}</div>;
const activeElement = <div>{this.locale?.dragger?.dragDropText || this.global.dragger.dragDropText}</div>;
return this.dragActive ? activeElement : unActiveElement;
},

Expand Down Expand Up @@ -140,7 +143,7 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
},

reUpload(e: MouseEvent) {
this.remove(e);
this.remove({ e, file: this.file });
this.trigger(e);
},

Expand All @@ -159,10 +162,10 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
{!this.loadingFile && !!this.file && <CheckCircleFilledIcon />}
</div>
<small class={`${this.classPrefix}-size-s`}>
{this.global.file.fileSizeText}{returnFileSize(this.size)}
{this.locale?.file?.fileSizeText || this.global.file.fileSizeText}{returnFileSize(this.size)}
</small>
<small class={`${this.classPrefix}-size-s`}>
{this.global.file.fileOperationDateText}{getCurrentDate()}
{this.locale?.file?.fileOperationDateText || this.global.file.fileOperationDateText}{getCurrentDate()}
</small>
<div class={`${this.componentName}__dragger-btns`}>
{['progress', 'waiting'].includes(this.loadingFile?.status) && (
Expand All @@ -172,7 +175,7 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
class={`${this.componentName}__dragger-progress-cancel`}
onClick={this.cancel}
>
{this.global.cancelUploadText}
{this.locale?.cancelUploadText || this.global.cancelUploadText}
</TButton>
)}
{!this.autoUpload && this.loadingFile?.status === 'waiting' && (
Expand All @@ -181,7 +184,7 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
variant="text"
onClick={(e: MouseEvent) => this.upload({ ...this.loadingFile }, e)}
>
{this.global.triggerUploadText.normal}
{this.locale?.triggerUploadText?.normal || this.global.triggerUploadText.normal}
</TButton>
)}
</div>
Expand All @@ -193,10 +196,10 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
class={`${this.componentName}__dragger-progress-cancel`}
onClick={this.reUpload}
>
{this.global.triggerUploadText.reupload}
{this.locale?.triggerUploadText?.reupload || this.global.triggerUploadText.reupload}
</TButton>
<TButton theme="primary" variant="text" onClick={this.remove}>
{this.global.triggerUploadText.delete}
{this.locale?.triggerUploadText?.delete || this.global.triggerUploadText.delete}
</TButton>
</div>
)}
Expand Down
46 changes: 28 additions & 18 deletions src/upload/flow-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
return ['file-flow', 'image-flow'].includes(val);
},
},
locale: props.locale,
},

data() {
Expand Down Expand Up @@ -92,10 +93,12 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
return Boolean(this.waitingUploadFiles && this.waitingUploadFiles.length) && !this.isUploading;
},
uploadText(): string {
if (this.isUploading) return `${this.global.progress.uploadingText}...`;
return this.failedList && this.failedList.length
? this.global.triggerUploadText.reupload
: this.global.triggerUploadText.normal;
const uploadingText = this.locale?.progress?.uploadingText || this.global.progress.uploadingText;
const reuploadText = this.locale?.triggerUploadText?.reupload || this.global.triggerUploadText.reupload;
const normalText = this.locale?.triggerUploadText?.normal || this.global.triggerUploadText.normal;

if (this.isUploading) return `${uploadingText}...`;
return this.failedList && this.failedList.length ? reuploadText : normalText;
},
batchRemoveRow(): boolean {
return this.batchUpload && this.files.length > 0;
Expand All @@ -114,15 +117,15 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
status = (
<div class={`${this.componentName}__flow-status`}>
<CheckCircleFilledIcon />
<span>{this.global.progress.successText}</span>
<span>{this.locale?.progress?.successText || this.global.progress.successText}</span>
</div>
);
break;
case 'fail':
status = (
<div class={`${this.componentName}__flow-status`}>
<ErrorCircleFilledIcon />
<span>{this.global.progress.failText}</span>
<span>{this.locale?.progress?.failText || this.global.progress.failText}</span>
</div>
);
break;
Expand All @@ -131,15 +134,18 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
&& (status = (
<div class={`${this.componentName}__flow-status`}>
<TLoading />
<span>{`${this.global.progress.uploadingText} ${Math.min(file.percent, 99)}%`}</span>
<span>{`${this.locale?.progress?.uploadingText || this.global.progress.uploadingText} ${Math.min(
file.percent,
99,
)}%`}</span>
</div>
));
break;
case 'waiting':
status = (
<div class={`${this.componentName}__flow-status`}>
<TimeFilledIcon />
<span>{this.global.progress.waitingText}</span>
<span>{this.locale?.progress?.waitingText || this.global.progress.waitingText}</span>
</div>
);
break;
Expand Down Expand Up @@ -176,6 +182,9 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
},

renderDragger() {
const dragDropText = this.locale?.dragger?.dragDropText || this.global.dragger.dragDropText;
const clickAndDragText = this.locale?.dragger?.clickAndDragText || this.global.dragger.clickAndDragText;

return (
<div
class={`${this.componentName}__flow-empty`}
Expand All @@ -184,7 +193,7 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
onDragover={this.handleDragover}
onDragleave={this.handleDragleave}
>
{this.dragActive ? this.global.dragger.dragDropText : this.global.dragger.clickAndDragText}
{this.dragActive ? dragDropText : clickAndDragText}
</div>
);
},
Expand All @@ -193,10 +202,10 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
return (
<table class={`${this.componentName}__flow-table`}>
<tr>
<th>{this.global.file.fileNameText}</th>
<th>{this.global.file.fileSizeText}</th>
<th>{this.global.file.fileStatusText}</th>
<th>{this.global.file.fileOperationText}</th>
<th>{this.locale?.file?.fileNameText || this.global.file.fileNameText}</th>
<th>{this.locale?.file?.fileSizeText || this.global.file.fileSizeText}</th>
<th>{this.locale?.file?.fileStatusText || this.global.file.fileStatusText}</th>
<th>{this.locale?.file?.fileOperationText || this.global.file.fileOperationText}</th>
</tr>
{this.showInitial && (
<tr>
Expand Down Expand Up @@ -231,7 +240,7 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
})
}
>
{this.global.triggerUploadText.delete}
{this.locale?.triggerUploadText?.delete || this.global.triggerUploadText.delete}
</span>
</td>
);
Expand All @@ -251,7 +260,7 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
})
}
>
{this.global.triggerUploadText.delete}
{this.locale?.triggerUploadText?.delete || this.global.triggerUploadText.delete}
</span>
</td>
) : (
Expand Down Expand Up @@ -281,14 +290,15 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
{file.status === 'fail' && (
<div class={`${this.componentName}__card-status-wrap`}>
<ErrorCircleFilledIcon />
<p>{this.global.progress.failText}</p>
<p>{this.locale?.progress?.failText || this.global.progress.failText}</p>
</div>
)}
{file.status === 'progress' && (
<div class={`${this.componentName}__card-status-wrap`}>
<TLoading />
<p>
{this.global.progress.uploadingText} {Math.min(file.percent, 99)}
{this.locale?.progress?.uploadingText || this.global.progress.uploadingText}{' '}
{Math.min(file.percent, 99)}
</p>
</div>
)}
Expand Down Expand Up @@ -336,7 +346,7 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
{this.display === 'image-flow' && this.renderImgList()}
<div class={`${this.componentName}__flow-bottom`}>
<TButton theme="default" onClick={this.cancel}>
{this.global.cancelUploadText}
{this.locale?.cancelUploadText || this.global.cancelUploadText}
</TButton>
<TButton
disabled={!this.allowUpload}
Expand Down
3 changes: 2 additions & 1 deletion src/upload/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
<div class={`${this.componentName}__card-container ${this.componentName}__card-box`}>
<TLoading />
<p>
{this.global.progress.uploadingText} {Math.min(this.loadingFile.percent, 99)}%
{this.locale?.progress?.uploadingText || this.global.progress.uploadingText}{' '}
{Math.min(this.loadingFile.percent, 99)}%
</p>
</div>
) : (
Expand Down
20 changes: 12 additions & 8 deletions src/upload/single-file.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PropType } from 'vue';
import { ScopedSlotReturnValue } from 'vue/types/vnode';
import {
CloseCircleFilledIcon as TdCloseCircleFilledIcon,
ErrorCircleFilledIcon as TdErrorCircleFilledIcon,
Expand All @@ -9,7 +8,6 @@ import Loading from '../loading';
import { UploadFile } from './type';
import { ClassName } from '../common';
import { abridgeName } from '../_common/js/upload/utils';
import { renderTNodeJSX } from '../utils/render-tnode';
import props from './props';
import mixins from '../utils/mixins';
import getConfigReceiverMixins, { UploadConfig, getGlobalIconMixins } from '../config-provider/config-receiver';
Expand All @@ -29,14 +27,18 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
showUploadProgress: props.showUploadProgress,
file: Object as PropType<UploadFile>,
loadingFile: Object as PropType<UploadFile>,
remove: Function as PropType<(e: MouseEvent) => void>,
remove: Function as PropType<({ e, file }: { e: MouseEvent; file: UploadFile }) => void>,
placeholder: String,
display: {
type: String as PropType<'file' | 'file-input'>,
validator(val: string) {
return ['file', 'file-input'].includes(val);
},
},
fileListDisplay: {
type: Function,
},
locale: props.locale,
},

computed: {
Expand Down Expand Up @@ -110,19 +112,18 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
// 文本型预览
renderFilePreviewAsText() {
if (!this.inputName) return;
const fileListDisplay: ScopedSlotReturnValue = renderTNodeJSX(this, 'fileListDisplay');
const { CloseCircleFilledIcon } = this.useGlobalIcon({
CloseCircleFilledIcon: TdCloseCircleFilledIcon,
});
return (
<div class={[`${this.componentName}__single-display-text`, `${this.componentName}__display-text--margin`]}>
{fileListDisplay || <span class={`${this.componentName}__single-name`}>{this.inputName}</span>}
{this.fileListDisplay() || <span class={`${this.componentName}__single-name`}>{this.inputName}</span>}
{this.showProgress ? (
this.renderProgress()
) : (
<CloseCircleFilledIcon
class={`${this.componentName}__icon-delete`}
nativeOnClick={(e: MouseEvent) => this.remove(e)}
nativeOnClick={(e: MouseEvent) => this.remove({ e, file: this.file })}
/>
)}
</div>
Expand All @@ -149,8 +150,11 @@ export default mixins(getConfigReceiverMixins<Vue, UploadConfig>('upload'), getG
{this.$scopedSlots.default && this.$scopedSlots.default(null)}
{this.showTextPreview && this.renderFilePreviewAsText()}
{this.showInput && this.showDelete && (
<span class={`${this.componentName}__single-input-delete`} onClick={(e: MouseEvent) => this.remove(e)}>
删除
<span
class={`${this.componentName}__single-input-delete`}
onClick={(e: MouseEvent) => this.remove({ e, file: this.file })}
>
{this.locale?.triggerUploadText?.delete || this.t(this.global.triggerUploadText.delete)}
</span>
)}
</div>
Expand Down
Loading

0 comments on commit 195df43

Please sign in to comment.