consumer模块完成度95%,检查消费者前端bug并修复

This commit is contained in:
cyh666666
2026-03-09 17:20:59 +08:00
parent 7b5801a72b
commit 2262d1bfd9
128 changed files with 13485 additions and 1670 deletions

View File

@@ -115,24 +115,56 @@ export class AkReq {
await this.refreshTokenIfNeeded(apikey);
}
// 统一 header,自动带上 Authorization/Content-Type/Accept
let headers = options.headers ?? ({} as UTSJSONObject);
const token = this.getToken();
if (token != null && token != "") {
headers = Object.assign({}, headers, { Authorization: `Bearer ${token}` }) as UTSJSONObject;
}
let contentType = options.contentType ?? '';
if (headers != null && typeof headers.getString === 'function') {
const headerContentType = headers.getString('Content-Type');
if (headerContentType != null) {
contentType = headerContentType;
// 构建新的 headers 对象,确保所有字段都被正确传递
const newHeaders = new UTSJSONObject()
// 首先复制原始 headers
if (options.headers != null) {
const originalHeaders = options.headers
if (typeof originalHeaders.getString === 'function') {
// 复制 apikey
const apikey = originalHeaders.getString('apikey')
if (apikey != null) {
newHeaders.set('apikey', apikey)
}
// 复制 Content-Type
const contentType = originalHeaders.getString('Content-Type')
if (contentType != null) {
newHeaders.set('Content-Type', contentType)
}
// 复制 Prefer
const prefer = originalHeaders.getString('Prefer')
if (prefer != null) {
newHeaders.set('Prefer', prefer)
}
// 复制 Authorization如果存在
const auth = originalHeaders.getString('Authorization')
if (auth != null) {
newHeaders.set('Authorization', auth)
}
}
}
if (contentType != null && contentType != "") {
headers = Object.assign({}, headers, { 'Content-Type': contentType }) as UTSJSONObject;
// 添加/更新 Authorization
const token = this.getToken();
if (token != null && token != "") {
newHeaders.set('Authorization', `Bearer ${token}`)
}
// 默认 Accept
headers = Object.assign({ Accept: 'application/json' } as UTSJSONObject, headers) as UTSJSONObject;
// 确保 Content-Type 存在
if (newHeaders.getString('Content-Type') == null) {
const contentType = options.contentType ?? 'application/json'
if (contentType != null && contentType != "") {
newHeaders.set('Content-Type', contentType)
}
}
// 添加 Accept
newHeaders.set('Accept', 'application/json')
console.log('[AkReq.request] headers:', JSON.stringify(newHeaders))
const headers = newHeaders
const timeout = options.timeout ?? 10000;
const maxRetry = Math.max(0, options.retryCount ?? 0);