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