Commit 729a5063 by liimin

feat: 优化上传管理模块并添加网络状态监听

重构上传管理模块,移除冗余代码并优化任务处理流程:
1. 添加网络状态变化监听,网络恢复时自动唤醒上传任务
2. 移除OperationQueue和TimeoutManager,简化任务调度逻辑
3. 优化日志记录,减少冗余信息
4. 添加任务看门狗机制防止长时间卡死
5. 改进错误处理和重试机制,使用指数退避策略
6. 优化文件解析和状态更新逻辑

同时更新全局错误处理:
1. 增强onError和onUnhandledRejection的错误捕获
2. 添加更详细的错误上下文信息
3. 优化日志上报内容

调整音频录制默认时长为1分钟
移除客户信息日志记录
1 parent bc02d785
<!--
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-07 17:09:53
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2025-01-14 11:27:04
* @FilePath: \gl_tape\App.vue
* @LastEditors: limin
* @LastEditTime: 2026-01-09 18:46:00
* @FilePath: \simgle_app\App.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script>
......@@ -57,6 +57,8 @@ export default {
onShow: async function () {
this.$store.dispatch('setBackgroundState', false)
// 触发轮询开始事件,通知上传管理重新开始轮询
uni.$emit('startPolling');
// const systemInfo = await uni.$api.systemApi.getMockData();
// if (systemInfo.isCheckedUpdate) {
// checkUpdate();
......@@ -72,9 +74,36 @@ export default {
},
onError: function (e) {
try {
uni.$logger?.error({ msg: e.message || '捕获全局异常', extra: { error: typeof e == 'string' ? e : JSON.stringify(e) } })
const msg = typeof e === 'string' ? e : e.message || '捕获全局异常'
const stack = typeof e === 'object' ? e.stack || JSON.stringify(e) : ''
uni.$logger?.error({
msg: `[全局异常] ${msg}`,
extra: {
stack,
raw: e,
url: this.$route?.path || 'unknown'
}
})
} catch (error) {
console.log(error)
console.error('日志上报失败:', error)
}
},
onUnhandledRejection: function (res) {
try {
const reason = res.reason
const msg = reason instanceof Error ? reason.message : (typeof reason === 'string' ? reason : '未处理的 Promise 拒绝')
const stack = reason instanceof Error ? reason.stack : JSON.stringify(reason)
uni.$logger?.error({
msg: `[UnhandledRejection] ${msg}`,
extra: {
stack,
reason: reason,
url: this.$route?.path || 'unknown'
}
})
} catch (error) {
console.error('Promise 异常上报失败:', error)
}
}
}
......
......@@ -7,13 +7,13 @@ const HOST = {
ip: 'http://192.168.1.125:8080'
}
class Request {
get (params, returnAll = false, hostType) {
get(params, returnAll = false, hostType) {
return this.request('GET', params, returnAll, hostType)
}
post (params, returnAll = false, hostType) {
post(params, returnAll = false, hostType) {
return this.request('POST', params, returnAll, hostType)
}
fetch (method, data, returnAll = true, hostType) {
fetch(method, data, returnAll = true, hostType) {
return this.post(
{
method,
......@@ -23,11 +23,11 @@ class Request {
hostType
)
}
request (RequestMethods, params, returnAll, hostType = 'dj') {
request(RequestMethods, params, returnAll, hostType = 'dj') {
return new Promise((resolve, reject) => {
let _this = this
uni.getNetworkType({
success (res) {
success(res) {
if (res.networkType == 'none') {
uni.hideLoading()
uni.showToast({
......@@ -40,11 +40,11 @@ class Request {
let header =
RequestMethods === 'POST'
? {
'content-type': 'application/x-www-form-urlencoded'
}
'content-type': 'application/x-www-form-urlencoded'
}
: {
'Cache-Control': 'no-cache'
}
'Cache-Control': 'no-cache'
}
let projectName = params.projectName
if (!projectName) projectName = _this.getRopProject(params.method)
const path = pathEnum[projectName]
......@@ -56,46 +56,51 @@ class Request {
header,
dataType: 'json',
responseType: 'text',
success (response) {
/**业务代码 */
let { data, statusCode } = response
if (!data || statusCode != 200) {
uni.hideLoading()
let errMsg = ''
if (!data) errMsg = '获取数据失败,请重试。'
else errMsg = '服务器暂时不可用,请稍后再次尝试。'
uni.$logger.error(`Request Fail: ${JSON.stringify(params)}->${errMsg}`)
return reject(errMsg)
}
let { code, message } = data
if (returnAll) {
resolve(data)
return
}
if (code == 20 || code == 21) {
const pages = getCurrentPages(),
currentPage = pages[pages.length - 1]
uni.$logger.local.warn(`HTTP Triggered Logout: params:${JSON.stringify(params)} method: ${params.method}->code:${code} msg:${message} currentPage:${currentPage.route}`)
uni.hideLoading()
if (currentPage.route != 'pages/common/login') {
uni.reLaunch({
url: '/pages/common/login'
})
success(response) {
try {
/**业务代码 */
let { data, statusCode } = response
if (!data || statusCode != 200) {
uni.hideLoading()
let errMsg = ''
if (!data) errMsg = '获取数据失败,请重试。'
else errMsg = '服务器暂时不可用,请稍后再次尝试。'
uni.$logger.error(`Request Fail: ${JSON.stringify(params)}->${errMsg}`)
return reject(errMsg)
}
} else {
if (code == '0') {
resolve(data.data)
} else {
let { code, message } = data
if (returnAll) {
resolve(data)
return
}
if (code == 20 || code == 21) {
const pages = getCurrentPages(),
currentPage = pages[pages.length - 1]
uni.$logger.local.warn(`HTTP Triggered Logout: params:${JSON.stringify(params)} method: ${params.method}->code:${code} msg:${message} currentPage:${currentPage.route}`)
uni.hideLoading()
uni.showToast({
title: message || '系统异常',
icon: 'none'
})
uni.$logger.error(`HTTP Request Error: ${JSON.stringify(params)}->${message}`)
if (currentPage.route != 'pages/common/login') {
uni.reLaunch({
url: '/pages/common/login'
})
}
} else {
if (code == '0') {
resolve(data.data)
} else {
uni.hideLoading()
uni.showToast({
title: message || '系统异常',
icon: 'none'
})
uni.$logger.error(`HTTP Request Error: ${JSON.stringify(params)}->${message}`)
}
}
} catch (error) {
uni.$logger.error(`${params.method}处理异常:${error.message}`)
reject(error)
}
},
fail (error) {
fail(error) {
uni.hideLoading()
uni.$logger.error(`HTTP Request Fail: ${JSON.stringify(params)}->${error.message}`)
// console.error(`${params.method}接口异常:`, error)
......@@ -105,7 +110,7 @@ class Request {
})
reject(error)
},
complete () {
complete() {
uni.stopPullDownRefresh()
}
})
......@@ -113,7 +118,7 @@ class Request {
})
})
}
getData (params, hostType = 'scrm') {
getData(params, hostType = 'scrm') {
let projectName = params.projectName
if (!projectName) projectName = this.getRopProject(params.method)
else delete params.projectName
......@@ -145,11 +150,11 @@ class Request {
params.appKey = appKey
return sign(params, secret, noSignAttr)
}
getRopProject (method) {
getRopProject(method) {
const projectName = method.split('.')[2]
return projectName
}
uni_request ({ url, method = 'GET', data = {}, header = {}, dataType = 'json', responseType = 'text' }) {
uni_request({ url, method = 'GET', data = {}, header = {}, dataType = 'json', responseType = 'text' }) {
return new Promise(resolve => {
uni.request({
url,
......@@ -158,28 +163,28 @@ class Request {
header,
dataType,
responseType,
success (response) {
success(response) {
resolve(response.data)
}
})
})
}
shukeRequest (url, data = {}, method = 'GET', returnAll = false) {
shukeRequest(url, data = {}, method = 'GET', returnAll = false) {
let header =
method === 'POST'
? {
'content-type': 'application/json'
}
'content-type': 'application/json'
}
: {
'Cache-Control': 'no-cache',
'Content-Type': 'application/json'
}
'Cache-Control': 'no-cache',
'Content-Type': 'application/json'
}
let { sessionId } = uni.$storage.get()
if (sessionId) header.Authorization = sessionId
return new Promise(resolve => {
uni.getNetworkType({
success (res) {
if (res.networkType == 'none') {
success(res) {
if (res.networkType == 'none') {
uni.hideLoading()
uni.showToast({
title: '网络异常',
......@@ -195,13 +200,13 @@ class Request {
header,
dataType: 'json',
responseType: 'text',
success (response) {
success(response) {
let { data, statusCode } = response
if (returnAll) {
resolve(data)
return
}
resolve(data.data)
}
})
......
......@@ -3,7 +3,7 @@
* @Author: huyue
* @Date: 2024-04-07 18:15:11
* @LastEditors: limin
* @LastEditTime: 2025-12-23 14:58:18
* @LastEditTime: 2026-01-12 09:21:13
*/
// import { setToken, getToken, removeToken } from '@/utils/token';;
......@@ -62,7 +62,7 @@ export default {
return state.customerInfo;
},
setCustomerInfo ({ commit }, value) {
uni.$logger.local.info(`当前接待客户信息: ${JSON.stringify(value)}`)
// uni.$logger.local.info(`当前接待客户信息: ${JSON.stringify(value)}`)
commit("setCustomerInfo", value);
},
clearCustomerInfo ({ commit }) {
......
......@@ -4,12 +4,12 @@
* @Author: limin
* @Date: 2024-12-04 18:17:23
* @LastEditors: limin
* @LastEditTime: 2025-12-25 11:00:13
* @LastEditTime: 2026-01-09 19:00:13
* @FilePath: \simgle_app\utils\recordManager\AudioManager.js
*/
class AudioManager {
startOptions = {
duration: 10 * 60 * 1000, //默认10分钟
duration: 1 * 60 * 1000, //默认10分钟
sampleRate: 16000,
numberOfChannels: 1
}
......
......@@ -145,6 +145,8 @@ class TempRecord {
uni.$logger.local.info('〖接待记录Record〗 == 更新文件,保存记录!')
await this.dbRecord.addRecord(__record)
await this.clearLocalRecord(record)
// 触发轮询开始事件,通知上传管理重新开始轮询
uni.$emit('startPolling');
} catch (error) {
uni.$logger.local.info('〖接待记录Record〗 == 保存记录异常' + error.message)
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!