diff --git a/electron/main.js b/electron/main.js
index e66c1dd..88ce55a 100644
--- a/electron/main.js
+++ b/electron/main.js
@@ -1,4 +1,4 @@
-const { app, BrowserWindow } = require('electron')
+const { app, BrowserWindow, session } = require('electron')
const path = require('path')
const devServerUrl = process.env.ELECTRON_RENDERER_URL
@@ -29,7 +29,34 @@ function createWindow() {
win.loadFile(rendererEntry)
}
+function setupMediaPermissions() {
+ const ses = session.defaultSession
+ if (!ses) {
+ return
+ }
+
+ const mediaPermissions = new Set(['media', 'videoCapture', 'audioCapture', 'camera', 'microphone'])
+
+ ses.setPermissionCheckHandler((webContents, permission) => {
+ if (mediaPermissions.has(permission)) {
+ return true
+ }
+ return false
+ })
+
+ ses.setPermissionRequestHandler((webContents, permission, callback) => {
+ callback(mediaPermissions.has(permission))
+ })
+
+ if (typeof ses.setDevicePermissionHandler === 'function') {
+ ses.setDevicePermissionHandler((details) => {
+ return details.deviceType === 'videoCapture' || details.deviceType === 'audioCapture'
+ })
+ }
+}
+
app.whenReady().then(() => {
+ setupMediaPermissions()
createWindow()
app.on('activate', () => {
diff --git a/src/components/top-nav.vue b/src/components/top-nav.vue
index cd31ee9..582998c 100644
--- a/src/components/top-nav.vue
+++ b/src/components/top-nav.vue
@@ -1,42 +1,46 @@
-
-
+
+
+
-
-
-
-
-
-
-
+
-
@@ -67,6 +71,13 @@ export default {
return {
activeIndex: 0,
showMinePopup: false,
+ isNavigating: false,
+ lastMenuClickAt: 0,
+ routeSyncTimer: null,
+ lastRoutePath: '',
+ showSwitchMask: false,
+ switchMaskTimer: null,
+ switchMaskStartedAt: 0,
currentUser: null,
defaultMenus: [
{
@@ -115,6 +126,29 @@ export default {
this.syncActiveIndex()
this.loadCurrentUserInfo()
},
+ mounted() {
+ this.lastRoutePath = this.getCurrentRoutePath()
+ if (this.useRedirect && !this.activePath) {
+ this.routeSyncTimer = setInterval(() => {
+ const currentPath = this.getCurrentRoutePath()
+ if (!currentPath || currentPath === this.lastRoutePath) {
+ return
+ }
+ this.lastRoutePath = currentPath
+ this.syncActiveByRoute()
+ }, 120)
+ }
+ },
+ beforeDestroy() {
+ if (this.routeSyncTimer) {
+ clearInterval(this.routeSyncTimer)
+ this.routeSyncTimer = null
+ }
+ if (this.switchMaskTimer) {
+ clearTimeout(this.switchMaskTimer)
+ this.switchMaskTimer = null
+ }
+ },
methods: {
normalizePath(path) {
const raw = String(path || '').trim()
@@ -143,15 +177,100 @@ export default {
const targetIndex = this.displayMenus.findIndex((item) => item.path === route)
this.activeIndex = targetIndex >= 0 ? targetIndex : 0
},
+ getCurrentRoutePath() {
+ const pages = getCurrentPages()
+ const currentPage = pages[pages.length - 1]
+ return currentPage?.route ? `/${currentPage.route}` : ''
+ },
+ showNavigationMask() {
+ this.showSwitchMask = true
+ this.switchMaskStartedAt = Date.now()
+ if (this.switchMaskTimer) {
+ clearTimeout(this.switchMaskTimer)
+ this.switchMaskTimer = null
+ }
+ },
+ hideNavigationMask() {
+ const elapsed = Date.now() - this.switchMaskStartedAt
+ const delay = elapsed >= 100 ? 0 : 100 - elapsed
+ if (this.switchMaskTimer) {
+ clearTimeout(this.switchMaskTimer)
+ }
+ this.switchMaskTimer = setTimeout(() => {
+ this.showSwitchMask = false
+ this.switchMaskTimer = null
+ }, delay)
+ },
+ navigateToMenu(targetPath) {
+ const pages = getCurrentPages()
+ const currentIndex = pages.length - 1
+ const targetRoute = targetPath.replace(/^\//, '')
+ const targetIndex = pages.map((page) => page?.route).lastIndexOf(targetRoute)
+ const finishNavigate = () => {
+ this.hideNavigationMask()
+ setTimeout(() => {
+ this.isNavigating = false
+ }, 60)
+ }
+
+ if (targetIndex >= 0 && currentIndex > targetIndex) {
+ uni.navigateBack({
+ delta: currentIndex - targetIndex,
+ animationType: 'none',
+ animationDuration: 0,
+ complete: finishNavigate,
+ })
+ return
+ }
+
+ uni.navigateTo({
+ url: targetPath,
+ animationType: 'none',
+ animationDuration: 0,
+ success: finishNavigate,
+ fail: () => {
+ uni.redirectTo({
+ url: targetPath,
+ animationType: 'none',
+ animationDuration: 0,
+ complete: finishNavigate,
+ })
+ },
+ })
+ },
handleMenuClick(item, index) {
- this.activeIndex = index
+ const now = Date.now()
+ if (now - this.lastMenuClickAt < 150) {
+ return
+ }
+ this.lastMenuClickAt = now
+
+ if (this.isNavigating) {
+ return
+ }
+
+ const targetPath = this.normalizePath(item?.path)
+ if (!targetPath) {
+ return
+ }
+
+ const currentPath = this.getCurrentRoutePath()
+ if (this.useRedirect && currentPath === targetPath) {
+ this.syncActiveByRoute()
+ this.closeMinePopup()
+ return
+ }
+
+ if (!this.useRedirect) {
+ this.activeIndex = index
+ }
this.$emit('menu-click', item.raw)
if (this.useRedirect) {
- uni.redirectTo({
- url: item.path,
- })
+ this.isNavigating = true
+ this.showNavigationMask()
+ this.navigateToMenu(targetPath)
}
this.closeMinePopup()
@@ -255,6 +374,7 @@ export default {
}
.top-nav-logo {
+ width: 240rpx;
height: 90rpx;
flex-shrink: 0;
}
@@ -381,4 +501,15 @@ export default {
background-color: #f5f7fb;
color: #333;
}
+
+.switch-mask {
+ position: fixed;
+ left: 0;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ background-color: rgba(248, 248, 248, 0.96);
+ z-index: 9999;
+ pointer-events: none;
+}
diff --git a/src/pages/order/index.vue b/src/pages/order/index.vue
index 7795fd8..f011ffc 100644
--- a/src/pages/order/index.vue
+++ b/src/pages/order/index.vue
@@ -48,17 +48,18 @@
-
-
-
+
+
+
- 暂无匹配数据
{{ item.pendingOrderNo }}
-
-
+
+
+ 暂无匹配数据
-
-
-
+
+
+
- 暂无匹配数据
{{ item.waveNo }}
-
-
+
+
+ 暂无匹配数据
@@ -132,8 +136,16 @@
-
-
+
+
+
+
+ {{ cameraLoading ? '摄像头启动中...' : cameraError || '暂无摄像头画面' }}
+
+
+
+
+
+
- 暂无匹配数据
{{ order.spec }}
-
-
+
+ 暂无匹配数据
+
@@ -218,6 +230,14 @@ export default {
selectedPendingOrderKey: '',
currentOrderHeader: null,
currentWaybillInfo: null,
+ cameraStream: null,
+ cameraVideoElement: null,
+ cameraLoading: false,
+ cameraReady: false,
+ cameraError: '',
+ cameraInitializing: false,
+ cameraInitToken: 0,
+ cameraStartTimer: null,
}
},
created() {
@@ -225,7 +245,35 @@ export default {
this.displayCurrentWaveOrders = this.allCurrentWaveOrders
this.displayReviewedOrders = this.allReviewedOrders
},
+ mounted() {
+ this.requestCameraPreview()
+ },
+ onReady() {
+ this.requestCameraPreview()
+ },
+ onShow() {
+ this.requestCameraPreview()
+ },
+ beforeUnmount() {
+ this.stopCameraPreview()
+ },
+ beforeDestroy() {
+ this.stopCameraPreview()
+ },
+ onUnload() {
+ this.stopCameraPreview()
+ },
methods: {
+ requestCameraPreview() {
+ if (this.cameraInitializing || this.cameraLoading || this.cameraReady) {
+ return
+ }
+
+ clearTimeout(this.cameraStartTimer)
+ this.cameraStartTimer = setTimeout(() => {
+ this.initCameraPreview()
+ }, 180)
+ },
handleLeftActionClick(action) {
this.activeLeftAction = action
this.handleSearch()
@@ -239,6 +287,186 @@ export default {
icon: 'success',
})
},
+ async initCameraPreview() {
+ if (typeof navigator === 'undefined' || !navigator?.mediaDevices?.getUserMedia) {
+ this.cameraError = '当前环境不支持摄像头预览'
+ this.cameraReady = false
+ return
+ }
+
+ if (this.cameraInitializing) {
+ return
+ }
+
+ const currentToken = ++this.cameraInitToken
+ this.cameraInitializing = true
+
+ await this.stopCameraPreview()
+ await new Promise((resolve) => setTimeout(resolve, 200))
+
+ this.cameraLoading = true
+ this.cameraError = ''
+
+ try {
+ const getStream = async () => {
+ try {
+ return await navigator.mediaDevices.getUserMedia({
+ video: {
+ width: { ideal: 1280 },
+ height: { ideal: 720 },
+ },
+ audio: false,
+ })
+ } catch (firstError) {
+ return await navigator.mediaDevices.getUserMedia({
+ video: true,
+ audio: false,
+ })
+ }
+ }
+
+ let stream = await getStream()
+
+ if (currentToken !== this.cameraInitToken) {
+ stream.getTracks().forEach((track) => track.stop())
+ return
+ }
+
+ this.cameraStream = stream
+
+ await this.$nextTick()
+ const hostRef = this.$refs.cameraHost
+ const hostElement = Array.isArray(hostRef) ? hostRef[0] : hostRef
+ const videoElement = this.ensureCameraVideoElement(hostElement)
+
+ if (videoElement) {
+ if (!('srcObject' in videoElement)) {
+ throw new Error('UNSUPPORTED_STREAM_SOURCE')
+ }
+
+ videoElement.srcObject = stream
+
+ const playPromise = videoElement.play ? videoElement.play() : null
+ if (playPromise && typeof playPromise.then === 'function') {
+ await playPromise
+ }
+ } else {
+ throw new Error('VIDEO_ELEMENT_NOT_FOUND')
+ }
+
+ this.cameraReady = true
+ } catch (error) {
+ if (error?.name === 'NotReadableError') {
+ try {
+ await this.stopCameraPreview()
+ await new Promise((resolve) => setTimeout(resolve, 500))
+
+ const retryStream = await navigator.mediaDevices.getUserMedia({
+ video: true,
+ audio: false,
+ })
+
+ if (currentToken !== this.cameraInitToken) {
+ retryStream.getTracks().forEach((track) => track.stop())
+ return
+ }
+
+ this.cameraStream = retryStream
+
+ await this.$nextTick()
+ const hostRef = this.$refs.cameraHost
+ const hostElement = Array.isArray(hostRef) ? hostRef[0] : hostRef
+ const videoElement = this.ensureCameraVideoElement(hostElement)
+
+ if (!videoElement || !('srcObject' in videoElement)) {
+ throw new Error('VIDEO_ELEMENT_NOT_FOUND')
+ }
+
+ videoElement.srcObject = retryStream
+ const playPromise = videoElement.play ? videoElement.play() : null
+ if (playPromise && typeof playPromise.then === 'function') {
+ await playPromise
+ }
+
+ this.cameraReady = true
+ this.cameraError = ''
+ return
+ } catch (retryError) {
+ error = retryError
+ }
+ }
+
+ this.cameraReady = false
+ if (error?.name === 'NotAllowedError' || error?.name === 'PermissionDeniedError') {
+ this.cameraError = '摄像头权限被拒绝'
+ } else if (error?.name === 'NotFoundError' || error?.name === 'DevicesNotFoundError') {
+ this.cameraError = '未检测到可用摄像头设备'
+ } else if (error?.name === 'NotReadableError') {
+ this.cameraError = '摄像头正被其他程序占用,请关闭后重试'
+ } else if (error?.name === 'NotSupportedError') {
+ this.cameraError = '当前视频源格式不受支持'
+ } else if (error?.message === 'UNSUPPORTED_STREAM_SOURCE' || error?.message === 'VIDEO_ELEMENT_NOT_FOUND') {
+ this.cameraError = '当前视频组件不支持实时流预览'
+ } else {
+ this.cameraError = `摄像头启动失败(${error?.name || 'Unknown'}${error?.message ? `: ${error.message}` : ''})`
+ }
+ } finally {
+ this.cameraLoading = false
+ this.cameraInitializing = false
+ }
+ },
+ async stopCameraPreview() {
+ this.cameraInitToken += 1
+ clearTimeout(this.cameraStartTimer)
+
+ const stream = this.cameraStream
+ if (stream && typeof stream.getTracks === 'function') {
+ stream.getTracks().forEach((track) => {
+ if (track && typeof track.stop === 'function') {
+ track.stop()
+ }
+ })
+ }
+
+ const videoElement = this.cameraVideoElement
+ if (videoElement) {
+ videoElement.srcObject = null
+ videoElement.removeAttribute('src')
+ if (typeof videoElement.load === 'function') {
+ videoElement.load()
+ }
+ }
+
+ this.cameraStream = null
+ this.cameraVideoElement = null
+ this.cameraReady = false
+ this.cameraLoading = false
+ this.cameraInitializing = false
+ this.cameraStartTimer = null
+ },
+ ensureCameraVideoElement(hostElement) {
+ if (typeof document === 'undefined' || !hostElement) {
+ return null
+ }
+
+ if (this.cameraVideoElement && hostElement.contains(this.cameraVideoElement)) {
+ return this.cameraVideoElement
+ }
+
+ hostElement.innerHTML = ''
+
+ const videoElement = document.createElement('video')
+ videoElement.className = 'camera-preview-video'
+ videoElement.muted = true
+ videoElement.autoplay = false
+ videoElement.playsInline = true
+ videoElement.setAttribute('playsinline', 'true')
+ videoElement.setAttribute('webkit-playsinline', 'true')
+
+ hostElement.appendChild(videoElement)
+ this.cameraVideoElement = videoElement
+ return videoElement
+ },
getRowValue(row, keys = []) {
for (const key of keys) {
const value = row?.[key]
@@ -325,7 +553,10 @@ export default {
})
.filter((item) => !!item.pendingOrderNo)
- this.displayOrders = list.map((item) => this.normalizeOrderRow(item))
+ this.displayOrders = []
+ this.selectedPendingOrderKey = ''
+ this.currentOrderHeader = null
+ this.currentWaybillInfo = null
this.allCurrentWaveOrders = pendingOrders
this.displayCurrentWaveOrders = pendingOrders
this.orderPagination = {
@@ -370,6 +601,12 @@ export default {
this.displayCurrentWaveOrders = this.allCurrentWaveOrders.filter((order) => {
return Object.values(order).some((value) => String(value || '').toLowerCase().includes(query))
})
+ if (this.displayCurrentWaveOrders.length === 0) {
+ this.selectedPendingOrderKey = ''
+ this.currentOrderHeader = null
+ this.currentWaybillInfo = null
+ this.displayOrders = []
+ }
return
}
@@ -419,12 +656,23 @@ export default {
diff --git a/src/pages/returns/index.vue b/src/pages/returns/index.vue
index e1a4fa9..f0f14ee 100644
--- a/src/pages/returns/index.vue
+++ b/src/pages/returns/index.vue
@@ -25,12 +25,23 @@ export default {