From 7862ff2b2a5b24a15c979197fa57815c49048156 Mon Sep 17 00:00:00 2001 From: 24kycj <1637269896@qq.com> Date: Sat, 13 Jun 2026 21:08:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B5=8B=E8=AF=95=E8=81=94=E8=B0=83?= =?UTF-8?q?=E5=9B=9B=E9=A1=B9=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 授权码并入加密狗行,password 掩码,窄宽样式 - 打印机信息仅调用 SAPI_GetPrinterInfo,移除 Ex 避免崩溃 - net_info 改为 JSON 数组,修复双重编码 Co-authored-by: Cursor --- app/scripts/network-path-selftest.mjs | 12 +++++-- app/src/main/ipc/register-handlers.ts | 2 +- app/src/main/services/work-dll.service.ts | 35 ++----------------- app/src/renderer/src/styles/pages/page4.css | 10 ++++++ app/src/renderer/src/utils/buildJobConfig.ts | 6 ++-- .../renderer/src/utils/copyNetworkHosts.ts | 6 ++-- .../renderer/src/utils/createDistributeJob.ts | 2 +- .../src/views/DistributeConfigView.vue | 20 +++-------- app/src/shared/network-host.ts | 12 +++++-- 9 files changed, 42 insertions(+), 63 deletions(-) diff --git a/app/scripts/network-path-selftest.mjs b/app/scripts/network-path-selftest.mjs index eeb2c0e..a201570 100644 --- a/app/scripts/network-path-selftest.mjs +++ b/app/scripts/network-path-selftest.mjs @@ -47,7 +47,9 @@ eq('collectHosts local only', collectHostsForCopyPaths(['E:\\data'], {}), []) const stored = new Map([['192.168.1.100', { userName: 'admin', password: 'pass', lastUsed: '' }]]) const r1 = buildNetInfo([{ hostName: '192.168.1.100' }], (h) => stored.get(h) || null) -eq('buildNetInfo single', r1, '[{"host_name":"192.168.1.100","user_name":"admin","password":"pass"}]') +eq('buildNetInfo single', r1, [ + { host_name: '192.168.1.100', user_name: 'admin', password: 'pass' } +]) const r2 = buildNetInfo( [ @@ -56,7 +58,7 @@ const r2 = buildNetInfo( ], () => null ) -eq('buildNetInfo dedup', r2, '[{"host_name":"192.168.1.100","user_name":"a","password":"p"}]') +eq('buildNetInfo dedup', r2, [{ host_name: '192.168.1.100', user_name: 'a', password: 'p' }]) let threw = false try { @@ -65,7 +67,11 @@ try { threw = e.message.includes('缺少网络凭据') } eq('buildNetInfo missing throws', threw, true) -eq('buildNetInfo empty list', buildNetInfo([], () => null), '') +eq('buildNetInfo empty list', buildNetInfo([], () => null), []) + +const jobBody = { net_info: r1 } +const jobParsed = JSON.parse(JSON.stringify(jobBody)) +eq('net_info is array in job json', Array.isArray(jobParsed.net_info), true) const pass = cases.filter((c) => c.ok).length const fail = cases.length - pass diff --git a/app/src/main/ipc/register-handlers.ts b/app/src/main/ipc/register-handlers.ts index 217ef65..dc304db 100644 --- a/app/src/main/ipc/register-handlers.ts +++ b/app/src/main/ipc/register-handlers.ts @@ -68,7 +68,7 @@ export function registerIpcHandlers(): void { return ok({ ...cached, fromCache: true, - liveError: r.code <= 0 ? '未连接打印机' : `GetPrinterInfoEx code=${r.code}` + liveError: r.code <= 0 ? '未连接打印机' : `GetPrinterInfo code=${r.code}` }) } return fail(0, '未连接打印机') diff --git a/app/src/main/services/work-dll.service.ts b/app/src/main/services/work-dll.service.ts index f22b3d3..5c77371 100644 --- a/app/src/main/services/work-dll.service.ts +++ b/app/src/main/services/work-dll.service.ts @@ -24,10 +24,6 @@ let SAPI_Init: any = null // eslint-disable-next-line @typescript-eslint/no-explicit-any let SAPI_GetPrinterInfo: any = null // eslint-disable-next-line @typescript-eslint/no-explicit-any -let SAPI_GetPrinterInfoEx: any = null -// eslint-disable-next-line @typescript-eslint/no-explicit-any -let SAPI_FreePrinterInfo: any = null -// eslint-disable-next-line @typescript-eslint/no-explicit-any let SAPI_GetPrinterErrorStr: any = null // eslint-disable-next-line @typescript-eslint/no-explicit-any let SAPI_RestJobEx: any = null @@ -56,7 +52,6 @@ let hasCardPositionApi = false let hasCheckstatusApi = false let hasCancelApi = false let hasUploadApi = false -let hasPrinterInfoEx = false let hasUsbReaderApi = false let loggedCancelMissing = false let loggedRejectMissing = false @@ -95,15 +90,7 @@ function readPrinterJsonFromOutPtr(len: number, outPtr: Buffer): { code: number; return { code: len } } } finally { - if (SAPI_FreePrinterInfo) { - try { - SAPI_FreePrinterInfo(ptr) - } catch (e) { - log.warn('SAPI_FreePrinterInfo', e) - } - } else { - koffi.free(ptr) - } + koffi.free(ptr) } } @@ -123,16 +110,6 @@ function loadLibrary(): void { SAPI_GetUsbCopyState = lib.func('int __stdcall SAPI_GetUsbCopyState(_Out_ int *, _Out_ int *)') SAPI_PrinterResetprinter = lib.func('int __stdcall SAPI_PrinterResetprinter()') - try { - SAPI_GetPrinterInfoEx = lib.func('int __stdcall SAPI_GetPrinterInfoEx(_Out_ void **)') - SAPI_FreePrinterInfo = lib.func('void __stdcall SAPI_FreePrinterInfo(void *)') - hasPrinterInfoEx = true - } catch { - SAPI_GetPrinterInfoEx = null - SAPI_FreePrinterInfo = null - hasPrinterInfoEx = false - } - try { SAPI_UploadFile = lib.func('int __stdcall SAPI_UploadFile(str, str, str)') hasUploadApi = true @@ -194,7 +171,6 @@ function loadLibrary(): void { log.info('workDll loaded', { upload: hasUploadApi, - printerInfoEx: hasPrinterInfoEx, cancel: hasCancelApi, reject: hasRejectApi, usbReader: hasUsbReaderApi, @@ -263,7 +239,7 @@ export function dllInit(params: InitParams): number { } function dllGetPrinterInfoInternal( - apiName: 'SAPI_GetPrinterInfo' | 'SAPI_GetPrinterInfoEx', + apiName: 'SAPI_GetPrinterInfo', fn: (outPtr: Buffer) => number ): { code: number; json?: Record } { return traceCall(apiName, undefined, () => { @@ -279,13 +255,6 @@ function dllGetPrinterInfoInternal( } export function dllGetPrinterInfo(): { code: number; json?: Record } { - loadLibrary() - if (hasPrinterInfoEx && SAPI_GetPrinterInfoEx) { - const ex = dllGetPrinterInfoInternal('SAPI_GetPrinterInfoEx', (p) => SAPI_GetPrinterInfoEx!(p)) - if (ex.json && Object.keys(ex.json).length > 0) { - return ex - } - } return dllGetPrinterInfoInternal('SAPI_GetPrinterInfo', (p) => SAPI_GetPrinterInfo!(p)) } diff --git a/app/src/renderer/src/styles/pages/page4.css b/app/src/renderer/src/styles/pages/page4.css index da3b3c0..932c4f3 100644 --- a/app/src/renderer/src/styles/pages/page4.css +++ b/app/src/renderer/src/styles/pages/page4.css @@ -110,6 +110,16 @@ margin-left: 3px; } +.m-panel-toolbar .c-checkbox-item .c-input.dog-auth { + width: 110px; + height: 20px; + padding: 0 4px; + font-size: 9px; + border-radius: 3px; + border: 1px solid #ced4da; + margin-left: 6px; +} + /* 提示文字 */ .m-panel-toolbar .c-checkbox-item .dog-hint { font-size: 9px; diff --git a/app/src/renderer/src/utils/buildJobConfig.ts b/app/src/renderer/src/utils/buildJobConfig.ts index 94a1f11..90d5693 100644 --- a/app/src/renderer/src/utils/buildJobConfig.ts +++ b/app/src/renderer/src/utils/buildJobConfig.ts @@ -1,11 +1,12 @@ import type { DistributeFormState } from '@/stores/distributeForm' +import type { NetInfoCredential } from '@shared/network-host' import { cleanPathPattern } from '@shared/path-pattern' import { resolveJobTasks } from '@/utils/validateJobConfig' export interface BuildJobOptions { taskId: string udfFile?: string - netInfo?: string + netInfo?: NetInfoCredential[] } function formatFileForApi(formatType: Exclude): string { @@ -62,8 +63,7 @@ export function buildJobConfig( if (form.generateZip) body.is_generate_zip = true if (form.failPrintLabel) body.is_printer_record_logo = true - const netInfo = opts.netInfo?.trim() - if (netInfo) body.net_info = netInfo + if (opts.netInfo?.length) body.net_info = opts.netInfo return body } diff --git a/app/src/renderer/src/utils/copyNetworkHosts.ts b/app/src/renderer/src/utils/copyNetworkHosts.ts index 2d1339a..2d7893b 100644 --- a/app/src/renderer/src/utils/copyNetworkHosts.ts +++ b/app/src/renderer/src/utils/copyNetworkHosts.ts @@ -1,5 +1,5 @@ import { cleanPathPattern } from '@shared/path-pattern' -import { buildNetInfo, collectHostsForCopyPaths } from '@shared/network-host' +import { buildNetInfo, collectHostsForCopyPaths, type NetInfoCredential } from '@shared/network-host' import type { DistributeFormState } from '@/stores/distributeForm' import { fsResolveNetworkHosts } from '@/api/cardsoon' import { useNetworkAuthStore } from '@/stores/networkAuth' @@ -20,9 +20,9 @@ export async function resolveCopyNetworkHosts(form: DistributeFormState): Promis return collectHostsForCopyPaths(paths, driveHostMap) } -export async function buildNetInfoForForm(form: DistributeFormState): Promise { +export async function buildNetInfoForForm(form: DistributeFormState): Promise { const hosts = await resolveCopyNetworkHosts(form) - if (!hosts.length) return '' + if (!hosts.length) return [] const netStore = useNetworkAuthStore() return buildNetInfo( hosts.map((h) => ({ hostName: h })), diff --git a/app/src/renderer/src/utils/createDistributeJob.ts b/app/src/renderer/src/utils/createDistributeJob.ts index 610bac7..7a142ba 100644 --- a/app/src/renderer/src/utils/createDistributeJob.ts +++ b/app/src/renderer/src/utils/createDistributeJob.ts @@ -34,7 +34,7 @@ async function buildJobJson( } } - let netInfo = '' + let netInfo: Awaited> = [] if (hasCopy) { try { netInfo = await buildNetInfoForForm(form) diff --git a/app/src/renderer/src/views/DistributeConfigView.vue b/app/src/renderer/src/views/DistributeConfigView.vue index 00aa5c1..6f56345 100644 --- a/app/src/renderer/src/views/DistributeConfigView.vue +++ b/app/src/renderer/src/views/DistributeConfigView.vue @@ -68,18 +68,15 @@ @input="onDongleCountInput" /> {{ dongleHint }} - - -
-
-
+
@@ -488,15 +485,6 @@ async function onSubmit(): Promise { color: #606266; } -.toolbar-item--full { - flex: 1; -} - -.dog-auth { - width: 100%; - max-width: 100%; -} - .m-print-side-picker { display: flex; gap: 16px; diff --git a/app/src/shared/network-host.ts b/app/src/shared/network-host.ts index 645887e..934cece 100644 --- a/app/src/shared/network-host.ts +++ b/app/src/shared/network-host.ts @@ -22,6 +22,12 @@ export function extractDriveLetter(p: string): string { return m ? m[1].toUpperCase() : '' } +export interface NetInfoCredential { + host_name: string + user_name: string + password: string +} + export function buildNetworkUrl(host: string, share: string): string { const h = host.trim() const s = share.trim().replace(/^[\\/]+/, '').replace(/[\\/]+$/, '') @@ -52,8 +58,8 @@ export function collectHostsForCopyPaths( export function buildNetInfo( networkItems: { hostName?: string; userName?: string; password?: string }[], getStored: (host: string) => { userName?: string; password?: string } | null -): string { - const creds: { host_name: string; user_name: string; password: string }[] = [] +): NetInfoCredential[] { + const creds: NetInfoCredential[] = [] const seen = new Set() for (const it of networkItems) { const host = (it.hostName || '').trim() @@ -71,5 +77,5 @@ export function buildNetInfo( password }) } - return creds.length > 0 ? JSON.stringify(creds) : '' + return creds }