Appearance
验证本地是否有数据库存在
js
/**
* 本地数据库
*/
function copyFile() {
const targetPath = path.join(app.getPath("userData"), "db", "zjyf.db");
const dbFilePath = path.join(app.getAppPath(), "public", "db", "zjyf.db");
const dbFolderPath = path.join(app.getPath("userData"), "db");
if (!fs.existsSync(dbFolderPath)) {
fs.mkdirSync(dbFolderPath, { recursive: true });
}
fs.access(targetPath, fs.constants.F_OK, (err) => {
if (err) {
// 创建读写流
const readStream = fs.createReadStream(dbFilePath);
const writeStream = fs.createWriteStream(targetPath);
// 管道传输数据
readStream.pipe(writeStream);
writeStream.on("finish", () => {
initJdk();
});
} else {
initJdk();
}
});
}
本地数据库存在用户目录下
开启子服务,启动java服务
js
async function initJdk() {
try {
const data = await axios.get(
"http://localhost:49080/admin-api/single/fin/service-matters/page"
);
} catch (error) {
if (process.platform === "win32") {
const publicPath = path.join(app.getAppPath(), "public");
const batFilePath = path.join(publicPath, "start.bat");
cmdProcess = spawn("cmd.exe", ["/c", batFilePath], {
cwd: publicPath,
});
}
}
}
监听服务是否跑通
js
function watchServerStart() {
async function pollServer() {
try {
const data = await axios.get(
"http://localhost:49080/admin-api/fin/getTime"
);
createWindow();
console.log("-----------------success---------------");
} catch (error) {
console.log("-error-");
setTimeout(() => {
pollServer();
}, 2000);
}
}
pollServer();
}