From e1897991ce3bf1f75c9f4f21aad71a04c6056f2e Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Sat, 2 Apr 2022 20:35:17 +0800 Subject: [PATCH 1/2] fix: form-data data should not be processed --- apps/vue/src/api/oss-management/oss.ts | 18 +++++++++++---- apps/vue/src/utils/helper/abpApiHelper.ts | 1 + apps/vue/src/utils/http/abp/abp.ts | 23 ++++++++++++++++--- apps/vue/src/utils/http/axios/index.ts | 2 +- .../src/views/account/setting/BaseSetting.vue | 8 +++++-- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/apps/vue/src/api/oss-management/oss.ts b/apps/vue/src/api/oss-management/oss.ts index d416339c4..a95e6eb41 100644 --- a/apps/vue/src/api/oss-management/oss.ts +++ b/apps/vue/src/api/oss-management/oss.ts @@ -14,6 +14,7 @@ import { format } from '/@/utils/strings'; import { AxiosResponse } from 'axios'; import { isFunction } from '/@/utils/is'; import { UploadFileParams } from '/#/axios'; +import { deepMerge } from '/@/utils'; enum Api { CreateObject = '/api/oss-management/objects', @@ -162,10 +163,19 @@ export const getContainers = (input: GetOssContainerPagedRequest) => { }); }; -export const createObject = (input: OssObjectCreate) => { - return defAbpHttp.post({ - url: Api.CreateObject, - data: input, +export const createObject = (input: OssObjectCreate, file?: Blob) => { + return defAbpHttp.request({ + service: 'AbpOssManagement', + controller: 'OssObject', + action: 'CreateAsync', + data: { + Bucket: input.bucket, + Path: input.path, + FileName: input.object, + Overwrite: input.overwrite, + ExpirationTime: input.expirationTime, + File: file, + }, }); }; diff --git a/apps/vue/src/utils/helper/abpApiHelper.ts b/apps/vue/src/utils/helper/abpApiHelper.ts index 3d52aa439..fd1730ca0 100644 --- a/apps/vue/src/utils/helper/abpApiHelper.ts +++ b/apps/vue/src/utils/helper/abpApiHelper.ts @@ -10,6 +10,7 @@ export enum ParameterBindingSources { body = 'Body', path = 'Path', form = 'Form', + formFile = 'FormFile', header = 'Header', custom = 'Custom', services = 'Services', diff --git a/apps/vue/src/utils/http/abp/abp.ts b/apps/vue/src/utils/http/abp/abp.ts index d7cb5bed9..473e168f8 100644 --- a/apps/vue/src/utils/http/abp/abp.ts +++ b/apps/vue/src/utils/http/abp/abp.ts @@ -13,6 +13,7 @@ import { ListResultDto, PagedResultDto } from '/@/api/model/baseModel'; import { useI18n } from '/@/hooks/web/useI18n'; import { AxiosRequestConfig } from 'axios'; import { RequestOptions, UploadFileParams } from '/#/axios'; +import { ContentTypeEnum } from '/@/enums/httpEnum'; const { t } = useI18n(); @@ -63,19 +64,35 @@ export class abpRequest { action: string; data?: any; params?: any; - }) { + }, requestOptions?: RequestOptions) { const abpStore = useAbpStoreWithOut(); const module = this.getModule(options.service, abpStore.apidefinition.modules); const controller = this.getController(options.controller, module.controllers); const action = this.getAction(options.action, controller.actions); const apiVersion = this.getApiVersionInfo(action); const url = UrlBuilder.generateUrlWithParameters(action, options.params, apiVersion); + let requestData = options.data; + const headers = {}; + + const formDataParams = action.parameters + .filter(p => [`${ParameterBindingSources.form}`, `${ParameterBindingSources.formFile}`].includes(p.bindingSourceId!)); + if (requestData && formDataParams.length > 0) { + headers['Content-Type'] = ContentTypeEnum.FORM_DATA; + const formData = new window.FormData(); + formDataParams.forEach(param => { + if (requestData[param.name]) { + formData.append(param.name, requestData[param.name]); + } + }) + requestData = formData + } return defHttp.request({ url: url, method: action?.httpMethod, - data: options.data, - }); + data: requestData, + headers: headers, + }, requestOptions); } private getModule(remoteService: string, modules: { [key: string]: ModuleApiDescriptionModel }) { diff --git a/apps/vue/src/utils/http/axios/index.ts b/apps/vue/src/utils/http/axios/index.ts index a00d3813d..f43470ef6 100644 --- a/apps/vue/src/utils/http/axios/index.ts +++ b/apps/vue/src/utils/http/axios/index.ts @@ -95,7 +95,7 @@ const transform: AxiosTransform = { if (Reflect.has(config, 'data') && config.data && Object.keys(config.data).length > 0) { config.data = data; config.params = params; - } else { + } else if (Reflect.has(config, 'headers') && config.headers && config.headers['Content-Type'] !== ContentTypeEnum.FORM_DATA) { // 防止form-data类型数据被清除 // 非GET请求如果没有提供data,则将params视为data config.data = params; config.params = undefined; diff --git a/apps/vue/src/views/account/setting/BaseSetting.vue b/apps/vue/src/views/account/setting/BaseSetting.vue index cbac82555..2fa75217f 100644 --- a/apps/vue/src/views/account/setting/BaseSetting.vue +++ b/apps/vue/src/views/account/setting/BaseSetting.vue @@ -68,13 +68,14 @@ }); const avatar = computed(() => { const { avatar } = userStore.getUserInfo; + console.log(avatar) return avatar ?? headerImg; }); onMounted(_fetchProfile); function _fetchProfile() { - getProfile().then((profile) => { + return getProfile().then((profile) => { setFieldsValue(profile); }); } @@ -85,7 +86,9 @@ .then((res) => { const path = encodeURIComponent(res.data.path.substring(0, res.data.path.length - 1)); changeAvatar({ avatarUrl: `${path}/${res.data.name}` }).then(() => { - resolve(res as unknown as void); + _fetchProfile().then(() => { + resolve({} as unknown as void); + }).catch((err) => reject(err)); }).catch((err) => reject(err)); }) .catch((err) => reject(err)); @@ -105,6 +108,7 @@ updateProfile(getFieldsValue() as UpdateMyProfile) .then(() => { createMessage.success(L('PersonalSettingsSaved')); + _fetchProfile(); }) .finally(() => { confirmButton.loading = false; From bd03d02eed862ce004cf84b99404922636710940 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Sat, 2 Apr 2022 20:37:13 +0800 Subject: [PATCH 2/2] fix: remove console --- apps/vue/src/views/account/setting/BaseSetting.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/vue/src/views/account/setting/BaseSetting.vue b/apps/vue/src/views/account/setting/BaseSetting.vue index 2fa75217f..af138d16d 100644 --- a/apps/vue/src/views/account/setting/BaseSetting.vue +++ b/apps/vue/src/views/account/setting/BaseSetting.vue @@ -68,7 +68,6 @@ }); const avatar = computed(() => { const { avatar } = userStore.getUserInfo; - console.log(avatar) return avatar ?? headerImg; });