打包模式(pages/packaging): - 工牌(base64 JSON)扫码识别,经 index.queryUserByToken 查询用户:同用户已在线则下线,否则绑定为在线成员 - 多成员模型 workbenchMembers:弹窗仅展示成员列表+逐个下线;上报打包携带全部在线成员(users) - 成员列表以服务端 getWorkbenchInfo.members 为准,绑定/下线后静默重拉 - 无在线成员时非工牌码拦截提示需要先登录,不走查询用户 - 带打包台 token 请求 401/403 统一清除工作台状态回登录(请求守卫) - 30 分钟无新打包任务:结束打包任务+下线全部成员(不退出工作台模式,留在当前页) - 移除手动退出工作台入口;扫描记录持久化 localStorage(50 条出入栈) - 操作员列表弹窗重新排版(头像/姓名/下线按钮) 其他: - 登录页扫码/更新流程、导航守卫与路由封装、Electron 主进程/预加载、发布脚本与配置模板(deploy.example.json)等调整
114 lines
4.7 KiB
JavaScript
114 lines
4.7 KiB
JavaScript
/**
|
|
* 一键打包 Windows exe 并发布:
|
|
* 1. 编译前端资源(uni build --mode electron)
|
|
* 2. electron-builder 生成 NSIS 安装包,输出 release/windows/
|
|
* 3. 可选:读取 config/deploy.json 的 windows 段,scp 上传安装包与 latest.json
|
|
* 用法:node scripts/build-exe.cjs [--no-upload]
|
|
*/
|
|
const { spawnSync } = require('child_process')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const crypto = require('crypto')
|
|
|
|
const ROOT = path.resolve(__dirname, '..')
|
|
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm'
|
|
const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx'
|
|
const useShell = process.platform === 'win32'
|
|
const noUpload = process.argv.includes('--no-upload')
|
|
|
|
function run(cmd, args) {
|
|
const command = `${cmd} ${args.join(' ')}`
|
|
console.log(`\n> ${command}`)
|
|
const result = spawnSync(command, { stdio: 'inherit', shell: useShell })
|
|
if (result.status !== 0) {
|
|
console.error(`\n[x] 命令失败(退出码 ${result.status}): ${command}`)
|
|
process.exit(result.status || 1)
|
|
}
|
|
}
|
|
|
|
console.log('[1/2] 编译前端资源 -> dist/build/h5')
|
|
run(npmCmd, ['run', 'build:h5:electron'])
|
|
|
|
console.log('\n[2/2] electron-builder 打包 exe -> release/windows/')
|
|
run(npxCmd, ['electron-builder', '--config', 'electron-builder.config.cjs'])
|
|
|
|
// ---------- 3. 发布上传(config/deploy.json 的 windows 段) ----------
|
|
if (noUpload) {
|
|
console.log('\n[跳过] --no-upload 已指定,跳过发布上传')
|
|
} else {
|
|
const deployPath = path.join(ROOT, 'config', 'deploy.json')
|
|
if (!fs.existsSync(deployPath)) {
|
|
console.log('\n[跳过] 未找到 config/deploy.json,跳过发布上传(复制 config/deploy.example.json 并填写)')
|
|
} else {
|
|
let deploy
|
|
try {
|
|
deploy = JSON.parse(fs.readFileSync(deployPath, 'utf-8'))
|
|
} catch (error) {
|
|
console.error(`\n[x] config/deploy.json 解析失败: ${error.message}`)
|
|
process.exit(1)
|
|
}
|
|
const win = deploy.windows
|
|
if (!win || !win.host || !win.user || !win.remoteDir || !win.downloadUrlPrefix) {
|
|
console.log('\n[跳过] config/deploy.json 缺少 windows 段或字段不全,跳过发布上传')
|
|
} else {
|
|
const keyPath = win.keyPath || ''
|
|
if (keyPath && !fs.existsSync(keyPath)) {
|
|
console.error(`\n[x] SSH 密钥不存在: ${keyPath}`)
|
|
process.exit(1)
|
|
}
|
|
const port = String(win.port || 22)
|
|
const remoteDir = String(win.remoteDir).replace(/\/$/, '')
|
|
const urlPrefix = String(win.downloadUrlPrefix).replace(/\/?$/, '/')
|
|
const latestName = win.latestJsonName || 'latest.json'
|
|
|
|
// 定位 NSIS 安装包(按当前版本精确匹配,避免目录残留旧包被误选)
|
|
const outDir = path.join(ROOT, 'release', 'windows')
|
|
const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf-8'))
|
|
const version = pkg.version
|
|
const productName = 'WMS工作台'
|
|
const expectedName = `${productName}-${version}-setup.exe`
|
|
const setupExe = fs.existsSync(path.join(outDir, expectedName))
|
|
? expectedName
|
|
: fs.readdirSync(outDir).find(
|
|
(file) => file.endsWith('.exe') && file.includes('setup') && !file.includes('__uninstaller')
|
|
)
|
|
if (!setupExe) {
|
|
console.error('\\n[x] 未在 release/windows 找到安装包')
|
|
process.exit(1)
|
|
}
|
|
const exePath = path.join(outDir, setupExe)
|
|
const sha256 = crypto.createHash('sha256').update(fs.readFileSync(exePath)).digest('hex')
|
|
const latest = {
|
|
version,
|
|
file: setupExe,
|
|
url: `${urlPrefix}${setupExe}`,
|
|
sha256,
|
|
publishedAtUtc: new Date().toISOString(),
|
|
}
|
|
const latestPath = path.join(outDir, latestName)
|
|
fs.writeFileSync(latestPath, JSON.stringify(latest, null, 2) + '\n', 'utf-8')
|
|
|
|
console.log(`\n[3/3] 发布上传 -> ${win.user}@${win.host}:${remoteDir}/ ...`)
|
|
const scpArgs = [
|
|
...(keyPath ? ['-i', keyPath] : []),
|
|
'-P', port,
|
|
'-o', 'StrictHostKeyChecking=accept-new',
|
|
]
|
|
const target = `${win.user}@${win.host}:${remoteDir}/`
|
|
const uploadExe = spawnSync('scp', [...scpArgs, exePath, target], { stdio: 'inherit' })
|
|
if (uploadExe.status !== 0) {
|
|
console.error(`\n[x] 安装包上传失败(scp 退出码 ${uploadExe.status})`)
|
|
process.exit(uploadExe.status || 1)
|
|
}
|
|
const uploadLatest = spawnSync('scp', [...scpArgs, latestPath, target], { stdio: 'inherit' })
|
|
if (uploadLatest.status !== 0) {
|
|
console.error(`\n[x] ${latestName} 上传失败(scp 退出码 ${uploadLatest.status})`)
|
|
process.exit(uploadLatest.status || 1)
|
|
}
|
|
console.log(`\n[ok] 发布完成: ${urlPrefix}${setupExe}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log('\n[ok] 打包完成,安装包位于 release/windows/ 目录')
|