Skip to content

Commit

Permalink
update: experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
kainonly committed Mar 20, 2023
1 parent f4a5349 commit 2955cce
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 33 deletions.
3 changes: 0 additions & 3 deletions library/directives/upload.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import { WpxService } from '../wpx.service';
selector: 'nz-upload[wpxUpload]'
})
export class WpxUploadDirective {
/**
* 自定义后缀,默认上传无后缀
*/
@Input() wpxExt?: string;

constructor(
Expand Down
17 changes: 12 additions & 5 deletions library/media/media.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<nz-space>
<button *nzSpaceItem type="button" nz-button (click)="view()">
<i nz-icon nzType="import"></i>
<span i18n>Import</span>
<span i18n>导入</span>
</button>
<button *nzSpaceItem type="button" nz-button nzType="link" [disabled]="values?.length === 0" (click)="openSort()">
<i nz-icon nzType="sort-descending"></i>
Sort
<span i18n>排序</span>
</button>
</nz-space>

Expand Down Expand Up @@ -36,10 +36,10 @@
</nz-col>
<nz-col></nz-col>
<nz-col>
<a target="_blank" [href]="[x] | wpxAssets" nz-button nzType="text" nz-tooltip="下载">
<a target="_blank" [href]="[x] | wpxAssets" nz-button nzType="text" nz-tooltip="下载" i18n-nz-tooltip>
<i nz-icon nzType="download"></i>
</a>
<button nz-button nzType="text" nz-tooltip="移除" (click)="removeValue(i)">
<button nz-button nzType="text" nz-tooltip="移除" i18n-nz-tooltip (click)="removeValue(i)">
<i nz-icon nzType="delete"></i>
</button>
</nz-col>
Expand All @@ -50,7 +50,14 @@
</nz-row>
</nz-list>

<nz-drawer nzTitle="排序" [nzVisible]="sortVisible" nzPlacement="right" [nzWidth]="420" (nzOnClose)="closeSort()">
<nz-drawer
nzTitle="排序"
i18n-nzTitle
[nzVisible]="sortVisible"
nzPlacement="right"
[nzWidth]="420"
(nzOnClose)="closeSort()"
>
<ng-container *nzDrawerContent>
<nz-list cdkDropList (cdkDropListDropped)="sort($event)">
<nz-list-item *ngFor="let x of values" cdkDrag>
Expand Down
8 changes: 4 additions & 4 deletions library/upload/avatar/avatar.component.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<nz-upload
class="upload"
wpxUpload
[wpxExt]="wpxExt"
nzListType="picture-card"
[wpxExt]="wpxExt"
[nzAccept]="wpxAccept"
[nzFileType]="wpxAccept | wpxJoin : ','"
(nzChange)="change($event)"
>
<ng-container *ngIf="value; else uploadBtn">
<ng-container *ngIf="url; else uploadBtn">
<img
style="width: 100%"
wpxRetry
nz-image
nzDisablePreview
[nzSrc]="[value, 'thumbnail'] | wpxAssets"
[nzSrc]="[url, 'thumbnail'] | wpxAssets"
[nzFallback]="wpxFallback"
alt=""
/>
Expand Down
8 changes: 0 additions & 8 deletions library/upload/avatar/avatar.component.scss

This file was deleted.

11 changes: 5 additions & 6 deletions library/upload/avatar/avatar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { NzUploadChangeParam } from 'ng-zorro-antd/upload';
@Component({
selector: 'wpx-upload-avatar',
templateUrl: './avatar.component.html',
styleUrls: ['./avatar.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
Expand All @@ -22,7 +21,7 @@ export class WpxUploadAvatarComponent implements ControlValueAccessor {
@Input() wpxFallback!: string;

loading = false;
value?: string;
url?: string;

private onChange!: (value: string) => void;
private onTouched!: () => void;
Expand All @@ -38,17 +37,17 @@ export class WpxUploadAvatarComponent implements ControlValueAccessor {
}

writeValue(v: any): void {
this.value = v;
this.url = v;
}

change(info: NzUploadChangeParam): void {
if (info.type === 'start') {
this.value = undefined;
this.url = undefined;
this.loading = true;
}
if (info.type === 'success') {
this.value = Reflect.get(info.file.originFileObj!, 'key');
this.onChange(this.value!);
this.url = Reflect.get(info.file.originFileObj!, 'key');
this.onChange(this.url!);
this.loading = false;
this.message.success($localize`上传成功`);
}
Expand Down
6 changes: 1 addition & 5 deletions library/wpx.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ export class WpxService {
this.document.location = `${l.origin}/${id}/${l.hash}`;
}

/**
* @deprecated
* 对象存储预签名
*/
cosPresigned(): Observable<any> {
return this.http.get(`tencent/cos-presigned`);
return this.http.get(`tencent/cos_presigned`);
}

/**
Expand Down
14 changes: 13 additions & 1 deletion src/experiment/plugins/upload/upload.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nz-card>
<form nz-form nzLayout="vertical" id="form" [formGroup]="form" (wpxSubmit)="submit($event)">
<nz-form-item>
<nz-form-label>Avatar</nz-form-label>
<nz-form-label>头像</nz-form-label>
<nz-form-control>
<wpx-upload-avatar
wpxExt="image"
Expand All @@ -12,5 +12,17 @@
</wpx-upload-avatar>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>媒体</nz-form-label>
<nz-form-control>
<wpx-media
[wpxType]="'pictures'"
[wpxFallback]="['assets', 'photon.svg'] | wpxAssets"
[wpxLimit]="5"
[wpxMax]="5"
formControlName="media"
></wpx-media>
</nz-form-control>
</nz-form-item>
</form>
</nz-card>
3 changes: 2 additions & 1 deletion src/experiment/plugins/upload/upload.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class UploadComponent implements OnInit {

ngOnInit(): void {
this.form = this.fb.group({
avatar: [null]
avatar: [null],
media: [[]]
});
}

Expand Down

0 comments on commit 2955cce

Please sign in to comment.