From 6921ac7e66515455117487f4b8360fd70342b944 Mon Sep 17 00:00:00 2001 From: wangys <3401275564@qq.com> Date: Mon, 12 Jan 2026 10:47:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../packages/workcase_wechat/api/ai/aiChat.ts | 49 ++++- .../packages/workcase_wechat/manifest.json | 198 +++++++++--------- 2 files changed, 146 insertions(+), 101 deletions(-) diff --git a/urbanLifelineWeb/packages/workcase_wechat/api/ai/aiChat.ts b/urbanLifelineWeb/packages/workcase_wechat/api/ai/aiChat.ts index a2eb1bae..ab2dd6ac 100644 --- a/urbanLifelineWeb/packages/workcase_wechat/api/ai/aiChat.ts +++ b/urbanLifelineWeb/packages/workcase_wechat/api/ai/aiChat.ts @@ -22,6 +22,51 @@ declare const uni: { request: (options: any) => any } +/** + * ArrayBuffer 转字符串(兼容微信小程序真机环境) + * 微信小程序真机不支持 TextDecoder,需要手动解码 UTF-8 + */ +function arrayBufferToString(buffer: ArrayBuffer): string { + // 优先使用 TextDecoder(开发者工具和支持的环境) + if (typeof TextDecoder !== 'undefined') { + return new TextDecoder('utf-8').decode(new Uint8Array(buffer)) + } + + // 微信小程序真机兼容方案:手动解码 UTF-8 + const bytes = new Uint8Array(buffer) + let result = '' + let i = 0 + + while (i < bytes.length) { + const byte1 = bytes[i++] + + if (byte1 < 0x80) { + // 单字节字符 (0xxxxxxx) + result += String.fromCharCode(byte1) + } else if ((byte1 & 0xE0) === 0xC0) { + // 双字节字符 (110xxxxx 10xxxxxx) + const byte2 = bytes[i++] & 0x3F + result += String.fromCharCode(((byte1 & 0x1F) << 6) | byte2) + } else if ((byte1 & 0xF0) === 0xE0) { + // 三字节字符 (1110xxxx 10xxxxxx 10xxxxxx) - 中文常用 + const byte2 = bytes[i++] & 0x3F + const byte3 = bytes[i++] & 0x3F + result += String.fromCharCode(((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3) + } else if ((byte1 & 0xF8) === 0xF0) { + // 四字节字符 (11110xxx 10xxxxxx 10xxxxxx 10xxxxxx) - emoji等 + const byte2 = bytes[i++] & 0x3F + const byte3 = bytes[i++] & 0x3F + const byte4 = bytes[i++] & 0x3F + const codePoint = ((byte1 & 0x07) << 18) | (byte2 << 12) | (byte3 << 6) | byte4 + // 转换为 UTF-16 代理对 + const surrogate = codePoint - 0x10000 + result += String.fromCharCode(0xD800 + (surrogate >> 10), 0xDC00 + (surrogate & 0x3FF)) + } + } + + return result +} + /** * @description AI对话相关接口(直接调用ai模块) * @filename aiChat.ts @@ -128,8 +173,8 @@ export const aiChatAPI = { // 监听分块数据 requestTask.onChunkReceived((res: any) => { try { - const decoder = new TextDecoder('utf-8') - const text = decoder.decode(new Uint8Array(res.data)) + // 兼容微信小程序真机环境(不支持 TextDecoder) + const text = arrayBufferToString(res.data) const lines = text.split('\n') for (const line of lines) { diff --git a/urbanLifelineWeb/packages/workcase_wechat/manifest.json b/urbanLifelineWeb/packages/workcase_wechat/manifest.json index f3e5a86a..3ec80b3f 100644 --- a/urbanLifelineWeb/packages/workcase_wechat/manifest.json +++ b/urbanLifelineWeb/packages/workcase_wechat/manifest.json @@ -1,100 +1,100 @@ { - "name": "泰豪小电", - "appid": "__UNI__69FD573", - "description": "泰豪小电智能工单系统", - "versionName": "1.0.0", - "versionCode": "100", - "uni-app-x": {}, - "quickapp": {}, - "mp-weixin": { - "appid": "wx3708f41b1dc31f52", - "setting": { - "urlCheck": true, - "postcss": true, - "minified": true - }, - "usingComponents": true, - "permission": { - "scope.camera": { - "desc": "用于视频会议时开启摄像头" - }, - "scope.record": { - "desc": "用于视频会议时开启麦克风" - } - }, - "requiredPrivateInfos": [] - }, - "mp-alipay": { - "usingComponents": true - }, - "mp-baidu": { - "usingComponents": true - }, - "mp-toutiao": { - "usingComponents": true - }, - "uniStatistics": { - "enable": false - }, - "vueVersion": "3", - "app": { - "distribute": { - "icons": { - "android": { - "hdpi": "", - "xhdpi": "", - "xxhdpi": "", - "xxxhdpi": "" - } - }, - "android": { - "permissions": [ - "", - "", - "" - ] - }, - "ios": { - "privacyDescription": { - "NSCameraUsageDescription": "用于视频会议时开启摄像头", - "NSMicrophoneUsageDescription": "用于视频会议时开启麦克风" - } - } - } - }, - "app-android": { - "distribute": { - "permissions": [ - "", - "", - "" - ], - "modules": {}, - "icons": { - "hdpi": "", - "xhdpi": "", - "xxhdpi": "", - "xxxhdpi": "" - }, - "splashScreens": { - "default": {} - } - } - }, - "app-ios": { - "distribute": { - "privacyDescription": { - "NSCameraUsageDescription": "用于视频会议时开启摄像头", - "NSMicrophoneUsageDescription": "用于视频会议时开启麦克风" - }, - "modules": {}, - "icons": {}, - "splashScreens": {} - } - }, - "web": { - "router": { - "mode": "" - } - } -} \ No newline at end of file + "name" : "泰豪小电", + "appid" : "__UNI__69FD573", + "description" : "泰豪小电智能工单系统", + "versionName" : "1.0.0", + "versionCode" : "100", + "uni-app-x" : {}, + "quickapp" : {}, + "mp-weixin" : { + "appid" : "wx3708f41b1dc31f52", + "setting" : { + "urlCheck" : true, + "postcss" : true, + "minified" : true + }, + "usingComponents" : true, + "permission" : { + "scope.camera" : { + "desc" : "用于视频会议时开启摄像头" + }, + "scope.record" : { + "desc" : "用于视频会议时开启麦克风" + } + }, + "requiredPrivateInfos" : [] + }, + "mp-alipay" : { + "usingComponents" : true + }, + "mp-baidu" : { + "usingComponents" : true + }, + "mp-toutiao" : { + "usingComponents" : true + }, + "uniStatistics" : { + "enable" : false + }, + "vueVersion" : "3", + "app" : { + "distribute" : { + "icons" : { + "android" : { + "hdpi" : "", + "xhdpi" : "", + "xxhdpi" : "", + "xxxhdpi" : "" + } + }, + "android" : { + "permissions" : [ + "", + "", + "" + ] + }, + "ios" : { + "privacyDescription" : { + "NSCameraUsageDescription" : "用于视频会议时开启摄像头", + "NSMicrophoneUsageDescription" : "用于视频会议时开启麦克风" + } + } + } + }, + "app-android" : { + "distribute" : { + "permissions" : [ + "", + "", + "" + ], + "modules" : {}, + "icons" : { + "hdpi" : "", + "xhdpi" : "", + "xxhdpi" : "", + "xxxhdpi" : "" + }, + "splashScreens" : { + "default" : {} + } + } + }, + "app-ios" : { + "distribute" : { + "privacyDescription" : { + "NSCameraUsageDescription" : "用于视频会议时开启摄像头", + "NSMicrophoneUsageDescription" : "用于视频会议时开启麦克风" + }, + "modules" : {}, + "icons" : {}, + "splashScreens" : {} + } + }, + "web" : { + "router" : { + "mode" : "" + } + } +}