-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
160 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './components/index'; | ||
export * from './shared.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,71 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { JsonPipe } from '@angular/common'; | ||
import { Component, OnDestroy } from '@angular/core'; | ||
import { Subscription } from 'rxjs'; | ||
|
||
import { STColumn, STComponent, STModule } from '@delon/abc/st'; | ||
import { CacheService } from '@delon/cache'; | ||
import { NzButtonModule } from 'ng-zorro-antd/button'; | ||
|
||
interface User { | ||
id: number; | ||
picture: { | ||
thumbnail: string; | ||
}; | ||
name: { | ||
last: string; | ||
first: string; | ||
}; | ||
nat: string; | ||
gender: string; | ||
email: string; | ||
phone: string; | ||
price: number; | ||
registered: Date; | ||
} | ||
import { NzMessageService } from 'ng-zorro-antd/message'; | ||
|
||
@Component({ | ||
selector: 'app-demo', | ||
template: ` | ||
<button nz-button nzType="primary" (click)="setRow()">setRow Method</button> | ||
<st #st [widthMode]="{ type: 'strict' }" [data]="url" [req]="{ params: params }" [columns]="columns" /> | ||
<p>value: {{ value | json }}</p> | ||
<div class="pt-sm"> | ||
Basic: | ||
<button nz-button (click)="srv.set(key, newValue)">Set</button> | ||
<button nz-button (click)="value = srv.getNone(key)">Get</button> | ||
<button nz-button (click)="srv.remove(key)">Remove</button> | ||
<button nz-button (click)="srv.clear()">Clear</button> | ||
</div> | ||
<div class="pt-sm"> | ||
Key is valid request: | ||
<button nz-button (click)="getByHttp()">Get</button> | ||
</div> | ||
<div class="pt-sm"> | ||
Notify: | ||
<button nz-button (click)="registerNotify()">Register</button> | ||
<button nz-button (click)="unRegisterNotify()">UnRegister</button> | ||
</div> | ||
`, | ||
standalone: true, | ||
imports: [STModule, NzButtonModule] | ||
imports: [JsonPipe, NzButtonModule] | ||
}) | ||
export class DemoComponent { | ||
url = `/users?total=2&field=list`; | ||
params = { a: 1, b: 2 }; | ||
@ViewChild('st', { static: false }) private st!: STComponent; | ||
columns: Array<STColumn<User>> = [ | ||
{ title: '编号', index: 'id', width: 80 }, | ||
{ title: '头像', index: 'picture.thumbnail', type: 'img', width: 60 }, | ||
{ title: '邮箱', index: 'email', width: 80 }, | ||
{ title: '电话', index: 'phone' }, | ||
{ | ||
title: { text: '佣金', optional: '(单位:元)', optionalHelp: '计算公式=订单金额 * 0.6%' }, | ||
index: 'price', | ||
type: 'currency' | ||
}, | ||
{ title: '注册时间', type: 'date', index: 'registered' } | ||
]; | ||
|
||
setRow(): void { | ||
this.st.setRow(0, { price: 100000000 }); | ||
export class DemoComponent implements OnDestroy { | ||
value: any; | ||
key = 'demo'; | ||
private notify$?: Subscription; | ||
|
||
get newValue(): number { | ||
return +new Date(); | ||
} | ||
|
||
constructor( | ||
public srv: CacheService, | ||
private msg: NzMessageService | ||
) {} | ||
|
||
getByHttp(): void { | ||
this.srv.get(`https://randomuser.me/api/?results=1`).subscribe(res => { | ||
this.value = res; | ||
}); | ||
} | ||
|
||
registerNotify(): void { | ||
if (this.notify$) this.notify$.unsubscribe(); | ||
this.notify$ = this.srv.notify(this.key).subscribe(res => { | ||
if (res == null) { | ||
this.msg.success('register success'); | ||
return; | ||
} | ||
this.msg.warning(`"${this.key}" new status: ${res.type}`); | ||
}); | ||
} | ||
|
||
unRegisterNotify(): void { | ||
this.srv.cancelNotify(this.key); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
if (this.notify$) this.notify$.unsubscribe(); | ||
} | ||
} |
Oops, something went wrong.