From 6874f958a5bfc3a83be3909ce2148a5954286e98 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:52:13 +0800 Subject: [PATCH] add data-list mixin --- vueJs/src/api/organizationunit.ts | 2 +- vueJs/src/api/roles.ts | 2 +- vueJs/src/api/tenant-management.ts | 1 - vueJs/src/mixins/DataListMiXin.ts | 99 +++++++++++++++++ .../views/admin/apigateway/aggregateRoute.vue | 84 +++++---------- vueJs/src/views/admin/apigateway/global.vue | 70 +++++------- vueJs/src/views/admin/apigateway/group.vue | 77 +++++--------- vueJs/src/views/admin/apigateway/route.vue | 82 +++++--------- .../identityServer/api-resources/index.vue | 81 +++++--------- .../admin/identityServer/client/index.vue | 100 ++++++------------ .../identity-resources/index.vue | 74 ++++--------- .../components/RoleOrganizationUint.vue | 43 +++----- .../components/UserOrganizationUint.vue | 29 +++-- vueJs/src/views/admin/roles/index.vue | 45 ++++---- vueJs/src/views/admin/tenants/index.vue | 71 ++++--------- vueJs/src/views/admin/users/index.vue | 72 ++++--------- vueJs/src/views/file-management/index.vue | 77 +++++--------- 17 files changed, 410 insertions(+), 599 deletions(-) create mode 100644 vueJs/src/mixins/DataListMiXin.ts diff --git a/vueJs/src/api/organizationunit.ts b/vueJs/src/api/organizationunit.ts index b48a0adb7..865ec9f17 100644 --- a/vueJs/src/api/organizationunit.ts +++ b/vueJs/src/api/organizationunit.ts @@ -204,7 +204,7 @@ export class OrganizationUnitGetRoleByPaged extends PagedAndSortedResultRequestD /** 主键标识 */ id!: string /** 过滤字符 */ - filter!: string + filter = '' } /** 组织机构创建对象 */ diff --git a/vueJs/src/api/roles.ts b/vueJs/src/api/roles.ts index fc39f2a55..d365b1a95 100644 --- a/vueJs/src/api/roles.ts +++ b/vueJs/src/api/roles.ts @@ -66,7 +66,7 @@ export class RoleDto extends RoleBaseDto { } export class RoleGetPagedDto extends PagedAndSortedResultRequestDto { - filter?: string + filter = '' } export class CreateRoleDto extends RoleBaseDto { diff --git a/vueJs/src/api/tenant-management.ts b/vueJs/src/api/tenant-management.ts index b4a741982..65b9c9f3c 100644 --- a/vueJs/src/api/tenant-management.ts +++ b/vueJs/src/api/tenant-management.ts @@ -87,7 +87,6 @@ export class TenantGetByPaged extends PagedAndSortedResultRequestDto { this.filter = '' this.sorting = '' this.skipCount = 1 - this.maxResultCount = 25 } } diff --git a/vueJs/src/mixins/DataListMiXin.ts b/vueJs/src/mixins/DataListMiXin.ts new file mode 100644 index 000000000..01303f6bc --- /dev/null +++ b/vueJs/src/mixins/DataListMiXin.ts @@ -0,0 +1,99 @@ +import { Component, Vue } from 'vue-property-decorator' +import { PagedResultDto, ListResultDto, PagedAndSortedResultRequestDto } from '@/api/types' +/** + * 数据列表mixin + * 复写大部分数据列表事件 + */ +@Component +export default class DataListMiXin extends Vue { + /** 数据列表 */ + public dataList = new Array() + /** 数据总数 */ + public dataTotal = 0 + /** 是否正在加载数据 */ + public dataLoading = false + /** 查询过滤器 + *如果继承自分页查询接口的其他过滤类型,需要重写初始化类型 + */ + public dataFilter = new PagedAndSortedResultRequestDto() + + /** + * 刷新数据 + */ + protected refreshData() { + this.dataLoading = true + this.getList(this.dataFilter) + .then(res => { + this.dataList = res.items + this.dataTotal = res.items.length + }) + .finally(() => { + this.dataLoading = false + }) + } + + /** + * 刷新分页数据 + */ + protected refreshPagedData() { + this.dataLoading = true + this.getPagedList(this.dataFilter) + .then(res => { + this.dataList = res.items + this.dataTotal = res.totalCount + }) + .finally(() => { + this.dataLoading = false + }) + } + + /** + * 重写已执行具体查询数据逻辑 + */ + protected getList(filter: any): Promise> { + console.log(filter) + return new Promise>((resolve) => { + return resolve(new ListResultDto()) + }) + } + + /** 获取空数据 */ + protected getEmptyList() { + return new Promise>((resolve) => { + return resolve(new ListResultDto()) + }) + } + + /** + * 重写以执行具体查询分页数据逻辑 + * @param filter 查询过滤器 + */ + protected getPagedList(filter: any): Promise> { + console.log(filter) + return this.getEmptyPagedList() + } + + /** 获取空分页数据 */ + protected getEmptyPagedList() { + return new Promise>((resolve) => { + return resolve(new PagedResultDto()) + }) + } + + /** + * 排序变更事件 + * @param column 事件列 + */ + protected handleSortChange(column: any) { + this.dataFilter.sorting = column.prop + } + + /** + * 本地化接口 + * @param name 本地化名称 + * @param values 参数 + */ + protected l(name: string, values?: any[] | { [key: string]: any }) { + return this.$t(name, values).toString() + } +} diff --git a/vueJs/src/views/admin/apigateway/aggregateRoute.vue b/vueJs/src/views/admin/apigateway/aggregateRoute.vue index 7d8ec5f21..4f34afba0 100644 --- a/vueJs/src/views/admin/apigateway/aggregateRoute.vue +++ b/vueJs/src/views/admin/apigateway/aggregateRoute.vue @@ -6,7 +6,7 @@ style="padding-left:10px;" >{{ $t('apiGateWay.appId') }} {{ $t('queryFilter') }} {{ $t('searchList') }} @@ -47,9 +47,9 @@ @@ -215,7 +215,8 @@ diff --git a/vueJs/src/views/admin/apigateway/global.vue b/vueJs/src/views/admin/apigateway/global.vue index 5096e746a..d2fddd51c 100644 --- a/vueJs/src/views/admin/apigateway/global.vue +++ b/vueJs/src/views/admin/apigateway/global.vue @@ -6,7 +6,7 @@ style="padding-left:10px;" >{{ $t('queryFilter') }} {{ $t('searchList') }} @@ -30,9 +30,9 @@ import { checkPermission } from '@/utils/permission' -import { Component, Vue } from 'vue-property-decorator' +import DataListMiXin from '@/mixins/DataListMiXin' +import Component, { mixins } from 'vue-class-component' import Pagination from '@/components/Pagination/index.vue' import GlobalCreateOrEditForm from './components/GlobalCreateOrEditForm.vue' -import ApiGatewayService, { GlobalGetByPagedDto, GlobalConfigurationDto } from '@/api/apigateway' +import ApiGatewayService, { GlobalGetByPagedDto } from '@/api/apigateway' @Component({ name: 'GlobalRoute', @@ -177,44 +178,26 @@ import ApiGatewayService, { GlobalGetByPagedDto, GlobalConfigurationDto } from ' checkPermission } }) -export default class extends Vue { - private editGlobalConfigurationTitle!: any - private globalConfigurationsCount!: number - private globalConfigurationsLoading!: boolean - private showEditGlobalConfiguration!: boolean - private editGlobalConfigurationAppId!: string - private globalConfigurations!: GlobalConfigurationDto[] - private globalConfigurationGetQuery!: GlobalGetByPagedDto +export default class extends mixins(DataListMiXin) { + private editGlobalConfigurationTitle = '' + private showEditGlobalConfiguration = false + private editGlobalConfigurationAppId = '' - constructor() { - super() - this.globalConfigurationsCount = 0 - this.editGlobalConfigurationTitle = '' - this.editGlobalConfigurationAppId = '' - this.globalConfigurationsLoading = false - this.showEditGlobalConfiguration = false - this.globalConfigurationGetQuery = new GlobalGetByPagedDto() - this.globalConfigurations = new Array() - } + public dataFilter = new GlobalGetByPagedDto() mounted() { - this.handledGetGlobalConfigurations() + this.refreshPagedData() } - private handledGetGlobalConfigurations() { - this.globalConfigurationsLoading = true - ApiGatewayService.getGlobalConfigurations(this.globalConfigurationGetQuery).then(globals => { - this.globalConfigurations = globals.items - this.globalConfigurationsCount = globals.totalCount - this.globalConfigurationsLoading = false - }) + protected getPagedList(filter: any) { + return ApiGatewayService.getGlobalConfigurations(filter) } private handleCreateOrEditGlobalConfiguration(appId: string) { this.editGlobalConfigurationAppId = appId - this.editGlobalConfigurationTitle = this.$t('apiGateWay.createGlobal') + this.editGlobalConfigurationTitle = this.l('apiGateWay.createGlobal') if (appId) { - this.editGlobalConfigurationTitle = this.$t('apiGateWay.updateGlobalByApp', { name: appId }) + this.editGlobalConfigurationTitle = this.l('apiGateWay.updateGlobalByApp', { name: appId }) } this.showEditGlobalConfiguration = true } @@ -224,7 +207,7 @@ export default class extends Vue { this.editGlobalConfigurationTitle = '' this.showEditGlobalConfiguration = false if (changed) { - this.handledGetGlobalConfigurations() + this.refreshPagedData() } } @@ -237,15 +220,10 @@ export default class extends Vue { await ApiGatewayService.deleteGlobalConfiguration(itemId) const successMessage = this.$t('dataHasBeenDeleted', { name: appId }).toString() this.$message.success(successMessage) - this.handledGetGlobalConfigurations() + this.refreshPagedData() } } }) } - - /** 响应表格排序事件 */ - private handleSortChange(column: any) { - this.globalConfigurationGetQuery.sorting = column.prop - } } diff --git a/vueJs/src/views/admin/apigateway/group.vue b/vueJs/src/views/admin/apigateway/group.vue index 3d5de6173..c121ab8e8 100644 --- a/vueJs/src/views/admin/apigateway/group.vue +++ b/vueJs/src/views/admin/apigateway/group.vue @@ -6,7 +6,7 @@ style="padding-left:0;" >{{ $t('apiGateWay.appId') }} {{ $t('queryFilter') }} {{ $t('searchList') }} @@ -40,14 +40,13 @@ import { dateFormat } from '@/utils' import { checkPermission } from '@/utils/permission' -import { Component, Vue } from 'vue-property-decorator' import Pagination from '@/components/Pagination/index.vue' +import DataListMiXin from '@/mixins/DataListMiXin' +import Component, { mixins } from 'vue-class-component' import RouteGroupCreateOrEditForm from './components/RouteGroupCreateOrEditForm.vue' -import ApiGatewayService, { RouteGroupDto, RouteGroupGetByPagedDto } from '@/api/apigateway' +import ApiGatewayService, { GlobalGetByPagedDto } from '@/api/apigateway' @Component({ name: 'RouteGroup', @@ -200,47 +200,26 @@ import ApiGatewayService, { RouteGroupDto, RouteGroupGetByPagedDto } from '@/api checkPermission } }) -export default class extends Vue { - private editRouteGroupAppId!: string - private editRouteGroupTitle!: any - private showEditRouteGroupDialog!: boolean - private routeGroupListLoading!: boolean - private routeGroupList?: RouteGroupDto[] - private routeGroupQuery!: RouteGroupGetByPagedDto - private routeGroupCount!: number - /** 排序组别 */ - private sortRule!: { prop: string, sort: string } +export default class extends mixins(DataListMiXin) { + private editRouteGroupAppId = '' + private editRouteGroupTitle = '' + private showEditRouteGroupDialog = false - constructor() { - super() - this.routeGroupCount = 0 - this.editRouteGroupAppId = '' - this.editRouteGroupTitle = '' - this.routeGroupListLoading = false - this.showEditRouteGroupDialog = false - this.sortRule = { prop: '', sort: '' } - this.routeGroupList = new Array() - this.routeGroupQuery = new RouteGroupGetByPagedDto() - } + public dataFilter = new GlobalGetByPagedDto() mounted() { - this.handleGetRouteGroups() + this.refreshPagedData() } - private handleGetRouteGroups() { - this.routeGroupListLoading = true - ApiGatewayService.getRouteGroups(this.routeGroupQuery).then(groupData => { - this.routeGroupList = groupData.items - this.routeGroupCount = groupData.totalCount - this.routeGroupListLoading = false - }) + protected getPagedList(filter: any) { + return ApiGatewayService.getRouteGroups(filter) } private handleCreateOrEditRouteGroup(appId: string, appName: string) { this.editRouteGroupAppId = appId - this.editRouteGroupTitle = this.$t('apiGateWay.createGroup') + this.editRouteGroupTitle = this.l('apiGateWay.createGroup') if (appName) { - this.editRouteGroupTitle = this.$t('apiGateWay.updateGroupByApp', { name: appName }) + this.editRouteGroupTitle = this.l('apiGateWay.updateGroupByApp', { name: appName }) } this.showEditRouteGroupDialog = true } @@ -250,7 +229,7 @@ export default class extends Vue { this.editRouteGroupTitle = '' this.showEditRouteGroupDialog = false if (hasChanged) { - this.handleGetRouteGroups() + this.refreshPagedData() } } @@ -263,16 +242,10 @@ export default class extends Vue { await ApiGatewayService.deleteRouteGroup(appId) const successMessage = this.$t('dataHasBeenDeleted', { name: appName }).toString() this.$message.success(successMessage) - this.handleGetRouteGroups() + this.refreshPagedData() } } }) } - - /** 响应表格排序事件 */ - private handleSortChange(column: any) { - this.sortRule.prop = column.prop - this.sortRule.sort = column.sort - } } diff --git a/vueJs/src/views/admin/apigateway/route.vue b/vueJs/src/views/admin/apigateway/route.vue index 3dadfe7af..9812a9230 100644 --- a/vueJs/src/views/admin/apigateway/route.vue +++ b/vueJs/src/views/admin/apigateway/route.vue @@ -6,7 +6,7 @@ style="padding-left:10px;" >{{ $t('apiGateWay.appId') }} {{ $t('queryFilter') }} {{ $t('searchList') }} @@ -47,9 +47,9 @@ @@ -216,10 +216,11 @@ diff --git a/vueJs/src/views/admin/identityServer/api-resources/index.vue b/vueJs/src/views/admin/identityServer/api-resources/index.vue index 10ea16fa8..31cc0c5e8 100644 --- a/vueJs/src/views/admin/identityServer/api-resources/index.vue +++ b/vueJs/src/views/admin/identityServer/api-resources/index.vue @@ -6,7 +6,7 @@ style="padding-left:10px;" >{{ $t('queryFilter') }} {{ $t('searchList') }} @@ -30,9 +30,9 @@ @@ -202,7 +202,7 @@ ref="formApiSecret" :api-resource-id="editApiResource.id" :api-secrets="editApiResource.secrets" - @apiSecretChanged="handleGetApiResources" + @apiSecretChanged="refreshPagedData" /> @@ -219,16 +219,17 @@ ref="formApiScope" :api-resource-id="editApiResource.id" :api-scopes="editApiResource.scopes" - @apiSecretChanged="handleGetApiResources" + @apiSecretChanged="refreshPagedData" /> diff --git a/vueJs/src/views/admin/organization-unit/components/UserOrganizationUint.vue b/vueJs/src/views/admin/organization-unit/components/UserOrganizationUint.vue index 1453d9a46..d66bcb2d5 100644 --- a/vueJs/src/views/admin/organization-unit/components/UserOrganizationUint.vue +++ b/vueJs/src/views/admin/organization-unit/components/UserOrganizationUint.vue @@ -5,7 +5,7 @@ fit highlight-current-row style="width: 100%;" - :data="organizationUnitUsers" + :data="dataList" > diff --git a/vueJs/src/views/admin/roles/index.vue b/vueJs/src/views/admin/roles/index.vue index 7e7dbe835..d55b10b52 100644 --- a/vueJs/src/views/admin/roles/index.vue +++ b/vueJs/src/views/admin/roles/index.vue @@ -5,7 +5,7 @@ class="filter-item" style="margin-left: 10px; text-alignt" type="primary" - @click="handleGetRoles" + @click="refreshPagedData" > {{ $t('roles.refreshList') }} @@ -20,9 +20,9 @@ diff --git a/vueJs/src/views/admin/users/index.vue b/vueJs/src/views/admin/users/index.vue index 9035bad44..6c48bb2da 100644 --- a/vueJs/src/views/admin/users/index.vue +++ b/vueJs/src/views/admin/users/index.vue @@ -6,6 +6,7 @@ style="padding-left:0;" >{{ $t('users.queryFilter') }} {{ $t('users.searchList') }} @@ -29,14 +30,13 @@ diff --git a/vueJs/src/views/file-management/index.vue b/vueJs/src/views/file-management/index.vue index ee0055c48..6c2b55fc0 100644 --- a/vueJs/src/views/file-management/index.vue +++ b/vueJs/src/views/file-management/index.vue @@ -27,9 +27,9 @@ import { dateFormat } from '@/utils' import { checkPermission } from '@/utils/permission' -import { Component, Vue } from 'vue-property-decorator' +import { Vue } from 'vue-property-decorator' +import DataListMiXin from '@/mixins/DataListMiXin' +import Component, { mixins } from 'vue-class-component' import FileUploadForm from './components/FileUploadForm.vue' import Pagination from '@/components/Pagination/index.vue' -import FileSystemService, { FileSystem, FileSystemGetByPaged, FileSystemType } from '@/api/filemanagement' +import FileSystemService, { FileSystemGetByPaged, FileSystemType } from '@/api/filemanagement' const kbUnit = 1 * 1024 const mbUnit = kbUnit * 1024 @@ -247,48 +250,28 @@ const $contextmenu = Vue.prototype.$contextmenu } } }) -export default class extends Vue { - private showFileUploadDialog!: boolean - private downloading!: boolean - private lastFilePath!: string - private fileSystemRoot!: string[] - private fileSystemList?: FileSystem[] - private fileSystemCount!: number - private fileSystemListLoading!: boolean - private fileSystemGetFilter!: FileSystemGetByPaged +export default class extends mixins(DataListMiXin) { + private showFileUploadDialog = false + private downloading = false + private lastFilePath = '' + private fileSystemRoot = new Array() - constructor() { - super() - this.lastFilePath = '' - this.fileSystemCount = 0 - this.downloading = false - this.fileSystemListLoading = false - this.showFileUploadDialog = false - this.fileSystemRoot = new Array() - this.fileSystemList = new Array() - this.fileSystemGetFilter = new FileSystemGetByPaged() - } + public dataFilter = new FileSystemGetByPaged() mounted() { this.fileSystemRoot.push(this.$t('fileSystem.root').toString()) - this.handleGetFileSystemList() + this.refreshPagedData() } - private handleGetFileSystemList() { - this.fileSystemListLoading = true - FileSystemService.getFileSystemList(this.fileSystemGetFilter).then(res => { - this.fileSystemCount = res.totalCount - this.fileSystemList = res.items - }).finally(() => { - this.fileSystemListLoading = false - }) + protected getPagedList(filter: any) { + return FileSystemService.getFileSystemList(filter) } private navigationToFilePath() { const fileSystemPathArray = this.fileSystemRoot.slice(1) const fileSystemPath = fileSystemPathArray.join('/') - this.fileSystemGetFilter.parent = fileSystemPath - this.handleGetFileSystemList() + this.dataFilter.parent = fileSystemPath + this.refreshPagedData() } private handleGoToLastFolder() { @@ -311,12 +294,12 @@ export default class extends Vue { } FileSystemService.deleteFolder(path).then(() => { this.$notify.success(this.l('global.dataHasBeenDeleted', { name: row.name })) - this.handleGetFileSystemList() + this.refreshPagedData() }) } else { FileSystemService.deleteFile(row.parent, row.name).then(() => { this.$notify.success(this.l('global.dataHasBeenDeleted', { name: row.name })) - this.handleGetFileSystemList() + this.refreshPagedData() }) } } @@ -412,12 +395,12 @@ export default class extends Vue { this.fileSystemRoot.splice(index + 1) this.navigationToFilePath() } else { - this.handleGetFileSystemList() + this.refreshPagedData() } } private onFileUploaded() { - this.handleGetFileSystemList() + this.refreshPagedData() } private onFileUploadFormClosed() { @@ -450,7 +433,7 @@ export default class extends Vue { }).then((val: any) => { FileSystemService.createFolder(val.value, parent).then(() => { this.$message.success(this.$t('fileSystem.folderCreateSuccess', { name: val.value }).toString()) - this.handleGetFileSystemList() + this.refreshPagedData() }) }).catch(_ => _) }, @@ -476,10 +459,6 @@ export default class extends Vue { }) return false } - - private l(name: string, values?: any[] | { [key: string]: any }) { - return this.$t(name, values).toString() - } }