geminis-ng
Version:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.2.14.
1,448 lines (1,413 loc) • 81.7 kB
JavaScript
import { Injectable, NgModule, Component, EventEmitter, forwardRef, Input, Output, Directive, ElementRef, Renderer2, ChangeDetectorRef, Optional, ViewChild, HostBinding, ComponentFactoryResolver, TemplateRef, ViewContainerRef, ContentChildren, HostListener } from '@angular/core';
import { NzMessageService, NzMessageModule } from 'ng-zorro-antd/message';
import { NzNotificationService, NzNotificationModule } from 'ng-zorro-antd/notification';
import { Router, RouterModule, ActivatedRoute } from '@angular/router';
import { HttpClientModule, HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
import { JwtHelperService } from '@auth0/angular-jwt';
import { NzIconService, NzIconModule } from 'ng-zorro-antd/icon';
import zh from '@angular/common/locales/zh';
import { registerLocaleData, CommonModule } from '@angular/common';
import { __decorate } from 'tslib';
import { NG_VALUE_ACCESSOR, FormsModule, FormGroupDirective, FormGroup, ControlContainer, ReactiveFormsModule } from '@angular/forms';
import { NzInputNumberComponent, NzInputNumberModule } from 'ng-zorro-antd/input-number';
import { NzSwitchComponent, NzSwitchModule } from 'ng-zorro-antd/switch';
import { NzDatePickerComponent } from 'ng-zorro-antd/date-picker';
import { NzSliderComponent } from 'ng-zorro-antd/slider';
import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
import { NzFormDirective, NzFormControlComponent, NzFormModule } from 'ng-zorro-antd/form';
import { DomSanitizer } from '@angular/platform-browser';
import { GnObjectUtils, GnJsonUtils, GnFormUtils, pipeTypes } from 'geminis-ng-core';
import { NzModalRef, NzModalService, NzModalModule } from 'ng-zorro-antd/modal';
import { NzInputModule } from 'ng-zorro-antd/input';
import SHA256 from 'crypto-js/sha256';
import HEX from 'crypto-js/enc-hex';
import { NzRadioModule } from 'ng-zorro-antd/radio';
import { NzSelectModule } from 'ng-zorro-antd/select';
import { NzSpinModule } from 'ng-zorro-antd/spin';
import { NzTableComponent, NzTableModule } from 'ng-zorro-antd/table';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';
import { NzLayoutModule } from 'ng-zorro-antd/layout';
import { NzMenuModule } from 'ng-zorro-antd/menu';
import { NzTreeComponent } from 'ng-zorro-antd/tree';
import { Observable } from 'rxjs';
class GnMessageService {
constructor(messageService, notificationService) {
this.messageService = messageService;
this.notificationService = notificationService;
}
success(content) {
this.messageService.success(content);
}
error(content) {
this.notificationService.error('错误', content);
}
warn(content) {
this.notificationService.warning('提示', content);
}
clean() {
this.messageService.remove();
this.notificationService.remove();
}
}
GnMessageService.decorators = [
{ type: Injectable }
];
GnMessageService.ctorParameters = () => [
{ type: NzMessageService },
{ type: NzNotificationService }
];
class GnMessageServiceModule {
}
GnMessageServiceModule.decorators = [
{ type: NgModule, args: [{
imports: [
NzMessageModule,
NzNotificationModule
],
providers: [GnMessageService]
},] }
];
class GnLoginUser {
}
GnLoginUser.decorators = [
{ type: Injectable }
];
class GnSiteInfo {
constructor(loginUser) {
this.loginUser = loginUser;
this.showBreadcrumb = false;
this.siderMenuTheme = 'dark';
this.authSiderMenu = [];
this.siteAuthorities = [];
this.siderMenu = [];
}
filterMenu() {
this.authSiderMenu = this.getAuthorityMenu(this.siderMenu, '');
}
getAuthorityMenu(menus, parentPath) {
if (this.loginUser.authorities && menus) {
return menus.map(menu => {
var _a;
const path = parentPath + (menu.router || '');
if (menu.authority) {
const authority = (_a = this.siteAuthorities) === null || _a === void 0 ? void 0 : _a.find((item) => item.url === path);
if (!authority) {
this.siteAuthorities.push({ url: path, authority: menu.authority });
}
}
return {
title: menu.title,
router: menu.router,
icon: menu.icon,
authority: menu.authority,
subMenu: this.getAuthorityMenu(menu.subMenu, path)
};
}).filter(menu => this.loginUser.authorities.includes(menu.authority)
|| ((!menu.subMenu || menu.subMenu.length === 0) && !menu.authority)
|| (menu.subMenu && menu.subMenu.length > 0));
}
else {
return menus;
}
}
}
GnSiteInfo.decorators = [
{ type: Injectable }
];
GnSiteInfo.ctorParameters = () => [
{ type: GnLoginUser }
];
class GnRouteGuard {
constructor(user, siteInfo, router, messageService) {
this.user = user;
this.siteInfo = siteInfo;
this.router = router;
this.messageService = messageService;
}
canActivate(route, state) {
var _a;
if (!this.user.isLogin) {
sessionStorage.setItem('blockUrl', state.url);
this.messageService.warn('请登录');
this.router.navigateByUrl(this.siteInfo.loginUrl);
return false;
}
else {
const authority = (_a = this.siteInfo.siteAuthorities) === null || _a === void 0 ? void 0 : _a.find((item) => item.url === state.url);
if (!authority || this.user.authorities.includes(authority.authority)) {
return true;
}
else {
sessionStorage.setItem('blockUrl', state.url);
this.messageService.warn('您的权限不足');
this.router.navigateByUrl(this.siteInfo.loginUrl);
return false;
}
}
}
}
GnRouteGuard.decorators = [
{ type: Injectable }
];
GnRouteGuard.ctorParameters = () => [
{ type: GnLoginUser },
{ type: GnSiteInfo },
{ type: Router },
{ type: GnMessageService }
];
class GnHttpInterceptorConfig {
constructor() {
this.ignoreUrls = [];
}
}
GnHttpInterceptorConfig.decorators = [
{ type: Injectable }
];
class GnOAuthUtils {
constructor() {
this.helper = new JwtHelperService();
}
setToken(token) {
return sessionStorage.setItem('Authorization', token);
}
getToken() {
return sessionStorage.getItem('Authorization');
}
parseToken(token) {
return this.helper.decodeToken(token);
}
tokenExpired(token) {
return this.helper.isTokenExpired(token);
}
}
class GnOAuthHttpInterceptor {
constructor(config, siteInfo, route) {
this.config = config;
this.siteInfo = siteInfo;
this.route = route;
this.oAuthUtils = new GnOAuthUtils();
}
intercept(req, next) {
let headers = req.headers;
if (this.config.startWithUrl
&& req.url.startsWith(this.config.startWithUrl)
&& !this.config.ignoreUrls.includes(req.url)) {
const token = this.oAuthUtils.getToken();
if (this.oAuthUtils.tokenExpired(token)) {
if (this.siteInfo && this.siteInfo.loginUrl) {
this.route.navigateByUrl(this.siteInfo.loginUrl);
}
}
else {
headers = req.headers.set('Authorization', 'Bearer ' + token);
}
}
return next.handle(req.clone({
headers
}));
}
}
GnOAuthHttpInterceptor.decorators = [
{ type: Injectable }
];
GnOAuthHttpInterceptor.ctorParameters = () => [
{ type: GnHttpInterceptorConfig },
{ type: GnSiteInfo },
{ type: Router }
];
registerLocaleData(zh);
class GnAppConfigModule {
constructor(httpClient, siteInfo, iconService, messageService) {
httpClient.get('assets/config/siteInfo.json')
.subscribe((value) => {
siteInfo.title = value.title;
siteInfo.siderMenu = value.siderMenu;
siteInfo.siderMenuTheme = value.siderMenuTheme || 'dark';
siteInfo.showBreadcrumb = value.showBreadcrumb;
siteInfo.siteAuthorities = value.siteAuthorities;
siteInfo.iconFontUrl = value.iconFontUrl;
siteInfo.authSiderMenu = siteInfo.getAuthorityMenu(siteInfo.siderMenu, '');
iconService.fetchFromIconfont({
scriptUrl: siteInfo.iconFontUrl
});
}, error => {
messageService.error('获取系统信息错误');
throw error;
});
}
}
GnAppConfigModule.decorators = [
{ type: NgModule, args: [{
declarations: [],
exports: [],
imports: [
HttpClientModule,
GnMessageServiceModule
],
providers: [
GnSiteInfo,
GnLoginUser,
GnRouteGuard,
GnHttpInterceptorConfig,
{ provide: HTTP_INTERCEPTORS, useClass: GnOAuthHttpInterceptor, multi: true }
]
},] }
];
GnAppConfigModule.ctorParameters = () => [
{ type: HttpClient },
{ type: GnSiteInfo },
{ type: NzIconService },
{ type: GnMessageService }
];
class GnAppRootComponent {
}
GnAppRootComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-app-root',
template: `
<router-outlet></router-outlet>
<div id="gn-app-root"></div>
`
},] }
];
class GnAppRootModule {
}
GnAppRootModule.decorators = [
{ type: NgModule, args: [{
declarations: [GnAppRootComponent],
exports: [
GnAppRootComponent
],
imports: [
RouterModule
]
},] }
];
const formItemTypes = {
'input-number': NzInputNumberComponent,
date: NzDatePickerComponent,
// 'date-range': NzRangePickerComponent,
// rate: NzRateComponent,
slider: NzSliderComponent,
switch: NzSwitchComponent,
};
function GnFormItem(key) {
return (target) => {
formItemTypes[key] = target;
};
}
var GnCheckboxGroupComponent_1;
let GnCheckboxGroupComponent = GnCheckboxGroupComponent_1 = class GnCheckboxGroupComponent {
constructor() {
this.valueChanged = new EventEmitter();
this.valueChange = (value) => {
};
}
set value(v) {
if (this.innerValue !== v) {
this.innerValue = v;
this.items.forEach(item => {
item.checked = this.innerValue.includes(item.value);
});
this.valueChange(this.innerValue);
}
}
get value() {
this.innerValue = this.items.filter(item => item.checked).map(item => item.value);
return this.innerValue;
}
registerOnChange(fn) {
this.valueChange = fn;
}
registerOnTouched(fn) {
}
writeValue(obj) {
this.value = obj;
}
};
GnCheckboxGroupComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-checkbox-group',
template: `
<nz-checkbox-group [(ngModel)]="items" (ngModelChange)="valueChange(value);valueChanged.emit()"></nz-checkbox-group>
`,
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => GnCheckboxGroupComponent_1),
multi: true
}]
},] }
];
GnCheckboxGroupComponent.propDecorators = {
value: [{ type: Input }],
valueChanged: [{ type: Output }]
};
GnCheckboxGroupComponent = GnCheckboxGroupComponent_1 = __decorate([
GnFormItem('checkbox-group')
], GnCheckboxGroupComponent);
class GnCheckboxGroupModule {
}
GnCheckboxGroupModule.decorators = [
{ type: NgModule, args: [{
declarations: [GnCheckboxGroupComponent],
imports: [
CommonModule,
FormsModule,
NzCheckboxModule,
],
exports: [GnCheckboxGroupComponent],
entryComponents: []
},] }
];
function controlContainerFactory() {
const formGroupDirective = new FormGroupDirective([], []);
formGroupDirective.form = new FormGroup({});
return formGroupDirective;
}
class GnFormDirective {
constructor(controlContainer, elementRef, renderer, http, changeDetectorRef, modalRef) {
this.controlContainer = controlContainer;
this.elementRef = elementRef;
this.renderer = renderer;
this.http = http;
this.changeDetectorRef = changeDetectorRef;
this.binded = false;
this.labelWidth = 6;
this.controlWidth = 18;
this.autoLoadData = true;
this.submitMethod = 'put';
this.loadMethod = 'post';
this.format = 'json';
this.formGroup = controlContainer.control;
this.formGroup.valueChanges.subscribe(newValue => {
if (modalRef) {
modalRef.updateConfig({ nzOkDisabled: this.formGroup.invalid });
}
if (this.innerBindValue && this.binded) {
Object.assign(this.innerBindValue, newValue);
}
});
}
set cols(value) {
this.colsValue = value;
if (!this.colsValue || this.colsValue < 1) {
return;
}
this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'grid');
this.renderer.setStyle(this.elementRef.nativeElement, 'grid-template-columns', 'repeat(' + this.colsValue + ', 1fr)');
}
get cols() {
return this.colsValue;
}
set bindValue(value) {
this.binded = false;
this.innerBindValue = value;
this.formGroup.patchValue(value);
this.binded = true;
}
setValue(value) {
this.defaultValue = value;
this.formGroup.patchValue(value);
}
get submitValue() {
let submitValue;
if (this.defaultValue) {
submitValue = Object.assign(GnObjectUtils.deepCopy(this.defaultValue), this.formGroup.value);
}
else {
submitValue = this.formGroup.value;
}
if (this.format === 'form') {
submitValue = GnJsonUtils.obj2FormData(submitValue);
}
return submitValue;
}
submit() {
if (!this.url) {
return Promise.resolve(this.submitValue);
}
else {
const options = Object.assign({ body: this.submitValue }, this.submitOptions);
return this.http.request(this.submitMethod, this.url, options).toPromise();
}
}
loadData() {
if (!this.url || !this.dataId) {
if (this.defaultValue) {
this.formGroup.patchValue(this.defaultValue);
}
return Promise.resolve(null);
}
const queryParameter = {
pageSize: 1,
pageIndex: 0,
includes: this.dataIncludes,
filterGroup: {
type: 'and',
filters: [{ field: this.dataKey, compareType: '=', value: this.dataId }]
}
};
const options = Object.assign({ body: queryParameter }, this.loadOptions);
return this.http.request(this.loadMethod, this.url, options)
.toPromise()
.then((resp) => {
if (resp.content.length === 0) {
throw new Error(`未找到数据[${this.dataId}]`);
}
this.defaultValue = this.defaultValue || {};
Object.assign(this.defaultValue, resp.content[0]);
this.formGroup.patchValue(this.defaultValue);
return this.defaultValue;
});
}
ngOnInit() {
if (this.autoLoadData) {
this.loadData();
}
}
ngAfterViewInit() {
this.changeDetectorRef.detectChanges();
}
}
GnFormDirective.decorators = [
{ type: Directive, args: [{
selector: '[gn-form]',
providers: [
{ provide: ControlContainer, useFactory: controlContainerFactory }
]
},] }
];
GnFormDirective.ctorParameters = () => [
{ type: ControlContainer },
{ type: ElementRef },
{ type: Renderer2 },
{ type: HttpClient },
{ type: ChangeDetectorRef },
{ type: NzModalRef, decorators: [{ type: Optional }] }
];
GnFormDirective.propDecorators = {
url: [{ type: Input }],
labelWidth: [{ type: Input }],
controlWidth: [{ type: Input }],
dataId: [{ type: Input }],
dataKey: [{ type: Input }],
dataIncludes: [{ type: Input }],
autoLoadData: [{ type: Input }],
submitMethod: [{ type: Input }],
loadMethod: [{ type: Input }],
format: [{ type: Input }],
submitOptions: [{ type: Input }],
loadOptions: [{ type: Input }],
defaultValue: [{ type: Input }],
cols: [{ type: Input }],
bindValue: [{ type: Input }]
};
class GnFormItemComponent {
constructor(gnForm, nzForm, cdr, domSanitizer) {
this.gnForm = gnForm;
this.nzForm = nzForm;
this.cdr = cdr;
this.domSanitizer = domSanitizer;
this.controlVisible = true;
this.validators = [];
}
set visible(value) {
this.controlVisible = value;
this.ensureFormControl();
}
get visible() {
return this.controlVisible;
}
set colspan(value) {
this.colspanValue = value;
if (this.colspanValue > 1 && this.label) {
this.labelWidth = Math.ceil(this.gnForm.labelWidth / this.colspanValue);
this.controlWidth = Math.floor((this.gnForm.controlWidth + (this.colspanValue - 1) * 24) / this.colspanValue);
}
else if (!this.label) {
this.controlWidth = 24;
}
}
get colspan() {
return this.colspanValue;
}
get hasRequired() {
return this.validators && this.validators.some((validator) => validator.validator === 'required');
}
get colSpan() {
return this.colspan ?
this.domSanitizer.bypassSecurityTrustStyle('auto / span ' + this.colspan) :
null;
}
get rowSpan() {
return this.colspan ?
this.domSanitizer.bypassSecurityTrustStyle('auto / span ' + this.rowspan) :
null;
}
get styleDisplay() {
return this.display === false ? 'none' : '';
}
ngOnInit() {
this.ensureFormControl();
}
ngAfterViewInit() {
// this.ensureFormControl();
if (this.nzFormControl) {
this.nzFormControl.nzValidateStatus = this.formControl;
}
if (this.defaultValue || this.defaultValue === false) {
if (typeof this.defaultValue === 'string' && this.defaultValue.startsWith('{') && this.defaultValue.endsWith('}')) {
// tslint:disable-next-line:no-eval
const calcValue = eval(this.defaultValue.substr(1, this.defaultValue.length - 2));
this.formControl.patchValue(calcValue);
}
else {
this.formControl.patchValue(this.defaultValue);
}
this.cdr.detectChanges();
}
}
ensureFormControl() {
if (this.field) {
if (this.controlVisible) {
this.formControl = GnFormUtils.ensureFormControl(this.gnForm.formGroup, this.field, this.validators);
}
else {
GnFormUtils.removeFormControl(this.gnForm.formGroup, this.field);
}
}
}
}
GnFormItemComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-form-item,[gn-form-item]',
template: "<nz-form-item *ngIf=\"controlVisible\">\n <nz-form-label *ngIf=\"label\" [nzRequired]=\"hasRequired\"\n [nzSpan]=\"nzForm.nzLayout === 'horizontal' ? (labelWidth || gnForm.labelWidth) : null\">{{label}}\n </nz-form-label>\n <nz-form-control [nzErrorTip]=\"errorTpl\"\n [nzSpan]=\"nzForm.nzLayout === 'horizontal' ? (controlWidth || gnForm.controlWidth) : null\">\n <ng-content></ng-content>\n <ng-template #errorTpl let-control>\n <ng-container *ngFor=\"let validator of validators\">\n <ng-container *ngIf=\"control.hasError(validator.validator)\">\n {{validator.message}}\n </ng-container>\n </ng-container>\n </ng-template>\n </nz-form-control>\n</nz-form-item>\n",
styles: [":host{padding:0 5px}"]
},] }
];
GnFormItemComponent.ctorParameters = () => [
{ type: GnFormDirective },
{ type: NzFormDirective },
{ type: ChangeDetectorRef },
{ type: DomSanitizer }
];
GnFormItemComponent.propDecorators = {
nzFormControl: [{ type: ViewChild, args: [NzFormControlComponent,] }],
visible: [{ type: Input }],
label: [{ type: Input }],
field: [{ type: Input }],
colspan: [{ type: Input }],
rowspan: [{ type: Input }],
validators: [{ type: Input }],
defaultValue: [{ type: Input }],
display: [{ type: Input }],
colSpan: [{ type: HostBinding, args: ['style.grid-column',] }],
rowSpan: [{ type: HostBinding, args: ['style.grid-row',] }],
styleDisplay: [{ type: HostBinding, args: ['style.display',] }]
};
class GnFormModule {
}
GnFormModule.decorators = [
{ type: NgModule, args: [{
declarations: [GnFormDirective, GnFormItemComponent],
exports: [
GnFormDirective,
GnFormItemComponent
],
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
NzFormModule
]
},] }
];
var GnHiddenComponent_1;
let GnHiddenComponent = GnHiddenComponent_1 = class GnHiddenComponent {
constructor(formItem) {
this.formItem = formItem;
this.valueChange = (value) => {
};
}
set value(v) {
if (this.innerValue !== v) {
this.innerValue = v;
this.valueChange(this.innerValue);
}
}
get value() {
return this.innerValue;
}
ngOnInit() {
if (this.formItem) {
this.formItem.display = false;
}
}
registerOnChange(fn) {
this.valueChange = fn;
}
registerOnTouched(fn) {
}
writeValue(obj) {
this.value = obj;
}
};
GnHiddenComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-hidden',
template: ``,
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => GnHiddenComponent_1),
multi: true
}]
},] }
];
GnHiddenComponent.ctorParameters = () => [
{ type: GnFormItemComponent, decorators: [{ type: Optional }] }
];
GnHiddenComponent.propDecorators = {
value: [{ type: Input }]
};
GnHiddenComponent = GnHiddenComponent_1 = __decorate([
GnFormItem('hidden')
], GnHiddenComponent);
class GnHiddenModule {
}
GnHiddenModule.decorators = [
{ type: NgModule, args: [{
declarations: [GnHiddenComponent],
exports: [GnHiddenComponent],
imports: [
CommonModule,
FormsModule
],
entryComponents: []
},] }
];
var GnInputComponent_1;
let GnInputComponent = GnInputComponent_1 = class GnInputComponent {
constructor() {
this.placeholder = '';
this.valueChange = (value) => {
};
}
set value(v) {
if (this.innerValue !== v) {
this.innerValue = v;
this.valueChange(this.innerValue);
}
}
get value() {
return this.innerValue;
}
registerOnChange(fn) {
this.valueChange = fn;
}
registerOnTouched(fn) {
}
writeValue(obj) {
this.value = obj;
}
};
GnInputComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-input',
template: "<input [(ngModel)]=\"value\" nz-input [placeholder]=\"placeholder\"/>\n",
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => GnInputComponent_1),
multi: true
}],
styles: [""]
},] }
];
GnInputComponent.propDecorators = {
placeholder: [{ type: Input }],
value: [{ type: Input }]
};
GnInputComponent = GnInputComponent_1 = __decorate([
GnFormItem('input')
], GnInputComponent);
class GnInputModule {
}
GnInputModule.decorators = [
{ type: NgModule, args: [{
declarations: [GnInputComponent],
exports: [GnInputComponent],
imports: [
CommonModule,
NzInputModule,
FormsModule
],
entryComponents: []
},] }
];
const modalContentTypes = {};
function GnModalContent(options) {
const option = typeof options === 'string' ? { key: options } : options;
return (target) => {
modalContentTypes[option.key] = Object.assign({ type: target }, option);
delete modalContentTypes[option.key].key;
};
}
var GnJsonFormComponent_1;
let GnJsonFormComponent = GnJsonFormComponent_1 = class GnJsonFormComponent {
constructor(http, messageService, changeDetectorRef) {
this.http = http;
this.messageService = messageService;
this.changeDetectorRef = changeDetectorRef;
this.config = { fields: [] };
this.configLoaded = new EventEmitter();
}
get url() {
return this.urlValue;
}
set url(value) {
this.urlValue = value;
if (this.urlValue) {
this.http.get(this.urlValue)
.subscribe((resp) => {
this.config = Object.assign(resp, this.defaultConfig);
this.config.fields.sort(GnJsonFormComponent_1.sortField);
this.changeDetectorRef.detectChanges();
this.configLoaded.emit(this.config);
this.form.loadData();
}, (err) => {
this.messageService.error('获取表单配置错误');
console.error(err);
});
}
}
static sortField(itemA, itemB) {
if ((itemA.showOrder || 0) > (itemB.showOrder || 0)) {
return 1;
}
else if ((itemA.showOrder || 0) < (itemB.showOrder || 0)) {
return -1;
}
else {
return 0;
}
}
sortFields() {
this.config.fields.sort(GnJsonFormComponent_1.sortField);
this.changeDetectorRef.detectChanges();
}
};
GnJsonFormComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-json-form',
template: "<form nz-form\n [nzLayout]=\"config?.layout||'horizontal'\"\n gn-form\n [url]=\"config?.url\"\n [dataKey]=\"config?.dataKey\"\n [dataIncludes]=\"config?.includes\"\n [defaultValue]=\"defaultValue || config?.defaultValue\"\n [autoLoadData]=\"false\"\n [dataId]=\"dataId\"\n [format]=\"config?.format || 'json'\"\n [loadMethod]=\"config?.loadMethod || 'post'\"\n [loadOptions]=\"config?.loadOptions\"\n [submitMethod]=\"config?.submitMethod || 'put'\"\n [submitOptions]=\"config?.submitOptions\"\n [cols]=\"config?.cols\"\n [labelWidth]=\"config?.labelWidth||6\"\n [controlWidth]=\"config?.controlWidth||18\">\n <gn-json-form-item *ngFor=\"let itemConfig of config?.fields\" [config]=\"itemConfig\"></gn-json-form-item>\n</form>\n",
styles: [""]
},] }
];
GnJsonFormComponent.ctorParameters = () => [
{ type: HttpClient },
{ type: GnMessageService },
{ type: ChangeDetectorRef }
];
GnJsonFormComponent.propDecorators = {
url: [{ type: Input }],
config: [{ type: Input }],
dataId: [{ type: Input }],
defaultValue: [{ type: Input }],
defaultConfig: [{ type: Input }],
configLoaded: [{ type: Output }],
form: [{ type: ViewChild, args: [GnFormDirective, { static: true },] }],
nzForm: [{ type: ViewChild, args: [NzFormDirective, { static: true },] }]
};
GnJsonFormComponent = GnJsonFormComponent_1 = __decorate([
GnModalContent('json-form')
], GnJsonFormComponent);
class GnJsonFormItemComponent {
constructor(resolver, changeDetectorRef, domSanitizer, controlContainer) {
this.resolver = resolver;
this.changeDetectorRef = changeDetectorRef;
this.domSanitizer = domSanitizer;
this.controlContainer = controlContainer;
this.form = this.controlContainer.control;
}
get colSpan() {
return this.config.colspan ?
this.domSanitizer.bypassSecurityTrustStyle('auto / span ' + this.config.colspan) :
null;
}
get rowSpan() {
return this.config.colspan ?
this.domSanitizer.bypassSecurityTrustStyle('auto / span ' + this.config.rowspan) :
null;
}
get visible() {
if (this.config.visible === undefined) {
return true;
}
else if (typeof this.config.visible === 'string') {
const form = this.form;
// tslint:disable-next-line:no-eval
return eval(this.config.visible);
}
else {
return this.config.visible;
}
}
ngOnInit() {
const inputType = formItemTypes[this.config.type];
if (!inputType) {
throw new Error(`输入组件[${this.config.type}]未注册`);
}
const controlFactory = this.resolver.resolveComponentFactory(inputType);
const componentRef = this.container.createComponent(controlFactory);
if (this.config.options) {
for (const key of Object.keys(this.config.options)) {
componentRef.instance[key] = this.config.options[key];
}
}
// 能够获取到子元素的ControlValueAccessor,可以直接绑定数据操作
if (this.config.field) {
const formControl = GnFormUtils.ensureFormControl(this.form, this.config.field, this.config.validators);
const accessors = componentRef.injector.get(NG_VALUE_ACCESSOR, null);
const accessor = accessors[0];
accessor.registerOnChange(value => {
formControl.markAsDirty();
formControl.setValue(value);
});
formControl.registerOnChange(value => {
accessor.writeValue(value);
});
}
}
}
GnJsonFormItemComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-json-form-item',
template: "<gn-form-item [label]=\"config.label\"\n [field]=\"config.field\"\n [validators]=\"config.validators\"\n [defaultValue]=\"config.defaultValue\"\n [visible]=\"visible\"\n [display]=\"config.display\"\n [rowspan]=\"config.rowspan\"\n [colspan]=\"config.colspan\">\n <ng-template></ng-template>\n</gn-form-item>\n",
styles: [":host{display:contents}"]
},] }
];
GnJsonFormItemComponent.ctorParameters = () => [
{ type: ComponentFactoryResolver },
{ type: ChangeDetectorRef },
{ type: DomSanitizer },
{ type: ControlContainer }
];
GnJsonFormItemComponent.propDecorators = {
container: [{ type: ViewChild, args: [TemplateRef, { static: true, read: ViewContainerRef },] }],
formItemComponent: [{ type: ViewChild, args: [GnFormItemComponent, { static: true },] }],
config: [{ type: Input }],
colSpan: [{ type: HostBinding, args: ['style.grid-column',] }],
rowSpan: [{ type: HostBinding, args: ['style.grid-row',] }]
};
var GnPasswordComponent_1;
let GnPasswordComponent = GnPasswordComponent_1 = class GnPasswordComponent {
constructor() {
this.passwordVisible = false;
this.placeholder = '';
this.valueChange = (value) => {
};
}
set value(value) {
if (this.password !== value && this.hash !== value) {
this.password = value;
this.hash = (!this.password || this.password === '') ? null : HEX.stringify(SHA256(this.password));
this.valueChange(this.hash);
}
}
get value() {
return this.password;
}
registerOnChange(fn) {
this.valueChange = fn;
}
registerOnTouched(fn) {
}
setDisabledState(isDisabled) {
}
writeValue(obj) {
this.value = obj;
}
};
GnPasswordComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-password',
template: "<nz-input-group [nzSuffix]=\"suffixTemplate\">\n <input [type]=\"passwordVisible ? 'text' : 'password'\" nz-input [placeholder]=\"placeholder\" [(ngModel)]=\"value\"/>\n</nz-input-group>\n<ng-template #suffixTemplate>\n <i nz-icon [nzIconfont]=\"passwordVisible ? 'visible' : 'invisible'\" (click)=\"passwordVisible = !passwordVisible\"></i>\n</ng-template>\n",
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => GnPasswordComponent_1),
multi: true
}],
styles: [""]
},] }
];
GnPasswordComponent.ctorParameters = () => [];
GnPasswordComponent.propDecorators = {
placeholder: [{ type: Input }],
value: [{ type: Input }]
};
GnPasswordComponent = GnPasswordComponent_1 = __decorate([
GnFormItem('password')
], GnPasswordComponent);
class GnPasswordModule {
}
GnPasswordModule.decorators = [
{ type: NgModule, args: [{
declarations: [GnPasswordComponent],
exports: [GnPasswordComponent],
imports: [
CommonModule,
NzInputModule,
FormsModule,
NzIconModule
],
entryComponents: []
},] }
];
var GnRadioComponent_1;
let GnRadioComponent = GnRadioComponent_1 = class GnRadioComponent {
constructor() {
this.items = [];
this.valueChanged = new EventEmitter();
this.valueChange = (value) => {
};
}
set value(v) {
if (this.innerValue !== v) {
this.innerValue = v;
this.valueChange(this.innerValue);
}
}
get value() {
return this.innerValue;
}
registerOnChange(fn) {
this.valueChange = fn;
}
registerOnTouched(fn) {
}
writeValue(obj) {
this.value = obj;
}
};
GnRadioComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-radio',
template: `
<nz-radio-group [(ngModel)]="value" (ngModelChange)="valueChanged.emit()">
<label nz-radio *ngFor="let item of items" [nzValue]="item.value">{{item.label}}</label>
</nz-radio-group>
`,
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => GnRadioComponent_1),
multi: true
}]
},] }
];
GnRadioComponent.propDecorators = {
value: [{ type: Input }],
items: [{ type: Input }],
valueChanged: [{ type: Output }]
};
GnRadioComponent = GnRadioComponent_1 = __decorate([
GnFormItem('radio')
], GnRadioComponent);
class GnRadioModule {
}
GnRadioModule.decorators = [
{ type: NgModule, args: [{
declarations: [GnRadioComponent],
imports: [
CommonModule,
FormsModule,
NzRadioModule
],
exports: [GnRadioComponent],
entryComponents: []
},] }
];
var GnSelectComponent_1;
let GnSelectComponent = GnSelectComponent_1 = class GnSelectComponent {
constructor(http, messageService) {
this.http = http;
this.messageService = messageService;
this.items = [];
this.pageSize = 10;
this.valueChanged = new EventEmitter();
this.valueChange = (value) => {
};
}
set value(v) {
if (this.innerValue !== v) {
this.innerValue = v;
this.valueChange(this.innerValue);
}
}
get value() {
return this.innerValue;
}
searchData(value) {
if (this.showSearch) {
this.searchValue = value;
this.pageIndex = 0;
this.noMore = false;
this.items = [];
this.fetchData();
}
}
appendData() {
if (this.showSearch && !this.noMore) {
this.pageIndex++;
this.fetchData();
}
}
fetchData() {
this.loading = true;
const queryParameter = {
pageSize: this.pageSize,
pageIndex: this.pageIndex,
includes: this.includes || [],
filterGroup: {
type: 'and',
filters: [
{
field: this.searchField,
compareType: 'like',
value: '%' + this.searchValue + '%'
}
]
}
};
this.http.post(this.url, queryParameter)
.subscribe((resp) => {
if (resp.content.length === 0) {
this.noMore = true;
}
resp.content.forEach(data => {
this.items.push({
value: GnObjectUtils.getValue(data, this.valueField),
label: GnObjectUtils.getValue(data, this.labelField)
});
});
this.loading = false;
}, error => {
this.loading = false;
this.messageService.error('获取数据错误');
throw error;
});
}
registerOnChange(fn) {
this.valueChange = fn;
}
registerOnTouched(fn) {
}
writeValue(obj) {
this.value = obj;
}
};
GnSelectComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-select',
template: `
<nz-select [(ngModel)]="value" [nzAllowClear]="allowClear" [nzPlaceHolder]="placeHolder"
(ngModelChange)="valueChanged.emit()" [nzShowSearch]="showSearch" [nzLoading]="loading"
(nzOnSearch)="searchData($event)" (nzScrollToBottom)="appendData()" [nzDropdownRender]="renderTemplate">
<nz-option *ngFor="let item of items" [nzValue]="item.value" [nzLabel]="item.label"></nz-option>
</nz-select>
<ng-template #renderTemplate>
<nz-spin *ngIf="loading"></nz-spin>
</ng-template>
`,
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => GnSelectComponent_1),
multi: true
}]
},] }
];
GnSelectComponent.ctorParameters = () => [
{ type: HttpClient },
{ type: GnMessageService }
];
GnSelectComponent.propDecorators = {
value: [{ type: Input }],
items: [{ type: Input }],
placeHolder: [{ type: Input }],
allowClear: [{ type: Input }],
showSearch: [{ type: Input }],
url: [{ type: Input }],
pageSize: [{ type: Input }],
includes: [{ type: Input }],
searchField: [{ type: Input }],
valueField: [{ type: Input }],
labelField: [{ type: Input }],
valueChanged: [{ type: Output }]
};
GnSelectComponent = GnSelectComponent_1 = __decorate([
GnFormItem('select')
], GnSelectComponent);
class GnSelectModule {
}
GnSelectModule.decorators = [
{ type: NgModule, args: [{
declarations: [GnSelectComponent],
imports: [
CommonModule,
FormsModule,
NzSelectModule,
NzSpinModule
],
exports: [GnSelectComponent],
entryComponents: []
},] }
];
class GnJsonFormModule {
}
GnJsonFormModule.decorators = [
{ type: NgModule, args: [{
declarations: [GnJsonFormComponent, GnJsonFormItemComponent],
exports: [
GnJsonFormComponent,
GnJsonFormItemComponent
],
imports: [
CommonModule,
NzFormModule,
NzInputNumberModule,
NzSwitchModule,
GnFormModule,
GnInputModule,
GnRadioModule,
GnSelectModule,
GnPasswordModule,
GnMessageServiceModule
]
},] }
];
class GnTableColumnDirective {
constructor(templateRef) {
this.templateRef = templateRef;
}
set setId(value) {
this.id = value;
}
}
GnTableColumnDirective.decorators = [
{ type: Directive, args: [{
selector: '[gnTableColumn]'
},] }
];
GnTableColumnDirective.ctorParameters = () => [
{ type: TemplateRef, decorators: [{ type: Optional }] }
];
GnTableColumnDirective.propDecorators = {
setId: [{ type: Input, args: ['gnTableColumn',] }],
id: [{ type: Input }],
title: [{ type: Input }],
pipe: [{ type: Input }],
pipeArgs: [{ type: Input }]
};
class RemoteDataStrategy {
constructor(table) {
this.table = table;
}
load() {
if (!this.table.url) {
return Promise.resolve(null);
}
const queryParameter = {
pageSize: this.table.pageSize,
pageIndex: this.table.pageIndex - 1,
includes: this.table.includes || [],
sorts: this.table.sorts,
filterGroup: this.table.filterGroup
};
return this.table.http.post(this.table.url, queryParameter)
.toPromise();
}
delete(url, id) {
this.table.isLoading = true;
return this.table.http.request('delete', url, { body: id })
.toPromise();
}
save(url, data) {
return this.table.http.put(this.table.url, data)
.toPromise();
}
}
class LocalDataStrategy {
constructor(table) {
this.table = table;
}
delete(url, ids) {
const deletedData = [];
ids.forEach(id => {
const data = this.table.data.find(dt => dt[this.table.dataKey] === id);
deletedData.push(data);
const index = this.table.data.findIndex(dt => dt === data);
this.table.data.splice(index, 1);
});
return Promise.resolve(deletedData);
}
load() {
return Promise.resolve({ content: this.table.data, totalElements: this.table.dataTotal });
}
save(url, data) {
return Promise.resolve(data);
}
}
class GnTableComponent {
constructor(http, modalService, messageService) {
this.http = http;
this.modalService = modalService;
this.messageService = messageService;
this.dataStrategies = {};
this.includes = [];
this.sorts = [];
this.data = [];
this.dataTotal = 0;
this.pageIndex = 1;
this.pageSize = 10;
this.showPagination = true;
this.showSizeChanger = true;
this.autoLoadData = true;
this.selectionMode = 'multi';
this.dataStrategy = 'remote';
this.dataSaved = new EventEmitter();
this.dataDeleted = new EventEmitter();
this.dataLoaded = new EventEmitter();
this.selectionStatus = {};
this.selected = [];
this.selectedKeys = [];
this.isSelected = false;
this.isAllSelected = false;
this.isSomeSelected = false;
this.isSingleSelected = false;
this.editData = null;
this.isLoading = false;
this.dataStrategies.remote = new RemoteDataStrategy(this);
this.dataStrategies.local = new LocalDataStrategy(this);
}
getValue(row, key) {
return GnObjectUtils.getValue(row, key);
}
getValueWithPipe(row, key, pipe, pipeArgs) {
if (!pipe) {
return this.getValue(row, key);
}
const pipeTransform = pipeTypes[pipe];
if (!pipeTransform) {
throw new Error('管道[' + pipe + ']未注册');
}
const value = this.getValue(row, key);
return pipeTransform.transform(value, pipeArgs);
}
loadData() {
this.isLoading = true;
return this.dataStrategies[this.dataStrategy].load()
.then((resp) => {
this.data = resp === null || resp === void 0 ? void 0 : resp.content;
this.dataTotal = resp === null || resp === void 0 ? void 0 : resp.totalElements;
this.dataLoaded.emit(this.data);
return this.data;
})
.catch(error => {
this.messageService.error('获取数据错误');
throw error;
})
.finally(() => {
this.isLoading = false;
});
}
loadDataAndCleanSelection() {
this.changeAllSelectStatus(false);
this.loadData();
}
deleteData(url, id) {
this.modalService.confirm({
nzContent: '确定删除所选数据?',
nzOnOk: () => {
this.isLoading = true;
return this.dataStrategies[this.dataStrategy].delete(url, id)
.then(() => {
this.messageService.success('删除数据成功');
this.dataDeleted.emit();
})
.catch(err => {
this.messageService.error('删除数据错误');
console.error(err);
})
.finally(() => {
this.isLoading = false;
this.loadDataAndCleanSelection();
});
}
}, 'confirm');
}
deleteSelectedData() {
this.deleteData(this.url, this.selectedKeys);
}
refreshSelectionStatus() {
this.selected = this.data.filter(item => this.selectionStatus[this.getValue(item, this.dataKey)]);
this.selectedKeys = this.selected.map(item => this.getValue(item, this.dataKey));
this.isSelected = this.selectedKeys.length > 0;
this.isAllSelected = this.isSelected && this.selectedKeys.length === this.data.length;
this.isSomeSelected = this.isSelected && this.selectedKeys.length < this.data.length;
this.isSingleSelected = this.selectedKeys.length === 1;
this.selectedKey = this.isSelected ? this.selectedKeys[0] : null;
this.selectedOne = this.isSelected ? this.selected[0] : null;
}
changeSelectStatus(key) {
if (this.selectionMode === 'none') {
return;
}
if (this.selectionMode === 'single') {
this.selectionStatus = {};
}
this.selectionStatus[key] = !this.selectionStatus[key];
this.refreshSelectionStatus();
}
changeAllSelectStatus(selected) {
this.data.forEach(item => this.selectionStatus[this.getValue(item, this.dataKey)] = selected);
this.refreshSelectionStatus();
}
selectOne(dataKey) {
this.select([dataKey]);
}
select(dataKeys) {
this.changeAllSelectStatus(false);
dataKeys.forEach(dataKey => this.selectionStatus[dataKey] = true);
this.refreshSelectionStatus();
}
ngOnInit() {
if (this.autoLoadData) {
this.loadData();
}
}
refreshData(data) {
this.data = data;
this.dataTotal = data.length;
}
startEdit(data) {
this.editData = data;
}
endEdit() {
this.isLoading = true;
this.dataStrategies[this.dataStrategy].save(this.url, this.editData)
.then((resp) => {
this.dataSaved.emit(this.editData);
this.editData = null;
})
.catch(error => {
this.messageService.error('更新数据错误');
throw error;
})
.finally(() => {
this.isLoading = false;
});
}
}
GnTableComponent.decorators = [
{ type: Component, args: [{
selector: 'gn-table',
template: "<nz-table\n [nzData]=\"data\"\n [nzLoading]=\"isLoading\"\n [nzFrontPagination]=\"false\"\n [nzShowPagination]=\"showPagination\"\n [nzTotal]=\"dataTotal\"\n [nzShowTotal]=\"totalTemplate\"\n [(nzPageIndex)]=\"pageIndex\"\n [(nzPageSize)]=\"pageSize\"\n (nzPageIndexChange)=\"loadData()\"\n [nzShowSizeChanger]=\"showSizeChanger\"\n (nzPageSizeChange)=\"loadData()\">\n <thead>\n <tr>\n <th class=\"selection\"\n *ngIf=\"selectionMode === 'multi'\"\n nzShowCheckbox\n [nzChecked]=\"isAllSelected\"\n [nzIndeterminate]=\"isSomeSelected\"\n (nzCheckedChange)=\"changeAllSelectStatus($event)\"></th>\n <th class=\"selection\"\n *ngIf=\"selectionMode === 'single'\"></th>\n <th *ngFor=\"let header of columns\" [innerHTML]=\"header.title\"></th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let row of data\" (click)=\"changeSelectStatus(getValue(row,dataKey))\">\n <td nzShowCheckbox *ngIf=\"selectionMode !== 'none'\"\n [(nzChecked)]=\"selectionStatus[getValue(row,dataKey)]\"\n (nzCheckedChange)=\"selectionMode === 'single'?selectOne(getValue(row,dataKey)):refresh