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