Commit 7d77f96e by liimin

feat(上传服务): 实现文件上传服务并重构相关组件

重构上传逻辑为独立的 UploadService 类,提供完整的文件上传管理功能
新增 Webview 实例管理、自动恢复机制和错误处理
在 Queue 工具类中添加 filter 方法支持任务过滤
优化文件状态处理和网络异常恢复逻辑
1 parent 729a5063
...@@ -11,6 +11,7 @@ const PATH = ['/pages/common/caseDetail'] ...@@ -11,6 +11,7 @@ const PATH = ['/pages/common/caseDetail']
const keepAlive = uni.requireNativePlugin('Ba-KeepAliveSuit') const keepAlive = uni.requireNativePlugin('Ba-KeepAliveSuit')
import { mapState } from 'vuex' import { mapState } from 'vuex'
import { Ws } from '@/ws/Ws.js' import { Ws } from '@/ws/Ws.js'
import UploadService from '@/utils/recordManager/UploadService.js'
export default { export default {
computed: { computed: {
...mapState('audio', ['isEnd', 'isStart']) ...mapState('audio', ['isEnd', 'isStart'])
...@@ -58,7 +59,7 @@ export default { ...@@ -58,7 +59,7 @@ export default {
onShow: async function () { onShow: async function () {
this.$store.dispatch('setBackgroundState', false) this.$store.dispatch('setBackgroundState', false)
// 触发轮询开始事件,通知上传管理重新开始轮询 // 触发轮询开始事件,通知上传管理重新开始轮询
uni.$emit('startPolling'); UploadService.startPolling()
// const systemInfo = await uni.$api.systemApi.getMockData(); // const systemInfo = await uni.$api.systemApi.getMockData();
// if (systemInfo.isCheckedUpdate) { // if (systemInfo.isCheckedUpdate) {
// checkUpdate(); // checkUpdate();
......
...@@ -36,7 +36,14 @@ ...@@ -36,7 +36,14 @@
<!-- 升级弹框 --> <!-- 升级弹框 -->
<update-box /> <update-box />
<slot name="content" /> <slot name="content" />
<web-view @message="handlerMessage" ref="webview" src="/hybrid/html/index.html"></web-view> <!-- 隐形 Webview (声明式) -->
<!-- 使用 webview-styles 控制原生层级位置 -->
<web-view
ref="uploaderWebview"
src="/hybrid/html/index.html"
@message="handleUploadMessage"
:webview-styles="webviewStyles"
></web-view>
<!-- <web-view <!-- <web-view
ref="studyWebview" ref="studyWebview"
:src="jumpUrl" :src="jumpUrl"
...@@ -50,18 +57,19 @@ import FinishReceptionDialog from './components/FinishReceptionDialog.vue' ...@@ -50,18 +57,19 @@ import FinishReceptionDialog from './components/FinishReceptionDialog.vue'
import StoreAddress from './components/StoreAddress.vue' import StoreAddress from './components/StoreAddress.vue'
import timeout from '@/mixin/timeout' import timeout from '@/mixin/timeout'
import recorder from '@/mixin/record/recorder' import recorder from '@/mixin/record/recorder'
import uploader from '@/mixin/record/uploader.js'
import versionCheck from '@/mixin/versionCheck.js' import versionCheck from '@/mixin/versionCheck.js'
import LeftSide from './components/LeftSide.vue' import LeftSide from './components/LeftSide.vue'
import Material from '@/components/MaterialIndex.vue' import Material from '@/components/MaterialIndex.vue'
import HomeSlot from './components/HomeSlot.vue' import HomeSlot from './components/HomeSlot.vue'
import Order from './components/Order/index.vue' import Order from './components/Order/index.vue'
import UploadService from '@/utils/recordManager/UploadService.js'
const TAB_COMPONENTS = { const TAB_COMPONENTS = {
1: 'ReceptionCenter', 1: 'ReceptionCenter',
2: 'Order' 2: 'Order'
} }
export default { export default {
mixins: [recorder, uploader, timeout, versionCheck], mixins: [recorder, timeout, versionCheck],
components: { LeftSide, Material, ReceptionCenter, FinishReceptionDialog, StoreAddress, HomeSlot, Order }, components: { LeftSide, Material, ReceptionCenter, FinishReceptionDialog, StoreAddress, HomeSlot, Order },
props: { props: {
activeDetailId: [String, Number], activeDetailId: [String, Number],
...@@ -97,7 +105,15 @@ export default { ...@@ -97,7 +105,15 @@ export default {
tipsObject: {}, tipsObject: {},
autoplay: true, autoplay: true,
previewOff: false, previewOff: false,
currentType: {} currentType: {},
webviewStyles: Object.freeze({
progress: false,
width: '10px',
height: '10px',
position: 'absolute',
top: '-1000px',
left: '-1000px'
})
} }
}, },
mounted() { mounted() {
...@@ -105,6 +121,9 @@ export default { ...@@ -105,6 +121,9 @@ export default {
this.userInfo = userInfo this.userInfo = userInfo
this.currentType = uni.$storage.get('typeItem') this.currentType = uni.$storage.get('typeItem')
// if (this.checkRecordAudio) permision.requestAndroidPermission('android.permission.RECORD_AUDIO') // 进入界面时检查权限 // if (this.checkRecordAudio) permision.requestAndroidPermission('android.permission.RECORD_AUDIO') // 进入界面时检查权限
// 初始化上传相关逻辑
this.initUploader()
}, },
provide() { provide() {
return { return {
...@@ -158,7 +177,30 @@ export default { ...@@ -158,7 +177,30 @@ export default {
this.currentType = item this.currentType = item
uni.$storage.set('typeItem', item) uni.$storage.set('typeItem', item)
this.$emit('changeType') this.$emit('changeType')
} },
handleUploadMessage(event) {
// 接收来自 Webview 的消息,并转发给 UploadService
const data = event.detail.data[0]
if (data) {
// 构造 Service 需要的格式 { detail: { data: [payload] } }
// 或者直接让 Service 接收 payload
// 目前 Service.handlerMessage 期望的是 { detail: { data: [...] } }
UploadService.handlerMessage(event)
}
},
initUploader() {
// 初始化上传服务
UploadService.init()
// 注入 Webview 实例
this.injectWebview()
},
injectWebview() {
// 恢复:通过 $refs 获取模板中声明的 Webview 实例
// 注意:需要等待 mounted 后一段时间确保 webview 已经渲染
this.$nextTick(() => {
UploadService.setWebviewContext(this.$refs.uploaderWebview, this)
})
}
} }
} }
</script> </script>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn * @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-12-26 10:03:54 * @Date: 2024-12-26 10:03:54
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2026-01-09 16:14:40 * @LastEditTime: 2026-01-12 18:16:49
* @FilePath: \simgle_app\mixin\record\recorder.js * @FilePath: \simgle_app\mixin\record\recorder.js
* @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
*/ */
......
...@@ -43,5 +43,9 @@ class Queue { ...@@ -43,5 +43,9 @@ class Queue {
clear() { clear() {
this._items = []; this._items = [];
} }
filter(callback) {
this._items = this._items.filter(callback);
}
} }
export default Queue; export default Queue;
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
* @Author: limin * @Author: limin
* @Date: 2025-01-02 18:49:17 * @Date: 2025-01-02 18:49:17
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2026-01-09 16:03:13 * @LastEditTime: 2026-01-12 11:30:31
* @FilePath: \simgle_app\utils\recordManager\TempRecord.js * @FilePath: \simgle_app\utils\recordManager\TempRecord.js
*/ */
import utils from '../utils' import utils from '../utils'
import helpler from './helpler' import helpler from './helpler'
import { FileStatus } from '../common/constants' import { FileStatus } from '../common/constants'
import UploadService from './UploadService.js'
// import { Command } from '../../ws/constants' // import { Command } from '../../ws/constants'
class TempRecord { class TempRecord {
...@@ -146,7 +147,7 @@ class TempRecord { ...@@ -146,7 +147,7 @@ class TempRecord {
await this.dbRecord.addRecord(__record) await this.dbRecord.addRecord(__record)
await this.clearLocalRecord(record) await this.clearLocalRecord(record)
// 触发轮询开始事件,通知上传管理重新开始轮询 // 触发轮询开始事件,通知上传管理重新开始轮询
uni.$emit('startPolling'); UploadService.startPolling()
} catch (error) { } catch (error) {
uni.$logger.local.info('〖接待记录Record〗 == 保存记录异常' + error.message) uni.$logger.local.info('〖接待记录Record〗 == 保存记录异常' + error.message)
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn * @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-08 17:16:46 * @Date: 2024-04-08 17:16:46
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2025-12-23 09:44:47 * @LastEditTime: 2026-01-12 16:59:04
* @FilePath: \simgle_app\utils\utils.js * @FilePath: \simgle_app\utils\utils.js
* @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
*/ */
...@@ -187,9 +187,43 @@ async function getAudioFilePath(path = '') { ...@@ -187,9 +187,43 @@ async function getAudioFilePath(path = '') {
const rootPath = await getFilePath() const rootPath = await getFilePath()
return `file://${rootPath}${path}` return `file://${rootPath}${path}`
} }
export function serializeIfObject(msg) { export function serializeIfObject(value) {
if (msg === undefined || msg === null) return String(msg) if (value && typeof value === 'object') {
return typeof msg === 'object' ? JSON.stringify(msg) : String(msg) return JSON.stringify(value)
}
return value
}
/**
* 获取 Webview 实例的工具方法
* @param {Object} webviewComponent - Vue 组件引用
* @param {Object} vueContext - Vue 实例上下文
*/
export function getWebviewInstance(component, context, retries = 3, interval = 300) {
return new Promise((resolve) => {
const tryGet = (left) => {
try {
// 按照指定逻辑获取: 依赖父组件作用域获取原生 Webview,并取第一个子窗口
const currentWebview = context?.$parent?.$scope?.$getAppWebview?.()
const wv = currentWebview?.children?.()?.[0]
if (wv) {
resolve(wv)
return
}
} catch (e) {
console.warn('Webview获取异常', e)
}
if (left > 0) {
setTimeout(() => tryGet(left - 1), interval)
} else {
resolve(null)
}
}
tryGet(retries)
})
} }
export function isInteger(value) { export function isInteger(value) {
if (typeof value === 'number') { if (typeof value === 'number') {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!