Header 状态改用 Checkstatus 查询并移除已发行
状态与 GetPrinterInfo 分离:启动仅拉色带/序列号,操作后通过 SAPI_PrinterCheckstatus 刷新状态文案。
This commit is contained in:
@@ -104,8 +104,7 @@ export function registerIpcHandlers(): void {
|
||||
const snapshot: PrinterStatusSnapshot = {
|
||||
ribbonType: cached?.ribbonType ?? '—',
|
||||
statusText: parsed.statusText,
|
||||
serialNo: cached?.serialNo ?? '—',
|
||||
printedCount: cached?.printedCount ?? 0
|
||||
serialNo: cached?.serialNo ?? '—'
|
||||
}
|
||||
configStore.set('lastPrinterStatus', snapshot)
|
||||
return ok({ statusText: parsed.statusText, statusCode: code })
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
>状态: <b :class="statusTone">{{ status.statusText }}</b></span
|
||||
>
|
||||
<span>序列号: <b>{{ status.serialNo }}</b></span>
|
||||
<span>已发行: <b>{{ status.printedCount }}</b></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="c-header__actions-slot">
|
||||
@@ -26,7 +25,7 @@
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { useConfigStore } from '@/stores/config'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import { refreshPrinterHeader } from '@/composables/usePrinterStatus'
|
||||
import { refreshLiveStatus } from '@/composables/usePrinterStatus'
|
||||
|
||||
defineProps<{ mode?: string }>()
|
||||
|
||||
@@ -35,12 +34,12 @@ const appStore = useAppStore()
|
||||
const status = computed(() => configStore.printer)
|
||||
|
||||
onMounted(() => {
|
||||
if (appStore.initialized) void refreshPrinterHeader(configStore)
|
||||
if (appStore.initialized) void refreshLiveStatus()
|
||||
})
|
||||
|
||||
const statusTone = computed(() => {
|
||||
const t = status.value.statusText
|
||||
if (t.includes('未初始化') || t.includes('未连接')) return 'c-status-warn'
|
||||
if (t.includes('未初始化') || t.includes('未连接') || t.includes('失败')) return 'c-status-warn'
|
||||
return ''
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { onMounted } from 'vue'
|
||||
import { notify } from '@/composables/useNotify'
|
||||
import { applyPrinterPayload, refreshPrinterFullInfo } from '@/composables/usePrinterStatus'
|
||||
import { refreshPrinterAfterInit } from '@/composables/usePrinterStatus'
|
||||
import { configGet, dllInit, dllRejectAvailable } from '@/api/cardsoon'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import { useConfigStore } from '@/stores/config'
|
||||
@@ -43,7 +43,7 @@ export function useAppBootstrap(): void {
|
||||
appStore.setInitialized(true)
|
||||
placeholderStatus(configStore, '就绪')
|
||||
await syncRejectApi()
|
||||
window.setTimeout(() => void refreshPrinterFullInfo(configStore), 1500)
|
||||
window.setTimeout(() => void refreshPrinterAfterInit(), 1500)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ export function useAppBootstrap(): void {
|
||||
if (initMeta?.warning) notify.warning(initMeta.warning)
|
||||
placeholderStatus(configStore, initMeta?.warning ? '未连接打印机' : '就绪')
|
||||
await syncRejectApi()
|
||||
window.setTimeout(() => void refreshPrinterFullInfo(configStore), 1500)
|
||||
window.setTimeout(() => void refreshPrinterAfterInit(), 1500)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -1,68 +1,41 @@
|
||||
import { dllPrinterInfo, dllPrinterStatus, parsePrinterInfo } from '@/api/cardsoon'
|
||||
import { useConfigStore } from '@/stores/config'
|
||||
import type { PrinterStatusDisplay } from '@/types/printer'
|
||||
|
||||
function isFullPrinterPayload(data: Record<string, unknown>): boolean {
|
||||
return (
|
||||
data.snapshot != null ||
|
||||
data.printerList != null ||
|
||||
data.serial_no != null ||
|
||||
data.SerialNo != null
|
||||
)
|
||||
}
|
||||
|
||||
export function applyPrinterPayload(
|
||||
configStore: ReturnType<typeof useConfigStore>,
|
||||
data: Record<string, unknown>
|
||||
): void {
|
||||
const snapshot = data.snapshot as PrinterStatusDisplay | undefined
|
||||
if (snapshot) {
|
||||
configStore.setPrinter(snapshot)
|
||||
return
|
||||
}
|
||||
if (isFullPrinterPayload(data)) {
|
||||
configStore.setPrinter(parsePrinterInfo(data))
|
||||
return
|
||||
}
|
||||
if (typeof data.statusText === 'string') {
|
||||
configStore.setPrinter({
|
||||
...configStore.printer,
|
||||
statusText: data.statusText
|
||||
})
|
||||
return
|
||||
}
|
||||
if (data.fromCache) {
|
||||
configStore.setPrinter({
|
||||
ribbonType: String(data.ribbonType ?? configStore.printer.ribbonType),
|
||||
statusText: String(data.statusText ?? configStore.printer.statusText),
|
||||
serialNo: String(data.serialNo ?? configStore.printer.serialNo),
|
||||
printedCount: Number(data.printedCount ?? configStore.printer.printedCount)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export async function refreshPrinterHeader(
|
||||
configStore: ReturnType<typeof useConfigStore>
|
||||
): Promise<void> {
|
||||
/** SAPI_PrinterCheckstatus:仅刷新 Header 状态文案 */
|
||||
export async function refreshLiveStatus(): Promise<void> {
|
||||
const store = useConfigStore()
|
||||
try {
|
||||
const r = await dllPrinterStatus()
|
||||
if (r.ok && r.data) {
|
||||
applyPrinterPayload(configStore, r.data as Record<string, unknown>)
|
||||
if (r.ok && r.data?.statusText) {
|
||||
store.setPrinter({ ...store.printer, statusText: r.data.statusText })
|
||||
}
|
||||
} catch {
|
||||
/* 无打印机时不阻塞 */
|
||||
}
|
||||
}
|
||||
|
||||
export async function refreshPrinterFullInfo(
|
||||
configStore: ReturnType<typeof useConfigStore>
|
||||
): Promise<void> {
|
||||
/** GetPrinterInfoEx:仅刷新色带、序列号(启动时一次) */
|
||||
export async function refreshPrinterInfo(): Promise<void> {
|
||||
const store = useConfigStore()
|
||||
try {
|
||||
const info = await dllPrinterInfo()
|
||||
if (info.ok && info.data) {
|
||||
applyPrinterPayload(configStore, info.data)
|
||||
}
|
||||
if (!info.ok || !info.data) return
|
||||
const data = info.data as Record<string, unknown>
|
||||
const parsed = data.snapshot
|
||||
? (data.snapshot as typeof store.printer)
|
||||
: parsePrinterInfo(data)
|
||||
store.setPrinter({
|
||||
...store.printer,
|
||||
ribbonType: parsed.ribbonType,
|
||||
serialNo: parsed.serialNo
|
||||
})
|
||||
} catch {
|
||||
/* 无打印机时不阻塞 */
|
||||
}
|
||||
}
|
||||
|
||||
/** 启动后:先拉静态信息,再查实时状态 */
|
||||
export async function refreshPrinterAfterInit(): Promise<void> {
|
||||
await refreshPrinterInfo()
|
||||
await refreshLiveStatus()
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ export interface PrinterStatusDisplay {
|
||||
ribbonType: string
|
||||
statusText: string
|
||||
serialNo: string
|
||||
printedCount: number
|
||||
}
|
||||
|
||||
export const defaultPrinterStatus: PrinterStatusDisplay = {
|
||||
ribbonType: '—',
|
||||
statusText: '—',
|
||||
serialNo: '—',
|
||||
printedCount: 0
|
||||
serialNo: '—'
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { notify } from '@/composables/useNotify'
|
||||
import { refreshLiveStatus } from '@/composables/usePrinterStatus'
|
||||
import AppShell from '@/layouts/AppShell.vue'
|
||||
import AppHeader from '@/components/AppHeader.vue'
|
||||
import AppFooter from '@/components/AppFooter.vue'
|
||||
@@ -259,6 +260,7 @@ async function enterWaitPhase(next: 'completed' | 'failed', errorText = ''): Pro
|
||||
appStore.setMode(sessionMode)
|
||||
lastCardPosition = -1
|
||||
await startCardPositionWatch(sessionMode)
|
||||
void refreshLiveStatus()
|
||||
}
|
||||
|
||||
async function enterFailedPhase(errorText = ''): Promise<void> {
|
||||
@@ -321,6 +323,7 @@ async function resubmitTask(): Promise<void> {
|
||||
usbAwaitNewCycle = true
|
||||
collectHint.value = usbTaskStatusHint(USB_TASK_PREPARING)
|
||||
unsubUsb = onUsbPollTick((payload) => applyUsbProgress(payload as UsbPollPayload))
|
||||
void refreshLiveStatus()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -349,6 +352,7 @@ async function resubmitTask(): Promise<void> {
|
||||
return
|
||||
}
|
||||
unsubJob = onJobPollTick((payload) => applyJobProgress(payload as JobPollPayload))
|
||||
void refreshLiveStatus()
|
||||
} catch (e) {
|
||||
await backToWait(String(e))
|
||||
} finally {
|
||||
@@ -460,6 +464,7 @@ onMounted(async () => {
|
||||
setProgress(0)
|
||||
collectHint.value = usbTaskStatusHint(USB_TASK_PREPARING)
|
||||
unsubUsb = onUsbPollTick((payload) => applyUsbProgress(payload as UsbPollPayload))
|
||||
void refreshLiveStatus()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -476,6 +481,7 @@ onMounted(async () => {
|
||||
return
|
||||
}
|
||||
unsubJob = onJobPollTick((payload) => applyJobProgress(payload as JobPollPayload))
|
||||
void refreshLiveStatus()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
import { computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { notify, notifyRequireInit } from '@/composables/useNotify'
|
||||
import { refreshPrinterHeader } from '@/composables/usePrinterStatus'
|
||||
import { refreshLiveStatus } from '@/composables/usePrinterStatus'
|
||||
import AppShell from '@/layouts/AppShell.vue'
|
||||
import AppHeader from '@/components/AppHeader.vue'
|
||||
import AppFooter from '@/components/AppFooter.vue'
|
||||
@@ -77,7 +77,7 @@ async function onReset(): Promise<void> {
|
||||
const r = await dllPrinterReset()
|
||||
if (r.ok) {
|
||||
notify.success('已发送重置指令')
|
||||
await refreshPrinterHeader(configStore)
|
||||
await refreshLiveStatus()
|
||||
} else notify.error(r.message || '重置失败')
|
||||
}
|
||||
|
||||
@@ -88,8 +88,10 @@ async function onReject(): Promise<void> {
|
||||
return
|
||||
}
|
||||
const r = await dllPrinterReject()
|
||||
if (r.ok) notify.success('已废弃卡片')
|
||||
else notify.error(r.message || '操作失败')
|
||||
if (r.ok) {
|
||||
notify.success('已废弃卡片')
|
||||
await refreshLiveStatus()
|
||||
} else notify.error(r.message || '操作失败')
|
||||
}
|
||||
|
||||
async function onTemplate(): Promise<void> {
|
||||
|
||||
@@ -2,7 +2,6 @@ export interface PrinterStatusSnapshot {
|
||||
ribbonType: string
|
||||
statusText: string
|
||||
serialNo: string
|
||||
printedCount: number
|
||||
}
|
||||
|
||||
const PRINTER_STATUS_MAP: Record<string, string> = {
|
||||
@@ -30,6 +29,7 @@ function normalizeStatus(raw: unknown): string {
|
||||
return PRINTER_STATUS_MAP[s] ?? s
|
||||
}
|
||||
|
||||
/** SAPI_PrinterCheckstatus 返回值 → 展示文案 */
|
||||
export function statusTextFromCheckstatus(code: number): {
|
||||
ok: boolean
|
||||
statusText: string
|
||||
@@ -59,36 +59,18 @@ function snapshotFromRecord(row: Record<string, unknown>): PrinterStatusSnapshot
|
||||
'PrinterSerial',
|
||||
'PrinterName'
|
||||
])
|
||||
const statusRaw = pickFirst(row, [
|
||||
'printer_status',
|
||||
'PrinterStatus',
|
||||
'PrinterType',
|
||||
'Status'
|
||||
])
|
||||
const ribbon = pickFirst(row, ['ribbon_type', 'RibbonType', 'RibbonAmount'])
|
||||
const printed = pickFirst(row, ['printed_count', 'PrintedCount', 'PrintCount', 'printedCount'])
|
||||
|
||||
let statusText = normalizeStatus(statusRaw)
|
||||
if (statusText === '—') {
|
||||
const remain = row.RibbonRemain ?? row.RemainCount
|
||||
const capacity = row.RibbonCapacity ?? row.Capacity ?? row.MaxCount
|
||||
if (remain != null && capacity != null) {
|
||||
statusText = `${remain}/${capacity}`
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ribbonType: String(ribbon ?? '—'),
|
||||
statusText,
|
||||
serialNo: String(serial ?? '—'),
|
||||
printedCount: Number(printed ?? 0)
|
||||
statusText: '—',
|
||||
serialNo: String(serial ?? '—')
|
||||
}
|
||||
}
|
||||
|
||||
export function parsePrinterInfoFromDll(json: Record<string, unknown>): PrinterStatusSnapshot {
|
||||
const flatSerial = pickFirst(json, ['serial_no', 'SerialNo', 'serialNo', 'szPrinterSerial'])
|
||||
const flatStatus = pickFirst(json, ['printer_status', 'PrinterStatus'])
|
||||
if (flatSerial != null || flatStatus != null) {
|
||||
if (flatSerial != null) {
|
||||
return snapshotFromRecord(json)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user