Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
electron-printer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhuzhequan
electron-printer
Commits
e34286ca
Commit
e34286ca
authored
Mar 30, 2026
by
linjinhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:添加命令行配置打包
parent
a487f84a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
20 deletions
+35
-20
config/env.json
+12
-4
package.json
+2
-0
src/background.js
+2
-2
src/server/entity/function.js
+18
-9
src/server/utils/store.js
+1
-4
vue.config.js
+0
-1
No files found.
config/env.json
View file @
e34286ca
{
"apiApiHost"
:
"http://172.16.19.100:8060/api"
,
"fileApiUrl"
:
"http://172.16.19.100:8060/upload/factory"
,
"visionUrl"
:
"http://console.jomalls.com"
,
"configPath"
:
"D:
\\
work
\\
electron-printer
\\
config
\\
env.json"
"test"
:
{
"apiApiHost"
:
"http://172.16.19.100:8060/api"
,
"fileApiUrl"
:
"http://172.16.19.100:8060/upload/factory"
,
"visionUrl"
:
"http://console.jomalls.com"
,
"configPath"
:
"D:
\\
work
\\
electron-printer
\\
config
\\
env.json"
},
"prod"
:
{
"apiApiHost"
:
"https://factory.jomalls.com/api"
,
"fileApiUrl"
:
"https://factory.jomalls.com/upload/factory"
,
"visionUrl"
:
"https://console.jomalls.com"
,
"configPath"
:
"D:
\\
work
\\
electron-printer
\\
config
\\
env.json"
}
}
package.json
View file @
e34286ca
...
...
@@ -8,6 +8,8 @@
"serve"
:
"vue-cli-service serve"
,
"build"
:
"vue-cli-service build"
,
"lint"
:
"vue-cli-service lint"
,
"electron:build:test"
:
"set VUE_APP_ENV=test&& vue-cli-service electron:build"
,
"electron:build:prod"
:
"set VUE_APP_ENV=prod&& vue-cli-service electron:build"
,
"electron:build"
:
"vue-cli-service electron:build"
,
"electron:serve"
:
"nodemon --watch src/server --exec vue-cli-service electron:serve"
,
"postinstall"
:
"electron-builder install-app-deps"
,
...
...
src/background.js
View file @
e34286ca
...
...
@@ -243,8 +243,8 @@ async function createWindow() {
}
try
{
let
configObj
=
JSON
.
parse
(
data
);
configObj
.
apiApiHost
=
`http://
${
newDomain
}
/api`
;
configObj
.
fileApiUrl
=
`http://
${
newDomain
}
/upload/factory`
;
configObj
.
apiApiHost
=
`http
s
://
${
newDomain
}
/api`
;
configObj
.
fileApiUrl
=
`http
s
://
${
newDomain
}
/upload/factory`
;
configObj
.
configPath
=
configPath
;
const
newData
=
JSON
.
stringify
(
configObj
);
// 使用2个空格缩进
...
...
src/server/entity/function.js
View file @
e34286ca
...
...
@@ -42,8 +42,16 @@ function getCurrentDesktopDevice() {
return
version
;
}
/**
* @function readEnv
* @description 【核心方法】读取项目配置文件,自动区分测试/生产环境
* 作用:1. 动态获取配置文件路径(开发/打包环境自动适配)
* 2. 读取env.json配置文件
* 3. 根据打包命令切换测试/生产环境接口地址
* 4. 初始化全局接口变量,供项目全局使用
* 5. 配置加载失败时自动兜底默认配置
*/
function
readEnv
()
{
// 不需要async了
let
exePath
,
configPath
;
try
{
if
(
process
.
env
.
NODE_ENV
===
"development"
)
{
...
...
@@ -52,29 +60,30 @@ function readEnv() {
exePath
=
path
.
dirname
(
app
.
getPath
(
"exe"
)).
replace
(
/
\\
/g
,
"/"
);
configPath
=
`
${
exePath
}
/config/env.json`
;
}
console
.
log
(
"configPath"
,
configPath
);
// ✅ 改用同步读取,确保配置加载完成
const
data
=
fs
.
readFileSync
(
configPath
,
"utf-8"
);
const
config
=
JSON
.
parse
(
data
);
const
allConfig
=
JSON
.
parse
(
data
);
const
isTest
=
process
.
env
.
VUE_APP_ENV
===
"test"
;
const
config
=
isTest
?
allConfig
.
test
:
allConfig
.
prod
;
config
.
configPath
=
configPath
;
setApi
(
config
);
// 如果setApi是异步的,这里需要改成同步,或用await(但readEnv要加async)
console
.
log
(
53
,
config
);
setApi
(
config
);
// 此时赋值一定完成
fileEnv
=
config
.
fileApiUrl
;
env
=
config
.
apiApiHost
;
visionUrl
=
config
.
visionUrl
;
console
.
log
(
"配置加载完成:"
,
{
fileEnv
,
env
,
visionUrl
});
}
catch
(
err
)
{
console
.
error
(
"读取配置文件失败:"
,
err
);
// 配置加载失败时,可设置默认值或抛出错误
fileEnv
=
"https://factory.jomalls.com/upload/factory"
;
env
=
"https://factory.jomalls.com/api"
;
visionUrl
=
"https://console.jomalls.com"
;
configPath
=
"D:
\\
work
\\
electron-printer
\\
config
\\
env.json"
;
throw
new
Error
(
`配置文件加载失败:
${
err
.
message
}
`
);
}
}
readEnv
();
export
default
{
saveImgByUrl
:
async
(
req
,
res
)
=>
{
...
...
src/server/utils/store.js
View file @
e34286ca
...
...
@@ -441,10 +441,7 @@ module.exports = {
// 步骤5:按后缀降序排序,取最新一条(只删这一条)
qualifiedOrders
.
sort
((
a
,
b
)
=>
b
.
suffix
-
a
.
suffix
);
const
latestQualifiedItem
=
qualifiedOrders
[
0
];
const
{
cacheKey
:
toDeleteCacheKey
,
order
:
toDeleteOrder
,
}
=
latestQualifiedItem
;
const
{
cacheKey
:
toDeleteCacheKey
}
=
latestQualifiedItem
;
// 步骤6:【核心修复】用「唯一cacheKey」精准匹配,只删除目标订单(避免误伤)
const
originalOrderArray
=
store
.
get
(
"orderInfo"
)
||
[];
...
...
vue.config.js
View file @
e34286ca
...
...
@@ -89,7 +89,6 @@ module.exports = {
warnings
:
true
,
errors
:
true
,
},
before
:
(
app
)
=>
{},
},
/**
* 第三方插件配置
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment