UNPKG

@ecip/auth

Version:
946 lines (936 loc) 33.8 kB
import { SharedModule } from '@ecip/shared'; import { ModalHelper } from '@delon/theme'; import '@delon/abc'; import { isNullOrUndefined } from 'util'; import { Component, Input, ViewChild, NgModule } from '@angular/core'; import { NzMessageService, NzModalRef } from 'ng-zorro-antd'; import '@delon/form'; import { map } from 'rxjs/operators'; import { DictService, DataSourceService, RuleService } from '@ecip/service'; import { ActivatedRoute, Router, RouterModule } from '@angular/router'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class AuthDataSourceEditComponent { /** * @param {?} modal * @param {?} dataSourceService * @param {?} messageService * @param {?} dictService */ constructor(modal, dataSourceService, messageService, dictService) { this.modal = modal; this.dataSourceService = dataSourceService; this.messageService = messageService; this.dictService = dictService; this.title = '编辑数据源'; this.schema = { properties: { dsName: { type: 'string', title: '数据源名称', ui: { //异步验证:判断是否已经存在相同数据源名称的记录, //如果是修改数据源,和自己原本的数据源名称相同则忽略 validator: (/** * @param {?} value * @return {?} */ (value) => this.dataSourceService.existsDsName(value) .pipe(map((/** * @param {?} res * @return {?} */ res => (res && (this.isNew || this.record.dsName != value)) ? [{ keyword: 'required', message: '数据源名已存在' }] : [])))) } }, dbType: { type: "string", title: '数据库类型', default: '', ui: { widget: 'select' } }, dbName: { type: 'string', title: '数据库名' }, url: { type: 'string', title: '协议(URL前缀)' }, ip: { type: 'string', title: '主机(IP或域名)' }, port: { type: 'number', title: '端口号', ui: { widget: 'string', } }, username: { type: 'string', title: '用户名' }, password: { type: 'string', title: '密码', ui: { widget: 'string', type: 'password' } }, }, required: ['dsName', 'dbType', 'dbName', 'url', 'ip', 'port', 'username', 'password'], }; this.ui = { '*': { grid: { span: 18, offset: 2 }, }, }; } /** * @return {?} */ ngOnInit() { if (this.isNew === true) { this.title = '新建数据源'; } } /** * @return {?} */ ngAfterViewInit() { //异步渲染下拉框 this.dictService.getTypeList('dbType').subscribe((/** * @param {?} res * @return {?} */ (res) => { this.sf.schema.properties.dbType.enum = [{ value: '', label: '请选择' }].concat(res); this.sf.refreshSchema(); })); } /** * @param {?} dataSource * @return {?} */ submit(dataSource) { if (this.isNew === true) { this.create(dataSource); } else { this.update(dataSource); } } /** * @param {?} dataSource * @return {?} */ create(dataSource) { this.dataSourceService.post(dataSource).subscribe((/** * @return {?} */ () => { this.modal.close(true); })); } /** * @param {?} dataSource * @return {?} */ update(dataSource) { this.dataSourceService.put(this.record.id, dataSource).subscribe((/** * @return {?} */ () => { this.modal.close(true); })); } /** * @param {?} dataSource * @return {?} */ testConnection(dataSource) { this.dataSourceService.testConnection(dataSource).subscribe((/** * @param {?} res * @return {?} */ res => { if (res.body === true) { this.messageService.success("连接成功"); } else { this.messageService.error("连接失败"); } })); } /** * @return {?} */ close() { this.modal.destroy(); } } AuthDataSourceEditComponent.decorators = [ { type: Component, args: [{ selector: 'app-auth-ds-edit', template: "<div class=\"modal-header\">\r\n <div class=\"modal-title\">{{title}}</div>\r\n</div>\r\n<nz-spin *ngIf=\"!isNew&&!record\"></nz-spin>\r\n<sf #sf mode=\"default\" [schema]=\"schema\" [ui]=\"ui\" [formData]=\"record\" button=\"none\">\r\n <div class=\"modal-footer\">\r\n <button nz-button type=\"button\" nzType=\"primary\" (click)=\"testConnection(sf.value)\" [disabled]=\"!sf.valid\" [nzLoading]=\"dataSourceService.http.loading\">\u6D4B\u8BD5\u8FDE\u63A5</button>\r\n <button nz-button type=\"submit\" nzType=\"primary\" (click)=\"submit(sf.value)\" [disabled]=\"!sf.valid\" [nzLoading]=\"dataSourceService.http.loading\">\u4FDD\u5B58</button>\r\n <button nz-button type=\"button\" (click)=\"close()\">\u53D6\u6D88</button>\r\n </div>\r\n</sf>\r\n" }] } ]; /** @nocollapse */ AuthDataSourceEditComponent.ctorParameters = () => [ { type: NzModalRef }, { type: DataSourceService }, { type: NzMessageService }, { type: DictService } ]; AuthDataSourceEditComponent.propDecorators = { sf: [{ type: ViewChild, args: ['sf',] }], record: [{ type: Input }], isNew: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class AuthDataSourceComponent { /** * @param {?} modalHelper * @param {?} messageService * @param {?} dataSourceService * @param {?} dictService */ constructor(modalHelper, messageService, dataSourceService, dictService) { this.modalHelper = modalHelper; this.messageService = messageService; this.dataSourceService = dataSourceService; this.dictService = dictService; this.url = 'api/v1/sysrDS'; this.selectedIds = []; this.pageTitle = '数据源管理'; this.params = {}; this.schema = { properties: { dsName: { type: 'string', title: '数据源名称', }, dbType: { type: "string", title: '数据库类型', ui: { widget: 'select', width: 260, notFoundContent: '没有数据', dropdownMatchSelectWidth: false, asyncData: (/** * @return {?} */ () => this.dictService.getTypeList("dbType")) } }, ip: { type: 'string', title: '主机名', }, dbName: { type: 'string', title: '数据库名', }, }, }; this.columns = [ { title: '编号', type: 'checkbox', index: 'id', fixed: 'left', width: '2%', }, { title: '数据源名称', index: 'dsName', fixed: 'left', width: '10%' }, { title: '数据库类型', index: 'dbType', fixed: 'left', width: '6%', format: (/** * @param {?} item * @return {?} */ (item) => { for (let pair of this.dbTypeList) { if (item.dbType == pair.value) { return pair.label; } } return item.dbType; }) }, { title: '数据库名', index: 'dbName', fixed: 'left', width: '8%' }, { title: 'URL', index: 'url', }, { title: '主机名', index: 'ip', }, { title: '端口号', index: 'port', }, { title: '用户名', index: 'username', }, { title: '操作', fixed: 'right', width: '9%', buttons: [ { text: '编辑', icon: 'edit', type: 'static', component: AuthDataSourceEditComponent, click: (/** * @param {?} record * @param {?} modal * @return {?} */ (record, modal) => { this.messageService.success("编辑成功"); this.st.load(-1, this.params); }), acl: { ability: ['datasource:edit'] } }, { text: '删除', icon: 'delete', type: 'del', click: (/** * @param {?} record * @param {?} modal * @param {?} component * @return {?} */ (record, modal, component) => { this.dataSourceService.deleteById(record.id).subscribe((/** * @return {?} */ () => { this.messageService.success("删除成功"); component.load(-1, this.params); })); }), acl: { ability: ['datasource:remove'] } } ], } ]; } /** * @return {?} */ ngOnInit() { this.dictService.getTypeList("dbType").subscribe((/** * @param {?} res * @return {?} */ res => { this.dbTypeList = res; })); } //即时监控选中项的ID列表 /** * @param {?} e * @return {?} */ checkboxChange(e) { this.selectedIds = []; for (let item of e) { this.selectedIds.push(item.id); } } //因为[formData]和st的params似乎不能绑定,所以手写了一个绑定数据的方法 /** * @return {?} */ formBind() { this.params = this.sf.value; } /** * @return {?} */ multiDelete() { //未选定任何一条 if (this.selectedIds.length == 0) { this.messageService.warning("未选择任何记录"); } else { this.dataSourceService.multiDelete(this.selectedIds).subscribe((/** * @return {?} */ () => { this.messageService.success("删除成功"); this.st.load(-1, this.params); })); } } /** * @return {?} */ create() { this.modalHelper.createStatic(AuthDataSourceEditComponent, { isNew: true }) .subscribe((/** * @return {?} */ () => { this.messageService.success("创建成功"); this.st.load(-1, this.params); })); } } AuthDataSourceComponent.decorators = [ { type: Component, args: [{ selector: 'app-auth-ds', template: "<page-header [action]=\"phPhAction\">\r\n <ng-template #phPhAction>\r\n <button acl [acl-ability]=\"'datasource:add'\" nz-button nzType=\"primary\" (click)=\"create()\">\u65B0\u5EFA</button>\r\n <!--<button nz-button (click)=\"multiDelete()\">\u5220\u9664</button>-->\r\n </ng-template>\r\n</page-header>\r\n<nz-card>\r\n <sf #sf mode=\"search\" [schema]=\"schema\" (formSubmit)=\"formBind();st.load(1, params);\" (formReset)=\"formBind();st.reset(params)\"></sf>\r\n <st #st [data]=\"url\" [columns]=\"columns\" [scroll]=\"{x:'150%'}\" (change)=\"checkboxChange($event)\" [req]=\"{params: params}\" [page]=\"{front: false}\"></st>\r\n</nz-card>\r\n" }] } ]; /** @nocollapse */ AuthDataSourceComponent.ctorParameters = () => [ { type: ModalHelper }, { type: NzMessageService }, { type: DataSourceService }, { type: DictService } ]; AuthDataSourceComponent.propDecorators = { st: [{ type: ViewChild, args: ['st',] }], sf: [{ type: ViewChild, args: ['sf',] }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class AuthRuleComponent { /** * @param {?} modalHelper * @param {?} messageService * @param {?} ruleService * @param {?} dataSourceService */ constructor(modalHelper, messageService, ruleService, dataSourceService) { this.modalHelper = modalHelper; this.messageService = messageService; this.ruleService = ruleService; this.dataSourceService = dataSourceService; this.url = 'api/v1/sysrRule'; this.selectedIds = []; this.params = {}; this.schema = { properties: { ruleName: { type: 'string', title: '规则名称', }, srcDs: { type: "string", title: '源数据源', ui: { widget: 'select', width: 260, notFoundContent: '没有数据', dropdownMatchSelectWidth: false, asyncData: (/** * @return {?} */ () => this.dataSourceService.getVoList()) } }, }, }; this.columns = [ { title: '编号', type: 'checkbox', index: 'id' }, { title: '规则名称', index: 'ruleName', }, { title: '源数据源', index: 'srcDsName', }, { title: '同步类型', index: 'syncType', format: (/** * @param {?} item * @return {?} */ (item) => { switch (item.syncType) { case 'user': return '同步用户'; case 'dept': return '同步组织'; case 'other': return `自定义(表名:${item.destTable})`; } }) }, { title: 'Cron表达式', index: 'cron', format: (/** * @param {?} item * @return {?} */ (item) => isNullOrUndefined(item.cron) || item.cron == '' ? '(无)' : item.cron) }, { title: '操作', buttons: [ { text: '编辑', icon: 'edit', type: 'link', click: (/** * @param {?} record * @return {?} */ (record) => { return `/auth/rule/edit/${record.id}`; }), acl: { ability: ['rule:edit'] } }, // { // text: '编辑', // icon: 'edit', // type: 'static', // component: AuthRuleEditComponent, // click: (record, modal) =>{ // this.messageService.success("编辑成功"); // this.st.load(-1, this.params); // } // }, { text: '删除', icon: 'delete', type: 'del', click: (/** * @param {?} record * @param {?} modal * @param {?} component * @return {?} */ (record, modal, component) => { this.ruleService.deleteById(record.id).subscribe((/** * @return {?} */ () => { this.messageService.success("删除成功"); component.load(-1, this.params); })); }), acl: { ability: ['rule:remove'] } } ], } ]; } //即时监控选中项的ID列表 /** * @param {?} e * @return {?} */ checkboxChange(e) { this.selectedIds = []; for (let item of e) { this.selectedIds.push(item.id); } } //因为[formData]和st的params似乎不能绑定,所以手写了一个绑定数据的方法 /** * @return {?} */ formBind() { this.params = this.sf.value; } /** * @return {?} */ multiDelete() { //未选定任何一条 if (this.selectedIds.length == 0) { this.messageService.warning("未选择任何记录"); } else { this.ruleService.multiDelete(this.selectedIds).subscribe((/** * @return {?} */ () => { this.messageService.success("删除成功"); this.st.load(-1, this.params); })); } } } AuthRuleComponent.decorators = [ { type: Component, args: [{ selector: 'app-auth-ds', template: "<page-header [action]=\"phPhAction\">\r\n <ng-template #phPhAction>\r\n <button acl [acl-ability]=\"'rule:add'\" nz-button nzType=\"primary\" routerLink=\"/auth/rule/edit\">\u65B0\u5EFA</button>\r\n <!--<button nz-button (click)=\"multiDelete()\">\u5220\u9664</button>-->\r\n </ng-template>\r\n</page-header>\r\n<nz-card>\r\n <sf #sf mode=\"search\" [schema]=\"schema\" (formSubmit)=\"formBind();st.load(1, params);\" (formReset)=\"formBind();st.reset(params)\"></sf>\r\n <st #st [data]=\"url\" [columns]=\"columns\" (change)=\"checkboxChange($event)\" [req]=\"{params: params}\" [page]=\"{front: false}\"></st>\r\n</nz-card>\r\n" }] } ]; /** @nocollapse */ AuthRuleComponent.ctorParameters = () => [ { type: ModalHelper }, { type: NzMessageService }, { type: RuleService }, { type: DataSourceService } ]; AuthRuleComponent.propDecorators = { st: [{ type: ViewChild, args: ['st',] }], sf: [{ type: ViewChild, args: ['sf',] }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class AuthRuleEditComponent { /** * @param {?} ruleService * @param {?} messageService * @param {?} dataSourceService * @param {?} dictService * @param {?} activeRoute * @param {?} router */ constructor(ruleService, messageService, dataSourceService, dictService, activeRoute, router) { this.ruleService = ruleService; this.messageService = messageService; this.dataSourceService = dataSourceService; this.dictService = dictService; this.activeRoute = activeRoute; this.router = router; this.schema = { properties: { ruleName: { type: 'string', title: '规则名称', ui: { //异步验证:判断是否已经存在相同数据源名称的记录, //如果是修改数据源,和修改前的数据源名称相同则忽略 validator: (/** * @param {?} value * @return {?} */ (value) => this.ruleService.existsRuleName(value) .pipe(map((/** * @param {?} res * @return {?} */ res => (res && (this.isNew || this.record.ruleName != value)) ? [{ keyword: 'required', message: '规则名称已存在' }] : [])))) } }, appId: { type: 'number', title: '源应用', ui: { widget: 'select', notFoundContent: '没有数据', asyncData: (/** * @return {?} */ () => this.ruleService.appListVL()), } }, srcDs: { type: "string", title: '源数据源', ui: { widget: 'select', notFoundContent: '没有数据', asyncData: (/** * @return {?} */ () => this.dataSourceService.getVoList()) } }, srcSql: { type: 'string', title: '源SQL', ui: { widget: 'textarea', autosize: { minRows: 3 } } }, cron: { type: "string", title: 'Cron表达式', ui: { placeholder: 'Cron为空时将立即执行同步', } }, syncType: { type: 'string', title: '同步类型', ui: { widget: 'radio', //todo:dirty asyncData: (/** * @return {?} */ () => this.dictService.getTypeList("syncType")) } }, destTable: { type: "string", title: '表名称', ui: { visibleIf: { syncType: ["other"] }, } }, idType: { type: "string", title: '新增主键策略', ui: { widget: 'radio', //todo:dirty asyncData: (/** * @return {?} */ () => this.dictService.getTypeList("syncIdType")), validator: (/** * @param {?} value * @return {?} */ (value) => { return value === 'auto' && this.sf.value.uniqConstraint.trim().toUpperCase() === 'ID' ? [{ keyword: 'format', message: "唯一约束字段为'ID'时新增主键策略不能为自动生成" }] : []; }), } }, uniqConstraint: { type: "string", title: '唯一约束字段', ui: { placeholder: "唯一约束字段为'ID'时不可选择自动生成新主键", validator: (/** * @param {?} value * @return {?} */ (value) => { return value.trim().toUpperCase() === 'ID' && this.sf.value.idType === 'auto' ? [{ keyword: 'format', message: "唯一约束字段为'ID'时新增主键策略不能为自动生成" }] : []; }), }, }, fieldMappings: { type: 'array', title: '字段映射', minItems: 1, uniqueItems: true, items: { type: 'object', properties: { srcField: { type: 'string', title: '源字段', }, destField: { type: 'string', title: '目标字段', }, }, required: ['srcField', 'destField'], }, ui: { grid: { arraySpan: 12, }, addTitle: '添加字段', } }, }, required: ['ruleName', 'srcDs', 'syncType', 'srcSql', 'uniqConstraint', 'appId', 'idType'], }; } /** * @return {?} */ ngOnInit() { this.isNew = this.activeRoute.snapshot.data.isNew; //必须由路由传入title值,否则不能在页标上显示 this.title = this.activeRoute.snapshot.data.title; if (this.isNew === false) { /** @type {?} */ let id = this.activeRoute.snapshot.params["id"]; if (id != null) { this.ruleService.getById(id).subscribe((/** * @param {?} res * @return {?} */ res => { //未查询到记录 if (res == null) { this.router.navigateByUrl("404"); } else { this.record = res; } })); } } } /** * @param {?} value * @return {?} */ submit(value) { if (this.isNew === true) { this.create(value); //回到同步策略列表页面 this.router.navigateByUrl("/auth/rule"); } else { this.update(value); } } /** * @param {?} value * @return {?} */ create(value) { this.ruleService.post(value).subscribe((/** * @return {?} */ () => { this.messageService.success("已保存"); })); } /** * @param {?} value * @return {?} */ update(value) { this.ruleService.put(this.record.id, value).subscribe((/** * @return {?} */ () => { this.messageService.success("已保存"); })); } /** * @return {?} */ close() { } /** * @param {?} value * @return {?} */ testSync(value) { this.ruleService.testSync(value).subscribe((/** * @param {?} res * @return {?} */ res => { if (res.body === true) { this.messageService.success("同步测试成功"); } else { this.messageService.error("同步测试失败"); } })); } } AuthRuleEditComponent.decorators = [ { type: Component, args: [{ selector: 'app-auth-rule-edit', template: "<page-header [title]=\"title\"></page-header>\r\n<nz-card>\r\n <sf #sf mode=\"edit\" [schema]=\"schema\" [formData]=\"record\" button=\"none\">\r\n <div class=\"modal-footer\">\r\n <button nz-button type=\"button\" nzType=\"primary\" (click)=\"testSync(sf.value)\" [disabled]=\"!sf.valid\" [nzLoading]=\"ruleService.http.loading\">\u540C\u6B65\u6D4B\u8BD5</button>\r\n <button nz-button type=\"submit\" nzType=\"primary\" (click)=\"submit(sf.value)\" [disabled]=\"!sf.valid\" [nzLoading]=\"ruleService.http.loading\">\u4FDD\u5B58</button>\r\n <button nz-button type=\"button\" routerLink=\"/auth/rule\">\u5173\u95ED</button>\r\n </div>\r\n </sf>\r\n</nz-card>" }] } ]; /** @nocollapse */ AuthRuleEditComponent.ctorParameters = () => [ { type: RuleService }, { type: NzMessageService }, { type: DataSourceService }, { type: DictService }, { type: ActivatedRoute }, { type: Router } ]; AuthRuleEditComponent.propDecorators = { sf: [{ type: ViewChild, args: ['sf',] }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ const ɵ0 = { isNew: true, title: '新建同步策略' }, ɵ1 = { isNew: false, title: '编辑同步策略' }; /** @type {?} */ const routes = [ { path: 'ds', component: AuthDataSourceComponent }, { path: 'rule', component: AuthRuleComponent }, { path: 'rule/edit', component: AuthRuleEditComponent, data: ɵ0 }, { path: 'rule/edit/:id', component: AuthRuleEditComponent, data: ɵ1 }, ]; class AuthRoutingModule { } AuthRoutingModule.decorators = [ { type: NgModule, args: [{ imports: [RouterModule.forChild(routes)], exports: [RouterModule] },] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const COMPONENTS = [ AuthDataSourceComponent, AuthRuleComponent, AuthRuleEditComponent ]; /** @type {?} */ const COMPONENTS_NOROUNT = [ AuthDataSourceEditComponent, ]; class AuthModule { } AuthModule.decorators = [ { type: NgModule, args: [{ imports: [ SharedModule, AuthRoutingModule ], declarations: [ ...COMPONENTS, ...COMPONENTS_NOROUNT ], entryComponents: COMPONENTS_NOROUNT },] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { AuthModule, AuthRoutingModule, AuthDataSourceComponent, AuthDataSourceEditComponent, AuthRuleComponent, AuthRuleEditComponent }; //# sourceMappingURL=auth.js.map