From 2842718b81c8ef604a0dd2a1674dd15d6633536d Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Thu, 25 Mar 2021 11:45:58 +0800 Subject: [PATCH] Change some API names and logic --- vueJs/src/App.vue | 8 +-- vueJs/src/api/dynamic-api.ts | 58 ------------------ vueJs/src/components/LangSelect/index.vue | 2 +- vueJs/src/components/TenantBox/index.vue | 2 +- vueJs/src/main.ts | 1 + vueJs/src/mixins/HttpProxyMiXin.ts | 61 +++++++++++++++++-- vueJs/src/store/modules/abp.ts | 2 +- vueJs/src/store/modules/http-proxy.ts | 19 ++---- vueJs/src/store/modules/user.ts | 2 +- .../identityServer/persisted-grants/index.vue | 18 +++--- 10 files changed, 77 insertions(+), 96 deletions(-) diff --git a/vueJs/src/App.vue b/vueJs/src/App.vue index 87e0b786d..70c48f0d9 100644 --- a/vueJs/src/App.vue +++ b/vueJs/src/App.vue @@ -17,14 +17,14 @@ import ServiceWorkerUpdatePopup from '@/pwa/components/ServiceWorkerUpdatePopup. ServiceWorkerUpdatePopup } }) -export default class extends Vue { +export default class App extends Vue { created() { - this.initializeAbpConfiguration() + this.initialize() } - private async initializeAbpConfiguration() { + private async initialize() { await HttpProxyModule.Initialize() - await AbpModule.LoadAbpConfiguration() + await AbpModule.Initialize() } } diff --git a/vueJs/src/api/dynamic-api.ts b/vueJs/src/api/dynamic-api.ts index c6aac5d7a..2e0d028da 100644 --- a/vueJs/src/api/dynamic-api.ts +++ b/vueJs/src/api/dynamic-api.ts @@ -207,44 +207,12 @@ export class ControllerApiDescriptionModel { type!: string interfaces = new Array() actions: {[key: string]: ActionApiDescriptionModel} = {} - - public static getAction( - actionName: string, - actions: {[key: string]: ActionApiDescriptionModel}) { - const actionKeys = Object.keys(actions) - const index = actionKeys.findIndex(key => { - const a = actions[key] - if (a.name.toLowerCase() === actionName.toLowerCase()) { - return a - } - }) - if (index < 0) { - throw new Error(`没有找到名为 ${actionName} 的方法定义!`) - } - return actions[actionKeys[index]] - } } export class ModuleApiDescriptionModel { rootPath = 'app' remoteServiceName = 'Default' controllers: {[key: string]: ControllerApiDescriptionModel} = {} - - public static getController( - controllerName: string, - controllers: {[key: string]: ControllerApiDescriptionModel}) { - const controllerKeys = Object.keys(controllers) - const index = controllerKeys.findIndex(key => { - const c = controllers[key] - if (c.controllerName.toLowerCase() === controllerName.toLowerCase()) { - return c - } - }) - if (index < 0) { - throw new Error(`没有找到名为 ${controllerName} 的接口定义!`) - } - return controllers[controllerKeys[index]] - } } export class TypeApiDescriptionModel { @@ -259,30 +227,4 @@ export class TypeApiDescriptionModel { export class ApplicationApiDescriptionModel { modules: {[key: string]: ModuleApiDescriptionModel} = {} types: {[key: string]: TypeApiDescriptionModel} = {} - - public static getAction( - remoteService: string, - controllerName: string, - actionName: string, - modules: {[key: string]: ModuleApiDescriptionModel}) { - const module = this.getModule(remoteService, modules) - const controller = ModuleApiDescriptionModel.getController(controllerName, module.controllers) - return ControllerApiDescriptionModel.getAction(actionName, controller.actions) - } - - private static getModule( - remoteService: string, - modules: {[key: string]: ModuleApiDescriptionModel}) { - const moduleKeys = Object.keys(modules) - const index = moduleKeys.findIndex(key => { - const m = modules[key] - if (m.remoteServiceName.toLowerCase() === remoteService.toLowerCase()) { - return m - } - }) - if (index < 0) { - throw new Error(`没有找到名为 ${remoteService} 的服务定义!`) - } - return modules[moduleKeys[index]] - } } diff --git a/vueJs/src/components/LangSelect/index.vue b/vueJs/src/components/LangSelect/index.vue index 8031383aa..f9e572c46 100644 --- a/vueJs/src/components/LangSelect/index.vue +++ b/vueJs/src/components/LangSelect/index.vue @@ -40,7 +40,7 @@ export default class extends Vue { AppModule.SetLanguage(lang) this.$i18n.locale = lang this.localization.currentCulture.cultureName = lang - AbpModule.LoadAbpConfiguration().then(() => { + AbpModule.Initialize().then(() => { this.$message({ message: 'Switch Language Success', type: 'success' diff --git a/vueJs/src/components/TenantBox/index.vue b/vueJs/src/components/TenantBox/index.vue index 64c5e856b..4600fc01b 100644 --- a/vueJs/src/components/TenantBox/index.vue +++ b/vueJs/src/components/TenantBox/index.vue @@ -49,7 +49,7 @@ export default class extends Vue { }) } else { AbpModule.configuration.currentTenant.isAvailable = false - AbpModule.LoadAbpConfiguration().finally(() => { + AbpModule.Initialize().finally(() => { this.$emit('input', '') }) } diff --git a/vueJs/src/main.ts b/vueJs/src/main.ts index a59ee9adb..a57a79654 100644 --- a/vueJs/src/main.ts +++ b/vueJs/src/main.ts @@ -59,6 +59,7 @@ Object.keys(filters).forEach(key => { }) Vue.config.productionTip = false +Vue.prototype.$r = {} new Vue({ router, diff --git a/vueJs/src/mixins/HttpProxyMiXin.ts b/vueJs/src/mixins/HttpProxyMiXin.ts index 6db5325ff..5482342e2 100644 --- a/vueJs/src/mixins/HttpProxyMiXin.ts +++ b/vueJs/src/mixins/HttpProxyMiXin.ts @@ -7,7 +7,9 @@ import { ApiVersionInfo, ParameterBindingSources, UrlBuilder, - ApplicationApiDescriptionModel + ApplicationApiDescriptionModel, + ModuleApiDescriptionModel, + ControllerApiDescriptionModel } from '@/api/dynamic-api' /** * 动态Http代理组件 @@ -16,6 +18,8 @@ import { name: 'HttpProxyMiXin' }) export default class HttpProxyMiXin extends Vue { + private apiDescriptor = HttpProxyModule.applicationApiDescriptionModel + protected pagedRequest(options: { service: string, controller: string, @@ -32,10 +36,9 @@ export default class HttpProxyMiXin extends Vue { action: string, data?: any }) { - const action = ApplicationApiDescriptionModel - .getAction( - options.service, options.controller, options.action, - HttpProxyModule.applicationApiDescriptionModel.modules) + const module = this.getModule(options.service, this.apiDescriptor.modules) + const controller = this.getController(options.controller, module.controllers) + const action = this.getAction(options.action, controller.actions) const apiVersion = this.getApiVersionInfo(action) let url = process.env.REMOTE_SERVICE_BASE_URL || '' url = this.ensureEndsWith(url, '/') + UrlBuilder.generateUrlWithParameters(action, options.data, apiVersion) @@ -47,6 +50,54 @@ export default class HttpProxyMiXin extends Vue { }) } + private getModule( + remoteService: string, + modules: {[key: string]: ModuleApiDescriptionModel}) { + const moduleKeys = Object.keys(modules) + const index = moduleKeys.findIndex(key => { + const m = modules[key] + if (m.remoteServiceName.toLowerCase() === remoteService.toLowerCase()) { + return m + } + }) + if (index < 0) { + throw new Error(`没有找到名为 ${remoteService} 的服务定义!`) + } + return modules[moduleKeys[index]] + } + + private getController( + controllerName: string, + controllers: {[key: string]: ControllerApiDescriptionModel}) { + const controllerKeys = Object.keys(controllers) + const index = controllerKeys.findIndex(key => { + const c = controllers[key] + if (c.controllerName.toLowerCase() === controllerName.toLowerCase()) { + return c + } + }) + if (index < 0) { + throw new Error(`没有找到名为 ${controllerName} 的接口定义!`) + } + return controllers[controllerKeys[index]] + } + + private getAction( + actionName: string, + actions: {[key: string]: ActionApiDescriptionModel}) { + const actionKeys = Object.keys(actions) + const index = actionKeys.findIndex(key => { + const a = actions[key] + if (a.name.toLowerCase() === actionName.toLowerCase()) { + return a + } + }) + if (index < 0) { + throw new Error(`没有找到名为 ${actionName} 的方法定义!`) + } + return actions[actionKeys[index]] + } + private getApiVersionInfo(action: ActionApiDescriptionModel) { const apiVersion = this.findBestApiVersion(action) const versionParam = diff --git a/vueJs/src/store/modules/abp.ts b/vueJs/src/store/modules/abp.ts index 1d9700d86..dda886e9e 100644 --- a/vueJs/src/store/modules/abp.ts +++ b/vueJs/src/store/modules/abp.ts @@ -27,7 +27,7 @@ class AbpConfiguration extends VuexModule implements IAbpState { } @Action({ rawError: true }) - public LoadAbpConfiguration() { + public Initialize() { return new Promise((resolve, reject) => { AbpConfigurationService.getAbpConfiguration().then(config => { this.SET_ABPCONFIGURATION(config) diff --git a/vueJs/src/store/modules/http-proxy.ts b/vueJs/src/store/modules/http-proxy.ts index cd3abf0b2..f9307e385 100644 --- a/vueJs/src/store/modules/http-proxy.ts +++ b/vueJs/src/store/modules/http-proxy.ts @@ -22,25 +22,16 @@ class HttpProxy extends VuexModule implements IHttpProxy { public async Initialize() { const dynamicApiJson = getItem(dynamicApiKey) if (dynamicApiJson) { - this.SET_API_DESCRIPTOR(JSON.parse(dynamicApiJson)) - return + const apiDescriptor = JSON.parse(dynamicApiJson) as ApplicationApiDescriptionModel + if (apiDescriptor) { + this.SET_API_DESCRIPTOR(apiDescriptor) + return + } } const dynamicApi = await DynamicApiService.get() this.SET_API_DESCRIPTOR(dynamicApi) setItem(dynamicApiKey, JSON.stringify(dynamicApi)) } - - @Action({ rawError: true }) - public findAction(service: { - name: string, - controller: string, - action: string - }) { - return ApplicationApiDescriptionModel - .getAction( - service.name, service.controller, service.action, - this.applicationApiDescriptionModel.modules) - } } export const HttpProxyModule = getModule(HttpProxy) diff --git a/vueJs/src/store/modules/user.ts b/vueJs/src/store/modules/user.ts index 9d8d96865..81a136311 100644 --- a/vueJs/src/store/modules/user.ts +++ b/vueJs/src/store/modules/user.ts @@ -136,7 +136,7 @@ class User extends VuexModule implements IUserState { @Action private async PostLogin() { - const abpConfig = await AbpModule.LoadAbpConfiguration() + const abpConfig = await AbpModule.Initialize() this.SET_CURRENTUSERINFO(abpConfig.currentUser) } } diff --git a/vueJs/src/views/admin/identityServer/persisted-grants/index.vue b/vueJs/src/views/admin/identityServer/persisted-grants/index.vue index c243cced2..b85414450 100644 --- a/vueJs/src/views/admin/identityServer/persisted-grants/index.vue +++ b/vueJs/src/views/admin/identityServer/persisted-grants/index.vue @@ -35,7 +35,7 @@ :label="$t('AbpIdentityServer.Client:Id')" prop="clientId" sortable - width="150px" + width="180px" >