Commit d4832c7895ae5a1aec9f7727baf0b45a291a414e
Merge branch 'ft' into 'main_dev'
fix(src/api/external): 修改传post请求body体里携带空字符串问题 See merge request yunteng/thingskit-view!136
Showing
4 changed files
with
28 additions
and
10 deletions
1 | -import { RequestBodyEnum, RequestParams } from "@/enums/httpEnum" | 1 | +import { RequestBodyEnum, RequestHttpEnum, RequestParams } from "@/enums/httpEnum" |
2 | import { ExtraRequestConfigType } from "@/store/external/modules/extraComponentInfo.d" | 2 | import { ExtraRequestConfigType } from "@/store/external/modules/extraComponentInfo.d" |
3 | import { RequestConfigType } from "@/store/modules/chartEditStore/chartEditStore.d" | 3 | import { RequestConfigType } from "@/store/modules/chartEditStore/chartEditStore.d" |
4 | import { isShareMode } from "@/views/share/hook" | 4 | import { isShareMode } from "@/views/share/hook" |
@@ -115,6 +115,22 @@ const handleParams = (Params: Recordable) => { | @@ -115,6 +115,22 @@ const handleParams = (Params: Recordable) => { | ||
115 | return Object.keys(Params).filter(Boolean).reduce((prev, next) => ({ ...prev, [next]: Params[next] }), {}) | 115 | return Object.keys(Params).filter(Boolean).reduce((prev, next) => ({ ...prev, [next]: Params[next] }), {}) |
116 | } | 116 | } |
117 | 117 | ||
118 | +//post请求动态追加query参数 | ||
119 | +const objConvertQuery= (data:Recordable)=> { | ||
120 | + const _result = []; | ||
121 | + for (const key in data) { | ||
122 | + const value = data[key]; | ||
123 | + if (value.constructor == Array) { | ||
124 | + value.forEach(function(_value) { | ||
125 | + _result.push(key + "=" + _value); | ||
126 | + }); | ||
127 | + } else { | ||
128 | + _result.push(key + '=' + value); | ||
129 | + } | ||
130 | + } | ||
131 | + return _result.join('&'); | ||
132 | +} | ||
133 | + | ||
118 | export const customRequest = async (request: RequestConfigType) => { | 134 | export const customRequest = async (request: RequestConfigType) => { |
119 | const { requestHttpType, requestParams, requestParamsBodyType, requestOriginUrl } = request as ExtraRequestConfigType | 135 | const { requestHttpType, requestParams, requestParamsBodyType, requestOriginUrl } = request as ExtraRequestConfigType |
120 | let { requestUrl } = request as ExtraRequestConfigType | 136 | let { requestUrl } = request as ExtraRequestConfigType |
@@ -130,18 +146,18 @@ export const customRequest = async (request: RequestConfigType) => { | @@ -130,18 +146,18 @@ export const customRequest = async (request: RequestConfigType) => { | ||
130 | const body = transformBodyValue(Body, requestParamsBodyType) | 146 | const body = transformBodyValue(Body, requestParamsBodyType) |
131 | 147 | ||
132 | /** | 148 | /** |
133 | - * ft 修改post请求针对这种接口(/api/yt/device,设备列表分页),是post请求,body体一定要携带内容,空内容也可以 | 149 | + * ft 修改post请求针对这种接口(/api/yt/device,设备列表分页),是post请求,page和pageSize是query参数,body可以不传内容 |
134 | * 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯 | 150 | * 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯 |
135 | - * 源代码 data: body, | ||
136 | - * 修改后代码 data: !body? {"":null} :body, | 151 | + * 源代码 url: requestUrl |
152 | + * 修改后代码 requestHttpType === RequestHttpEnum.GET.toUpperCase() ? requestUrl: `${requestUrl}?${objConvertQuery(Params)} | ||
137 | */ | 153 | */ |
138 | Params = handleParams(Params) | 154 | Params = handleParams(Params) |
139 | return customHttp.request<any>({ | 155 | return customHttp.request<any>({ |
140 | - url: requestUrl, | 156 | + url: requestHttpType === RequestHttpEnum.GET.toUpperCase() ? requestUrl: `${requestUrl}?${objConvertQuery(Params)}`, |
141 | baseURL: getOriginUrl(requestOriginUrl!), | 157 | baseURL: getOriginUrl(requestOriginUrl!), |
142 | method: requestHttpType, | 158 | method: requestHttpType, |
143 | - params: Params, | ||
144 | - data: !body? {"":null} :body, | 159 | + params: requestHttpType === RequestHttpEnum.GET.toUpperCase() ? Params: null, |
160 | + data: body, | ||
145 | headers: extraValue(Header) | 161 | headers: extraValue(Header) |
146 | }, { | 162 | }, { |
147 | joinPrefix: false, | 163 | joinPrefix: false, |
63 KB
12.1 KB
1 | import { ChartFrameEnum, PackagesCategoryEnum } from '@/packages/index.d' | 1 | import { ChartFrameEnum, PackagesCategoryEnum } from '@/packages/index.d' |
2 | import { ImageConfig } from '@/packages/components/Informations/Mores/Image/index' | 2 | import { ImageConfig } from '@/packages/components/Informations/Mores/Image/index' |
3 | import { ChatCategoryEnum, ChatCategoryEnumName } from '../index.d' | 3 | import { ChatCategoryEnum, ChatCategoryEnumName } from '../index.d' |
4 | +import carousel1 from '@/assets/images/chart/photos/carousel1.jpeg' | ||
5 | +import carousel2 from '@/assets/images/chart/photos/carousel2.jpeg' | ||
4 | 6 | ||
5 | // 远程共享库(调接口获取图像列表) | 7 | // 远程共享库(调接口获取图像列表) |
6 | const imageList = [ | 8 | const imageList = [ |
7 | - { imageName: 'carousel1', imageUrl: 'https://naive-ui.oss-cn-beijing.aliyuncs.com/carousel-img/carousel1.jpeg' }, | ||
8 | - { imageName: 'carousel2', imageUrl: 'https://naive-ui.oss-cn-beijing.aliyuncs.com/carousel-img/carousel2.jpeg' } | 9 | + { imageName: 'carousel1', imageUrl: 'carousel1.jpeg' }, |
10 | + { imageName: 'carousel2', imageUrl: 'carousel2.jpeg' } | ||
9 | ] | 11 | ] |
10 | 12 | ||
11 | const photoConfigList = imageList.map(i => ({ | 13 | const photoConfigList = imageList.map(i => ({ |
@@ -15,7 +17,7 @@ const photoConfigList = imageList.map(i => ({ | @@ -15,7 +17,7 @@ const photoConfigList = imageList.map(i => ({ | ||
15 | package: PackagesCategoryEnum.PHOTOS, | 17 | package: PackagesCategoryEnum.PHOTOS, |
16 | chartFrame: ChartFrameEnum.STATIC, | 18 | chartFrame: ChartFrameEnum.STATIC, |
17 | image: i.imageUrl, | 19 | image: i.imageUrl, |
18 | - dataset: i.imageUrl, | 20 | + dataset: i.imageName==='carousel1' ? carousel1 : carousel2, |
19 | title: i.imageName, | 21 | title: i.imageName, |
20 | redirectComponent: `${ImageConfig.package}/${ImageConfig.category}/${ImageConfig.key}` // 跳转组件路径规则:packageName/categoryName/componentKey | 22 | redirectComponent: `${ImageConfig.package}/${ImageConfig.category}/${ImageConfig.key}` // 跳转组件路径规则:packageName/categoryName/componentKey |
21 | })) | 23 | })) |