Skip to content

Commit 7b7971f

Browse files
hpyourdkmaster
authored andcommitted
[新增] 新增穿梭(Transfer)组件,支持大数据量的呈现和选择
1 parent 1281075 commit 7b7971f

28 files changed

+1018
-36
lines changed

src/app/app.interceptor.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {PagingInfo} from "../jigsaw/core/data/component-data";
88
@Injectable()
99
export class AjaxInterceptor implements HttpInterceptor {
1010

11-
private static _usingRealRDK: boolean = false;
11+
private static _usingRealRDK: boolean = true;
1212
private static _processors: any[] = [];
1313

1414
public static registerProcessor(urlPattern: RegExp | string, processor: (req: HttpRequest<any>) => any, context?: any) {
@@ -49,9 +49,12 @@ export class AjaxInterceptor implements HttpInterceptor {
4949
dealServerSidePagingRequest(req: HttpRequest<any>): Observable<HttpEvent<any>> {
5050
const params = req.method.toLowerCase() == 'post' ? 'body' : 'params';
5151
const service = this.getParamValue(req, params, 'service');
52-
const paging = this.getParamValue(req, params, 'paging') ? JSON.parse(this.getParamValue(req, params, 'paging')) : null;
53-
const filter = this.getParamValue(req, params, 'filter') ? JSON.parse(this.getParamValue(req, params, 'filter')) : null;
54-
const sort = this.getParamValue(req, params, 'sort') ? JSON.parse(this.getParamValue(req, params, 'sort')) : null;
52+
let paging = this.getParamValue(req, params, 'paging') ? this.getParamValue(req, params, 'paging') : null;
53+
paging = typeof paging === 'string' ? JSON.stringify(paging) : paging;
54+
let filter = this.getParamValue(req, params, 'filter') ? this.getParamValue(req, params, 'filter') : null;
55+
filter = typeof filter === 'string' ? JSON.stringify(filter) : filter;
56+
let sort = this.getParamValue(req, params, 'sort') ? this.getParamValue(req, params, 'sort') : null;
57+
sort = typeof sort === 'string' ? JSON.stringify(sort) : sort;
5558
return PageableData.get({service, paging, filter, sort});
5659
}
5760

@@ -176,7 +179,7 @@ class PageableData {
176179
}
177180

178181
private static _filter(dataTable, filter) {
179-
return filter.hasOwnProperty('rawFunction') ?
182+
return filter.hasOwnProperty('rawFunction') && !!filter.rawFunction ?
180183
this._filterWithFunction(dataTable.data, filter.rawFunction, filter.context) :
181184
this._filterWithKeyword(dataTable.data, filter.key, filter.field, dataTable.field);
182185
}
@@ -222,7 +225,7 @@ class PageableData {
222225
private static _filterWithFunction(data, rawFunction, context) {
223226
let func;
224227
try {
225-
func = eval('(' + rawFunction.replace(/\b_this\b/g, 'this') + ')');
228+
func = eval('(' + rawFunction + ')');
226229
} catch (e) {
227230
console.error('eval raw filter function error, detail: ' + e.message);
228231
return data;

src/app/demo-list.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {routerConfig as treeConfig} from "./demo/tree/demo-set.module";
4747
import {routerConfig as trustedHtmlConfig} from "./demo/trusted-html/demo-set.module";
4848
import {routerConfig as uploadConfig} from "./demo/upload/demo-set.module";
4949
import {routerConfig as iconConfig} from "./demo/icon/demo-set.module";
50+
import {routerConfig as transferConfig} from "./demo/transfer/demo-set.module";
5051
import {routerConfig} from "./router-config";
5152

5253
@Component({
@@ -140,6 +141,7 @@ export class DemoListManager {
140141
this._addRouterConfig(routerConfig, 'trusted-html', trustedHtmlConfig);
141142
this._addRouterConfig(routerConfig, 'upload', uploadConfig);
142143
this._addRouterConfig(routerConfig, 'icon', iconConfig);
144+
this._addRouterConfig(routerConfig, 'transfer', transferConfig);
143145
}
144146

145147
private static _addRouterConfig(routerConfig: any[], path: string, childConfig: any[]) {

src/app/demo/pagination/basic/demo.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ <h3>默认模式</h3>
2323
<div class="demo-2 live-demo">
2424
<h3>简约模式</h3>
2525
<jigsaw-pagination [data]="pageableForSimple"
26-
[showQuickJumper]="true"
2726
(currentChange)="getCurrentPage($event)"
2827
mode="simple">
2928
</jigsaw-pagination>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- ignore the following lines, they are not important to this demo -->
2+
<jigsaw-demo-description [summary]="summary" [content]="description">
3+
</jigsaw-demo-description>
4+
5+
6+
<!-- start to learn the demo from here -->
7+
8+
<div class="live-demo-wrap">
9+
<h2>Transfer</h2>
10+
<div class="demo-1 live-demo">
11+
<h3>普通数据</h3>
12+
<j-transfer width="100%" height="500" [data]="data" labelField="zhName" subLabelField="shortName"
13+
[searchable]="true" (selectedItemsChange)="handleSelectChange($event)"
14+
[selectedItems]="selectedCountries"></j-transfer>
15+
<p class="message">选择的地区:{{selectedCountriesStr}}</p>
16+
</div>
17+
</div>
18+
19+
20+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {Component} from "@angular/core";
2+
import {HttpClient} from "@angular/common/http";
3+
import {ArrayCollection, LocalPageableArray} from "jigsaw/core/data/array-collection";
4+
import {TableData} from "jigsaw/core/data/table-data";
5+
6+
@Component({
7+
templateUrl: './demo.component.html'
8+
})
9+
export class TransferArrayDemoComponent {
10+
constructor(private _http: HttpClient) {
11+
this.data = new ArrayCollection();
12+
this.data.http = _http;
13+
this.data.fromAjax('mock-data/countries');
14+
this.data.dataReviser = (td: TableData) => TableData.toArray(td);
15+
16+
this.selectedCountries = new ArrayCollection();
17+
this.selectedCountries.http = _http;
18+
this.selectedCountries.fromAjax('mock-data/countries');
19+
this.selectedCountries.dataReviser = (td: TableData) => TableData.toArray(td).slice(0,5);
20+
}
21+
22+
data: ArrayCollection<any>;
23+
selectedCountries: ArrayCollection<any>;
24+
selectedCountriesStr: string;
25+
26+
handleSelectChange($event) {
27+
this.selectedCountriesStr = $event.map(item => item.zhName).join(',');
28+
}
29+
30+
// ====================================================================
31+
// ignore the following lines, they are not important to this demo
32+
// ====================================================================
33+
summary: string = '';
34+
description: string = '';
35+
36+
}
37+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {NgModule} from "@angular/core";
2+
import {JigsawDemoDescriptionModule} from "app/demo-description/demo-description";
3+
import {TransferArrayDemoComponent} from "./demo.component";
4+
import {JigsawTransferModule} from "jigsaw/component/transfer/transfer";
5+
6+
@NgModule({
7+
declarations: [TransferArrayDemoComponent],
8+
exports: [ TransferArrayDemoComponent ],
9+
imports: [JigsawDemoDescriptionModule, JigsawTransferModule]
10+
})
11+
export class TransferArrayDemoModule{
12+
13+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {NgModule} from "@angular/core";
2+
import {RouterModule} from "@angular/router";
3+
import {TransferArrayDemoComponent} from "./basic/demo.component";
4+
import {TransferArrayDemoModule} from "./basic/demo.module";
5+
import {TransferLocalPageableArrayComponent} from "./local-pageable-array/demo.component";
6+
import {TransferLocalPageableArrayDemoModule} from "./local-pageable-array/demo.module";
7+
import {TransferPageableArrayComponent} from "./pageable-array/demo.component";
8+
import {TransferPageableArrayDemoModule} from "./pageable-array/demo.module";
9+
import {TransferItemDisabledDemoComponent} from "./item-disabled/demo.component";
10+
import {TransferItemDisabledDemoModule} from "./item-disabled/demo.module";
11+
12+
export const routerConfig = [
13+
{
14+
path: 'basic', component: TransferArrayDemoComponent
15+
},
16+
{
17+
path: 'local-pageable-array', component: TransferLocalPageableArrayComponent
18+
},
19+
{
20+
path: 'pageable-array', component: TransferPageableArrayComponent
21+
},
22+
{
23+
path: 'item-disabled', component: TransferItemDisabledDemoComponent
24+
}
25+
];
26+
27+
@NgModule({
28+
imports: [
29+
RouterModule.forChild(routerConfig),
30+
TransferArrayDemoModule,
31+
TransferLocalPageableArrayDemoModule,
32+
TransferPageableArrayDemoModule,
33+
TransferItemDisabledDemoModule
34+
]
35+
})
36+
export class TransferDemoModule {
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- ignore the following lines, they are not important to this demo -->
2+
<jigsaw-demo-description [summary]="summary" [content]="description">
3+
</jigsaw-demo-description>
4+
5+
6+
<!-- start to learn the demo from here -->
7+
8+
<div class="live-demo-wrap">
9+
<h2>Transfer</h2>
10+
<div class="demo-1 live-demo">
11+
<h3>随机设置不可操作条目</h3>
12+
<j-transfer width="100%" height="500" [data]="data" labelField="zhName" subLabelField="enName"></j-transfer>
13+
</div>
14+
</div>
15+
16+
17+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {Component} from "@angular/core";
2+
import {HttpClient} from "@angular/common/http";
3+
import {ArrayCollection} from "jigsaw/core/data/array-collection";
4+
import {TableData} from "jigsaw/core/data/table-data";
5+
6+
@Component({
7+
templateUrl: './demo.component.html'
8+
})
9+
export class TransferItemDisabledDemoComponent {
10+
constructor(private _http: HttpClient) {
11+
this.data = new ArrayCollection();
12+
this.data.http = _http;
13+
this.data.fromAjax('mock-data/countries');
14+
this.data.dataReviser = (td: TableData) => {
15+
return TableData.toArray(td).map(item => {
16+
item.disabled = Math.random() > 0.8;
17+
return item;
18+
})
19+
}
20+
}
21+
22+
data: ArrayCollection<any>;
23+
24+
// ====================================================================
25+
// ignore the following lines, they are not important to this demo
26+
// ====================================================================
27+
summary: string = '';
28+
description: string = '';
29+
30+
}
31+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {NgModule} from "@angular/core";
2+
import {JigsawTransferModule} from "jigsaw/component/transfer/transfer";
3+
import {JigsawDemoDescriptionModule} from "app/demo-description/demo-description";
4+
import {TransferItemDisabledDemoComponent} from "./demo.component";
5+
6+
@NgModule({
7+
declarations: [TransferItemDisabledDemoComponent],
8+
exports: [ TransferItemDisabledDemoComponent ],
9+
imports: [JigsawDemoDescriptionModule, JigsawTransferModule]
10+
})
11+
export class TransferItemDisabledDemoModule{
12+
13+
}

0 commit comments

Comments
 (0)