this.controller = uni.request({
url,
method: "POST",
header: httpHeaders,
data: params,
responseType: "arraybuffer",
enableChunked: true,
timeout: 60000,
dataType: 'text',
success() { console.log("流式请求完成"); },
fail(err) { console.error("连接错误:", err); }
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
let i = 0
this.controller?.onChunkReceived(chunk => {
const decoder = new TextDecoder('utf-8', { fatal: false });
const text = decoder.decode(new Uint8Array(chunk.data), { stream: true });
const data = parser.feed(text) as EventSourceMessage;
i++
console.log("收到数据块:", i, data);
if (data) {
this.callback(data);
}
});
event:start
data:{"content":"正在思考..."}
event:commodity
data:{"content":"{\"code\":200,\"data\":{\"total\":4,\"data\":[{\"activityLabels\":[{\"actConfig\":\"{\\"maxDiscountPrice\\":-1.0,\\"calDiscountPrice\\":false,\\"actId\\":\\"2077228467517136898\\",\\"actType\\":3,\\"rules\\":[{\\"discountRate\\":0.9800,\\"meetPrice\\":0.0,\\"discountValue\\":0.0}],\\"actName\\":\\"未开始\\"}\",\"id\":832,\"labelCode\":\"onebuygz_market_activity_2077228467517136898\",\"labelName\":\"未开始\",\"labelStyleConfig\":\"{\\"labelText\\":\\"9.8折券\\"}\",\"priority\":98,\"queryScope\":1},{\"actConfig\":\"{\\"calDiscountPrice\\":false,\\"actId\\":\\"2082652253791985666\\",\\"actType\\":4,\\"rules\\":[{\\"discountRate\\":0.0000,\\"meetPrice\\":0.0,\\"discountValue\\":5.0}],\\"actName\\":\\"一码游优惠券对接勿动\\"}\",\"id\":842,\"labelCode\":\"onebuygz_market_activity_2082652253791985666\",\"labelName\":\"一码游优惠券对接勿动\",\"labelStyleConfig\":\"{\\"labelText\\":\\"5元券\\"}\",\"priority\":98,\"queryScope\":1}],\"categoryId\":\"11573\",\"categoryName\":\"茗茶/绿茶/都匀毛尖\",\"dataType\":1,\"id\":\"gogbuy_1000010171\",\"itemDiscountPrice\":null,\"itemId\":\"1000010171\",\"itemName\":\"扭扭车儿童溜溜车防侧翻1-2一3岁女宝四轮可坐摇摆玩具滑滑妞妞车\",\"itemPictureUrl\":\"https://b2ctest.gcongo.cn/ymgzsc/tx/2026/5/20/d3c26c2a555640daa1b37dc8247cba15.jpg\",\"itemPrice\":59.9,\"itemRoute\":\"https://testb2ch5.gcongo.cn/#/pages/commodity-detail/index?itemId=1000010171\",\"onSale\":1,\"platform\":\"gogbuy\",\"saleQuantity\":0,\"score\":0.03278688524590164,\"shopId\":\"2000000841\",\"shopLogoUrl\":\"https://b2ctest.gcongo.cn/ymgzsc/tx/2026/7/20/ae0dc6bfc1934c8eaf809364d89aae0e.png\",\"shopMarkFlag\":[\"2\"],\"shopName\":\"tc_18585073449专营店(测试)\",\"shopRoute\":\"https://testb2ch5.gcongo.cn/#/pages/shop/index?shopId=2000000841\",\"shopStatus\":1},{\"activityLabels\":[{\"actConfig\":\"{\\"maxDiscountPrice\\":-1.0,\\"calDiscountPrice\\":false,\\"actId\\":\\"2077228467517136898\\",\\"actType\\":3,\\"rules\\":[{\\"discountRate\\":0.9800,\\"meetPrice\\":0.0,\\"discountValue\\":0.0}],\\"actName\\":\\"未开始\\"}\",\"id\":832,\"labelCode\":\"onebuygz_market_activity_2077228467517136898\",\"labelName\":\"未开始\",\"labelStyleConfig\":\"{\\"labelText\\":\\"9.8折券\\"}\",\"priority\":98,\"queryScope\":1},{\"actConfig\":\"{\\"calDiscountPrice\\":false,\\"actId\\":\\"2082652253791985666\\",\\"actType\\":4,\\"rules\\":[{\\"discountRate\\":0.0000,\\"meetPrice\\":0.0,\\"discountValue\\":5.0}],\\"actName\\":\\"一码游优惠券对接勿动\\"}\",\"id\":842,\"labelCode\":\"onebuygz_market_activity_2082652253791985666\",\"labelName\":\"一码游优惠券对接勿动\",\"labelStyleConfig\":\"{\\"labelText\\":\\"5元券\\"}\",\"priority\":98,\"queryScope\":1}],\"categoryId\":\"11795\",\"categoryName\":\"2026家电以旧换新6类/空调1/一级能效空调1\",\"dataType\":1,\"id\":\"gogbuy_1000010096\",\"itemDiscountPrice\":null,\"itemId\":\"1000010096\",\"itemName\":\"tc3449店铺-空调1-一级能效-包邮\",\"itemPictureUrl\":\"https://b2ctest.gcongo.cn/hw/2025/1/17/bd244569-3cab-4b8a-aa2a-691ee27fb249.png\",\"itemPrice\":1.4,\"itemRoute\":\"https://testb2ch5.gcongo.cn/#/pages/commodity-detail/index?itemId=1000010096\",\"onSale\":1,\"platform\":\"gogbuy\",\"saleQuantity\":0,\"score\":0.03225806451612903,\"shopId\":\"2000000841\",\"shopLogoUrl\":\"https://b2ctest.gcongo.cn/ymgzsc/tx/2026/7/20/ae0dc6bfc1934c8eaf809364d89aae0e.png\",\"shopMarkFlag\":[\"2\"],\"shopName\":\"tc_18585073449专营店(测试)\",\"shopRoute\":\"https://testb2ch5.gcongo.cn/#/pages/shop/index?shopId=2000000841\",\"shopStatus\":1},{\"activityLabels\":[{\"actConfig\":\"{\\"maxDiscountPrice\\":-1.0,\\"calDiscountPrice\\":false,\\"actId\\":\\"2077228467517136898\\",\\"actType\\":3,\\"rules\\":[{\\"discountRate\\":0.9800,\\"meetPrice\\":0.0,\\"discountValue\\":0.0}],\\"actName\\":\\"未开始\\"}\",\"id\":832,\"labelCode\":\"onebuygz_market_activity_2077228467517136898\",\"labelName\":\"未开始\",\"labelStyleConfig\":\"{\\"labelText\\":\\"9.8折券\\"}\",\"priority\":98,\"queryScope\":1},{\"actConfig\":\"{\\"calDiscountPrice\\":false,\\"actId\\":\\"2082652253791985666\\",\\"actType\\":4,\\"rules\\":[{\\"discountRate\\":0.0000,\\"meetPrice\\":0.0,\\"discountValue\\":5.0}],\\"actName\\":\\"一码游优惠券对接勿动\\"}\",\"id\":842,\"labelCode\":\"onebuygz_market_activity_2082652253791985666\",\"labelName\":\"一码游优惠券对接勿动\",\"labelStyleConfig\":\"{\\"labelText\\":\\"5元券\\"}\",\"priority\":98,\"queryScope\":1}],\"categoryId\":\"11828\",\"categoryName\":\"O2O类目/O2O文旅商品/文旅商品\",\"dataType\":1,\"id\":\"gogbuy_1000010141\",\"itemDiscountPrice\":null,\"itemId\":\"1000010141\",\"itemName\":\"tc3449店铺-文旅商品1-包邮\",\"itemPictureUrl\":\"https://b2ctest.gcongo.cn/hw/2025/11/24/966d3727-ab4f-4b77-9aa9-ccbf3d0f8ae8.jpg\",\"itemPrice\":0.5,\"itemRoute\":\"https://testb2ch5.gcongo.cn/#/pages/commodity-detail/index?itemId=1000010141\",\"onSale\":1,\"platform\":\"gogbuy\",\"saleQuantity\":0,\"score\":0.031746031746031744,\"shopId\":\"2000000841\",\"shopLogoUrl\":\"https://b2ctest.gcongo.cn/ymgzsc/tx/2026/7/20/ae0dc6bfc1934c8eaf809364d89aae0e.png\",\"shopMarkFlag\":[\"2\"],\"shopName\":\"tc_18585073449专营店(测试)\",\"shopRoute\":\"https://testb2ch5.gcongo.cn/#/pages/shop/index?shopId=2000000841\",\"shopStatus\":1},{\"activityLabels\":[{\"actConfig\":\"{\\"maxDiscountPrice\\":-1.0,\\"calDiscountPrice\\":false,\\"actId\\":\\"2077228467517136898\\",\\"actType\\":3,\\"rules\\":[{\\"discountRate\\":0.9800,\\"meetPrice\\":0.0,\\"discountValue\\":0.0}],\\"actName\\":\\"未开始\\"}\",\"id\":832,\"labelCode\":\"onebuygz_market_activity_2077228467517136898\",\"labelName\":\"未开始\",\"labelStyleConfig\":\"{\\"labelText\\":\\"9.8折券\\"}\",\"priority\":98,\"queryScope\":1},{\"actConfig\":\"{\\"calDiscountPrice\\":false,\\"actId\\":\\"2082652253791985666\\",\\"actType\\":4,\\"rules\\":[{\\"discountRate\\":0.0000,\\"meetPrice\\":0.0,\\"discountValue\\":5.0}],\\"actName\\":\\"一码游优惠券对接勿动\\"}\",\"id\":842,\"labelCode\":\"onebuygz_market_activity_2082652253791985666\",\"labelName\":\"一码游优惠券对接勿动\",\"labelStyleConfig\":\"{\\"labelText\\":\\"5元券\\"}\",\"priority\":98,\"queryScope\":1}],\"categoryId\":\"11823\",\"categoryName\":\"2026以旧换新数码3C/平板/一级能效平板\",\"dataType\":1,\"id\":\"gogbuy_1000010155\",\"itemDiscountPrice\":null,\"itemId\":\"1000010155\",\"itemName\":\"联想平板来酷Pro12.7二合一 【618好价速抢】平板PC双模式办公娱乐 护眼2.1K超清大屏 1\",\"itemPictureUrl\":\"https://b2ctest.gcongo.cn/hw/2026/4/8/d8717573-4728-4d50-b472-05fa8ec236e8.png\",\"itemPrice\":22.0,\"itemRoute\":\"https://testb2ch5.gcongo.cn/#/pages/commodity-detail/index?itemId=1000010155\",\"onSale\":1,\"platform\":\"gogbuy\",\"saleQuantity\":0,\"score\":0.03125,\"shopId\":\"2000000841\",\"shopLogoUrl\":\"https://b2ctest.gcongo.cn/ymgzsc/tx/2026/7/20/ae0dc6bfc1934c8eaf809364d89aae0e.png\",\"shopMarkFlag\":[\"2\"],\"shopName\":\"tc_18585073449专营店(测试)\",\"shopRoute\":\"https://testb2ch5.gcongo.cn/#/pages/shop/index?shopId=2000000841\",\"shopStatus\":1}],\"after\":\"WzIwLjU3MjM2MSwiZ29nYnV5XzEwMDAwMTAxNTUiXQ==\"},\"extData\":null,\"msg\":\"查询成功\"}"}
event:end
data:{"content":"done"}
收到数据块: 1 {event: 'start', data: '{"content":"正在思考..."}'}
vconsole.min.js:10 收到数据块: 2 {event: 'commodity', data: '{"content":"{\"code\":200,\"data\":{\"total\":4,\"…xNTUiXQ==\"},\"extData\":null,\"msg\":\"查询成功\"}"}'}
1 个回复
Ask小助手 - Ask社区AI助手
感谢您的反馈。针对您提交的 Bug 报告,我们进行了评审与分析,以下是详细的评审意见与排查建议:
1. Bug 反馈内容完整性评审
request开启enableChunked后onChunkReceived回调丢包的问题,官方人员能够理解您的意图。parser对象的定义,官方人员难以直接复现。建议补充完整的复现工程或提供可复现的接口服务信息。enableChunked的底层实现存在平台差异,请务必补充具体运行平台(如 App-Android、App-iOS、Web/H5 或微信小程序等)、手机系统版本、设备机型以及 Vue 版本等信息。2. Bug 是否成立分析
从您提供的日志来看,收到了数据块 1 和数据块 2,但缺少了后续的
event:end数据。针对此现象,结合enableChunked的流式传输特性,有以下几个方向需要您进一步排查确认:数据包粘包/分包解析问题:
流式传输(SSE/Chunked)中,网络层回调的
chunk并不保证与业务层的“一条完整消息”一一对应。可能会出现一个chunk包含多条消息,或者一条消息被拆分到多个chunk中的情况。在您的代码中,使用了
TextDecoder的decode方法并配合自定义的parser.feed(text)进行解析。如果parser在处理未接收完整的跨包数据时存在逻辑缺陷,或者decode的stream: true在特定断点处处理异常,可能会导致后续数据无法正确解析并触发回调。建议您在onChunkReceived中直接打印原始chunk.data的字节长度或原始文本,确认底层是否真的没有回调event:end的数据,还是回调了但被parser过滤或解析失败了。平台差异与已知限制:
知识库中暂未检索到
enableChunked在当前版本存在大面积丢包的已知 Bug。但该能力在不同平台(如 App 端 webview 与小程序原生)的底层网络实现不同。例如,部分小程序基础库或 App webview 的底层网络层在处理大块连续到达的流式数据时,其触发机制可能存在差异。明确运行平台有助于精准定位。3. 下一步建议
为了更准确地定位该问题是否为框架 Bug,请您补充以下信息:
onChunkReceived回调中增加原始字节数组的日志打印,确认底层是否真的丢失了数据回调。提供以上信息后,我们将进一步排查确认是否为框架缺陷。如果是特定平台的底层网络机制限制,也会为您提供相应的兼容处理方案。
要回复问题请先登录或注册
公告
更多>相关问题