小程序聊天修正
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
"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": "用于视频会议时开启摄像头"
|
||||
"usingComponents" : true,
|
||||
"permission" : {
|
||||
"scope.camera" : {
|
||||
"desc" : "用于视频会议时开启摄像头"
|
||||
},
|
||||
"scope.record": {
|
||||
"desc": "用于视频会议时开启麦克风"
|
||||
"scope.record" : {
|
||||
"desc" : "用于视频会议时开启麦克风"
|
||||
}
|
||||
},
|
||||
"requiredPrivateInfos": []
|
||||
"requiredPrivateInfos" : []
|
||||
},
|
||||
"mp-alipay": {
|
||||
"usingComponents": true
|
||||
"mp-alipay" : {
|
||||
"usingComponents" : true
|
||||
},
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
"mp-baidu" : {
|
||||
"usingComponents" : true
|
||||
},
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true
|
||||
"mp-toutiao" : {
|
||||
"usingComponents" : true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
"uniStatistics" : {
|
||||
"enable" : false
|
||||
},
|
||||
"vueVersion": "3",
|
||||
"app": {
|
||||
"distribute": {
|
||||
"icons": {
|
||||
"android": {
|
||||
"hdpi": "",
|
||||
"xhdpi": "",
|
||||
"xxhdpi": "",
|
||||
"xxxhdpi": ""
|
||||
"vueVersion" : "3",
|
||||
"app" : {
|
||||
"distribute" : {
|
||||
"icons" : {
|
||||
"android" : {
|
||||
"hdpi" : "",
|
||||
"xhdpi" : "",
|
||||
"xxhdpi" : "",
|
||||
"xxxhdpi" : ""
|
||||
}
|
||||
},
|
||||
"android": {
|
||||
"permissions": [
|
||||
"android" : {
|
||||
"permissions" : [
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>"
|
||||
]
|
||||
},
|
||||
"ios": {
|
||||
"privacyDescription": {
|
||||
"NSCameraUsageDescription": "用于视频会议时开启摄像头",
|
||||
"NSMicrophoneUsageDescription": "用于视频会议时开启麦克风"
|
||||
"ios" : {
|
||||
"privacyDescription" : {
|
||||
"NSCameraUsageDescription" : "用于视频会议时开启摄像头",
|
||||
"NSMicrophoneUsageDescription" : "用于视频会议时开启麦克风"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"app-android": {
|
||||
"distribute": {
|
||||
"permissions": [
|
||||
"app-android" : {
|
||||
"distribute" : {
|
||||
"permissions" : [
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>"
|
||||
],
|
||||
"modules": {},
|
||||
"icons": {
|
||||
"hdpi": "",
|
||||
"xhdpi": "",
|
||||
"xxhdpi": "",
|
||||
"xxxhdpi": ""
|
||||
"modules" : {},
|
||||
"icons" : {
|
||||
"hdpi" : "",
|
||||
"xhdpi" : "",
|
||||
"xxhdpi" : "",
|
||||
"xxxhdpi" : ""
|
||||
},
|
||||
"splashScreens": {
|
||||
"default": {}
|
||||
"splashScreens" : {
|
||||
"default" : {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"app-ios": {
|
||||
"distribute": {
|
||||
"privacyDescription": {
|
||||
"NSCameraUsageDescription": "用于视频会议时开启摄像头",
|
||||
"NSMicrophoneUsageDescription": "用于视频会议时开启麦克风"
|
||||
"app-ios" : {
|
||||
"distribute" : {
|
||||
"privacyDescription" : {
|
||||
"NSCameraUsageDescription" : "用于视频会议时开启摄像头",
|
||||
"NSMicrophoneUsageDescription" : "用于视频会议时开启麦克风"
|
||||
},
|
||||
"modules": {},
|
||||
"icons": {},
|
||||
"splashScreens": {}
|
||||
"modules" : {},
|
||||
"icons" : {},
|
||||
"splashScreens" : {}
|
||||
}
|
||||
},
|
||||
"web": {
|
||||
"router": {
|
||||
"mode": ""
|
||||
"web" : {
|
||||
"router" : {
|
||||
"mode" : ""
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user