diff --git a/backend/app/model/workstation.js b/backend/app/model/workstation.js index 8a39a15..8a50f41 100644 --- a/backend/app/model/workstation.js +++ b/backend/app/model/workstation.js @@ -20,7 +20,7 @@ module.exports = (app) => { /** 录制范围(团购以扫码时间为基准,散单以任务结束时间为基准) */ recordBeforeSec: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 60, comment: '录制范围:触发点之前秒数' }, recordAfterSec: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 60, comment: '录制范围:触发点之后秒数' }, - recordMaxSec: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 240, comment: '最大录制时长(秒)' }, status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1启用 0停用' }, + recordMaxSec: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 240, comment: '最大录制时长(秒);团购无此限制,固定存 0' }, status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1启用 0停用' }, remark: { type: STRING(255), comment: '备注' }, // ↓ 合成画面画布(默认 1920×1080) diff --git a/backend/app/service/workstation.js b/backend/app/service/workstation.js index 735754b..efe71b7 100644 --- a/backend/app/service/workstation.js +++ b/backend/app/service/workstation.js @@ -201,10 +201,12 @@ class WorkstationService extends Service { * 最大录制时长 * * - 散单:用户可设(不传则沿用旧值 / 默认 240) - * - 团购:以扫码时间为基准,前 + 后就是总时长,没有额外上限(不返回/忽略前端传的值) + * - 团购:**没有**最大时长(web 也不提供配置),总时长就是 前 + 后; + * 这里落库为 0(= 不限制),不再写成 before+after 的派生值, + * 避免库里出现一个像“限制 30 秒”的数字被误读 */ _maxSec(wsType, before, after, incoming, fallback) { - if (Number(wsType) === 2) return Number(before) + Number(after); + if (Number(wsType) === 2) return 0; if (incoming !== undefined && incoming !== null) return incoming; return Number(fallback ?? 240); } diff --git a/backend/database/migrations/20261020010000-group-workstation-max-zero.js b/backend/database/migrations/20261020010000-group-workstation-max-zero.js new file mode 100644 index 0000000..f71c995 --- /dev/null +++ b/backend/database/migrations/20261020010000-group-workstation-max-zero.js @@ -0,0 +1,27 @@ +'use strict'; + +/** + * 团购工作台不再写「最大录制时长」 + * + * 团购的录制区间 = 扫码时间 - record_before_sec ~ 扫码时间 + record_after_sec, + * web 上也没有「最大时长」这个配置项(只有散单有)。 + * + * 之前按 before + after 派生写进 record_max_sec(例如 20 + 10 = 30), + * 在库里看起来就像一个「30 秒的限制」,容易被误读成「被多加了限制、实际只录 30 秒」。 + * 现在统一写成 0 = 不限制(服务层 `_maxSec()` 对 ws_type=2 返回 0)。 + * + * 只改工作台的当前配置;scan_records.workstation_snapshot 是历史快照,保持原样。 + */ +module.exports = { + async up(queryInterface) { + await queryInterface.sequelize.query( + 'UPDATE workstations SET record_max_sec = 0 WHERE ws_type = 2' + ); + }, + + async down(queryInterface) { + await queryInterface.sequelize.query( + 'UPDATE workstations SET record_max_sec = record_before_sec + record_after_sec WHERE ws_type = 2' + ); + }, +}; diff --git a/frontend/src/components/LocalServiceGate.vue b/frontend/src/components/LocalServiceGate.vue index b764332..9ad62e3 100644 --- a/frontend/src/components/LocalServiceGate.vue +++ b/frontend/src/components/LocalServiceGate.vue @@ -14,6 +14,7 @@ */ import { computed, ref, watch } from 'vue'; import ModalBox from '@/components/ModalBox.vue'; +import { LOCAL_BASE } from '@/api/local'; import { waitForLocalWs, wakeLocalSoftware } from '@/api/localWs'; import { fetchSoftwareRelease, softwareDownloadUrl, type SoftwareRelease } from '@/utils/localSoftware'; @@ -24,10 +25,13 @@ const props = withDefaults(defineProps<{ message?: string; /** 唤起后最多等多久(毫秒) */ waitMs?: number; + /** 探活方式:ws = WebSocket 17301(预览类);http = HTTP 17300 根路径(查件页,兼容老版本) */ + probe?: 'ws' | 'http'; }>(), { title: '连接不上本机软件', message: '', waitMs: 12000, + probe: 'ws', }); const emit = defineEmits<{ (e: 'close'): void; (e: 'ready'): void }>(); @@ -50,6 +54,24 @@ watch(() => props.open, async open => { release.value = await fetchSoftwareRelease(); }); +async function probeReady(): Promise { + if (props.probe === 'http') { + // 查件页走 HTTP 17300(老版本软件也有这个端口,但不一定有 WS) + const deadline = Date.now() + props.waitMs; + while (Date.now() < deadline) { + try { + await fetch(`${LOCAL_BASE}/`, { cache: 'no-store' }); + return true; + } catch { + await new Promise(resolve => setTimeout(resolve, 700)); + } + } + return false; + } + + return waitForLocalWs(props.waitMs); +} + async function launch() { if (launching.value) return; @@ -59,7 +81,7 @@ async function launch() { // 必须在用户点击的调用栈里触发协议(浏览器会拦自动唤起) wakeLocalSoftware(); - const ok = await waitForLocalWs(props.waitMs); + const ok = await probeReady(); launching.value = false; if (ok) { diff --git a/frontend/src/views/LocalServiceView.vue b/frontend/src/views/LocalServiceView.vue index 3a309b9..8a3cf6a 100644 --- a/frontend/src/views/LocalServiceView.vue +++ b/frontend/src/views/LocalServiceView.vue @@ -18,8 +18,6 @@ import { computed, onMounted, ref } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import { - APP_PROTOCOL, - launchApp, requestLocalLogin, queryLocal, waitForQuery, @@ -27,12 +25,7 @@ import { LOCAL_BASE, type LocalQueryResult, } from '@/api/local'; - -/** - * 安装包下载地址:换成真实地址,或用环境变量 `VITE_SOFTWARE_DOWNLOAD_URL` 覆盖 - * (没配时按钮点不动,只作为提示) - */ -const DOWNLOAD_URL = (import.meta.env.VITE_SOFTWARE_DOWNLOAD_URL as string | undefined) || '#'; +import LocalServiceGate from '@/components/LocalServiceGate.vue'; const route = useRoute(); const router = useRouter(); @@ -44,7 +37,8 @@ const code = ref(String(route.query.code || '').trim()); const info = ref | null>(null); const querying = ref(false); const error = ref(''); -const launchFailed = ref(false); +/** 连不上本机软件:弹统一提示窗(启动 / 下载) */ +const gateOpen = ref(false); /** 本机软件当前登录用户(查询接口一起带回来的) */ const loggedUser = ref(null); @@ -90,14 +84,15 @@ async function load() { status.value = 'checking'; error.value = ''; info.value = null; - launchFailed.value = false; + gateOpen.value = false; try { const res = await queryLocal(code.value.trim()); await apply(res); } catch { - // 连不上 = 软件没启动(或刚被用户退掉)→ 直接给下载 / 唤起入口 + // 连不上 = 软件没启动(或刚被用户退掉)→ 弹统一提示窗 status.value = 'offline'; + gateOpen.value = true; } } @@ -116,23 +111,7 @@ async function askLogin() { if (outcome.offline) { status.value = 'offline'; - return; - } - if (outcome.result) await apply(outcome.result); -} - -/** 「启动本机软件」:协议叫醒(带 code)→ 轮询查询接口等它起来 */ -async function launch() { - launchFailed.value = false; - status.value = 'launching'; - - launchApp(code.value.trim() || undefined); - - const outcome = await waitForQuery(code.value.trim(), 15000); - - if (outcome.offline) { - launchFailed.value = true; - status.value = 'offline'; + gateOpen.value = true; return; } if (outcome.result) await apply(outcome.result); @@ -146,9 +125,10 @@ async function runQuery() { querying.value = true; const res = await queryLocal(code.value.trim()); await apply(res); } catch { - // 中途退出了软件 / 服务停了:直接切到「可以唤起」的提示,不用用户再踩坑 + // 中途退出了软件 / 服务停了:弹统一提示窗 status.value = 'offline'; info.value = null; + gateOpen.value = true; } finally { querying.value = false; } @@ -243,20 +223,14 @@ onMounted(load);

等它启动完成后本页会自动继续

- + + + +