Compare commits
172 Commits
2025-08
...
d050dbc6e7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d050dbc6e7 | ||
|
|
3b2f6b2517 | ||
|
|
45a010b3a4 | ||
| 081a77ac4c | |||
|
|
ca8f173394 | ||
|
|
2e377bcca2 | ||
|
|
2a8757c9f1 | ||
|
|
35f21b7140 | ||
|
|
b0ca84c8fd | ||
|
|
045acfa061 | ||
|
|
55ff45f9a9 | ||
|
|
7afccb58fd | ||
|
|
11c6704f11 | ||
|
|
97d1f08bbe | ||
|
|
7d0053eb71 | ||
|
|
666fb22c49 | ||
|
|
b319a89501 | ||
|
|
8e0b3be438 | ||
|
|
b0d92de738 | ||
|
|
92b3e25989 | ||
|
|
43c75c96a7 | ||
|
|
da0aa0cd0f | ||
|
|
b0c88b9df2 | ||
|
|
7c0ec5844a | ||
|
|
a4a64ef0f9 | ||
|
|
58bb25500e | ||
|
|
3d73c34343 | ||
|
|
f74fedc213 | ||
|
|
8ea49f9609 | ||
|
|
9ee71d29d4 | ||
|
|
039a67c35a | ||
|
|
e17749d47e | ||
|
|
21c859c8f1 | ||
|
|
4fe239c86f | ||
| ab62e56bbb | |||
| 5730b9c5cf | |||
|
|
d4992db198 | ||
|
|
5ccd1709a5 | ||
|
|
b48c1e0d78 | ||
|
|
fcdbbce7a9 | ||
|
|
d08194bfd8 | ||
|
|
55f579ef64 | ||
|
|
783e1c080b | ||
|
|
44cdb3273c | ||
|
|
dbc21cdbfa | ||
|
|
24d83cfd39 | ||
|
|
b213b721bb | ||
|
|
4ae42408c3 | ||
|
|
a9156f0954 | ||
|
|
3e7509cd44 | ||
|
|
24becb82e1 | ||
|
|
6608587edd | ||
|
|
5ad8cdecba | ||
|
|
6b4cca1ef7 | ||
|
|
dea0844829 | ||
|
|
bbd438d23f | ||
|
|
c88128b63b | ||
|
|
95c68942ed | ||
|
|
5db685baca | ||
|
|
fa710efea4 | ||
|
|
d0c3e1d9bd | ||
|
|
589ddd38f3 | ||
|
|
47d1500296 | ||
|
|
4a8f8bff6a | ||
|
|
2b9b87a3db | ||
|
|
b241128105 | ||
|
|
226e3271ee | ||
|
|
1c253fd713 | ||
|
|
ed81d3d398 | ||
|
|
09b54a29ab | ||
|
|
b27615baaf | ||
|
|
c735e7a5bb | ||
|
|
c78f591baf | ||
|
|
cfd8b072dd | ||
|
|
d18e34d2c9 | ||
|
|
53813795db | ||
|
|
8c3098e19a | ||
|
|
780a446aed | ||
|
|
375f01a6ab | ||
|
|
48aab7c1e9 | ||
|
|
d7cfe665e2 | ||
|
|
237c23bb70 | ||
|
|
4cd6302ee0 | ||
|
|
6a75709774 | ||
|
|
629dff1256 | ||
|
|
6d6d03c03c | ||
|
|
6122f53c8e | ||
|
|
5a7eea1052 | ||
|
|
25f3570c18 | ||
|
|
74e015bd12 | ||
|
|
da6a72807b | ||
|
|
bb7ebaea45 | ||
|
|
ae51b590af | ||
|
|
2ec3102eff | ||
|
|
f5f7d259a9 | ||
|
|
4364f88526 | ||
|
|
0f5e21a06c | ||
|
|
ddbaf5651a | ||
|
|
a847419ab5 | ||
|
|
d5fb41cbab | ||
|
|
25e7b754b7 | ||
|
|
a32ca3c849 | ||
|
|
6e979c5dcb | ||
|
|
8b578d4d8b | ||
|
|
52fcdbfe1e | ||
|
|
4559a7b5e2 | ||
|
|
567201563d | ||
|
|
772707ac42 | ||
|
|
4a6db824ba | ||
|
|
8b4c22e959 | ||
|
|
d7f1224df4 | ||
|
|
ac4e0e2077 | ||
|
|
56a6f199c0 | ||
|
|
0abb765b32 | ||
|
|
4f8fdb83d1 | ||
|
|
300b220de2 | ||
|
|
825d2cc46a | ||
|
|
95b602e6d4 | ||
|
|
a7b5bbf0bf | ||
|
|
dfbba11aae | ||
|
|
5cf39e8aa8 | ||
|
|
a19a20ddd8 | ||
|
|
0985cc5d7c | ||
|
|
2be0be681e | ||
|
|
dd9ca8f956 | ||
|
|
5cd60d9a32 | ||
|
|
959ae1dee9 | ||
|
|
d2d1490e9b | ||
|
|
7bcd88c3a7 | ||
|
|
8e3368bd29 | ||
|
|
bc03ba88f0 | ||
|
|
2aee4b281d | ||
|
|
26647222e2 | ||
|
|
a2db45cace | ||
|
|
d761c0449b | ||
|
|
dc6a346fd4 | ||
|
|
e938c6b3d9 | ||
|
|
c9fef2a9d7 | ||
|
|
9319dd06c5 | ||
|
|
7b96ce84fc | ||
|
|
b105ff890c | ||
|
|
61b87304e6 | ||
|
|
83c8dc5f19 | ||
|
|
b1ddf540ca | ||
|
|
0025895696 | ||
|
|
1ec8cce63e | ||
|
|
865d52c135 | ||
|
|
ce8607af36 | ||
|
|
4e8a6300dd | ||
| 919e81da8b | |||
|
|
18cb6dbde8 | ||
| 6d405d16ed | |||
|
|
77d2176812 | ||
| c85eac3888 | |||
|
|
27d2d82fcd | ||
|
|
ecbc3c30c8 | ||
|
|
0a65efd235 | ||
|
|
5cd8fea60c | ||
|
|
3d1b4eb7c6 | ||
| ec1330bdb8 | |||
|
|
e66bcdb293 | ||
|
|
88f1876ef0 | ||
|
|
fdc1fd6fbd | ||
|
|
022d80f30e | ||
| f59f287b63 | |||
| 6e573cc597 | |||
| d2f92ecde4 | |||
|
|
b2a6a1de4e | ||
|
|
f374df79a6 | ||
|
|
154eb9f79c | ||
|
|
d0724cb7f6 | ||
| d6d63523a3 |
3
.gitignore
vendored
@@ -7,5 +7,6 @@ package-lock.json
|
||||
data/
|
||||
.vscode/launch.json
|
||||
public/electron/
|
||||
public/dist/
|
||||
pnpm-lock.yaml
|
||||
CLAUDE.md
|
||||
/public/dist/
|
||||
|
||||
6
.npmrc
@@ -2,3 +2,9 @@ registry=https://registry.npmmirror.com/
|
||||
disturl=https://registry.npmmirror.com/-/binary/node
|
||||
electron_mirror=https://npmmirror.com/mirrors/electron/
|
||||
electron-builder-binaries_mirror=https://registry.npmmirror.com/-/binary/electron-builder-binaries/
|
||||
|
||||
# 屏蔽警告配置
|
||||
legacy-peer-deps=true
|
||||
audit=false
|
||||
fund=false
|
||||
loglevel=error
|
||||
|
||||
61
README.md
@@ -1,61 +0,0 @@
|
||||
#### 项目简介
|
||||
|
||||
#### 常用命令
|
||||
```shell
|
||||
|
||||
# 运行项目
|
||||
npm run dev
|
||||
|
||||
# 仅运行前端
|
||||
npm run dev-frontend
|
||||
|
||||
# 仅运行后端
|
||||
npm run dev-electron
|
||||
|
||||
|
||||
# 预发布模式(环境变量为:prod),请先移动资源
|
||||
npm run start
|
||||
|
||||
# 移动前端静态资源
|
||||
npm run rd
|
||||
|
||||
# 移动资源,可配置
|
||||
npm run move
|
||||
|
||||
# 代码加密
|
||||
npm run encrypt
|
||||
|
||||
# 清除加密的代码
|
||||
npm run clean
|
||||
|
||||
# 生成logo
|
||||
npm run icon
|
||||
|
||||
# 打包 (windows版)
|
||||
npm run build-w (调整为64位)
|
||||
npm run build-w-32 (32位)
|
||||
npm run build-w-64 (64位)
|
||||
npm run build-w-arm64 (arm64)
|
||||
|
||||
# 打包 (windows 免安装版)
|
||||
# ee > v2.2.1
|
||||
npm run build-wz (调整为64位)
|
||||
npm run build-wz-32 (32位)
|
||||
npm run build-wz-64 (64位)
|
||||
npm run build-wz-arm64 (arm64)
|
||||
|
||||
# 打包 (mac版)
|
||||
npm run build-m
|
||||
npm run build-m-arm64 (m1芯片架构)
|
||||
|
||||
# 打包 (linux版)
|
||||
# ee > v2.2.1
|
||||
npm run build-l (默认64位 deb包)
|
||||
npm run build-l-32 (32位 deb包)
|
||||
npm run build-l-64 (64位 deb包)
|
||||
npm run build-l-arm64 (64位 deb包 arm64)
|
||||
npm run build-l-armv7l (64位 deb包 armv7l)
|
||||
npm run build-lr-64 (64位 rpm包)
|
||||
npm run build-lp-64 (64位 pacman包)
|
||||
|
||||
```
|
||||
@@ -1 +0,0 @@
|
||||
chrome应用商店ctx文件,解压后,放置在此目录中,打包时会将资源加入安装包内。
|
||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 745 B After Width: | Height: | Size: 930 B |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 26 KiB |
205
cmd/bin.js
Normal file
@@ -0,0 +1,205 @@
|
||||
/**
|
||||
* ee-bin 配置
|
||||
* 仅适用于开发环境
|
||||
*/
|
||||
module.exports = {
|
||||
/**
|
||||
* development serve ("frontend" "electron" )
|
||||
* ee-bin dev
|
||||
*/
|
||||
dev: {
|
||||
// frontend:前端服务
|
||||
// 说明:该配置的意思是,进入 frontend 目录,执行 npm run dev
|
||||
// 运行后的服务为 http://localhost:8080
|
||||
// 如果 protocol 属性为 'file://' 那么不会执行命令,项目直接加载 indexPath 对应的文件。
|
||||
frontend: {
|
||||
directory: './frontend',
|
||||
cmd: 'npm',
|
||||
args: ['run', 'dev'],
|
||||
port: 18091,
|
||||
},
|
||||
// electron:主进程服务
|
||||
// 说明:该配置的意思是,在根目录,执行 electron . --env=local
|
||||
electron: {
|
||||
directory: './',
|
||||
cmd: 'electron',
|
||||
args: ['.', '--env=local'],
|
||||
watch: false,
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 构建
|
||||
* ee-bin build
|
||||
*/
|
||||
build: {
|
||||
frontend: {
|
||||
directory: './frontend',
|
||||
cmd: 'npm',
|
||||
args: ['run', 'build'],
|
||||
},
|
||||
electron: {
|
||||
type: 'javascript',
|
||||
bundleType: 'copy'
|
||||
},
|
||||
win64: {
|
||||
cmd: 'electron-builder',
|
||||
directory: './',
|
||||
args: ['--config=./cmd/builder.json', '-w=nsis', '--x64'],
|
||||
},
|
||||
win32: {
|
||||
args: ['--config=./cmd/builder.json', '-w=nsis', '--ia32'],
|
||||
},
|
||||
win_e: {
|
||||
args: ['--config=./cmd/builder.json', '-w=portable', '--x64'],
|
||||
},
|
||||
win_7z: {
|
||||
args: ['--config=./cmd/builder.json', '-w=7z', '--x64'],
|
||||
},
|
||||
mac: {
|
||||
args: ['--config=./cmd/builder-mac.json', '-m'],
|
||||
},
|
||||
mac_arm64: {
|
||||
args: ['--config=./cmd/builder-mac-arm64.json', '-m', '--arm64'],
|
||||
},
|
||||
linux: {
|
||||
args: ['--config=./cmd/builder-linux.json', '-l=deb', '--x64'],
|
||||
},
|
||||
linux_arm64: {
|
||||
args: ['--config=./cmd/builder-linux.json', '-l=deb', '--arm64'],
|
||||
},
|
||||
go_w: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o=../build/extraResources/goapp.exe'],
|
||||
},
|
||||
go_m: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o=../build/extraResources/goapp'],
|
||||
},
|
||||
go_l: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o=../build/extraResources/goapp'],
|
||||
},
|
||||
python: {
|
||||
directory: './python',
|
||||
cmd: 'python',
|
||||
args: ['./setup.py', 'build'],
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 移动资源
|
||||
* ee-bin move
|
||||
*/
|
||||
move: {
|
||||
frontend_dist: {
|
||||
src: './frontend/dist',
|
||||
dest: './public/dist'
|
||||
},
|
||||
go_static: {
|
||||
src: './frontend/dist',
|
||||
dest: './go/public/dist'
|
||||
},
|
||||
go_config: {
|
||||
src: './go/config',
|
||||
dest: './go/public/config'
|
||||
},
|
||||
go_package: {
|
||||
src: './package.json',
|
||||
dest: './go/public/package.json'
|
||||
},
|
||||
go_images: {
|
||||
src: './public/images',
|
||||
dest: './go/public/images'
|
||||
},
|
||||
python_dist: {
|
||||
src: './python/dist',
|
||||
dest: './build/extraResources/py'
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 预发布模式(prod)
|
||||
* ee-bin start
|
||||
*/
|
||||
start: {
|
||||
directory: './',
|
||||
cmd: 'electron',
|
||||
args: ['.', '--env=prod']
|
||||
},
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*/
|
||||
encrypt: {
|
||||
frontend: {
|
||||
type: 'none',
|
||||
files: [
|
||||
'./public/dist/**/*.(js|json)',
|
||||
],
|
||||
cleanFiles: ['./public/dist'],
|
||||
confusionOptions: {
|
||||
compact: true,
|
||||
stringArray: true,
|
||||
stringArrayEncoding: ['none'],
|
||||
stringArrayCallsTransform: true,
|
||||
numbersToExpressions: true,
|
||||
target: 'browser',
|
||||
}
|
||||
},
|
||||
electron: {
|
||||
type: 'confusion',
|
||||
files: [
|
||||
'./public/electron/**/*.(js|json)',
|
||||
],
|
||||
cleanFiles: ['./public/electron'],
|
||||
specificFiles: [
|
||||
'./public/electron/main.js',
|
||||
'./public/electron/preload/bridge.js',
|
||||
],
|
||||
confusionOptions: {
|
||||
compact: true,
|
||||
stringArray: true,
|
||||
stringArrayEncoding: ['rc4'],
|
||||
deadCodeInjection: false,
|
||||
stringArrayCallsTransform: true,
|
||||
numbersToExpressions: true,
|
||||
target: 'node',
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 执行自定义命令
|
||||
* ee-bin exec
|
||||
*/
|
||||
exec: {
|
||||
// 单独调试,air 实现 go 热重载
|
||||
go: {
|
||||
directory: './go',
|
||||
cmd: 'air',
|
||||
args: ['-c=config/.air.toml' ],
|
||||
},
|
||||
// windows 单独调试,air 实现 go 热重载
|
||||
go_w: {
|
||||
directory: './go',
|
||||
cmd: 'air',
|
||||
args: ['-c=config/.air.windows.toml' ],
|
||||
},
|
||||
// 单独调试,以基础方式启动 go
|
||||
go2: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['run', './main.go', '--env=dev','--basedir=../', '--port=7073'],
|
||||
},
|
||||
python: {
|
||||
directory: './python',
|
||||
cmd: 'python',
|
||||
args: ['./main.py', '--port=7074'],
|
||||
stdio: "inherit", // ignore
|
||||
},
|
||||
},
|
||||
};
|
||||
40
cmd/builder-linux.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"productName": "ee",
|
||||
"appId": "com.bilibili.ee",
|
||||
"copyright": "© 2025 duola Technology Co., Ltd.",
|
||||
"directories": {
|
||||
"output": "out"
|
||||
},
|
||||
"asar": true,
|
||||
"files": [
|
||||
"**/*",
|
||||
"!cmd/",
|
||||
"!data/",
|
||||
"!electron/",
|
||||
"!frontend/",
|
||||
"!logs/",
|
||||
"!out/",
|
||||
"!go/",
|
||||
"!python/"
|
||||
],
|
||||
"extraResources": [
|
||||
{
|
||||
"from": "build/extraResources",
|
||||
"to": "extraResources"
|
||||
}
|
||||
],
|
||||
"publish": [
|
||||
{
|
||||
"provider": "generic",
|
||||
"url": ""
|
||||
}
|
||||
],
|
||||
"linux": {
|
||||
"icon": "build/icons/icon.icns",
|
||||
"artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
|
||||
"target": [
|
||||
"deb"
|
||||
],
|
||||
"category": "Utility"
|
||||
}
|
||||
}
|
||||
38
cmd/builder-mac-arm64.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"productName": "ee",
|
||||
"appId": "com.bilibili.ee",
|
||||
"copyright": "© 2025 duola Technology Co., Ltd.",
|
||||
"directories": {
|
||||
"output": "out"
|
||||
},
|
||||
"asar": true,
|
||||
"files": [
|
||||
"**/*",
|
||||
"!cmd/",
|
||||
"!data/",
|
||||
"!electron/",
|
||||
"!frontend/",
|
||||
"!logs/",
|
||||
"!out/",
|
||||
"!go/",
|
||||
"!python/"
|
||||
],
|
||||
"extraResources": [
|
||||
{
|
||||
"from": "build/extraResources",
|
||||
"to": "extraResources"
|
||||
}
|
||||
],
|
||||
"publish": [
|
||||
{
|
||||
"provider": "generic",
|
||||
"url": ""
|
||||
}
|
||||
],
|
||||
"mac": {
|
||||
"icon": "build/icons/icon.icns",
|
||||
"artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
|
||||
"darkModeSupport": true,
|
||||
"hardenedRuntime": false
|
||||
}
|
||||
}
|
||||
38
cmd/builder-mac.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"productName": "ee",
|
||||
"appId": "com.bilibili.ee",
|
||||
"copyright": "© 2025 duola Technology Co., Ltd.",
|
||||
"directories": {
|
||||
"output": "out"
|
||||
},
|
||||
"asar": true,
|
||||
"files": [
|
||||
"**/*",
|
||||
"!cmd/",
|
||||
"!data/",
|
||||
"!electron/",
|
||||
"!frontend/",
|
||||
"!logs/",
|
||||
"!out/",
|
||||
"!go/",
|
||||
"!python/"
|
||||
],
|
||||
"extraResources": [
|
||||
{
|
||||
"from": "build/extraResources",
|
||||
"to": "extraResources"
|
||||
}
|
||||
],
|
||||
"publish": [
|
||||
{
|
||||
"provider": "generic",
|
||||
"url": ""
|
||||
}
|
||||
],
|
||||
"mac": {
|
||||
"icon": "build/icons/icon.icns",
|
||||
"artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
|
||||
"darkModeSupport": true,
|
||||
"hardenedRuntime": false
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,21 @@
|
||||
{
|
||||
"productName": "pqs9100",
|
||||
"appId": "com.njcn.pqs9100",
|
||||
"copyright": "hongawen.com",
|
||||
"productName": "NPQS9100",
|
||||
"appId": "NQPS9100",
|
||||
"copyright": "© 2025 南京灿能",
|
||||
"directories": {
|
||||
"output": "out"
|
||||
},
|
||||
"asar": true,
|
||||
"files": [
|
||||
"**/*",
|
||||
"!cmd/",
|
||||
"!data/",
|
||||
"!electron/",
|
||||
"!frontend/",
|
||||
"!run/",
|
||||
"!logs/",
|
||||
"!data/"
|
||||
"!out/",
|
||||
"!go/",
|
||||
"!python/"
|
||||
],
|
||||
"extraResources": {
|
||||
"from": "build/extraResources/",
|
||||
@@ -26,35 +30,15 @@
|
||||
"installerHeaderIcon": "build/icons/icon.ico",
|
||||
"createDesktopShortcut": true,
|
||||
"createStartMenuShortcut": true,
|
||||
"shortcutName": "自动检测平台"
|
||||
},
|
||||
"publish": [
|
||||
{
|
||||
"provider": "generic",
|
||||
"url": "http://www.shining-electric.com/"
|
||||
}
|
||||
],
|
||||
"mac": {
|
||||
"icon": "build/icons/icon.icns",
|
||||
"artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
|
||||
"darkModeSupport": true,
|
||||
"hardenedRuntime": false
|
||||
"shortcutName": "灿能检测"
|
||||
},
|
||||
"win": {
|
||||
"icon": "build/icons/icon.ico",
|
||||
"artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis"
|
||||
"target": "portable"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"icon": "build/icons/icon.icns",
|
||||
"artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
|
||||
"target": [
|
||||
"deb"
|
||||
],
|
||||
"category": "Utility"
|
||||
}
|
||||
}
|
||||
133
doc/便携式JRE集成指南.md
Normal file
@@ -0,0 +1,133 @@
|
||||
## 便携式 JRE/JDK8 集成指南
|
||||
|
||||
本指南介绍如何将 JRE 8 以“便携式”(解压即用、无需安装)的方式随应用打包,并在 Electron 主进程中通过绝对路径调用,从而避免要求用户在系统中安装 JDK/JRE。
|
||||
|
||||
### 为什么选择便携式 JRE
|
||||
- 无需管理员权限与系统环境变量配置,用户无感知。
|
||||
- 不污染系统环境(不写入 JAVA_HOME/PATH)。
|
||||
- 跨平台一致,可精简体积、可控版本。
|
||||
|
||||
### 适用场景
|
||||
- 运行 Java 程序或 JAR 包(仅需运行时)。
|
||||
- 不需要 javac/jcmd/jmap 等开发/诊断工具(若需要,请改为随包便携式 JDK)。
|
||||
|
||||
### 推荐的 JRE 8 发行版(可再分发)
|
||||
- Azul Zulu 8 JRE(可选 ZuluFX 含 JavaFX):[下载页面](https://www.azul.com/downloads/?version=java-8-lts&package=jre)
|
||||
- BellSoft Liberica 8 JRE(Standard/Full,Full 含 JavaFX):[下载页面](https://bell-sw.com/pages/downloads/#/java-8-lts)
|
||||
- Eclipse Temurin 8 JRE(Adoptium):[下载页面](https://adoptium.net/temurin/releases/?version=8)
|
||||
|
||||
选择要点:
|
||||
- 需要 AWT/Swing/字体/打印 → 选择非 headless 包。
|
||||
- 需要 JavaFX → 选择 Liberica Full 或 ZuluFX。
|
||||
- 仅命令行/服务端 → 任意 JRE 8(headless 也可)。
|
||||
|
||||
### 目录放置约定
|
||||
将解压后的 JRE 放入项目的 `build/extraResources/jre`,保证内部存在 `bin/java(.exe)`:
|
||||
|
||||
```
|
||||
build/
|
||||
extraResources/
|
||||
jre/
|
||||
bin/
|
||||
java(.exe)
|
||||
lib/
|
||||
...
|
||||
```
|
||||
|
||||
构建后在生产环境可通过 `process.resourcesPath` 访问:
|
||||
`<app>/resources/extraResources/jre/bin/java(.exe)`。
|
||||
|
||||
### 主进程调用示例
|
||||
在 `electron/preload/lifecycle.js` 或你的业务模块中封装 Java 运行工具(开发/生产两种路径):
|
||||
|
||||
```js
|
||||
const path = require('path');
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
function getExtraResourcesDir() {
|
||||
// 开发态:使用项目目录;生产态:使用 asar/resources 目录
|
||||
const isDev = !!process.env.EE_DEV || process.env.NODE_ENV === 'development';
|
||||
return isDev
|
||||
? path.join(process.cwd(), 'build', 'extraResources')
|
||||
: path.join(process.resourcesPath, 'extraResources');
|
||||
}
|
||||
|
||||
function getJavaBinPath() {
|
||||
const extraDir = getExtraResourcesDir();
|
||||
const javaBinName = process.platform === 'win32' ? 'java.exe' : 'java';
|
||||
return path.join(extraDir, 'jre', 'bin', javaBinName);
|
||||
}
|
||||
|
||||
function runJavaJar(jarAbsPath, args = [], options = {}) {
|
||||
const javaPath = getJavaBinPath();
|
||||
const child = spawn(javaPath, ['-jar', jarAbsPath, ...args], {
|
||||
stdio: 'inherit',
|
||||
...options,
|
||||
});
|
||||
return child;
|
||||
}
|
||||
|
||||
async function ensureJavaVersion(logger) {
|
||||
return new Promise((resolve) => {
|
||||
const child = spawn(getJavaBinPath(), ['-version']);
|
||||
let out = '';
|
||||
let err = '';
|
||||
child.stdout && child.stdout.on('data', (d) => (out += d.toString()))
|
||||
child.stderr && child.stderr.on('data', (d) => (err += d.toString()))
|
||||
child.on('close', () => {
|
||||
const text = (out + '\n' + err).trim();
|
||||
logger && logger.info('[java] version check:', text);
|
||||
resolve(text.includes('1.8.0'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { getJavaBinPath, runJavaJar, ensureJavaVersion };
|
||||
```
|
||||
|
||||
在生命周期中调用(示例):
|
||||
|
||||
```js
|
||||
const { logger } = require('ee-core/log');
|
||||
const path = require('path');
|
||||
const { runJavaJar, ensureJavaVersion } = require('./java-runner');
|
||||
|
||||
class Lifecycle {
|
||||
async ready() {
|
||||
const ok = await ensureJavaVersion(logger);
|
||||
if (!ok) {
|
||||
logger.error('[java] 未检测到 JRE 8,请检查 extraResources/jre 是否存在');
|
||||
}
|
||||
}
|
||||
|
||||
async windowReady() {
|
||||
const jarPath = path.join(process.resourcesPath || process.cwd(), 'extraResources', 'tools', 'your-app.jar');
|
||||
// 示例:延后在某业务时机再启动 Java 进程
|
||||
// const proc = runJavaJar(jarPath, ['--arg1', 'value']);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
注意:示例中的 `java-runner` 为上文工具函数文件,实际请按你的项目结构放置。
|
||||
|
||||
### 验证清单
|
||||
- 运行 `jre/bin/java -version` 输出包含 `1.8.0_xxx`。
|
||||
- 若涉及 GUI/字体/打印,验证 AWT/Swing 中文渲染与打印。
|
||||
- 若需 JavaFX,验证 JavaFX Demo 启动。
|
||||
- 若涉及 TLS/HTTPS,验证 SSL 通信正常。
|
||||
|
||||
### 许可与合规
|
||||
- Azul Zulu、Eclipse Temurin(Adoptium)、BellSoft Liberica 的 JRE/JDK 8 发行包均可免费再分发(GPLv2+CE 或厂商许可证)。
|
||||
- 建议在应用的“关于/许可证”中附上所选发行版的许可证链接与致谢。
|
||||
|
||||
### 常见问题
|
||||
1) 是否“阉割”?
|
||||
— 上述 JRE 8 发行版均为标准运行时,通过兼容性测试;JRE 不包含开发者工具属于正常区别,不是删减。
|
||||
|
||||
2) 何时需要 JDK 而不是 JRE?
|
||||
— 需要 `javac` 编译或 `jcmd/jmap` 等诊断工具,或你的 Java 组件依赖 `tools.jar` 时。
|
||||
|
||||
3) 体积如何优化?
|
||||
— 选择 headless(若无 GUI 需求)、去除无用语言/字体包;或改用 JDK 9+ 使用 jlink(不适用于 8)。
|
||||
|
||||
|
||||
436
doc/打包方案对比.md
Normal file
@@ -0,0 +1,436 @@
|
||||
# 应用打包方案对比与实现
|
||||
|
||||
本文档详细说明 ElectronEgg 应用的两种打包方案:纯绿色版方案 和 双版本方案。
|
||||
|
||||
---
|
||||
|
||||
## 方案对比
|
||||
|
||||
| 特性 | 方案一:纯绿色版 | 方案二:双版本打包 |
|
||||
|------|-----------------|-------------------|
|
||||
| **打包产物** | 单个便携版 exe | 安装版 exe + 便携版 exe |
|
||||
| **安装过程** | 无需安装 | 安装版需安装,便携版无需 |
|
||||
| **桌面快捷方式** | 应用内自动创建 | 安装版自动创建,便携版手动或自动 |
|
||||
| **开始菜单** | 无 | 安装版有 |
|
||||
| **卸载程序** | 无(直接删除) | 安装版有 |
|
||||
| **适用场景** | 临时使用、U盘携带 | 正式部署、企业分发 |
|
||||
| **用户体验** | 灵活、轻量 | 专业、完整 |
|
||||
| **打包时间** | 快 | 较慢(打包两次) |
|
||||
| **分发复杂度** | 简单(单文件) | 中等(两个文件) |
|
||||
|
||||
---
|
||||
|
||||
## 方案一:纯绿色版 + 自动创建快捷方式
|
||||
|
||||
### 特点
|
||||
- ✅ 单个 exe 文件,双击即用
|
||||
- ✅ 首次启动时询问是否创建桌面快捷方式
|
||||
- ✅ 无需安装,无需卸载
|
||||
- ✅ 适合快速分发和临时使用
|
||||
|
||||
### 实现步骤
|
||||
|
||||
#### 1. 修改打包配置
|
||||
|
||||
**文件**:[cmd/builder.json](../cmd/builder.json)
|
||||
|
||||
```json
|
||||
{
|
||||
"productName": "南京灿能工具",
|
||||
"appId": "com.canneng.tool",
|
||||
"copyright": "© 2025 hongawen",
|
||||
"directories": {
|
||||
"output": "out"
|
||||
},
|
||||
"asar": true,
|
||||
"files": [
|
||||
"**/*",
|
||||
"!cmd/",
|
||||
"!data/",
|
||||
"!electron/",
|
||||
"!frontend/",
|
||||
"!logs/",
|
||||
"!out/",
|
||||
"!go/",
|
||||
"!python/"
|
||||
],
|
||||
"extraResources": {
|
||||
"from": "build/extraResources/",
|
||||
"to": "extraResources"
|
||||
},
|
||||
"publish": [
|
||||
{
|
||||
"provider": "generic",
|
||||
"url": "https://your-update-server.com"
|
||||
}
|
||||
],
|
||||
"win": {
|
||||
"icon": "build/icons/icon.ico",
|
||||
"artifactName": "${productName}-${os}-${version}-${arch}.${ext}",
|
||||
"target": [
|
||||
{
|
||||
"target": "portable"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 2. 添加自动创建快捷方式功能
|
||||
|
||||
**文件**:[electron/preload/lifecycle.js](../electron/preload/lifecycle.js)
|
||||
|
||||
在 `windowReady()` 钩子中添加以下代码:
|
||||
|
||||
```javascript
|
||||
const { logger } = require('ee-core/log');
|
||||
const { getConfig } = require('ee-core/config');
|
||||
const { getMainWindow } = require('ee-core/electron');
|
||||
|
||||
class Lifecycle {
|
||||
|
||||
async ready() {
|
||||
logger.info('[lifecycle] ready');
|
||||
}
|
||||
|
||||
async electronAppReady() {
|
||||
logger.info('[lifecycle] electron-app-ready');
|
||||
}
|
||||
|
||||
async windowReady() {
|
||||
logger.info('[lifecycle] window-ready');
|
||||
|
||||
// 延迟加载,无白屏
|
||||
const { windowsOption } = getConfig();
|
||||
if (windowsOption.show == false) {
|
||||
const win = getMainWindow();
|
||||
win.once('ready-to-show', () => {
|
||||
win.show();
|
||||
win.focus();
|
||||
})
|
||||
}
|
||||
|
||||
// 绿色版自动创建桌面快捷方式
|
||||
await this.createDesktopShortcut();
|
||||
}
|
||||
|
||||
/**
|
||||
* 为绿色版创建桌面快捷方式
|
||||
*/
|
||||
async createDesktopShortcut() {
|
||||
const { app, dialog, shell } = require('electron');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// 判断是否为便携版(绿色版)
|
||||
// 安装版通常在 C:\Program Files 或 AppData\Local\Programs
|
||||
const isPortable = process.platform === 'win32' &&
|
||||
!process.execPath.includes('Program Files') &&
|
||||
!process.execPath.includes('AppData\\Local\\Programs');
|
||||
|
||||
if (!isPortable) {
|
||||
logger.info('[lifecycle] 非便携版,跳过快捷方式创建');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const desktopPath = app.getPath('desktop');
|
||||
const shortcutPath = path.join(desktopPath, '南京灿能工具.lnk');
|
||||
|
||||
// 如果快捷方式已存在,跳过
|
||||
if (fs.existsSync(shortcutPath)) {
|
||||
logger.info('[lifecycle] 桌面快捷方式已存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 询问用户是否创建快捷方式
|
||||
const result = await dialog.showMessageBox({
|
||||
type: 'question',
|
||||
buttons: ['创建', '跳过'],
|
||||
defaultId: 0,
|
||||
title: '创建桌面快捷方式',
|
||||
message: '是否在桌面创建快捷方式?',
|
||||
detail: '方便您下次快速启动应用'
|
||||
});
|
||||
|
||||
if (result.response === 0) {
|
||||
// Windows 下创建快捷方式
|
||||
const success = shell.writeShortcutLink(shortcutPath, {
|
||||
target: process.execPath,
|
||||
cwd: path.dirname(process.execPath),
|
||||
description: '南京灿能C端工具',
|
||||
icon: process.execPath,
|
||||
iconIndex: 0
|
||||
});
|
||||
|
||||
if (success) {
|
||||
logger.info('[lifecycle] 桌面快捷方式创建成功');
|
||||
await dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: '成功',
|
||||
message: '桌面快捷方式已创建',
|
||||
buttons: ['确定']
|
||||
});
|
||||
} else {
|
||||
logger.error('[lifecycle] 桌面快捷方式创建失败');
|
||||
}
|
||||
} else {
|
||||
logger.info('[lifecycle] 用户跳过创建快捷方式');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('[lifecycle] 创建快捷方式时出错:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async beforeClose() {
|
||||
logger.info('[lifecycle] before-close');
|
||||
}
|
||||
}
|
||||
Lifecycle.toString = () => '[class Lifecycle]';
|
||||
|
||||
module.exports = {
|
||||
Lifecycle
|
||||
};
|
||||
```
|
||||
|
||||
#### 3. 打包命令
|
||||
|
||||
```bash
|
||||
npm run build # 完整构建
|
||||
npm run build-w # 打包 Windows 便携版
|
||||
```
|
||||
|
||||
#### 4. 产物说明
|
||||
|
||||
打包完成后,在 `out/` 目录下会生成:
|
||||
```
|
||||
out/
|
||||
└── 南京灿能工具-win-4.0.0-x64.exe (便携版,约 150-200MB)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 方案二:双版本打包(安装版 + 便携版)
|
||||
|
||||
### 特点
|
||||
- ✅ 提供两种版本供用户选择
|
||||
- ✅ 安装版:专业、完整的安装体验
|
||||
- ✅ 便携版:灵活、轻量,无需安装
|
||||
- ✅ 适合正式产品发布
|
||||
|
||||
### 实现步骤
|
||||
|
||||
#### 1. 修改打包配置
|
||||
|
||||
**文件**:[cmd/builder.json](../cmd/builder.json)
|
||||
|
||||
```json
|
||||
{
|
||||
"productName": "南京灿能工具",
|
||||
"appId": "com.canneng.tool",
|
||||
"copyright": "© 2025 hongawen",
|
||||
"directories": {
|
||||
"output": "out"
|
||||
},
|
||||
"asar": true,
|
||||
"files": [
|
||||
"**/*",
|
||||
"!cmd/",
|
||||
"!data/",
|
||||
"!electron/",
|
||||
"!frontend/",
|
||||
"!logs/",
|
||||
"!out/",
|
||||
"!go/",
|
||||
"!python/"
|
||||
],
|
||||
"extraResources": {
|
||||
"from": "build/extraResources/",
|
||||
"to": "extraResources"
|
||||
},
|
||||
"nsis": {
|
||||
"oneClick": false,
|
||||
"allowElevation": true,
|
||||
"allowToChangeInstallationDirectory": true,
|
||||
"installerIcon": "build/icons/icon.ico",
|
||||
"uninstallerIcon": "build/icons/icon.ico",
|
||||
"installerHeaderIcon": "build/icons/icon.ico",
|
||||
"createDesktopShortcut": true,
|
||||
"createStartMenuShortcut": true,
|
||||
"shortcutName": "南京灿能工具",
|
||||
"artifactName": "${productName}-Setup-${version}.${ext}"
|
||||
},
|
||||
"portable": {
|
||||
"artifactName": "${productName}-Portable-${version}.${ext}"
|
||||
},
|
||||
"publish": [
|
||||
{
|
||||
"provider": "generic",
|
||||
"url": "https://your-update-server.com"
|
||||
}
|
||||
],
|
||||
"win": {
|
||||
"icon": "build/icons/icon.ico",
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis",
|
||||
"arch": ["x64"]
|
||||
},
|
||||
{
|
||||
"target": "portable",
|
||||
"arch": ["x64"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 2. 便携版快捷方式功能(可选)
|
||||
|
||||
如果希望便携版也能自动创建快捷方式,使用**方案一**中的 `createDesktopShortcut()` 代码。
|
||||
|
||||
#### 3. 打包命令
|
||||
|
||||
```bash
|
||||
npm run build # 完整构建
|
||||
npm run build-w # 打包两个版本
|
||||
```
|
||||
|
||||
#### 4. 产物说明
|
||||
|
||||
打包完成后,在 `out/` 目录下会生成:
|
||||
```
|
||||
out/
|
||||
├── 南京灿能工具-Setup-4.0.0.exe (安装版,约 150MB)
|
||||
└── 南京灿能工具-Portable-4.0.0.exe (便携版,约 150-200MB)
|
||||
```
|
||||
|
||||
#### 5. 版本差异说明
|
||||
|
||||
**安装版 (NSIS)**:
|
||||
- 需要安装到系统(默认 C:\Program Files)
|
||||
- 自动创建桌面快捷方式
|
||||
- 自动创建开始菜单项
|
||||
- 提供卸载程序
|
||||
- 支持自动更新
|
||||
- 适合企业部署、长期使用
|
||||
|
||||
**便携版 (Portable)**:
|
||||
- 单个 exe 文件
|
||||
- 双击直接运行(首次会自解压)
|
||||
- 无需安装,无需卸载
|
||||
- 可放在 U 盘随身携带
|
||||
- 适合临时使用、测试环境
|
||||
|
||||
---
|
||||
|
||||
## 快捷方式创建原理(技术细节)
|
||||
|
||||
### Windows 快捷方式 (.lnk)
|
||||
|
||||
```javascript
|
||||
shell.writeShortcutLink(shortcutPath, {
|
||||
target: process.execPath, // 目标程序路径
|
||||
cwd: path.dirname(process.execPath), // 工作目录
|
||||
description: '应用描述', // 快捷方式描述
|
||||
icon: process.execPath, // 图标路径
|
||||
iconIndex: 0, // 图标索引
|
||||
args: '', // 启动参数(可选)
|
||||
appUserModelId: 'com.app.id' // Windows 应用 ID(可选)
|
||||
})
|
||||
```
|
||||
|
||||
### 判断是否为便携版
|
||||
|
||||
```javascript
|
||||
const isPortable = process.platform === 'win32' &&
|
||||
!process.execPath.includes('Program Files') &&
|
||||
!process.execPath.includes('AppData\\Local\\Programs');
|
||||
```
|
||||
|
||||
**原理**:
|
||||
- 安装版通常安装在 `C:\Program Files\YourApp\`
|
||||
- 或者 `C:\Users\用户名\AppData\Local\Programs\YourApp\`
|
||||
- 便携版可以在任意位置运行
|
||||
|
||||
---
|
||||
|
||||
## 推荐配置
|
||||
|
||||
### 企业级应用(推荐方案二)
|
||||
```
|
||||
✅ 提供两个版本
|
||||
✅ 主推安装版(专业形象)
|
||||
✅ 提供便携版作为备选
|
||||
```
|
||||
|
||||
### 轻量工具(推荐方案一)
|
||||
```
|
||||
✅ 只提供便携版
|
||||
✅ 应用内自动创建快捷方式
|
||||
✅ 简化分发流程
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 常见问题
|
||||
|
||||
### Q1: 便携版首次启动为什么慢?
|
||||
**A**: 便携版是自解压程序,首次运行需要解压资源到临时目录(约 3-5 秒)。后续启动会快很多。
|
||||
|
||||
### Q2: 便携版数据存储在哪里?
|
||||
**A**:
|
||||
- 用户数据:`C:\Users\用户名\AppData\Roaming\你的appId\`
|
||||
- 临时文件:`C:\Users\用户名\AppData\Local\Temp\`
|
||||
|
||||
### Q3: 如何让便携版也支持自动更新?
|
||||
**A**: 需要配置 `electron-updater`,但便携版更新体验不如安装版。建议:
|
||||
- 安装版:使用自动更新
|
||||
- 便携版:提示用户下载新版本
|
||||
|
||||
### Q4: 可以同时运行两个版本吗?
|
||||
**A**: 不建议。虽然技术上可行,但会导致数据冲突(共享同一个 userData 目录)。
|
||||
|
||||
### Q5: 如何自定义快捷方式图标?
|
||||
**A**: 在 `build/icons/` 目录放置 `.ico` 文件,并在 `builder.json` 中配置:
|
||||
```json
|
||||
"win": {
|
||||
"icon": "build/icons/custom-icon.ico"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 测试检查清单
|
||||
|
||||
打包完成后,请进行以下测试:
|
||||
|
||||
### 安装版测试
|
||||
- [ ] 安装到默认路径成功
|
||||
- [ ] 安装到自定义路径成功
|
||||
- [ ] 桌面快捷方式正常
|
||||
- [ ] 开始菜单项正常
|
||||
- [ ] 应用启动正常
|
||||
- [ ] 卸载程序正常
|
||||
|
||||
### 便携版测试
|
||||
- [ ] 双击 exe 正常启动
|
||||
- [ ] 首次启动自动创建快捷方式(如已实现)
|
||||
- [ ] 桌面快捷方式可用
|
||||
- [ ] 应用功能正常
|
||||
- [ ] 关闭后再次启动正常
|
||||
- [ ] 可移动到其他目录运行
|
||||
|
||||
---
|
||||
|
||||
## 参考资源
|
||||
|
||||
- electron-builder 官方文档: https://www.electron.build/
|
||||
- NSIS 配置: https://www.electron.build/configuration/nsis
|
||||
- Portable 配置: https://www.electron.build/configuration/portable
|
||||
- Electron shell API: https://www.electronjs.org/docs/latest/api/shell
|
||||
|
||||
---
|
||||
|
||||
*文档创建时间: 2025-10-14*
|
||||
*作者: hongawen*
|
||||
459
doc/生命周期描述.md
Normal file
@@ -0,0 +1,459 @@
|
||||
# ElectronEgg 生命周期详解
|
||||
|
||||
本文档详细说明 ElectronEgg 框架的应用生命周期机制及其在项目中的实现。
|
||||
|
||||
## 生命周期流程图
|
||||
|
||||
```
|
||||
┌─────────────┐
|
||||
│ new │ 创建 ElectronEgg 实例
|
||||
└──────┬──────┘
|
||||
│
|
||||
┌──────▼──────┐
|
||||
│ ready │ core app 加载完成(ee-core 框架初始化)
|
||||
└──────┬──────┘
|
||||
│
|
||||
┌──────▼─────────────┐
|
||||
│ electronAppReady │ Electron app 加载完成
|
||||
└──────┬─────────────┘
|
||||
│
|
||||
├─────────────────┐
|
||||
│ │
|
||||
┌──────▼──────┐ ┌─────▼────────┐
|
||||
│ mainWindow │ │ windowReady │ 主窗口创建完成
|
||||
└──────┬──────┘ └─────▲────────┘
|
||||
│ │
|
||||
└─────────────────┘
|
||||
│
|
||||
┌──────▼──────┐
|
||||
│ running │ 应用运行中
|
||||
└──────┬──────┘
|
||||
│
|
||||
┌──────▼──────┐
|
||||
│beforeClose │ 退出之前触发
|
||||
└──────┬──────┘
|
||||
│
|
||||
┌──────▼──────┐
|
||||
│ quit │ 应用退出
|
||||
└─────────────┘
|
||||
```
|
||||
|
||||
## 生命周期钩子详解
|
||||
|
||||
### 1. new - 实例创建
|
||||
|
||||
**触发时机**:调用 `new ElectronEgg()` 时
|
||||
|
||||
**实现位置**:[electron/main.js](electron/main.js#L6)
|
||||
|
||||
```javascript
|
||||
const { ElectronEgg } = require('ee-core');
|
||||
const app = new ElectronEgg();
|
||||
```
|
||||
|
||||
**作用**:
|
||||
- 创建 ElectronEgg 应用实例
|
||||
- 初始化框架核心模块
|
||||
- 准备生命周期管理器
|
||||
|
||||
---
|
||||
|
||||
### 2. ready - 核心应用就绪
|
||||
|
||||
**触发时机**:ee-core 框架加载完成,Electron app 启动之前
|
||||
|
||||
**实现位置**:
|
||||
- 注册:[electron/main.js](electron/main.js#L10)
|
||||
- 实现:[electron/preload/lifecycle.js](electron/preload/lifecycle.js#L12-L14)
|
||||
|
||||
```javascript
|
||||
// 注册
|
||||
app.register("ready", life.ready);
|
||||
|
||||
// 实现
|
||||
async ready() {
|
||||
logger.info('[lifecycle] ready');
|
||||
// 在这里可以做:
|
||||
// - 初始化数据库连接
|
||||
// - 加载配置文件
|
||||
// - 初始化全局变量
|
||||
}
|
||||
```
|
||||
|
||||
**适用场景**:
|
||||
- ✅ 初始化数据库连接
|
||||
- ✅ 加载应用配置
|
||||
- ✅ 注册全局服务
|
||||
- ✅ 初始化日志系统
|
||||
- ❌ 不能操作窗口(窗口还未创建)
|
||||
|
||||
---
|
||||
|
||||
### 3. electronAppReady - Electron 应用就绪
|
||||
|
||||
**触发时机**:Electron 的 `app.ready` 事件触发后,主窗口创建之前
|
||||
|
||||
**实现位置**:
|
||||
- 注册:[electron/main.js](electron/main.js#L11)
|
||||
- 实现:[electron/preload/lifecycle.js](electron/preload/lifecycle.js#L19-L21)
|
||||
|
||||
```javascript
|
||||
// 注册
|
||||
app.register("electron-app-ready", life.electronAppReady);
|
||||
|
||||
// 实现
|
||||
async electronAppReady() {
|
||||
logger.info('[lifecycle] electron-app-ready');
|
||||
// 在这里可以做:
|
||||
// - 注册全局快捷键
|
||||
// - 设置应用菜单
|
||||
// - 初始化托盘图标
|
||||
// - 注册协议处理
|
||||
}
|
||||
```
|
||||
|
||||
**适用场景**:
|
||||
- ✅ 注册全局快捷键 (globalShortcut)
|
||||
- ✅ 创建应用菜单 (Menu)
|
||||
- ✅ 创建系统托盘 (Tray)
|
||||
- ✅ 注册自定义协议 (protocol)
|
||||
- ⚠️ 可以创建窗口,但通常在框架内部自动创建
|
||||
|
||||
---
|
||||
|
||||
### 4. mainWindow - 主窗口创建
|
||||
|
||||
**触发时机**:框架创建主窗口时(内部流程,不需要手动注册)
|
||||
|
||||
**说明**:
|
||||
- 这是框架内部自动执行的步骤
|
||||
- 根据 `electron/config/config.*.js` 中的 `windowsOption` 配置创建窗口
|
||||
- 窗口创建完成后会触发 `windowReady` 钩子
|
||||
|
||||
**配置示例**:
|
||||
```javascript
|
||||
// electron/config/config.default.js
|
||||
windowsOption: {
|
||||
width: 1200,
|
||||
height: 800,
|
||||
show: false, // 设置为 false 可实现无白屏启动
|
||||
webPreferences: {
|
||||
contextIsolation: false,
|
||||
nodeIntegration: true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 5. windowReady - 窗口就绪
|
||||
|
||||
**触发时机**:主窗口创建完成,页面加载完毕
|
||||
|
||||
**实现位置**:
|
||||
- 注册:[electron/main.js](electron/main.js#L12)
|
||||
- 实现:[electron/preload/lifecycle.js](electron/preload/lifecycle.js#L26-L37)
|
||||
|
||||
```javascript
|
||||
// 注册
|
||||
app.register("window-ready", life.windowReady);
|
||||
|
||||
// 实现
|
||||
async windowReady() {
|
||||
logger.info('[lifecycle] window-ready');
|
||||
|
||||
// 延迟显示窗口,避免白屏
|
||||
const { windowsOption } = getConfig();
|
||||
if (windowsOption.show == false) {
|
||||
const win = getMainWindow();
|
||||
win.once('ready-to-show', () => {
|
||||
win.show(); // 显示窗口
|
||||
win.focus(); // 聚焦窗口
|
||||
})
|
||||
}
|
||||
|
||||
// 在这里可以做:
|
||||
// - 向渲染进程发送初始化数据
|
||||
// - 检查更新
|
||||
// - 加载用户配置
|
||||
}
|
||||
```
|
||||
|
||||
**适用场景**:
|
||||
- ✅ 操作主窗口 (show/hide/maximize 等)
|
||||
- ✅ 向渲染进程发送消息
|
||||
- ✅ 执行自动更新检查
|
||||
- ✅ 加载用户数据并同步到前端
|
||||
- ✅ 实现无白屏启动(配合 `show: false`)
|
||||
|
||||
---
|
||||
|
||||
### 6. running - 应用运行中
|
||||
|
||||
**触发时机**:窗口显示后,应用正常运行期间
|
||||
|
||||
**说明**:
|
||||
- 这不是一个独立的生命周期钩子
|
||||
- 表示应用的正常运行状态
|
||||
- 此时所有功能都可用
|
||||
|
||||
**可用操作**:
|
||||
- IPC 通信(前后端交互)
|
||||
- 业务逻辑处理
|
||||
- 数据库操作
|
||||
- 网络请求
|
||||
- 文件系统操作
|
||||
|
||||
---
|
||||
|
||||
### 7. beforeClose - 关闭前钩子
|
||||
|
||||
**触发时机**:用户点击关闭按钮或调用 `app.quit()` 之前
|
||||
|
||||
**实现位置**:
|
||||
- 注册:[electron/main.js](electron/main.js#L13)
|
||||
- 实现:[electron/preload/lifecycle.js](electron/preload/lifecycle.js#L42-L44)
|
||||
|
||||
```javascript
|
||||
// 注册
|
||||
app.register("before-close", life.beforeClose);
|
||||
|
||||
// 实现
|
||||
async beforeClose() {
|
||||
logger.info('[lifecycle] before-close');
|
||||
// 在这里可以做:
|
||||
// - 保存用户数据
|
||||
// - 关闭数据库连接
|
||||
// - 清理临时文件
|
||||
// - 释放系统资源
|
||||
// - 确认是否退出
|
||||
}
|
||||
```
|
||||
|
||||
**适用场景**:
|
||||
- ✅ 保存应用状态
|
||||
- ✅ 关闭数据库连接
|
||||
- ✅ 清理临时资源
|
||||
- ✅ 询问用户是否确认退出
|
||||
- ✅ 上传日志或统计数据
|
||||
|
||||
**阻止关闭示例**:
|
||||
```javascript
|
||||
async beforeClose(args, event) {
|
||||
const { dialog } = require('electron');
|
||||
const result = await dialog.showMessageBox({
|
||||
type: 'question',
|
||||
buttons: ['取消', '退出'],
|
||||
message: '确定要退出应用吗?'
|
||||
});
|
||||
|
||||
if (result.response === 0) {
|
||||
// 阻止关闭
|
||||
return false;
|
||||
}
|
||||
|
||||
// 允许关闭
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 8. quit - 应用退出
|
||||
|
||||
**触发时机**:`beforeClose` 完成后,应用进程终止
|
||||
|
||||
**说明**:
|
||||
- 这是最终状态,不可逆
|
||||
- 所有资源清理应在 `beforeClose` 中完成
|
||||
- 退出后进程结束,无法执行代码
|
||||
|
||||
---
|
||||
|
||||
## 额外生命周期:preload
|
||||
|
||||
### preload - 预加载模块
|
||||
|
||||
**触发时机**:应用启动时,在所有其他钩子之前
|
||||
|
||||
**实现位置**:
|
||||
- 注册:[electron/main.js](electron/main.js#L16)
|
||||
- 实现:[electron/preload/index.js](electron/preload/index.js#L7-L9)
|
||||
|
||||
```javascript
|
||||
// 注册
|
||||
app.register("preload", preload);
|
||||
|
||||
// 实现
|
||||
function preload() {
|
||||
logger.info('[preload] load 1');
|
||||
// 在这里可以做:
|
||||
// - 加载环境变量
|
||||
// - 注册原生模块
|
||||
// - 设置全局异常处理
|
||||
}
|
||||
```
|
||||
|
||||
**适用场景**:
|
||||
- ✅ 加载环境变量
|
||||
- ✅ 注册 Node.js 原生模块
|
||||
- ✅ 设置全局错误处理
|
||||
- ✅ 初始化第三方 SDK
|
||||
|
||||
---
|
||||
|
||||
## 实际开发示例
|
||||
|
||||
### 示例 1:数据库初始化
|
||||
|
||||
```javascript
|
||||
// electron/preload/lifecycle.js
|
||||
const Database = require('better-sqlite3');
|
||||
let db;
|
||||
|
||||
class Lifecycle {
|
||||
async ready() {
|
||||
// 在 ready 钩子中初始化数据库
|
||||
const path = require('path');
|
||||
const dbPath = path.join(app.getPath('userData'), 'app.db');
|
||||
db = new Database(dbPath);
|
||||
logger.info('[lifecycle] database initialized');
|
||||
}
|
||||
|
||||
async beforeClose() {
|
||||
// 在关闭前关闭数据库连接
|
||||
if (db) {
|
||||
db.close();
|
||||
logger.info('[lifecycle] database closed');
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 示例 2:自动更新检查
|
||||
|
||||
```javascript
|
||||
// electron/preload/lifecycle.js
|
||||
const { autoUpdater } = require('electron-updater');
|
||||
|
||||
class Lifecycle {
|
||||
async windowReady() {
|
||||
// 窗口就绪后检查更新
|
||||
const { getMainWindow } = require('ee-core/electron');
|
||||
const win = getMainWindow();
|
||||
|
||||
autoUpdater.checkForUpdates();
|
||||
|
||||
autoUpdater.on('update-available', () => {
|
||||
win.webContents.send('update-available');
|
||||
});
|
||||
|
||||
logger.info('[lifecycle] update check started');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 示例 3:托盘图标
|
||||
|
||||
```javascript
|
||||
// electron/preload/lifecycle.js
|
||||
const { Tray, Menu } = require('electron');
|
||||
let tray;
|
||||
|
||||
class Lifecycle {
|
||||
async electronAppReady() {
|
||||
// 在 Electron 就绪后创建托盘
|
||||
const path = require('path');
|
||||
const iconPath = path.join(__dirname, '../../public/images/tray-icon.png');
|
||||
|
||||
tray = new Tray(iconPath);
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{ label: '打开主窗口', click: () => {
|
||||
const { getMainWindow } = require('ee-core/electron');
|
||||
getMainWindow().show();
|
||||
}},
|
||||
{ label: '退出', click: () => {
|
||||
const { app } = require('electron');
|
||||
app.quit();
|
||||
}}
|
||||
]);
|
||||
|
||||
tray.setContextMenu(contextMenu);
|
||||
logger.info('[lifecycle] tray created');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 示例 4:无白屏启动
|
||||
|
||||
```javascript
|
||||
// electron/config/config.default.js
|
||||
windowsOption: {
|
||||
width: 1200,
|
||||
height: 800,
|
||||
show: false, // 关键配置:初始不显示
|
||||
backgroundColor: '#ffffff'
|
||||
}
|
||||
|
||||
// electron/preload/lifecycle.js
|
||||
class Lifecycle {
|
||||
async windowReady() {
|
||||
// 页面加载完成后再显示,避免白屏
|
||||
const { getMainWindow } = require('ee-core/electron');
|
||||
const win = getMainWindow();
|
||||
|
||||
win.once('ready-to-show', () => {
|
||||
win.show();
|
||||
win.focus();
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 生命周期执行顺序总结
|
||||
|
||||
```
|
||||
1. preload() # 预加载模块
|
||||
2. new ElectronEgg() # 创建应用实例
|
||||
3. ready() # 核心框架就绪
|
||||
4. electronAppReady() # Electron 就绪
|
||||
5. [创建主窗口] # 框架内部创建窗口
|
||||
6. windowReady() # 窗口就绪
|
||||
7. [应用运行中] # 正常运行状态
|
||||
8. beforeClose() # 关闭前钩子
|
||||
9. [应用退出] # 进程结束
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **异步支持**:所有生命周期钩子都支持 `async/await`,可以执行异步操作
|
||||
|
||||
2. **错误处理**:建议在每个钩子中添加 try-catch 错误处理
|
||||
|
||||
3. **顺序依赖**:不要在早期钩子中访问尚未初始化的资源(如在 `ready` 中操作窗口)
|
||||
|
||||
4. **性能优化**:避免在钩子中执行耗时操作,会阻塞应用启动
|
||||
|
||||
5. **资源清理**:在 `beforeClose` 中务必清理所有资源,避免内存泄漏
|
||||
|
||||
6. **日志记录**:建议在每个钩子中记录日志,方便排查问题
|
||||
|
||||
---
|
||||
|
||||
## 相关文件
|
||||
|
||||
- 生命周期注册:[electron/main.js](electron/main.js)
|
||||
- 生命周期实现:[electron/preload/lifecycle.js](electron/preload/lifecycle.js)
|
||||
- 预加载模块:[electron/preload/index.js](electron/preload/index.js)
|
||||
- 窗口配置:[electron/config/config.default.js](electron/config/config.default.js)
|
||||
|
||||
---
|
||||
|
||||
## 参考资源
|
||||
|
||||
- ElectronEgg 官方文档:https://www.kaka996.com/pages/987b1c/
|
||||
- Electron 官方文档:https://www.electronjs.org/zh/docs/latest/
|
||||
@@ -1,11 +0,0 @@
|
||||
#### 基础配置
|
||||
主进程的配置文件在./config文件夹下
|
||||
```shell
|
||||
# 说明
|
||||
bin.js // 开发配置
|
||||
config.default.js // 默认配置文件,开发环境和生产环境都会加载
|
||||
config.local.js // 开发环境配置文件,追加和覆盖default配置文件
|
||||
config.prod.js // 生产环境配置文件,追加和覆盖default配置文件
|
||||
nodemon.json // 开发环境,代码(监控)热加载
|
||||
builder.json // 打包配置
|
||||
```
|
||||
@@ -1,170 +0,0 @@
|
||||
const { app: electronApp } = require('electron');
|
||||
const { autoUpdater } = require("electron-updater");
|
||||
const is = require('ee-core/utils/is');
|
||||
const Log = require('ee-core/log');
|
||||
const Conf = require('ee-core/config');
|
||||
const CoreWindow = require('ee-core/electron/window');
|
||||
const Electron = require('ee-core/electron');
|
||||
|
||||
/**
|
||||
* 自动升级插件
|
||||
* @class
|
||||
*/
|
||||
class AutoUpdaterAddon {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*/
|
||||
create () {
|
||||
Log.info('[addon:autoUpdater] load');
|
||||
const cfg = Conf.getValue('addons.autoUpdater');
|
||||
if ((is.windows() && cfg.windows)
|
||||
|| (is.macOS() && cfg.macOS)
|
||||
|| (is.linux() && cfg.linux))
|
||||
{
|
||||
// continue
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
// 是否检查更新
|
||||
if (cfg.force) {
|
||||
this.checkUpdate();
|
||||
}
|
||||
|
||||
const status = {
|
||||
error: -1,
|
||||
available: 1,
|
||||
noAvailable: 2,
|
||||
downloading: 3,
|
||||
downloaded: 4,
|
||||
}
|
||||
|
||||
const version = electronApp.getVersion();
|
||||
Log.info('[addon:autoUpdater] current version: ', version);
|
||||
|
||||
// 设置下载服务器地址
|
||||
let server = cfg.options.url;
|
||||
let lastChar = server.substring(server.length - 1);
|
||||
server = lastChar === '/' ? server : server + "/";
|
||||
//Log.info('[addon:autoUpdater] server: ', server);
|
||||
cfg.options.url = server;
|
||||
|
||||
// 是否后台自动下载
|
||||
autoUpdater.autoDownload = cfg.force ? true : false;
|
||||
|
||||
try {
|
||||
autoUpdater.setFeedURL(cfg.options);
|
||||
} catch (error) {
|
||||
Log.error('[addon:autoUpdater] setFeedURL error : ', error);
|
||||
}
|
||||
|
||||
autoUpdater.on('checking-for-update', () => {
|
||||
//sendStatusToWindow('正在检查更新...');
|
||||
})
|
||||
autoUpdater.on('update-available', (info) => {
|
||||
info.status = status.available;
|
||||
info.desc = '有可用更新';
|
||||
this.sendStatusToWindow(info);
|
||||
})
|
||||
autoUpdater.on('update-not-available', (info) => {
|
||||
info.status = status.noAvailable;
|
||||
info.desc = '没有可用更新';
|
||||
this.sendStatusToWindow(info);
|
||||
})
|
||||
autoUpdater.on('error', (err) => {
|
||||
let info = {
|
||||
status: status.error,
|
||||
desc: err
|
||||
}
|
||||
this.sendStatusToWindow(info);
|
||||
})
|
||||
autoUpdater.on('download-progress', (progressObj) => {
|
||||
let percentNumber = parseInt(progressObj.percent);
|
||||
let totalSize = this.bytesChange(progressObj.total);
|
||||
let transferredSize = this.bytesChange(progressObj.transferred);
|
||||
let text = '已下载 ' + percentNumber + '%';
|
||||
text = text + ' (' + transferredSize + "/" + totalSize + ')';
|
||||
|
||||
let info = {
|
||||
status: status.downloading,
|
||||
desc: text,
|
||||
percentNumber: percentNumber,
|
||||
totalSize: totalSize,
|
||||
transferredSize: transferredSize
|
||||
}
|
||||
Log.info('[addon:autoUpdater] progress: ', text);
|
||||
this.sendStatusToWindow(info);
|
||||
})
|
||||
autoUpdater.on('update-downloaded', (info) => {
|
||||
info.status = status.downloaded;
|
||||
info.desc = '下载完成';
|
||||
this.sendStatusToWindow(info);
|
||||
|
||||
// 托盘插件默认会阻止窗口关闭,这里设置允许关闭窗口
|
||||
Electron.extra.closeWindow = true;
|
||||
|
||||
autoUpdater.quitAndInstall();
|
||||
// const mainWindow = CoreWindow.getMainWindow();
|
||||
// if (mainWindow) {
|
||||
// mainWindow.destroy()
|
||||
// }
|
||||
// electronApp.appQuit()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查更新
|
||||
*/
|
||||
checkUpdate () {
|
||||
autoUpdater.checkForUpdates();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载更新
|
||||
*/
|
||||
download () {
|
||||
autoUpdater.downloadUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 向前端发消息
|
||||
*/
|
||||
sendStatusToWindow(content = {}) {
|
||||
const textJson = JSON.stringify(content);
|
||||
const channel = 'app.updater';
|
||||
const win = CoreWindow.getMainWindow();
|
||||
win.webContents.send(channel, textJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单位转换
|
||||
*/
|
||||
bytesChange (limit) {
|
||||
let size = "";
|
||||
if(limit < 0.1 * 1024){
|
||||
size = limit.toFixed(2) + "B";
|
||||
}else if(limit < 0.1 * 1024 * 1024){
|
||||
size = (limit/1024).toFixed(2) + "KB";
|
||||
}else if(limit < 0.1 * 1024 * 1024 * 1024){
|
||||
size = (limit/(1024 * 1024)).toFixed(2) + "MB";
|
||||
}else{
|
||||
size = (limit/(1024 * 1024 * 1024)).toFixed(2) + "GB";
|
||||
}
|
||||
|
||||
let sizeStr = size + "";
|
||||
let index = sizeStr.indexOf(".");
|
||||
let dou = sizeStr.substring(index + 1 , index + 3);
|
||||
if(dou == "00"){
|
||||
return sizeStr.substring(0, index) + sizeStr.substring(index + 3, index + 5);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
AutoUpdaterAddon.toString = () => '[class AutoUpdaterAddon]';
|
||||
module.exports = AutoUpdaterAddon;
|
||||
@@ -1,67 +0,0 @@
|
||||
const { app: electronApp } = require('electron');
|
||||
const Log = require('ee-core/log');
|
||||
const Conf = require('ee-core/config');
|
||||
|
||||
/**
|
||||
* 唤醒插件
|
||||
* @class
|
||||
*/
|
||||
class AwakenAddon {
|
||||
|
||||
constructor() {
|
||||
this.protocol = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*/
|
||||
create () {
|
||||
Log.info('[addon:awaken] load');
|
||||
|
||||
const cfg = Conf.getValue('addons.awaken');
|
||||
this.protocol = cfg.protocol;
|
||||
|
||||
electronApp.setAsDefaultProtocolClient(this.protocol);
|
||||
|
||||
this.handleArgv(process.argv);
|
||||
electronApp.on('second-instance', (event, argv) => {
|
||||
if (process.platform === 'win32') {
|
||||
this.handleArgv(argv)
|
||||
}
|
||||
})
|
||||
|
||||
// 仅用于macOS
|
||||
electronApp.on('open-url', (event, urlStr) => {
|
||||
this.handleUrl(urlStr)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数处理
|
||||
*/
|
||||
handleArgv(argv) {
|
||||
const offset = electronApp.isPackaged ? 1 : 2;
|
||||
const url = argv.find((arg, i) => i >= offset && arg.startsWith(this.protocol));
|
||||
this.handleUrl(url)
|
||||
}
|
||||
|
||||
/**
|
||||
* url解析
|
||||
*/
|
||||
handleUrl(awakeUrlStr) {
|
||||
if (!awakeUrlStr || awakeUrlStr.length === 0) {
|
||||
return
|
||||
}
|
||||
const {hostname, pathname, search} = new URL(awakeUrlStr);
|
||||
let awakeUrlInfo = {
|
||||
urlStr: awakeUrlStr,
|
||||
urlHost: hostname,
|
||||
urlPath: pathname,
|
||||
urlParams: search && search.slice(1)
|
||||
}
|
||||
Log.info('[addon:awaken] awakeUrlInfo:', awakeUrlInfo);
|
||||
}
|
||||
}
|
||||
|
||||
AwakenAddon.toString = () => '[class AwakenAddon]';
|
||||
module.exports = AwakenAddon;
|
||||
@@ -1,94 +0,0 @@
|
||||
const { app, session } = require('electron');
|
||||
const _ = require('lodash');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Log = require('ee-core/log');
|
||||
|
||||
/**
|
||||
* 扩展插件 (electron自身对该功能并不完全支持,官方也不建议使用)
|
||||
* @class
|
||||
*/
|
||||
class ChromeExtensionAddon {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*/
|
||||
async create () {
|
||||
Log.info('[addon:chromeExtension] load');
|
||||
|
||||
const extensionIds = this.getAllIds();
|
||||
for (let i = 0; i < extensionIds.length; i++) {
|
||||
await this.load(extensionIds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扩展id列表(crx解压后的目录名,即是该扩展的id)
|
||||
*/
|
||||
getAllIds () {
|
||||
const extendsionDir = this.getDirectory();
|
||||
const ids = this.getDirs(extendsionDir);
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展所在目录
|
||||
*/
|
||||
getDirectory () {
|
||||
let extensionDirPath = '';
|
||||
let variablePath = 'build'; // 打包前路径
|
||||
if (app.isPackaged) {
|
||||
variablePath = '..'; // 打包后路径
|
||||
}
|
||||
extensionDirPath = path.join(app.getAppPath(), variablePath, "extraResources", "chromeExtension");
|
||||
|
||||
return extensionDirPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载扩展
|
||||
*/
|
||||
async load (extensionId = '') {
|
||||
if (_.isEmpty(extensionId)) {
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
const extensionPath = path.join(this.getDirectory(), extensionId);
|
||||
Log.info('[addon:chromeExtension] extensionPath:', extensionPath);
|
||||
await session.defaultSession.loadExtension(extensionPath, { allowFileAccess: true });
|
||||
} catch (e) {
|
||||
Log.info('[addon:chromeExtension] load extension error extensionId:%s, errorInfo:%s', extensionId, e.toString());
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取目录下所有文件夹
|
||||
*/
|
||||
getDirs(dir) {
|
||||
if (!dir) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const components = [];
|
||||
const files = fs.readdirSync(dir);
|
||||
files.forEach(function(item, index) {
|
||||
const stat = fs.lstatSync(dir + '/' + item);
|
||||
if (stat.isDirectory() === true) {
|
||||
components.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
return components;
|
||||
};
|
||||
}
|
||||
|
||||
ChromeExtensionAddon.toString = () => '[class ChromeExtensionAddon]';
|
||||
module.exports = ChromeExtensionAddon;
|
||||
@@ -1,33 +0,0 @@
|
||||
const Log = require('ee-core/log');
|
||||
const EE = require('ee-core/ee');
|
||||
|
||||
/**
|
||||
* 安全插件
|
||||
* @class
|
||||
*/
|
||||
class SecurityAddon {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*/
|
||||
create () {
|
||||
Log.info('[addon:security] load');
|
||||
const { CoreApp } = EE;
|
||||
const runWithDebug = process.argv.find(function(e){
|
||||
let isHasDebug = e.includes("--inspect") || e.includes("--inspect-brk") || e.includes("--remote-debugging-port");
|
||||
return isHasDebug;
|
||||
})
|
||||
|
||||
// 不允许远程调试
|
||||
if (runWithDebug) {
|
||||
Log.error('[error] Remote debugging is not allowed, runWithDebug:', runWithDebug);
|
||||
CoreApp.appQuit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SecurityAddon.toString = () => '[class SecurityAddon]';
|
||||
module.exports = SecurityAddon;
|
||||
@@ -1,72 +0,0 @@
|
||||
const { Tray, Menu } = require('electron');
|
||||
const path = require('path');
|
||||
const Ps = require('ee-core/ps');
|
||||
const Log = require('ee-core/log');
|
||||
const Electron = require('ee-core/electron');
|
||||
const CoreWindow = require('ee-core/electron/window');
|
||||
const Conf = require('ee-core/config');
|
||||
const EE = require('ee-core/ee');
|
||||
|
||||
/**
|
||||
* 托盘插件
|
||||
* @class
|
||||
*/
|
||||
class TrayAddon {
|
||||
|
||||
constructor() {
|
||||
this.tray = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建托盘
|
||||
*/
|
||||
create () {
|
||||
// 开发环境,代码热更新开启时,会导致托盘中有残影
|
||||
if (Ps.isDev() && Ps.isHotReload()) return;
|
||||
|
||||
Log.info('[addon:tray] load');
|
||||
const { CoreApp } = EE;
|
||||
const cfg = Conf.getValue('addons.tray');
|
||||
const mainWindow = CoreWindow.getMainWindow();
|
||||
|
||||
// 托盘图标
|
||||
let iconPath = path.join(Ps.getHomeDir(), cfg.icon);
|
||||
|
||||
// 托盘菜单功能列表
|
||||
let trayMenuTemplate = [
|
||||
{
|
||||
label: '显示',
|
||||
click: function () {
|
||||
mainWindow.show();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '退出',
|
||||
click: function () {
|
||||
CoreApp.appQuit();
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
// 点击关闭,最小化到托盘
|
||||
mainWindow.on('close', (event) => {
|
||||
if (Electron.extra.closeWindow == true) {
|
||||
return;
|
||||
}
|
||||
mainWindow.hide();
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
// 实例化托盘
|
||||
this.tray = new Tray(iconPath);
|
||||
this.tray.setToolTip(cfg.title);
|
||||
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate);
|
||||
this.tray.setContextMenu(contextMenu);
|
||||
this.tray.on('double-click', () => {
|
||||
mainWindow.show()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
TrayAddon.toString = () => '[class TrayAddon]';
|
||||
module.exports = TrayAddon;
|
||||
@@ -1,108 +0,0 @@
|
||||
/**
|
||||
* ee-bin 配置
|
||||
* 仅适用于开发环境
|
||||
*/
|
||||
module.exports = {
|
||||
/**
|
||||
* development serve ("frontend" "electron" )
|
||||
* ee-bin dev
|
||||
*/
|
||||
dev: {
|
||||
frontend: {
|
||||
directory: './frontend',
|
||||
cmd: 'npm',
|
||||
args: ['run', 'dev'],
|
||||
protocol: 'http://',
|
||||
hostname: 'localhost',
|
||||
port: 18091,
|
||||
indexPath: 'index.html'
|
||||
},
|
||||
electron: {
|
||||
directory: './',
|
||||
cmd: 'electron',
|
||||
args: ['.', '--env=local', '--color=always'], // --env: local|prod; '--color=always' 控制台颜色
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 构建
|
||||
* ee-bin build
|
||||
*/
|
||||
build: {
|
||||
frontend: {
|
||||
directory: './frontend',
|
||||
cmd: 'npm',
|
||||
args: ['run', 'build'],
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 移动资源
|
||||
* ee-bin move
|
||||
*/
|
||||
move: {
|
||||
frontend_dist: {
|
||||
dist: './frontend/dist',
|
||||
target: './public/dist'
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 预发布模式(prod)
|
||||
* ee-bin start
|
||||
*/
|
||||
start: {
|
||||
directory: './',
|
||||
cmd: 'electron',
|
||||
args: ['.', '--env=prod']
|
||||
},
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*/
|
||||
encrypt: {
|
||||
// confusion - 压缩混淆加密
|
||||
// bytecode - 字节码加密
|
||||
// strict - 先混淆加密,然后字节码加密
|
||||
type: 'confusion',
|
||||
// 文件匹配
|
||||
// ! 符号开头的意思是过滤
|
||||
files: [
|
||||
'electron/**/*.(js|json)',
|
||||
'!electron/config/encrypt.js',
|
||||
'!electron/config/nodemon.json',
|
||||
'!electron/config/builder.json',
|
||||
'!electron/config/bin.json',
|
||||
],
|
||||
// 需要加密的文件后缀,暂时只支持js
|
||||
fileExt: ['.js'],
|
||||
// 混淆加密配置
|
||||
confusionOptions: {
|
||||
// 压缩成一行
|
||||
compact: true,
|
||||
// 删除字符串文字并将其放置在一个特殊数组中
|
||||
stringArray: true,
|
||||
// 对stringArray的所有字符串文字进行编码,值:'none' | 'base64' | 'rc4'
|
||||
stringArrayEncoding: ['none'],
|
||||
// 注入死代码,注:影响性能
|
||||
deadCodeInjection: false,
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 执行自定义命令
|
||||
* ee-bin exec
|
||||
*/
|
||||
exec: {
|
||||
node_v: {
|
||||
directory: './',
|
||||
cmd: 'node',
|
||||
args: ['-v'],
|
||||
},
|
||||
npm_v: {
|
||||
directory: './',
|
||||
cmd: 'npm',
|
||||
args: ['-v'],
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,185 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const {getBaseDir} = require('ee-core/ps');
|
||||
|
||||
/**
|
||||
* 默认配置
|
||||
*/
|
||||
module.exports = (appInfo) => {
|
||||
|
||||
const config = {};
|
||||
|
||||
/**
|
||||
* 开发者工具
|
||||
*/
|
||||
config.openDevTools = false;
|
||||
|
||||
/**
|
||||
* 应用程序顶部菜单
|
||||
*/
|
||||
config.openAppMenu = true;
|
||||
|
||||
/**
|
||||
* 1.507
|
||||
* 主窗口
|
||||
*/
|
||||
config.windowsOption = {
|
||||
title: '自动检测平台',
|
||||
width: 1600,
|
||||
height: 950,
|
||||
minWidth: 1600,
|
||||
minHeight: 950,
|
||||
webPreferences: {
|
||||
//webSecurity: false,
|
||||
contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge)
|
||||
nodeIntegration: true,
|
||||
//preload: path.join(appInfo.baseDir, 'preload', 'bridge.js'),
|
||||
},
|
||||
frame: true,
|
||||
show: false,
|
||||
icon: path.join(appInfo.home, 'public', 'images', 'logo-32.png'),
|
||||
};
|
||||
|
||||
/**
|
||||
* ee框架日志
|
||||
*/
|
||||
config.logger = {
|
||||
encoding: 'utf8',
|
||||
level: 'INFO',
|
||||
outputJSON: false,
|
||||
buffer: true,
|
||||
enablePerformanceTimer: false,
|
||||
rotator: 'day',
|
||||
appLogName: 'pqs9100.log',
|
||||
coreLogName: 'pqs9100-core.log',
|
||||
errorLogName: 'pqs9100-error.log'
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程模式-web地址
|
||||
*/
|
||||
config.remoteUrl = {
|
||||
enable: false,
|
||||
url: 'http://electron-egg.kaka996.com/'
|
||||
};
|
||||
|
||||
/**
|
||||
* 内置socket服务
|
||||
*/
|
||||
config.socketServer = {
|
||||
enable: false, // 是否开启
|
||||
port: 7070,// 默认端口
|
||||
path: "/socket.io/", // 默认路径名称
|
||||
connectTimeout: 45000, // 客户端连接超时时间
|
||||
pingTimeout: 30000, // 心跳检测超时时间
|
||||
pingInterval: 25000, // 心跳检测间隔时间
|
||||
maxHttpBufferSize: 1e8, // 每条消息的数据最大值
|
||||
transports: ["polling", "websocket"], // http轮询和websocket
|
||||
cors: {
|
||||
origin: true, // http协议时,需要设置允许跨域
|
||||
},
|
||||
channel: 'c1' // 默认频道c1,可以自定义
|
||||
};
|
||||
|
||||
/**
|
||||
* 内置http服务
|
||||
*/
|
||||
config.httpServer = {
|
||||
enable: false,
|
||||
https: {
|
||||
enable: false,
|
||||
key: '/public/ssl/localhost+1.key',
|
||||
cert: '/public/ssl/localhost+1.pem'
|
||||
},
|
||||
host: '127.0.0.1',
|
||||
port: 7071,
|
||||
cors: {
|
||||
origin: "*" // 默认允许跨域
|
||||
},
|
||||
body: {
|
||||
multipart: true,
|
||||
formidable: {
|
||||
keepExtensions: true
|
||||
}
|
||||
},
|
||||
filterRequest: {
|
||||
uris: [
|
||||
'favicon.ico' // 默认过滤的uri favicon.ico
|
||||
],
|
||||
returnData: ''
|
||||
module.exports = () => {
|
||||
return {
|
||||
openDevTools: false,
|
||||
singleLock: true,
|
||||
windowsOption: {
|
||||
title: 'NPQS9100-自动检测平台',
|
||||
menuBarVisible: false,
|
||||
width: 1920,
|
||||
height: 1000,
|
||||
minWidth: 1024,
|
||||
minHeight: 640,
|
||||
webPreferences: {
|
||||
//webSecurity: false,
|
||||
contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge)
|
||||
nodeIntegration: true,
|
||||
//preload: path.join(getElectronDir(), 'preload', 'bridge.js'),
|
||||
},
|
||||
frame: true,
|
||||
show: true,
|
||||
icon: path.join(getBaseDir(), 'public', 'images', 'logo-32.png'),
|
||||
},
|
||||
logger: {
|
||||
level: 'INFO',
|
||||
outputJSON: false,
|
||||
appLogName: '9100.log',
|
||||
coreLogName: '9100-core.log',
|
||||
errorLogName: '9100-error.log'
|
||||
},
|
||||
// 远程web地址
|
||||
remote: {
|
||||
enable: false,
|
||||
url: ''
|
||||
},
|
||||
socketServer: {
|
||||
enable: false,
|
||||
port: 7070,
|
||||
path: "/socket.io/",
|
||||
connectTimeout: 45000,
|
||||
pingTimeout: 30000,
|
||||
pingInterval: 25000,
|
||||
maxHttpBufferSize: 1e8,
|
||||
transports: ["polling", "websocket"],
|
||||
cors: {
|
||||
origin: true,
|
||||
},
|
||||
channel: 'socket-channel'
|
||||
},
|
||||
httpServer: {
|
||||
enable: false,
|
||||
https: {
|
||||
enable: false,
|
||||
key: '/public/ssl/localhost+1.key',
|
||||
cert: '/public/ssl/localhost+1.pem'
|
||||
},
|
||||
host: '127.0.0.1',
|
||||
port: 7071,
|
||||
},
|
||||
mainServer: {
|
||||
indexPath: '/public/dist/index.html',
|
||||
channelSeparator: '/',
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 主进程
|
||||
*/
|
||||
config.mainServer = {
|
||||
protocol: 'file://',
|
||||
indexPath: '/public/dist/index.html',
|
||||
};
|
||||
|
||||
/**
|
||||
* 硬件加速
|
||||
*/
|
||||
config.hardGpu = {
|
||||
enable: true
|
||||
};
|
||||
|
||||
/**
|
||||
* 异常捕获
|
||||
*/
|
||||
config.exception = {
|
||||
mainExit: false, // 主进程退出时是否捕获异常
|
||||
childExit: true,
|
||||
rendererExit: true,
|
||||
};
|
||||
|
||||
/**
|
||||
* jobs
|
||||
*/
|
||||
config.jobs = {
|
||||
messageLog: true // 是否打印进程间通信的消息log
|
||||
};
|
||||
|
||||
/**
|
||||
* 插件功能
|
||||
* @param window 官方内置插件
|
||||
* @param tray 托盘插件
|
||||
* @param security 安全插件
|
||||
* @param awaken 唤醒插件
|
||||
* @param autoUpdater 自动升级插件
|
||||
*/
|
||||
config.addons = {
|
||||
window: {
|
||||
enable: true,
|
||||
},
|
||||
tray: {
|
||||
enable: true,
|
||||
title: '自动检测平台',
|
||||
icon: '/public/images/tray.png'
|
||||
},
|
||||
security: {
|
||||
enable: true,
|
||||
},
|
||||
awaken: {
|
||||
enable: true,
|
||||
protocol: 'ee',
|
||||
args: []
|
||||
},
|
||||
autoUpdater: {
|
||||
enable: true,
|
||||
windows: false,
|
||||
macOS: false,
|
||||
linux: false,
|
||||
options: {
|
||||
provider: 'generic',
|
||||
url: 'http://kodo.qiniu.com/'
|
||||
},
|
||||
force: false,
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
...config
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,31 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 开发环境配置,覆盖 config.default.js
|
||||
* Development environment configuration, coverage config.default.js
|
||||
*/
|
||||
module.exports = (appInfo) => {
|
||||
const config = {};
|
||||
|
||||
/**
|
||||
* 开发者工具
|
||||
*/
|
||||
config.openDevTools = {
|
||||
mode: 'undocked'
|
||||
};
|
||||
|
||||
/**
|
||||
* 应用程序顶部菜单
|
||||
*/
|
||||
config.openAppMenu = false;
|
||||
|
||||
/**
|
||||
* jobs
|
||||
*/
|
||||
config.jobs = {
|
||||
messageLog: true
|
||||
};
|
||||
|
||||
module.exports = () => {
|
||||
return {
|
||||
...config
|
||||
openDevTools: false,
|
||||
jobs: {
|
||||
messageLog: false
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,29 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 生产环境配置,覆盖 config.default.js
|
||||
* coverage config.default.js
|
||||
*/
|
||||
module.exports = (appInfo) => {
|
||||
const config = {};
|
||||
|
||||
/**
|
||||
* 开发者工具
|
||||
*/
|
||||
config.openDevTools = true;
|
||||
|
||||
/**
|
||||
* 应用程序顶部菜单
|
||||
*/
|
||||
config.openAppMenu = false;
|
||||
|
||||
/**
|
||||
* jobs
|
||||
*/
|
||||
config.jobs = {
|
||||
messageLog: false
|
||||
};
|
||||
|
||||
module.exports = () => {
|
||||
return {
|
||||
...config
|
||||
openDevTools: false,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"watch": [
|
||||
"electron/",
|
||||
"main.js"
|
||||
],
|
||||
"ignore": [],
|
||||
"ext": "js,json",
|
||||
"verbose": true,
|
||||
"exec": "electron . --env=local --hot-reload=1",
|
||||
"restartable": "hr",
|
||||
"colours": true,
|
||||
"events": {}
|
||||
}
|
||||
@@ -1,19 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const { Controller } = require('ee-core');
|
||||
const Log = require('ee-core/log');
|
||||
const Services = require('ee-core/services');
|
||||
const { logger } = require('ee-core/log');
|
||||
const { exampleService } = require('../service/example');
|
||||
|
||||
/**
|
||||
* example
|
||||
* @class
|
||||
*/
|
||||
class ExampleController extends Controller {
|
||||
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
class ExampleController {
|
||||
|
||||
/**
|
||||
* 所有方法接收两个参数
|
||||
@@ -25,12 +19,12 @@ class ExampleController extends Controller {
|
||||
* test
|
||||
*/
|
||||
async test () {
|
||||
const result = await Services.get('example').test('electron');
|
||||
Log.info('service result:', result);
|
||||
const result = await exampleService.test('electron');
|
||||
logger.info('service result:', result);
|
||||
|
||||
return 'hello electron-egg';
|
||||
}
|
||||
}
|
||||
|
||||
ExampleController.toString = () => '[class ExampleController]';
|
||||
module.exports = ExampleController;
|
||||
|
||||
module.exports = ExampleController;
|
||||
@@ -1,50 +0,0 @@
|
||||
const { Application } = require('ee-core');
|
||||
|
||||
class Index extends Application {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
// this === eeApp;
|
||||
}
|
||||
|
||||
/**
|
||||
* core app have been loaded
|
||||
*/
|
||||
async ready () {
|
||||
// do some things
|
||||
}
|
||||
|
||||
/**
|
||||
* electron app ready
|
||||
*/
|
||||
async electronAppReady () {
|
||||
// do some things
|
||||
}
|
||||
|
||||
/**
|
||||
* main window have been loaded
|
||||
*/
|
||||
async windowReady () {
|
||||
// do some things
|
||||
// 延迟加载,无白屏
|
||||
const winOpt = this.config.windowsOption;
|
||||
if (winOpt.show == false) {
|
||||
const win = this.electron.mainWindow;
|
||||
win.once('ready-to-show', () => {
|
||||
win.show();
|
||||
win.focus();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* before app close
|
||||
*/
|
||||
async beforeClose () {
|
||||
// do some things
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Index.toString = () => '[class Index]';
|
||||
module.exports = Index;
|
||||
@@ -1,5 +0,0 @@
|
||||
const Log = require('ee-core/log');
|
||||
|
||||
exports.welcome = function () {
|
||||
Log.info('[child-process] [jobs/example/hello] welcome ! ');
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
const Job = require('ee-core/jobs/baseJobClass');
|
||||
const Log = require('ee-core/log');
|
||||
const Ps = require('ee-core/ps');
|
||||
|
||||
/**
|
||||
* example - TimerJob
|
||||
* @class
|
||||
*/
|
||||
class TimerJob extends Job {
|
||||
|
||||
constructor(params) {
|
||||
super();
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
/**
|
||||
* handle()方法是必要的,且会被自动调用
|
||||
*/
|
||||
async handle () {
|
||||
Log.info("[child-process] TimerJob params: ", this.params);
|
||||
|
||||
if (Ps.isChildJob()) {
|
||||
Ps.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TimerJob.toString = () => '[class TimerJob]';
|
||||
module.exports = TimerJob;
|
||||
19
electron/main.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const { ElectronEgg } = require('ee-core');
|
||||
const { Lifecycle } = require('./preload/lifecycle');
|
||||
const { preload } = require('./preload');
|
||||
|
||||
// new app
|
||||
const app = new ElectronEgg();
|
||||
|
||||
// register lifecycle
|
||||
const life = new Lifecycle();
|
||||
app.register("ready", life.ready);
|
||||
app.register("electron-app-ready", life.electronAppReady);
|
||||
app.register("window-ready", life.windowReady);
|
||||
app.register("before-close", life.beforeClose);
|
||||
|
||||
// register preload
|
||||
app.register("preload", preload);
|
||||
|
||||
// run
|
||||
app.run();
|
||||
@@ -1,14 +1,16 @@
|
||||
/*************************************************
|
||||
** preload为预加载模块,该文件将会在程序启动时加载 **
|
||||
*************************************************/
|
||||
const Addon = require('ee-core/addon');
|
||||
|
||||
/**
|
||||
* 预加载模块入口
|
||||
*/
|
||||
module.exports = async () => {
|
||||
|
||||
// 示例功能模块,可选择性使用和修改
|
||||
Addon.get('tray').create();
|
||||
Addon.get('security').create();
|
||||
}
|
||||
const { logger } = require('ee-core/log');
|
||||
|
||||
function preload() {
|
||||
logger.info('[preload] load 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载模块入口
|
||||
*/
|
||||
module.exports = {
|
||||
preload
|
||||
}
|
||||
58
electron/preload/lifecycle.js
Normal file
@@ -0,0 +1,58 @@
|
||||
'use strict';
|
||||
|
||||
const { logger } = require('ee-core/log');
|
||||
const { getConfig } = require('ee-core/config');
|
||||
const { getMainWindow } = require('ee-core/electron');
|
||||
|
||||
class Lifecycle {
|
||||
|
||||
/**
|
||||
* core app have been loaded
|
||||
*/
|
||||
async ready() {
|
||||
logger.info('[lifecycle] ready');
|
||||
// 在这里可以做:
|
||||
// - 初始化数据库连接
|
||||
// - 加载配置文件
|
||||
// - 初始化全局变量
|
||||
}
|
||||
|
||||
/**
|
||||
* electron app ready
|
||||
*/
|
||||
async electronAppReady() {
|
||||
logger.info('[lifecycle] electron-app-ready');
|
||||
}
|
||||
|
||||
/**
|
||||
* main window have been loaded
|
||||
*/
|
||||
async windowReady() {
|
||||
logger.info('[lifecycle] window-ready');
|
||||
|
||||
// 延迟加载,无白屏
|
||||
const win = getMainWindow();
|
||||
const { windowsOption } = getConfig();
|
||||
if (windowsOption.show == false) {
|
||||
win.once('ready-to-show', () => {
|
||||
win.show();
|
||||
win.focus();
|
||||
})
|
||||
} else {
|
||||
win.show();
|
||||
win.focus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* before app close
|
||||
*/
|
||||
async beforeClose() {
|
||||
logger.info('[lifecycle] before-close');
|
||||
}
|
||||
}
|
||||
Lifecycle.toString = () => '[class Lifecycle]';
|
||||
|
||||
module.exports = {
|
||||
Lifecycle
|
||||
};
|
||||
@@ -1,16 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const { Service } = require('ee-core');
|
||||
const { logger } = require('ee-core/log');
|
||||
|
||||
/**
|
||||
* 示例服务(service层为单例)
|
||||
* 示例服务
|
||||
* @class
|
||||
*/
|
||||
class ExampleService extends Service {
|
||||
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
class ExampleService {
|
||||
|
||||
/**
|
||||
* test
|
||||
@@ -21,9 +17,14 @@ class ExampleService extends Service {
|
||||
params: args
|
||||
}
|
||||
|
||||
logger.info('ExampleService obj:', obj);
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
ExampleService.toString = () => '[class ExampleService]';
|
||||
module.exports = ExampleService;
|
||||
|
||||
module.exports = {
|
||||
ExampleService,
|
||||
exampleService: new ExampleService()
|
||||
};
|
||||
@@ -20,6 +20,8 @@ VITE_API_URL=/api
|
||||
# 开发环境跨域代理,支持配置多个
|
||||
|
||||
#VITE_PROXY=[["/api","http://127.0.0.1:18092/"]]
|
||||
VITE_PROXY=[["/api","http://192.168.1.124:18092/"]]
|
||||
VITE_PROXY=[["/api","http://192.168.1.125:18092/"]]
|
||||
#VITE_PROXY=[["/api","http://192.168.1.125:18092/"]]
|
||||
# VITE_PROXY=[["/api","http://192.168.1.138:8080/"]]张文
|
||||
# 开启激活验证
|
||||
VITE_ACTIVATE_OPEN=false
|
||||
@@ -24,3 +24,5 @@ VITE_PWA=true
|
||||
# 线上环境接口地址
|
||||
#VITE_API_URL="/api" # 打包时用
|
||||
VITE_API_URL="http://192.168.1.125:18092/"
|
||||
# 开启激活验证
|
||||
VITE_ACTIVATE_OPEN=false
|
||||
@@ -14,8 +14,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
"@types/event-source-polyfill": "^1.0.5",
|
||||
"@vue-flow/core": "^1.45.0",
|
||||
"@vueuse/core": "^10.4.1",
|
||||
"autofit.js": "^3.2.8",
|
||||
"axios": "^1.7.3",
|
||||
"crypto-js": "^4.2.0",
|
||||
"dayjs": "^1.11.9",
|
||||
@@ -23,6 +25,7 @@
|
||||
"echarts": "^5.4.3",
|
||||
"echarts-liquidfill": "^3.1.0",
|
||||
"element-plus": "^2.7.8",
|
||||
"event-source-polyfill": "^1.0.31",
|
||||
"html2canvas": "^1.4.1",
|
||||
"md5": "^2.3.0",
|
||||
"mitt": "^3.0.1",
|
||||
@@ -77,7 +80,7 @@
|
||||
"vite-plugin-compression": "^0.5.1",
|
||||
"vite-plugin-eslint": "^1.8.1",
|
||||
"vite-plugin-html": "^3.2.0",
|
||||
"vite-plugin-node-polyfills": "^0.23.0",
|
||||
"vite-plugin-node-polyfills": "^0.24.0",
|
||||
"vite-plugin-pwa": "^0.16.5",
|
||||
"vite-plugin-svg-icons": "^2.0.1",
|
||||
"vue-tsc": "^2.0.21"
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
<template>
|
||||
<!--element-plus语言国际化,全局修改为中文-->
|
||||
<el-config-provider
|
||||
:locale='locale'
|
||||
:size='assemblySize'
|
||||
:button='buttonConfig'
|
||||
>
|
||||
<router-view />
|
||||
</el-config-provider>
|
||||
<!--element-plus语言国际化,全局修改为中文-->
|
||||
<el-config-provider :locale="locale" :size="assemblySize" :button="buttonConfig">
|
||||
<router-view />
|
||||
</el-config-provider>
|
||||
</template>
|
||||
|
||||
<script lang='ts' setup>
|
||||
defineOptions({
|
||||
name: 'App',
|
||||
})
|
||||
<script lang="ts" setup>
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getBrowserLang } from '@/utils'
|
||||
import { useTheme } from '@/hooks/useTheme'
|
||||
import { ElConfigProvider } from 'element-plus'
|
||||
import { LanguageType } from './stores/interface'
|
||||
import { type LanguageType } from './stores/interface'
|
||||
import { useGlobalStore } from '@/stores/modules/global'
|
||||
import en from 'element-plus/es/locale/lang/en'
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||
|
||||
defineOptions({
|
||||
name: 'App'
|
||||
})
|
||||
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
// init theme
|
||||
@@ -31,16 +28,24 @@ initTheme()
|
||||
// init language
|
||||
const i18n = useI18n()
|
||||
onMounted(() => {
|
||||
const language = globalStore.language ?? getBrowserLang()
|
||||
i18n.locale.value = language
|
||||
globalStore.setGlobalState('language', language as LanguageType)
|
||||
const language = globalStore.language ?? getBrowserLang()
|
||||
i18n.locale.value = language
|
||||
globalStore.setGlobalState('language', language as LanguageType)
|
||||
// 移除 autofit,使用 CSS 自适应
|
||||
// autofit.init({
|
||||
// el: '#app',
|
||||
// dw: 1440,
|
||||
// dh: 900,
|
||||
// resize: true,
|
||||
// limit: 0.1
|
||||
// })
|
||||
})
|
||||
|
||||
// element language
|
||||
const locale = computed(() => {
|
||||
if (globalStore.language == 'zh') return zhCn
|
||||
if (globalStore.language == 'en') return en
|
||||
return getBrowserLang() == 'zh' ? zhCn : en
|
||||
if (globalStore.language == 'zh') return zhCn
|
||||
if (globalStore.language == 'en') return en
|
||||
return getBrowserLang() == 'zh' ? zhCn : en
|
||||
})
|
||||
|
||||
// element assemblySize
|
||||
@@ -51,4 +56,10 @@ const buttonConfig = reactive({ autoInsertSpace: false })
|
||||
|
||||
document.getElementById('loadingPage')?.remove()
|
||||
</script>
|
||||
<style scoped></style>
|
||||
<style scoped>
|
||||
#app {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
14
frontend/src/api/activate/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import http from '@/api'
|
||||
import type { Activate } from '@/api/activate/interface'
|
||||
|
||||
export const generateApplicationCode = (params: Activate.ApplicationCodePlaintext) => {
|
||||
return http.post(`/activate/generateApplicationCode`, params)
|
||||
}
|
||||
|
||||
export const verifyActivationCode = (activationCode: string) => {
|
||||
return http.post(`/activate/verifyActivationCode`, { activationCode })
|
||||
}
|
||||
|
||||
export const getLicense = () => {
|
||||
return http.post(`/activate/getLicense`)
|
||||
}
|
||||
55
frontend/src/api/activate/interface/index.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
//激活模块
|
||||
export namespace Activate {
|
||||
|
||||
export interface ApplicationModule {
|
||||
/**
|
||||
* 是否申请 1是 0否
|
||||
*/
|
||||
apply: number;
|
||||
}
|
||||
|
||||
export interface ActivateModule extends ApplicationModule {
|
||||
/**
|
||||
* 是否永久 1是 0否
|
||||
*/
|
||||
permanently: number;
|
||||
}
|
||||
|
||||
export interface ApplicationCodePlaintext {
|
||||
|
||||
/**
|
||||
* 模拟式模块
|
||||
*/
|
||||
simulate: ApplicationModule;
|
||||
|
||||
/**
|
||||
* 数字式模块
|
||||
*/
|
||||
digital: ApplicationModule;
|
||||
|
||||
/**
|
||||
* 比对式模块
|
||||
*/
|
||||
contrast: ApplicationModule;
|
||||
}
|
||||
export interface ActivationCodePlaintext {
|
||||
|
||||
/**
|
||||
* 模拟式模块
|
||||
*/
|
||||
simulate: ActivateModule;
|
||||
|
||||
/**
|
||||
* 数字式模块
|
||||
*/
|
||||
digital: ActivateModule;
|
||||
|
||||
/**
|
||||
* 比对式模块
|
||||
*/
|
||||
contrast: ActivateModule;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,126 +1,158 @@
|
||||
export namespace CheckData {
|
||||
export interface DataCheck {
|
||||
scriptName: string,
|
||||
errorSysId: string,
|
||||
dataRule: string,
|
||||
deviceName: string,
|
||||
chnNum: string,
|
||||
scriptName: string
|
||||
errorSysId: string
|
||||
dataRule: string
|
||||
deviceName: string
|
||||
chnNum: string
|
||||
deviceId: string
|
||||
num?: string | number
|
||||
}
|
||||
|
||||
export interface PhaseCheckResult {
|
||||
// 检测源定值-标准值
|
||||
resultData: number,
|
||||
resultData: number
|
||||
// 装置原始数据-被检值
|
||||
data: number,
|
||||
data: number
|
||||
|
||||
// 误差值
|
||||
errorData: number,
|
||||
errorData: number
|
||||
// 第几次谐波
|
||||
num?: number,
|
||||
num?: number
|
||||
//符合、不符合
|
||||
isData?: number,
|
||||
isData?: number
|
||||
//最大误差值
|
||||
radius?: string,
|
||||
unit?: string,
|
||||
radius?: string
|
||||
unit?: string
|
||||
}
|
||||
export interface DataItem {
|
||||
num: number
|
||||
isData: number
|
||||
data: number
|
||||
resultData: number
|
||||
radius: string
|
||||
errorData: number
|
||||
unit: string
|
||||
}
|
||||
|
||||
export interface TableRow {
|
||||
isData: number
|
||||
harmNum: number
|
||||
radius: string
|
||||
dataA: DataItem
|
||||
dataB: DataItem
|
||||
dataC: DataItem
|
||||
dataT: DataItem | null
|
||||
unit: string
|
||||
timeDev?: string
|
||||
uaDev?: string | number
|
||||
ubDev?: string | number
|
||||
ucDev?: string | number
|
||||
utDev?: string | number
|
||||
uaStdDev?: string | number
|
||||
ubStdDev?: string | number
|
||||
ucStdDev?: string | number
|
||||
utStdDev?: string | number
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于定义 查看(设备)通道检测结果响应数据 类型
|
||||
*/
|
||||
export interface ResCheckResult {
|
||||
dataA?: PhaseCheckResult | null,
|
||||
dataB?: PhaseCheckResult | null,
|
||||
dataC?: PhaseCheckResult | null,
|
||||
dataT?: PhaseCheckResult | null,
|
||||
dataA?: PhaseCheckResult | null
|
||||
dataB?: PhaseCheckResult | null
|
||||
dataC?: PhaseCheckResult | null
|
||||
dataT?: PhaseCheckResult | null
|
||||
|
||||
// 第几次谐波
|
||||
//num: number | null,
|
||||
//符合、不符合
|
||||
isData?: number,
|
||||
isData?: number
|
||||
//最大误差值
|
||||
radius?: string,
|
||||
radius?: string
|
||||
//单位
|
||||
unit?: string,
|
||||
unit?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于定义 查看(设备)通道检测结果表格展示数据 类型
|
||||
*/
|
||||
export interface CheckResult {
|
||||
stdA?: string,
|
||||
dataA?: string,
|
||||
errorA?: string,
|
||||
maxErrorA?: string,
|
||||
isDataA?: number,
|
||||
unitA?: string,
|
||||
stdB?: string,
|
||||
dataB?: string,
|
||||
errorB?: string,
|
||||
maxErrorB?: string,
|
||||
isDataB?: number,
|
||||
unitB?: string,
|
||||
stdC?: string,
|
||||
dataC?: string,
|
||||
errorC?: string,
|
||||
maxErrorC?: string,
|
||||
isDataC?: number,
|
||||
unitC?: string,
|
||||
stdT?: string,
|
||||
dataT?: string,
|
||||
errorT?: string,
|
||||
maxErrorT?: string,
|
||||
isDataT?: number,
|
||||
unitT?: string,
|
||||
stdA?: string
|
||||
dataA?: string
|
||||
errorA?: string
|
||||
maxErrorA?: string
|
||||
isDataA?: number
|
||||
unitA?: string
|
||||
stdB?: string
|
||||
dataB?: string
|
||||
errorB?: string
|
||||
maxErrorB?: string
|
||||
isDataB?: number
|
||||
unitB?: string
|
||||
stdC?: string
|
||||
dataC?: string
|
||||
errorC?: string
|
||||
maxErrorC?: string
|
||||
isDataC?: number
|
||||
unitC?: string
|
||||
stdT?: string
|
||||
dataT?: string
|
||||
errorT?: string
|
||||
maxErrorT?: string
|
||||
isDataT?: number
|
||||
unitT?: string
|
||||
|
||||
//最大误差值
|
||||
maxError?: string,
|
||||
unit?: string,
|
||||
maxError?: string
|
||||
unit?: string
|
||||
//符合、不符合
|
||||
result?: number,
|
||||
result?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于定义 具体通道的原始数据类型
|
||||
*/
|
||||
export interface RawDataItem {
|
||||
time?: string,
|
||||
harmNum?: number | null,
|
||||
dataA?: string,
|
||||
dataB?: string,
|
||||
dataC?: string,
|
||||
dataT?: string,
|
||||
time?: string
|
||||
harmNum?: number | null
|
||||
dataA?: string
|
||||
dataB?: string
|
||||
dataC?: string
|
||||
dataT?: string
|
||||
unit?: string | null
|
||||
}
|
||||
|
||||
export interface Device {
|
||||
deviceId: string; //装置序号Id
|
||||
deviceName: string; //设备名称
|
||||
chnNum: number; //设备通道数
|
||||
deviceId: string //装置序号Id
|
||||
deviceName: string //设备名称
|
||||
chnNum: number //设备通道数
|
||||
|
||||
planId: string; //计划Id
|
||||
devType: string; //设备类型
|
||||
devVolt: number; //设备电压
|
||||
devCurr: number; //设备电流
|
||||
factorFlag: number; //是否支持系数校准
|
||||
checkResult:number; //检测结果
|
||||
planId: string //计划Id
|
||||
devType: string //设备类型
|
||||
devVolt: number //设备电压
|
||||
devCurr: number //设备电流
|
||||
factorFlag: number //是否支持系数校准
|
||||
checkResult: number //检测结果
|
||||
chnNumList: string[] //连线存储数据
|
||||
}
|
||||
|
||||
// 用来描述检测脚本类型
|
||||
export interface ScriptItem {
|
||||
id: string,
|
||||
code: string,
|
||||
scriptName: string,
|
||||
id: string
|
||||
code: string
|
||||
scriptName: string
|
||||
}
|
||||
|
||||
// 用来描述 检测数据-左侧树结构
|
||||
export interface TreeItem {
|
||||
id: string | null,
|
||||
scriptTypeName: string | null,
|
||||
sourceDesc: string | null,
|
||||
harmNum: number | null,
|
||||
index: number | null,
|
||||
fly: number | null,
|
||||
children: TreeItem[] | null,
|
||||
id: string | null
|
||||
scriptTypeName: string | null
|
||||
sourceDesc: string | null
|
||||
harmNum: number | null
|
||||
index: number | null
|
||||
fly: number | null
|
||||
children: TreeItem[] | null
|
||||
}
|
||||
|
||||
// 用来描述 通道检测结果
|
||||
@@ -135,16 +167,17 @@ export namespace CheckData {
|
||||
}
|
||||
|
||||
export interface DeviceCheckResult {
|
||||
deviceId: string,
|
||||
deviceName: string,
|
||||
deviceId: string
|
||||
deviceName: string
|
||||
code?: string
|
||||
chnResult: ChnCheckResultEnum[] //通道检测结果
|
||||
}
|
||||
|
||||
//用来描述 某个脚本测试项对所有通道的检测结果
|
||||
export interface ScriptChnItem {
|
||||
scriptType: string
|
||||
scriptName?: string //可以不要该属性,有点多余
|
||||
|
||||
scriptName?: string //可以不要该属性,有点多余
|
||||
code?: string
|
||||
// 设备
|
||||
devices: Array<DeviceCheckResult>
|
||||
}
|
||||
@@ -154,7 +187,7 @@ export namespace CheckData {
|
||||
LOADING = 'var(--el-color-primary)',
|
||||
SUCCESS = '#91cc75',
|
||||
WARNING = '#e6a23c',
|
||||
DANGER = '#f56c6c',
|
||||
DANGER = '#f56c6c'
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,18 +202,17 @@ export namespace CheckData {
|
||||
* 用于描述 脚本检测结果展示的按钮类型
|
||||
*/
|
||||
export interface ScriptChnViewItem {
|
||||
scriptType: string,
|
||||
scriptType: string
|
||||
scriptName?: string //脚本项名称,可以不要该属性,有点多余
|
||||
|
||||
// 设备
|
||||
devices: Array<{
|
||||
deviceId: string,
|
||||
deviceName: string,
|
||||
chnResult: ButtonResult[],
|
||||
deviceId: string
|
||||
deviceName: string
|
||||
chnResult: ButtonResult[]
|
||||
}>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定义检测日志类型
|
||||
*/
|
||||
@@ -193,13 +225,16 @@ export namespace CheckData {
|
||||
* 定义手动检测时,勾选的测试项
|
||||
*/
|
||||
export interface SelectTestItem {
|
||||
preTest: boolean,
|
||||
timeTest: boolean,
|
||||
channelsTest: boolean,
|
||||
preTest: boolean
|
||||
timeTest: boolean
|
||||
channelsTest: boolean
|
||||
test: boolean
|
||||
}
|
||||
|
||||
//描述比对式检测项描述
|
||||
export interface CompareTestItem {
|
||||
id: string
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
import http from "@/api";
|
||||
import {CheckData} from "@/api/check/interface";
|
||||
import { pa } from 'element-plus/es/locale/index.mjs';
|
||||
import http from '@/api'
|
||||
import {CheckData} from '@/api/check/interface'
|
||||
|
||||
export const getBigTestItem = (params: {
|
||||
reCheckType: number,
|
||||
planId: string,
|
||||
devIds: string[],
|
||||
reCheckType: number
|
||||
planId: string
|
||||
devIds: string[]
|
||||
patternId: string
|
||||
}) => {
|
||||
return http.post(`/adPlan/getBigTestItem`, params, {loading: false});
|
||||
return http.post(`/adPlan/getBigTestItem`, params, {loading: false})
|
||||
}
|
||||
|
||||
export const getScriptList = (params: {
|
||||
devId:string,
|
||||
chnNum:number,
|
||||
num:number
|
||||
}) => {
|
||||
return http.post('/result/getCheckItem', params, {loading: false})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -14,12 +24,12 @@ export const getBigTestItem = (params: {
|
||||
* @param params 当为scriptType为null时,表示查询所有脚本类型,否则只查询指定脚本类型。当为chnNum为-1时,表示查询所有通道,否则只查询指定通道。
|
||||
*/
|
||||
export const getFormData = (params: {
|
||||
planId: string,
|
||||
deviceId: string,
|
||||
chnNum: string,
|
||||
planId: string
|
||||
deviceId: string
|
||||
chnNum: string
|
||||
scriptType: string | null
|
||||
}) => {
|
||||
return http.post("/result/formContent/", params, {loading: false});
|
||||
return http.post('/result/formContent/', params, {loading: false})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,13 +37,13 @@ export const getFormData = (params: {
|
||||
* @param params
|
||||
*/
|
||||
export const getTreeData = (params: {
|
||||
scriptId?: string,
|
||||
devId?: string,
|
||||
devNum?: string,
|
||||
scriptType?: string | null,
|
||||
code?: string,
|
||||
scriptId?: string
|
||||
devId?: string
|
||||
devNum?: string
|
||||
scriptType?: string | null
|
||||
code?: string
|
||||
}) => {
|
||||
return http.post<CheckData.TreeItem[]>("/result/treeData/", params, {loading: false});
|
||||
return http.post<CheckData.TreeItem[]>('/result/treeData/', params, {loading: false})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,25 +51,25 @@ export const getTreeData = (params: {
|
||||
* @param params
|
||||
*/
|
||||
export const getTableData = (params: {
|
||||
scriptType: string | null,
|
||||
scriptId: string,
|
||||
devId: string,
|
||||
devNum: string,
|
||||
code: string,
|
||||
index: number,
|
||||
scriptType: string | null
|
||||
scriptId: string
|
||||
devId: string
|
||||
devNum: string
|
||||
code: string
|
||||
index: number
|
||||
}) => {
|
||||
return http.post("/result/resultData/", params, {loading: false});
|
||||
return http.post('/result/resultData/', params, {loading: false})
|
||||
}
|
||||
|
||||
export const exportRawData = (params: {
|
||||
scriptType: string | null,
|
||||
scriptId: string,
|
||||
devId: string,
|
||||
devNum: string,
|
||||
code: string,
|
||||
index: number,
|
||||
scriptType: string | null
|
||||
scriptId: string
|
||||
devId: string
|
||||
devNum: string
|
||||
code: string
|
||||
index: number
|
||||
}) => {
|
||||
return http.download("/result/exportRawData", params, {loading: false});
|
||||
return http.download('/result/exportRawData', params, {loading: false})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,13 +77,46 @@ export const exportRawData = (params: {
|
||||
* @param params
|
||||
*/
|
||||
export const reCalculate = (params: {
|
||||
planId: string,
|
||||
scriptId: string,
|
||||
errorSysId: string,
|
||||
deviceId: string,
|
||||
planId: string
|
||||
scriptId: string
|
||||
errorSysId: string
|
||||
deviceId: string
|
||||
code: string
|
||||
patternId: string
|
||||
|
||||
}) => {
|
||||
return http.post("/result/reCalculate", params, {loading: true});
|
||||
return http.post('/result/reCalculate', params, {loading: true})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据获取基本信息
|
||||
* @param params
|
||||
*/
|
||||
export const getContrastFormContent = (params: {
|
||||
planId: string
|
||||
scriptType: string
|
||||
deviceId: string
|
||||
chnNum: string
|
||||
num: number | null
|
||||
patternId: string
|
||||
}) => {
|
||||
return http.post('/result/getContrastFormContent', params, {loading: false})
|
||||
}
|
||||
/**
|
||||
* 获取检测结果
|
||||
* @param params
|
||||
*/
|
||||
export const getContrastResult = (params: {
|
||||
planId: string
|
||||
scriptType: string
|
||||
deviceId: string
|
||||
chnNum: string | number
|
||||
num: number | string | null
|
||||
waveNum: number | null
|
||||
isWave: boolean
|
||||
patternId: string
|
||||
}) => {
|
||||
return http.post('/result/getContrastResult', params, {loading: true})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,13 +124,14 @@ export const reCalculate = (params: {
|
||||
* @param params
|
||||
*/
|
||||
export const changeErrorSystem = (params: {
|
||||
planId: string,
|
||||
scriptId: string,
|
||||
errorSysId: string,
|
||||
deviceId: string,
|
||||
planId: string
|
||||
scriptId: string
|
||||
errorSysId: string
|
||||
deviceId: string
|
||||
code: string
|
||||
patternId: string
|
||||
}) => {
|
||||
return http.post("/result/changeErrorSystem", params, {loading: true});
|
||||
return http.post('/result/changeErrorSystem', params, {loading: true})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,4 +140,4 @@ export const changeErrorSystem = (params: {
|
||||
*/
|
||||
export const deleteTempTable = (code: string) => {
|
||||
return http.get(`/result/deleteTempTable?code=${code}`, null, {loading: false})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,172 +266,4 @@ const data = [
|
||||
reCheck_Num: 0, //复检次数
|
||||
},
|
||||
]
|
||||
// const plan_devicedata = [
|
||||
// {
|
||||
// id: '1', //装置序号ID
|
||||
// name: '模拟装置1', //设备名称
|
||||
// dev_Type: 'PQS882A',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 0, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '2', //装置序号ID
|
||||
// name: '模拟装置2', //设备名称
|
||||
// dev_Type: 'PQS882B4',//设备类型
|
||||
// dev_Chns: 4, //设备通道数
|
||||
// check_Result: '/', //检测结果
|
||||
// report_State: '未生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'未检',//检测状态
|
||||
// reCheck_Num: 0, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '3', //装置序号ID
|
||||
// name: '模拟装置3', //设备名称
|
||||
// dev_Type: 'PQS882B4',//设备类型
|
||||
// dev_Chns: 4, //设备通道数
|
||||
// check_Result: '/', //检测结果
|
||||
// report_State: '未生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测中',//检测状态
|
||||
// reCheck_Num: 0, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '4', //装置序号ID
|
||||
// name: '模拟装置4', //设备名称
|
||||
// dev_Type: 'PQS882B4',//设备类型
|
||||
// dev_Chns: 4, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '未生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 1, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '5', //装置序号ID
|
||||
// name: '中电测试装置', //设备名称
|
||||
// dev_Type: 'PMC-680M-22-22-00-115ANBC',//设备类型
|
||||
// dev_Chns: 4, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '未生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 1, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '6', //装置序号ID
|
||||
// name: '易司拓测试装置1', //设备名称
|
||||
// dev_Type: 'E703A',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 1, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '7', //装置序号ID
|
||||
// name: '易司拓测试装置2', //设备名称
|
||||
// dev_Type: 'E703A',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 1, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '8', //装置序号ID
|
||||
// name: '山大电力测试装置1', //设备名称
|
||||
// dev_Type: 'SDL-3002C',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 1, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '9', //装置序号ID
|
||||
// name: '山大电力测试装置2', //设备名称
|
||||
// dev_Type: 'SDL-3002C',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 2, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '10', //装置序号ID
|
||||
// name: '山大电力测试装置2', //设备名称
|
||||
// dev_Type: 'SDL-3002C',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 2, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '11', //装置序号ID
|
||||
// name: '山大电力测试装置2', //设备名称
|
||||
// dev_Type: 'SDL-3002C',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 2, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '12', //装置序号ID
|
||||
// name: '山大电力测试装置2', //设备名称
|
||||
// dev_Type: 'SDL-3002C',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 2, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '13', //装置序号ID
|
||||
// name: '山大电力测试装置2', //设备名称
|
||||
// dev_Type: 'SDL-3002C',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 2, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '14', //装置序号ID
|
||||
// name: '山大电力测试装置3', //设备名称
|
||||
// dev_Type: 'SDL-3002C',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 2, //复检次数
|
||||
// },
|
||||
// {
|
||||
// id: '15', //装置序号ID
|
||||
// name: '山大电力测试装置4', //设备名称
|
||||
// dev_Type: 'SDL-3002C',//设备类型
|
||||
// dev_Chns: 1, //设备通道数
|
||||
// check_Result: '不合格', //检测结果
|
||||
// report_State: '已生成', //报告状态
|
||||
// document_State: '未归档', //归档状态
|
||||
// check_State:'检测完成',//检测状态
|
||||
// reCheck_Num: 2, //复检次数
|
||||
// },
|
||||
// ]
|
||||
|
||||
export default {data,plan_devicedata}
|
||||
@@ -25,6 +25,7 @@ export namespace DevType {
|
||||
devChns: number; //设备通道数
|
||||
reportName: string| null;//报告模版名称
|
||||
state: number;
|
||||
waveCmd:string| null;//录波指令
|
||||
createBy?: string| null; //创建用户
|
||||
createTime?: string| null; //创建时间
|
||||
updateBy?: string| null; //更新用户
|
||||
|
||||
@@ -1,124 +1,119 @@
|
||||
import { getPqDevById } from './../device/index';
|
||||
import type {ReqPage, ResPage} from '@/api/interface'
|
||||
import type { Monitor } from './monitor';
|
||||
import type { ReqPage, ResPage } from '@/api/interface'
|
||||
import type { Monitor } from './monitor'
|
||||
|
||||
// 被检设备模块
|
||||
export namespace Device {
|
||||
|
||||
/**
|
||||
* 被检设备表格分页查询参数
|
||||
*/
|
||||
export interface ReqPqDevParams extends ReqPage {
|
||||
id: string; // 装置序号id 必填
|
||||
name: string; //设备名称
|
||||
devType?: string; // 设备名称
|
||||
createTime?: string; //创建时间
|
||||
pattern: string;
|
||||
id: string // 装置序号id 必填
|
||||
name: string //设备名称
|
||||
devType?: string // 设备名称
|
||||
createTime?: string //创建时间
|
||||
pattern: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 被检设备表格分页查询参数
|
||||
*/
|
||||
export interface ReqDevReportParams extends ReqPage {
|
||||
planId?: string; // 计划id
|
||||
devId?: string; // 装置id
|
||||
scriptId?: string; // 脚本id
|
||||
planCode?: string;
|
||||
devIdList?: string[]; // 装置id列表
|
||||
planId?: string // 计划id
|
||||
devId?: string // 装置id
|
||||
scriptId?: string // 脚本id
|
||||
planCode?: string
|
||||
devIdList?: string[] // 装置id列表
|
||||
}
|
||||
|
||||
/**
|
||||
* 被检设备新增、修改、根据id查询返回的对象
|
||||
*/
|
||||
export interface ResPqDev {
|
||||
id: string; //装置序号ID
|
||||
name: string; //设备名称
|
||||
pattern: string; //设备模式 模拟 数字 比对
|
||||
devType: string;//设备类型
|
||||
manufacturer?: string | null;//生产厂家
|
||||
createDate: string; //生产日期
|
||||
createId: string; //出厂编号
|
||||
hardwareVersion: string; //固件版本
|
||||
softwareVersion: string; //软件版本
|
||||
protocol: string; //通讯协议
|
||||
ip: string; //IP地址
|
||||
port: number; //端口号
|
||||
encryptionFlag: number; //装置是否为加密版本
|
||||
series?: string | null; //装置识别码(3ds加密)
|
||||
devKey?: string | null; //装置秘钥(3ds加密)
|
||||
sampleId?: string | null; //样品编号
|
||||
arrivedDate?: string; //送样日期
|
||||
cityName?: string | null; //所属地市名称
|
||||
gdName?: string | null; //所属供电公司名称
|
||||
subName?: string | null; //所属电站名称
|
||||
reportPath?: string | null; //报告路径
|
||||
planId?: string;//检测计划Id
|
||||
factorFlag?: number;//是否支持系数校准(0:不支持,1:支持)
|
||||
preinvestmentPlan: string | null;//预投计划
|
||||
delegate: string | null; //委托方
|
||||
inspectChannel?: string[] | string;//被检通道
|
||||
inspectDate?: string | null;//定检日期
|
||||
harmSysId?: string | null;//谐波系统设备id
|
||||
importFlag?: number;//是否为导入设备 0否 1是
|
||||
state: number; //状态
|
||||
createBy?: string | null; //创建用户
|
||||
createTime?: string | null; //创建时间
|
||||
updateBy?: string | null; //更新用户
|
||||
updateTime?: string | null; //更新时间
|
||||
|
||||
devChns: number; //设备通道数
|
||||
devVolt: number; //额定电压(V)
|
||||
devCurr: number; //额定电流(A)
|
||||
icdId: string | null;
|
||||
power: string | null;//工作电源
|
||||
id: string //装置序号ID
|
||||
name: string //设备名称
|
||||
pattern: string //设备模式 模拟 数字 比对
|
||||
devType: string //设备类型
|
||||
manufacturer?: string | null //生产厂家
|
||||
createDate: string //生产日期
|
||||
createId: string //出厂编号
|
||||
hardwareVersion: string //固件版本
|
||||
softwareVersion: string //软件版本
|
||||
protocol: string //通讯协议
|
||||
ip: string //IP地址
|
||||
port: number //端口号
|
||||
encryptionFlag: number //装置是否为加密版本
|
||||
series?: string | null //装置识别码(3ds加密)
|
||||
devKey?: string | null //装置秘钥(3ds加密)
|
||||
sampleId?: string | null //样品编号
|
||||
arrivedDate?: string //送样日期
|
||||
cityName?: string | null //所属地市名称
|
||||
gdName?: string | null //所属供电公司名称
|
||||
subName?: string | null //所属电站名称
|
||||
reportPath?: string | null //报告路径
|
||||
planId?: string //检测计划Id
|
||||
factorFlag?: number //是否支持系数校准(0:不支持,1:支持)
|
||||
preinvestmentPlan: string | null //预投计划
|
||||
delegate: string | null //委托方
|
||||
inspectChannel?: string[] | string //被检通道
|
||||
inspectDate?: string | null //定检日期
|
||||
harmSysId?: string | null //谐波系统设备id
|
||||
importFlag?: number //是否为导入设备 0否 1是
|
||||
state: number //状态
|
||||
createBy?: string | null //创建用户
|
||||
createTime?: string | null //创建时间
|
||||
updateBy?: string | null //更新用户
|
||||
updateTime?: string | null //更新时间
|
||||
|
||||
devId?: number;
|
||||
checkState?: number | null; //检测状态(0:未检,1:检测中,2:检测完成 3:归档)
|
||||
checkResult?: number | null; //检测结果(0:不符合,1:符合,2:未检)
|
||||
reportState?: number | null; //报告状态(0:未生成,1:已生成,2:未检)
|
||||
recheckNum: number; //复检次数
|
||||
timeCheckResult?: number;//守时检测结果(0:不符合1:符合)
|
||||
factorCheckResult?: number;//系数校准结果(0:不合格,1:合格,2:未检)
|
||||
realtimeResult?: number;//实时数据结论(0:不符合,1:符合,2:未检)
|
||||
statisticsResult?: number;//统计数据结论(0:不符合,1:符合,2:未检)
|
||||
recordedResult?: number;//录波数据结论(0:不符合,1:符合,2:未检)
|
||||
checkBy?: string | null;//检测人
|
||||
checkTime?: string | null;//检测时间
|
||||
preDetectTime?: number;//预检测耗时
|
||||
coefficientTime?: number;//系数校准耗时
|
||||
formalCheckTime?: number;//正式检测耗时
|
||||
devChns: number //设备通道数
|
||||
devVolt: number //额定电压(V)
|
||||
devCurr: number //额定电流(A)
|
||||
icdId: string | null
|
||||
power: string | null //工作电源
|
||||
|
||||
boundPlanName?: string| null;
|
||||
assign?: number;////是否分配给检测人员 0否 1是
|
||||
monitorList: Monitor.ResPqMon[] ;
|
||||
devId?: number
|
||||
checkState?: number | null //检测状态(0:未检,1:检测中,2:检测完成 3:归档)
|
||||
checkResult?: number | null //检测结果(0:不符合,1:符合,2:未检)
|
||||
reportState?: number | null //报告状态(0:未生成,1:已生成,2:未检)
|
||||
recheckNum: number //复检次数
|
||||
timeCheckResult?: number //守时检测结果(0:不符合1:符合)
|
||||
factorCheckResult?: number //系数校准结果(0:不合格,1:合格,2:未检)
|
||||
realtimeResult?: number //实时数据结论(0:不符合,1:符合,2:未检)
|
||||
statisticsResult?: number //统计数据结论(0:不符合,1:符合,2:未检)
|
||||
recordedResult?: number //录波数据结论(0:不符合,1:符合,2:未检)
|
||||
checkBy?: string | null //检测人
|
||||
checkTime?: string | null //检测时间
|
||||
preDetectTime?: number //预检测耗时
|
||||
coefficientTime?: number //系数校准耗时
|
||||
formalCheckTime?: number //正式检测耗时
|
||||
|
||||
boundPlanName?: string | null
|
||||
assign?: number ////是否分配给检测人员 0否 1是
|
||||
monitorList: Monitor.ResPqMon[]
|
||||
checked: boolean // 是否已选择
|
||||
disabled: boolean // 是否禁用
|
||||
}
|
||||
|
||||
export interface SelectOption {
|
||||
label: string;
|
||||
value: string | number;
|
||||
label: string
|
||||
value: string | number
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export interface ResDev {
|
||||
id: string;
|
||||
name: string,
|
||||
icd: string,
|
||||
power: string,
|
||||
devVolt: number,
|
||||
devCurr: number,
|
||||
devChns: number,
|
||||
id: string
|
||||
name: string
|
||||
icd: string
|
||||
power: string
|
||||
devVolt: number
|
||||
devCurr: number
|
||||
devChns: number
|
||||
}
|
||||
|
||||
export interface ResTH {
|
||||
temperature :number | null;//温度
|
||||
humidity:number | null;//湿度
|
||||
temperature: number | null //温度
|
||||
humidity: number | null //湿度
|
||||
}
|
||||
/**
|
||||
* 被检设备表格查询分页返回的对象;
|
||||
*/
|
||||
export interface ResPqDevPage extends ResPage<ResPqDev> {
|
||||
|
||||
}
|
||||
export interface ResPqDevPage extends ResPage<ResPqDev> {}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ export namespace ICD {
|
||||
createTime?: string| null; //创建时间
|
||||
updateBy?: string| null; //更新用户
|
||||
updateTime?: string| null; //更新时间
|
||||
angle: number; // 是否支持电压相角、电流相角指标
|
||||
usePhaseIndex: number; // 角型接线时是否使用相别的指标来进行检测
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,7 @@ export namespace Monitor {
|
||||
connection: string; //接线方式,字典表
|
||||
statInterval: number; //统计间隔
|
||||
harmSysId: string; //默认与谐波系统监测点ID相同
|
||||
checkFlag: number;//是否参与检测0否1是
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type {ReqPage, ResPage} from '@/api/interface'
|
||||
import type { ReqPage, ResPage } from '@/api/interface'
|
||||
|
||||
// 标准设备模块
|
||||
export namespace StandardDevice {
|
||||
@@ -34,6 +34,7 @@ export namespace StandardDevice {
|
||||
createTime?: string | null; //创建时间
|
||||
updateBy?: string | null; //更新用户
|
||||
updateTime?: string | null; //更新时间
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { Monitor } from '@/api/device/interface/monitor'
|
||||
import http from '@/api'
|
||||
|
||||
/**
|
||||
@@ -6,23 +5,9 @@ import http from '@/api'
|
||||
*/
|
||||
|
||||
//获取监测点
|
||||
export const getPqMonList = (params: Monitor.ReqPqMonParams) => {
|
||||
//return http.post(`/pqMon/list`, params)
|
||||
}
|
||||
|
||||
//添加监测点
|
||||
export const addPqMon = (params: Monitor.ResPqMon) => {
|
||||
//return http.post(`/pqMon/add`, params)
|
||||
}
|
||||
|
||||
//编辑监测点
|
||||
export const updatePqMon = (params: Monitor.ResPqMon) => {
|
||||
//return http.post(`/pqMon/update`, params)
|
||||
}
|
||||
|
||||
//删除监测点
|
||||
export const deletePqMon = (params: string[]) => {
|
||||
//return http.post(`/pqMon/delete`, params)
|
||||
export const getPqMonList = (param:any) => {
|
||||
return http.post(`/pqMonitor/list`, param)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type {StandardDevice} from '@/api/device/interface/standardDevice'
|
||||
import type { StandardDevice } from '@/api/device/interface/standardDevice'
|
||||
import http from '@/api'
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,6 @@ export const deletePqStandardDev = (params: string[]) => {
|
||||
return http.post(`/pqStandardDev/delete`, params)
|
||||
}
|
||||
|
||||
|
||||
//导出标准设备
|
||||
export const exportPqStandardDev = (params: StandardDevice.ReqPqStandardDeviceParams) => {
|
||||
return http.download(`/pqStandardDev/export`, params)
|
||||
@@ -49,3 +48,8 @@ export const importPqStandardDev = (params: StandardDevice.ReqPqStandardDevicePa
|
||||
export const getAllPqStandardDev = () => {
|
||||
return http.get(`/pqStandardDev/getAll`)
|
||||
}
|
||||
|
||||
//获取可以绑定的标准设备
|
||||
export const canBindingList = () => {
|
||||
return http.get(`/pqStandardDev/canBindingList`)
|
||||
}
|
||||
|
||||
@@ -1,190 +1,242 @@
|
||||
import { ElMessage, ElTreeSelect } from 'element-plus';
|
||||
import axios, { AxiosInstance, AxiosError, AxiosRequestConfig, InternalAxiosRequestConfig, AxiosResponse } from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import axios, {
|
||||
AxiosError,
|
||||
type AxiosInstance,
|
||||
type AxiosRequestConfig,
|
||||
type AxiosResponse,
|
||||
type InternalAxiosRequestConfig
|
||||
} from 'axios'
|
||||
import { showFullScreenLoading, tryHideFullScreenLoading } from '@/components/Loading/fullScreen'
|
||||
import { LOGIN_URL } from '@/config'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ResultData } from '@/api/interface'
|
||||
import { type ResultData } from '@/api/interface'
|
||||
import { ResultEnum } from '@/enums/httpEnum'
|
||||
import { checkStatus } from './helper/checkStatus'
|
||||
import { useUserStore } from '@/stores/modules/user'
|
||||
import router from '@/routers'
|
||||
import {refreshToken} from '@/api/user/login'
|
||||
import { refreshToken } from '@/api/user/login'
|
||||
import { EventSourcePolyfill } from 'event-source-polyfill'
|
||||
|
||||
export interface CustomAxiosRequestConfig extends InternalAxiosRequestConfig {
|
||||
loading?: boolean;
|
||||
loading?: boolean
|
||||
}
|
||||
|
||||
const config = {
|
||||
// 默认地址请求地址,可在 .env.** 文件中修改
|
||||
baseURL: import.meta.env.VITE_API_URL as string,
|
||||
// 设置超时时间
|
||||
timeout: ResultEnum.TIMEOUT as number,
|
||||
// 跨域时候允许携带凭证
|
||||
withCredentials: true,
|
||||
// post请求指定数据类型以及编码
|
||||
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
||||
// 默认地址请求地址,可在 .env.** 文件中修改
|
||||
baseURL: import.meta.env.VITE_API_URL as string,
|
||||
// 设置超时时间
|
||||
timeout: ResultEnum.TIMEOUT as number,
|
||||
// 跨域时候允许携带凭证
|
||||
withCredentials: true,
|
||||
// post请求指定数据类型以及编码
|
||||
headers: { 'Content-Type': 'application/json;charset=utf-8' }
|
||||
}
|
||||
|
||||
class RequestHttp {
|
||||
service: AxiosInstance
|
||||
service: AxiosInstance
|
||||
|
||||
public constructor(config: AxiosRequestConfig) {
|
||||
// 创建实例
|
||||
this.service = axios.create(config)
|
||||
public constructor(config: AxiosRequestConfig) {
|
||||
// 创建实例
|
||||
this.service = axios.create(config)
|
||||
|
||||
/**
|
||||
* @description 请求拦截器
|
||||
* 客户端发送请求 -> [请求拦截器] -> 服务器
|
||||
* token校验(JWT) : 接受服务器返回的 token,存储到 vuex/pinia/本地储存当中
|
||||
*/
|
||||
this.service.interceptors.request.use(
|
||||
(config: CustomAxiosRequestConfig) => {
|
||||
isFirst = true
|
||||
const userStore = useUserStore()
|
||||
// 当前请求不需要显示 loading,在 api 服务中通过指定的第三个参数: { loading: false } 来控制
|
||||
config.loading ?? (config.loading = true)
|
||||
config.loading && showFullScreenLoading()
|
||||
if (config.headers && typeof config.headers.set === 'function') {
|
||||
config.headers.set('Authorization', 'Bearer ' + userStore.accessToken)
|
||||
config.headers.set('Is-Refresh-Token', userStore.isRefreshToken+"")
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
let isFirst = true
|
||||
/**
|
||||
* @description 响应拦截器
|
||||
* 服务器换返回信息 -> [拦截统一处理] -> 客户端JS获取到信息
|
||||
*/
|
||||
this.service.interceptors.response.use(
|
||||
async (response: AxiosResponse) => {
|
||||
const { data } = response
|
||||
const userStore = useUserStore()
|
||||
tryHideFullScreenLoading()
|
||||
|
||||
if(data.code === ResultEnum.ACCESSTOKEN_EXPIRED){
|
||||
// 用长token去换短token
|
||||
userStore.setAccessToken(userStore.refreshToken)
|
||||
userStore.setIsRefreshToken(true)
|
||||
const result = await refreshToken()
|
||||
if (result) { //获取新token成功的话
|
||||
// 有新的token后,重新请求
|
||||
userStore.setAccessToken(result.data.accessToken)
|
||||
userStore.setRefreshToken(result.data.refreshToken)
|
||||
userStore.setIsRefreshToken(false)
|
||||
userStore.setExp(1000 * 60 * 60 * 24 * 30)
|
||||
response.config.headers.Authorization = `Bearer ${result.data.accessToken}`//重新请求前需要将更新后的新token更换掉之前无效的token,不然会死循环
|
||||
const resp = await this.service.request(response.config)
|
||||
return resp
|
||||
} else {
|
||||
// 刷新失效,跳转登录页
|
||||
/**
|
||||
* @description 请求拦截器
|
||||
* 客户端发送请求 -> [请求拦截器] -> 服务器
|
||||
* token校验(JWT) : 接受服务器返回的 token,存储到 vuex/pinia/本地储存当中
|
||||
*/
|
||||
this.service.interceptors.request.use(
|
||||
(config: CustomAxiosRequestConfig) => {
|
||||
isFirst = true
|
||||
const userStore = useUserStore()
|
||||
// 当前请求不需要显示 loading,在 api 服务中通过指定的第三个参数: { loading: false } 来控制
|
||||
config.loading ?? (config.loading = true)
|
||||
config.loading && showFullScreenLoading()
|
||||
if (config.headers && typeof config.headers.set === 'function') {
|
||||
config.headers.set('Authorization', 'Bearer ' + userStore.accessToken)
|
||||
config.headers.set('Is-Refresh-Token', userStore.isRefreshToken + '')
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
// 登陆失效
|
||||
if (data.code === ResultEnum.OVERDUE) {
|
||||
console.log("登陆失效")
|
||||
userStore.setAccessToken('')
|
||||
userStore.setRefreshToken('')
|
||||
userStore.setIsRefreshToken(false)
|
||||
userStore.setUserInfo({ id:'',name: '' })
|
||||
userStore.setExp(0)
|
||||
await router.replace(LOGIN_URL)
|
||||
if(isFirst){//临时处理token失效弹窗多次
|
||||
ElMessage.error(data.message)
|
||||
isFirst = false
|
||||
}
|
||||
return Promise.reject(data)
|
||||
)
|
||||
|
||||
let isFirst = true
|
||||
/**
|
||||
* @description 响应拦截器
|
||||
* 服务器换返回信息 -> [拦截统一处理] -> 客户端JS获取到信息
|
||||
*/
|
||||
this.service.interceptors.response.use(
|
||||
async (response: AxiosResponse) => {
|
||||
const { data } = response
|
||||
const userStore = useUserStore()
|
||||
tryHideFullScreenLoading()
|
||||
|
||||
if (data.code === ResultEnum.ACCESSTOKEN_EXPIRED) {
|
||||
// 用长token去换短token
|
||||
userStore.setAccessToken(userStore.refreshToken)
|
||||
userStore.setIsRefreshToken(true)
|
||||
const result = await refreshToken()
|
||||
if (result) {
|
||||
//获取新token成功的话
|
||||
// 有新的token后,重新请求
|
||||
userStore.setAccessToken(result.data.accessToken)
|
||||
userStore.setRefreshToken(result.data.refreshToken)
|
||||
userStore.setIsRefreshToken(false)
|
||||
userStore.setExp(1000 * 60 * 60 * 24 * 30)
|
||||
response.config.headers.Authorization = `Bearer ${result.data.accessToken}` //重新请求前需要将更新后的新token更换掉之前无效的token,不然会死循环
|
||||
const resp = await this.service.request(response.config)
|
||||
return resp
|
||||
} else {
|
||||
// 刷新失效,跳转登录页
|
||||
}
|
||||
}
|
||||
// 登陆失效
|
||||
if (data.code === ResultEnum.OVERDUE) {
|
||||
//console.log('登陆失效')
|
||||
userStore.setAccessToken('')
|
||||
userStore.setRefreshToken('')
|
||||
userStore.setIsRefreshToken(false)
|
||||
userStore.setUserInfo({ id: '', name: '' })
|
||||
userStore.setExp(0)
|
||||
await router.replace(LOGIN_URL)
|
||||
if (isFirst) {
|
||||
//临时处理token失效弹窗多次
|
||||
ElMessage.error(data.message)
|
||||
isFirst = false
|
||||
}
|
||||
return Promise.reject(data)
|
||||
}
|
||||
// 全局错误信息拦截(防止下载文件的时候返回数据流,没有 code 直接报错)
|
||||
if (data.code && data.code !== ResultEnum.SUCCESS) {
|
||||
if (data.message.includes('&')) {
|
||||
let formattedMessage = data.message.split('&').join('<br>')
|
||||
if (data.message.includes(':')) {
|
||||
formattedMessage = formattedMessage.replace(':', '')
|
||||
}
|
||||
ElMessage.error({ message: formattedMessage, dangerouslyUseHTMLString: true })
|
||||
return Promise.reject(data)
|
||||
}
|
||||
|
||||
ElMessage.error(data.message)
|
||||
return Promise.reject(data)
|
||||
}
|
||||
// 成功请求(在页面上除非特殊情况,否则不用处理失败逻辑)
|
||||
|
||||
if (userStore.exp <= Date.now() && userStore.exp !== 0) {
|
||||
userStore.setAccessToken('')
|
||||
userStore.setRefreshToken('')
|
||||
userStore.setIsRefreshToken(false)
|
||||
userStore.setUserInfo({ id: '', name: '' })
|
||||
userStore.setExp(0)
|
||||
ElMessage.error('登录已过期,请重新登录!')
|
||||
await router.replace(LOGIN_URL)
|
||||
return Promise.reject(data)
|
||||
}
|
||||
// 对于blob类型的响应,返回完整的response对象以保留响应头
|
||||
if (response.config.responseType === 'blob') {
|
||||
return response
|
||||
}
|
||||
return data
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
const { response } = error
|
||||
tryHideFullScreenLoading()
|
||||
//console.log('error', error.message)
|
||||
// 请求超时 && 网络错误单独判断,没有 response
|
||||
if (error.message.indexOf('timeout') !== -1) ElMessage.error('请求超时!请您稍后重试')
|
||||
if (error.message.indexOf('Network Error') !== -1) ElMessage.error('网络错误!请您稍后重试')
|
||||
// 根据服务器响应的错误状态码,做不同的处理
|
||||
if (response) checkStatus(response.status)
|
||||
// 服务器结果都没有返回(可能服务器错误可能客户端断网),断网处理:可以跳转到断网页面
|
||||
if (!window.navigator.onLine) router.replace('/500')
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 常用请求方法封装
|
||||
*/
|
||||
get<T>(url: string, params?: object, _object = {}): Promise<ResultData<T>> {
|
||||
return this.service.get(url, { params, ..._object })
|
||||
}
|
||||
|
||||
post<T>(url: string, params?: object | string, _object = {}): Promise<ResultData<T>> {
|
||||
return this.service.post(url, params, _object)
|
||||
}
|
||||
|
||||
put<T>(url: string, params?: object, _object = {}): Promise<ResultData<T>> {
|
||||
return this.service.put(url, params, _object)
|
||||
}
|
||||
|
||||
delete<T>(url: string, params?: any, _object = {}): Promise<ResultData<T>> {
|
||||
return this.service.delete(url, { params, ..._object })
|
||||
}
|
||||
|
||||
download(url: string, params?: object, _object = {}): Promise<BlobPart> {
|
||||
return this.service.post(url, params, { ..._object, responseType: 'blob' }).then(res => res.data)
|
||||
}
|
||||
|
||||
downloadWithHeaders(url: string, params?: object, _object = {}): Promise<AxiosResponse<Blob>> {
|
||||
return this.service.post(url, params, { ..._object, responseType: 'blob' })
|
||||
}
|
||||
|
||||
upload(url: string, params?: object, _object = {}): Promise<BlobPart> {
|
||||
return this.service.post(url, params, {
|
||||
..._object,
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对excel的上传,默认返回的是blob类型,Excel没问题时返回json特殊处理
|
||||
*/
|
||||
uploadExcel(url: string, params?: object, _object = {}): Promise<BlobPart> {
|
||||
return this.service
|
||||
.post(url, params, {
|
||||
..._object,
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
responseType: 'blob'
|
||||
})
|
||||
.then(res => res.data)
|
||||
}
|
||||
|
||||
// 添加SSE连接方法
|
||||
sse(url: string, params?: any): EventSource {
|
||||
const userStore = useUserStore()
|
||||
// 构造带参数的URL
|
||||
let requestUrl = config.baseURL + url
|
||||
if (params) {
|
||||
const searchParams = new URLSearchParams()
|
||||
for (const key in params) {
|
||||
if (Object.prototype.hasOwnProperty.call(params, key)) {
|
||||
searchParams.append(key, String(params[key]))
|
||||
}
|
||||
}
|
||||
requestUrl += '?' + searchParams.toString()
|
||||
}
|
||||
// 全局错误信息拦截(防止下载文件的时候返回数据流,没有 code 直接报错)
|
||||
if (data.code && data.code !== ResultEnum.SUCCESS) {
|
||||
if(data.message.includes('&')){
|
||||
let formattedMessage = data.message.split('&').join('<br>');
|
||||
if (data.message.includes(':')) {
|
||||
formattedMessage = formattedMessage.replace(':', '')
|
||||
}
|
||||
ElMessage.error({ message: formattedMessage, dangerouslyUseHTMLString: true });
|
||||
return Promise.reject(data)
|
||||
}
|
||||
|
||||
ElMessage.error(data.message)
|
||||
return Promise.reject(data)
|
||||
}
|
||||
// 成功请求(在页面上除非特殊情况,否则不用处理失败逻辑)
|
||||
|
||||
if (userStore.exp <= Date.now() && userStore.exp !== 0) {
|
||||
userStore.setAccessToken('')
|
||||
userStore.setRefreshToken('')
|
||||
userStore.setIsRefreshToken(false)
|
||||
userStore.setUserInfo({ id:'',name: '' })
|
||||
userStore.setExp(0)
|
||||
ElMessage.error('登录已过期,请重新登录!')
|
||||
await router.replace(LOGIN_URL)
|
||||
return Promise.reject(data)
|
||||
}
|
||||
return data
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
const { response } = error
|
||||
tryHideFullScreenLoading()
|
||||
console.log('error', error.message)
|
||||
// 请求超时 && 网络错误单独判断,没有 response
|
||||
if (error.message.indexOf('timeout') !== -1) ElMessage.error('请求超时!请您稍后重试')
|
||||
if (error.message.indexOf('Network Error') !== -1) ElMessage.error('网络错误!请您稍后重试')
|
||||
// 根据服务器响应的错误状态码,做不同的处理
|
||||
if (response) checkStatus(response.status)
|
||||
// 服务器结果都没有返回(可能服务器错误可能客户端断网),断网处理:可以跳转到断网页面
|
||||
if (!window.navigator.onLine) router.replace('/500')
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 常用请求方法封装
|
||||
*/
|
||||
get<T>(url: string, params?: object, _object = {}): Promise<ResultData<T>> {
|
||||
return this.service.get(url, { params, ..._object })
|
||||
}
|
||||
|
||||
post<T>(url: string, params?: object | string, _object = {}): Promise<ResultData<T>> {
|
||||
return this.service.post(url, params, _object)
|
||||
}
|
||||
|
||||
put<T>(url: string, params?: object, _object = {}): Promise<ResultData<T>> {
|
||||
return this.service.put(url, params, _object)
|
||||
}
|
||||
|
||||
delete<T>(url: string, params?: any, _object = {}): Promise<ResultData<T>> {
|
||||
return this.service.delete(url, { params, ..._object })
|
||||
}
|
||||
|
||||
download(url: string, params?: object, _object = {}): Promise<BlobPart> {
|
||||
return this.service.post(url, params, { ..._object, responseType: 'blob' })
|
||||
}
|
||||
|
||||
upload(url: string, params?: object, _object = {}): Promise<BlobPart> {
|
||||
return this.service.post(url, params, {
|
||||
..._object,
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对excel的上传,默认返回的是blob类型,Excel没问题时返回json特殊处理
|
||||
*/
|
||||
uploadExcel(url: string, params?: object, _object = {}): Promise<BlobPart> {
|
||||
return this.service.post(url, params, {
|
||||
..._object,
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
responseType: 'blob',
|
||||
})
|
||||
}
|
||||
// 创建EventSource连接
|
||||
const eventSource = new EventSourcePolyfill(requestUrl, {
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + userStore.accessToken
|
||||
},
|
||||
// 增加超时时间到1200秒
|
||||
heartbeatTimeout: 1200000
|
||||
})
|
||||
|
||||
// 设置默认的Authorization头部
|
||||
eventSource.addEventListener('open', function () {
|
||||
//console.log('SSE连接已建立')
|
||||
})
|
||||
// 添加错误处理
|
||||
eventSource.addEventListener('error', function (err) {
|
||||
console.error('SSE连接错误:', err)
|
||||
})
|
||||
|
||||
return eventSource
|
||||
}
|
||||
}
|
||||
|
||||
export default new RequestHttp(config)
|
||||
|
||||
@@ -34,6 +34,11 @@ export namespace Plan {
|
||||
Check_By?:string;//计划检测人
|
||||
progress?: number; // 进度百分比,例如 75
|
||||
children?: ResPlan[];
|
||||
testConfig?: PlanTestConfig;
|
||||
importFlag?: number; // 导入标识,0-否,1-是
|
||||
leader?: string; // 负责人
|
||||
memberIds?: string | string[]; //成员
|
||||
members?: string; //成员字符串
|
||||
}
|
||||
|
||||
// 检测计划 + 分页
|
||||
@@ -42,8 +47,9 @@ export namespace Plan {
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface ReqPlan extends ResPlan {
|
||||
datasourceIds:string;
|
||||
datasourceIds:string | string[];
|
||||
sourceIds: string | null;
|
||||
planId:string;
|
||||
scriptName: string ;
|
||||
@@ -54,5 +60,14 @@ export namespace Plan {
|
||||
devIds: string[];
|
||||
}
|
||||
|
||||
export interface PlanTestConfig {
|
||||
planId: string;
|
||||
waveRecord: number;
|
||||
realTime: number;
|
||||
statistics: number;
|
||||
flicker: number;
|
||||
maxTime: number;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,54 +2,53 @@ import type { Plan } from './interface'
|
||||
import http from '@/api'
|
||||
import type { ErrorSystem } from '../device/interface/error'
|
||||
import type { Device } from '../device/interface/device'
|
||||
import { pa } from 'element-plus/es/locale/index.mjs'
|
||||
|
||||
/**
|
||||
* @name 检测计划管理模块
|
||||
*/
|
||||
// 获取检测计划列表
|
||||
export const getPlanList = (params: Plan.ReqPlanParams) => {
|
||||
return http.post(`/adPlan/list`, params)
|
||||
return http.post(`/adPlan/list`, params)
|
||||
}
|
||||
|
||||
// 新增检测计划
|
||||
export const addPlan = (params: any) => {
|
||||
return http.post(`/adPlan/add`, params)
|
||||
return http.post(`/adPlan/add`, params)
|
||||
}
|
||||
|
||||
// 编辑检测计划
|
||||
export const updatePlan = (params: any) => {
|
||||
return http.post(`/adPlan/update`, params)
|
||||
return http.post(`/adPlan/update`, params)
|
||||
}
|
||||
|
||||
// 删除检测计划
|
||||
export const deletePlan = (params: { id: string[] ,pattern: string}) => {
|
||||
return http.post(`/adPlan/delete?pattern=${params.pattern}`, params.id)
|
||||
export const deletePlan = (params: { id: string[]; pattern: string }) => {
|
||||
return http.post(`/adPlan/delete?pattern=${params.pattern}`, params.id)
|
||||
}
|
||||
|
||||
// 获取指定模式下所有检测源
|
||||
// 获取指定模式下所有检测源
|
||||
export const getTestSourceList = (params: Plan.ReqPlan) => {
|
||||
return http.get(`/pqSource/getAll?patternId=${params.pattern}`)
|
||||
return http.get(`/pqSource/getAll?patternId=${params.pattern}`)
|
||||
}
|
||||
|
||||
// 获取指定模式下所有检测脚本
|
||||
export const getPqScriptList = (params: Plan.ReqPlan) => {
|
||||
return http.get(`/pqScript/getAll?patternId=${params.pattern}`)
|
||||
return http.get(`/pqScript/getAll?patternId=${params.pattern}`)
|
||||
}
|
||||
|
||||
//获取所有误差体系
|
||||
export const getPqErrSysList = () => {
|
||||
return http.get<ErrorSystem.ErrorSystemList>(`/pqErrSys/getAll`)
|
||||
return http.get<ErrorSystem.ErrorSystemList>(`/pqErrSys/getAll`)
|
||||
}
|
||||
|
||||
//获取指定模式下所有未绑定的设备
|
||||
export const getUnboundPqDevList = (params: Plan.ReqPlan) => {
|
||||
return http.get(`/pqDev/listUnbound?pattern=${params.pattern}`)
|
||||
export const getUnboundPqDevList = (params: { pattern: string}) => {
|
||||
return http.get(`/pqDev/listUnbound?pattern=${params.pattern}`)
|
||||
}
|
||||
|
||||
//根据检测计划id查询出所有已绑定的设备
|
||||
export const getBoundPqDevList = (params: any) => {
|
||||
return http.post(`/adPlan/listByPlanId`, params)
|
||||
return http.post(`/adPlan/listByPlanId`, params)
|
||||
}
|
||||
|
||||
//检测计划绑定设备
|
||||
@@ -59,63 +58,105 @@ export const getBoundPqDevList = (params: any) => {
|
||||
|
||||
// 按照模式查询检测计划(用于首页展示)
|
||||
export const getPlanListByPattern = (params: Plan.ReqPlan) => {
|
||||
return http.get(`/adPlan/listByPattern?pattern=${params.pattern}`)
|
||||
return http.get(`/adPlan/listByPattern?pattern=${params.pattern}`)
|
||||
}
|
||||
|
||||
// 导出检测计划
|
||||
export const exportPlan = (params: Device.ReqPqDevParams) => {
|
||||
return http.download(`/adPlan/export`, params)
|
||||
return http.download(`/adPlan/export`, params)
|
||||
}
|
||||
|
||||
// 下载模板
|
||||
export const downloadTemplate = (params: { patternId: string }) => {
|
||||
return http.download(`/adPlan/downloadTemplate`, params)
|
||||
return http.download(`/adPlan/downloadTemplate`, params)
|
||||
}
|
||||
// 导入检测计划
|
||||
export const importPlan = (params: Device.ReqPqDevParams) => {
|
||||
return http.uploadExcel(`/adPlan/import`, params)
|
||||
return http.uploadExcel(`/adPlan/import`, params)
|
||||
}
|
||||
|
||||
// 装置检测报告生成
|
||||
export const generateDevReport = (params: Device.ReqDevReportParams) => {
|
||||
return http.post(`/report/generateReport`, params)
|
||||
return http.post(`/report/generateReport`, params)
|
||||
}
|
||||
|
||||
// 装置检测报告下载
|
||||
export const downloadDevData = (params: Device.ReqDevReportParams) => {
|
||||
return http.download(`/report/downloadReport`, params)
|
||||
return http.download(`/report/downloadReport`, params)
|
||||
}
|
||||
|
||||
// 装置检测报告下载(带响应头)
|
||||
export const downloadDevDataWithHeaders = (params: Device.ReqDevReportParams) => {
|
||||
return http.downloadWithHeaders(`/report/downloadReport`, params)
|
||||
}
|
||||
|
||||
export const staticsAnalyse = (params: { id: string[] }) => {
|
||||
return http.download('/adPlan/analyse', params)
|
||||
return http.download('/adPlan/analyse', params)
|
||||
}
|
||||
|
||||
//根据计划id分页查询被检设
|
||||
export const getDevListByPlanId = (params:any) => {
|
||||
return http.post(`/adPlan/listDevByPlanId`, params)
|
||||
export const getDevListByPlanId = (params: any) => {
|
||||
return http.post(`/adPlan/listDevByPlanId`, params)
|
||||
}
|
||||
|
||||
//修改子计划名称
|
||||
export const updateSubPlanName = (params:Plan.ReqPlan) => {
|
||||
return http.get(`/adPlan/updateSubPlanName?planId=${params.id}&name=${params.name}`)
|
||||
export const updateSubPlanName = (params: Plan.ReqPlan) => {
|
||||
return http.get(`/adPlan/updateSubPlanName?planId=${params.id}&name=${params.name}`)
|
||||
}
|
||||
|
||||
//子计划绑定/解绑标准设备
|
||||
export const subPlanBindStandardDevList = (params:Plan.ReqPlan) => {
|
||||
return http.post(`/adPlan/updateBindStandardDev`, params)
|
||||
export const subPlanBindStandardDevList = (params: Plan.ReqPlan) => {
|
||||
return http.post(`/adPlan/updateBindStandardDev`, params)
|
||||
}
|
||||
|
||||
//子计划绑定/解绑被检设备
|
||||
export const subPlanBindDev = (params:Plan.ReqPlan) => {
|
||||
return http.post(`/adPlan/updateBindDev`, params)
|
||||
export const subPlanBindDev = (params: Plan.ReqPlan) => {
|
||||
return http.post(`/adPlan/updateBindDev`, params)
|
||||
}
|
||||
|
||||
//根据父计划ID获取未被子计划绑定的标准设备
|
||||
export const getUnboundStandardDevList = (params:Plan.ResPlan) => {
|
||||
return http.get(`/adPlan/getUnBoundStandardDev?fatherPlanId=${params.fatherPlanId}`)
|
||||
export const getUnboundStandardDevList = (params: Plan.ResPlan) => {
|
||||
return http.get(`/adPlan/getUnBoundStandardDev?fatherPlanId=${params.fatherPlanId}`)
|
||||
}
|
||||
|
||||
//根据计划ID获取已绑定的标准设备
|
||||
export const getBoundStandardDevList = (params:Plan.ResPlan) => {
|
||||
return http.get(`/adPlan/getBoundStandardDev?planId=${params.id}`)
|
||||
export const getBoundStandardDevList = (params: Plan.ResPlan) => {
|
||||
return http.get(`/adPlan/getBoundStandardDev?planId=${params.id}`)
|
||||
}
|
||||
|
||||
//根据计划ID获取已绑定的所有标准设备
|
||||
export const getBoundStandardDevAllList = (params: { id: string }) => {
|
||||
return http.get(`/adPlan/getBoundStandardDev?planId=${params.id}&all=1`)
|
||||
}
|
||||
|
||||
// 导出子计划
|
||||
export const exportSubPlan = (params: Plan.ResPlan) => {
|
||||
return http.download(`/adPlan/exportSubPlan?planId=${params.id}`)
|
||||
}
|
||||
|
||||
// 导入子检测计划
|
||||
export const importSubPlan = (params: Plan.ResPlan) => {
|
||||
return http.upload(`/adPlan/importSubPlan`, params)
|
||||
}
|
||||
|
||||
// 导出计划检测结果数据
|
||||
export const exportPlanCheckData = (params: any) => {
|
||||
return http.post(
|
||||
`/adPlan/exportPlanCheckData?planId=${params.id}&devIds=${params.devIds}&report=${params.report}`
|
||||
)
|
||||
}
|
||||
|
||||
//根据误差体系id获取测试项
|
||||
export const getPqErrSysTestItemList = (params: {errorSysId : string}) => {
|
||||
return http.get(`/pqErrSys/getTestItems?id=${params.errorSysId}`)
|
||||
}
|
||||
|
||||
// 获取计划项目成员
|
||||
export const getMemberList = (params: {id : string}) => {
|
||||
return http.get(`/adPlan/getMemberList?planId=${params.id}`)
|
||||
}
|
||||
|
||||
// 导入并合并子检测计划检测结果数据
|
||||
export const importAndMergePlanCheckData = (params: Plan.ResPlan) => {
|
||||
return http.upload(`/adPlan/importAndMergePlanCheckData`, params)
|
||||
}
|
||||
51
frontend/src/api/result/interface/index.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
export interface MonitorResult {
|
||||
/**
|
||||
* 监测点id
|
||||
*/
|
||||
monitorId: string;
|
||||
|
||||
/**
|
||||
* 监测点序号
|
||||
*/
|
||||
monitorNum: number;
|
||||
|
||||
/**
|
||||
* 总检测次数
|
||||
*/
|
||||
totalNum: number;
|
||||
|
||||
/**
|
||||
* 合格检测次数
|
||||
*/
|
||||
qualifiedNum: number;
|
||||
|
||||
/**
|
||||
* 不合格检测次数
|
||||
*/
|
||||
unQualifiedNum: number;
|
||||
|
||||
/**
|
||||
* 误差体系名称
|
||||
*/
|
||||
errorSysName: string;
|
||||
|
||||
/**
|
||||
* 检测结果
|
||||
*/
|
||||
checkResult: number;
|
||||
|
||||
/**
|
||||
* 哪次
|
||||
*/
|
||||
whichTime: string;
|
||||
|
||||
/**
|
||||
* 结论来源
|
||||
*/
|
||||
resultOrigin: string;
|
||||
/**
|
||||
* 来源类型
|
||||
*/
|
||||
resultType: string;
|
||||
}
|
||||
7
frontend/src/api/result/result.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import http from '@/api'
|
||||
|
||||
export const getMonitorResult = (devId: string) => http.post(`/result/getMonitorResult?devId=${devId}`)
|
||||
export const getMonitorDataSourceResult = (monitorId: string) =>
|
||||
http.get(`/result/getMonitorDataSourceResult?monitorId=${monitorId}`)
|
||||
|
||||
export const updateMonitorResult = (data: any) => http.post('/result/updateMonitorResult', data)
|
||||
@@ -32,3 +32,15 @@ export const pauseTest = () => {
|
||||
export const resumeTest = (params) => {
|
||||
return http.post(`/prepare/restartTemTest/`, params, {loading: false})
|
||||
}
|
||||
|
||||
/**
|
||||
* 比对式通道配对
|
||||
* @param params
|
||||
*/
|
||||
export const contrastTest = (params: any) => {
|
||||
return http.post(`/prepare/startContrastTest`,params)
|
||||
}
|
||||
|
||||
export const exportAlignData= () => {
|
||||
return http.download(`/prepare/exportAlignData`)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import http from '@/api'
|
||||
import {type VersionRegister} from '@/api/system/versionRegister/interface'
|
||||
import { type VersionRegister } from '@/api/system/versionRegister/interface'
|
||||
|
||||
//获取有效数据配置
|
||||
export const getRegRes = (params: VersionRegister.ResSys_Reg_Res) => {
|
||||
export const getRegRes = (params: { type: string }) => {
|
||||
return http.get(`/sysRegRes/getRegResByType?id=${params.type}`)
|
||||
}
|
||||
|
||||
|
||||
//编辑有效数据配置
|
||||
export const updateRegRes = (params: VersionRegister.Sys_Reg_Res) => {
|
||||
return http.post(`/sysRegRes/update`, params)
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
// 登录模块
|
||||
import type { ReqPage,ResPage } from '@/api/interface'
|
||||
import type { ReqPage, ResPage } from '@/api/interface'
|
||||
|
||||
export namespace Login {
|
||||
export interface ReqLoginForm {
|
||||
username: string;
|
||||
password: string;
|
||||
checked: boolean;
|
||||
}
|
||||
export interface ResLogin {
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
userInfo:{
|
||||
id: string;
|
||||
name: string;
|
||||
export interface ReqLoginForm {
|
||||
username: string
|
||||
password: string
|
||||
checked: boolean
|
||||
}
|
||||
export interface ResLogin {
|
||||
accessToken: string
|
||||
refreshToken: string
|
||||
userInfo: {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
}
|
||||
export interface ResAuthButtons {
|
||||
[key: string]: string[]
|
||||
}
|
||||
}
|
||||
export interface ResAuthButtons {
|
||||
[key: string]: string[];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ export namespace User {
|
||||
updateTime?: string;//更新时间
|
||||
roleIds?: string[]; //
|
||||
roleNames?:string[]; //
|
||||
roleCodes?:string[]; //
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
// 用户接口
|
||||
|
||||
BIN
frontend/src/assets/images/inspected1.jpg
Normal file
|
After Width: | Height: | Size: 3.4 MiB |
BIN
frontend/src/assets/images/inspected2.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
@@ -1,19 +1,20 @@
|
||||
<template>
|
||||
<div class="not-container">
|
||||
<img src="@/assets/images/403.png" class="not-img" alt="403" />
|
||||
<div class="not-detail">
|
||||
<h2>403</h2>
|
||||
<h4>抱歉,您无权访问该页面~🙅♂️🙅♀️</h4>
|
||||
<el-button type="primary" @click="router.back"> 返回上一页 </el-button>
|
||||
<div class="not-container">
|
||||
<img src="@/assets/images/403.png" class="not-img" alt="403" />
|
||||
<div class="not-detail">
|
||||
<h2>403</h2>
|
||||
<h4>抱歉,您无权访问该页面~🙅♂️🙅♀️</h4>
|
||||
<el-button type="primary" @click="router.back">返回上一页</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="403">
|
||||
import { useRouter } from "vue-router";
|
||||
const router = useRouter();
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
<template>
|
||||
<div class="not-container">
|
||||
<img src="@/assets/images/404.png" class="not-img" alt="404" />
|
||||
<div class="not-detail">
|
||||
<h2>404</h2>
|
||||
<h4>抱歉,您访问的页面不存在~🤷♂️🤷♀️</h4>
|
||||
<el-button type="primary" @click="router.back"> 返回上一页 </el-button>
|
||||
<div class="not-container">
|
||||
<img src="@/assets/images/404.png" class="not-img" alt="404" />
|
||||
<div class="not-detail">
|
||||
<h2>404</h2>
|
||||
<h4>抱歉,您访问的页面不存在~🤷♂️🤷♀️</h4>
|
||||
<el-button type="primary" @click="router.back">返回上一页</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="404">
|
||||
import { useRouter } from "vue-router";
|
||||
const router = useRouter();
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
<template>
|
||||
<div class="not-container">
|
||||
<img src="@/assets/images/500.png" class="not-img" alt="500" />
|
||||
<div class="not-detail">
|
||||
<h2>500</h2>
|
||||
<h4>抱歉,您的网络不见了~🤦♂️🤦♀️</h4>
|
||||
<el-button type="primary" @click="router.back"> 返回上一页 </el-button>
|
||||
<div class="not-container">
|
||||
<img src="@/assets/images/500.png" class="not-img" alt="500" />
|
||||
<div class="not-detail">
|
||||
<h2>500</h2>
|
||||
<h4>抱歉,您的网络不见了~🤦♂️🤦♀️</h4>
|
||||
<el-button type="primary" @click="router.back">返回上一页</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="500">
|
||||
import { useRouter } from "vue-router";
|
||||
const router = useRouter();
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -1,59 +1,69 @@
|
||||
<template>
|
||||
<el-dialog v-model='dialogVisible' :title='`批量添加${parameter.title}`' :destroy-on-close='true' width='580px'
|
||||
draggable>
|
||||
<el-form class='drawer-multiColumn-form' label-width='100px'>
|
||||
<el-form-item label='模板下载 :'>
|
||||
<el-button type='primary' :icon='Download' @click='downloadTemp'> 点击下载</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label='文件上传 :'>
|
||||
<el-upload
|
||||
action='#'
|
||||
class='upload'
|
||||
:drag='true'
|
||||
:limit='excelLimit'
|
||||
:multiple='true'
|
||||
:show-file-list='true'
|
||||
:http-request='uploadExcel'
|
||||
:before-upload='beforeExcelUpload'
|
||||
:on-exceed='handleExceed'
|
||||
:accept="parameter.fileType!.join(',')"
|
||||
>
|
||||
<slot name='empty'>
|
||||
<el-icon class='el-icon--upload'>
|
||||
<upload-filled />
|
||||
</el-icon>
|
||||
<div class='el-upload__text'>将文件拖到此处,或<em>点击上传</em></div>
|
||||
</slot>
|
||||
<template #tip>
|
||||
<slot name='tip'>
|
||||
<div class='el-upload__tip'>请上传 .xls , .xlsx 标准格式文件,文件最大为 {{ parameter.fileSize }}M</div>
|
||||
</slot>
|
||||
</template>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
<el-form-item v-if='parameter.showCover' label='数据覆盖 :'>
|
||||
<el-switch v-model='isCover' />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-dialog>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="`批量添加${parameter.title}`"
|
||||
:destroy-on-close="true"
|
||||
width="580px"
|
||||
draggable
|
||||
>
|
||||
<el-form class="drawer-multiColumn-form" label-width="100px">
|
||||
<el-form-item label="模板下载 :">
|
||||
<el-button type="primary" :icon="Download" @click="downloadTemp">点击下载</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label="文件上传 :">
|
||||
<el-upload
|
||||
action="#"
|
||||
class="upload"
|
||||
:drag="true"
|
||||
:limit="excelLimit"
|
||||
:multiple="true"
|
||||
:show-file-list="true"
|
||||
:http-request="uploadExcel"
|
||||
:before-upload="beforeExcelUpload"
|
||||
:on-exceed="handleExceed"
|
||||
:accept="parameter.fileType!.join(',')"
|
||||
>
|
||||
<slot name="empty">
|
||||
<el-icon class="el-icon--upload">
|
||||
<upload-filled />
|
||||
</el-icon>
|
||||
<div class="el-upload__text">
|
||||
将文件拖到此处,或
|
||||
<em>点击上传</em>
|
||||
</div>
|
||||
</slot>
|
||||
<template #tip>
|
||||
<slot name="tip">
|
||||
<div class="el-upload__tip">
|
||||
请上传 .xls , .xlsx 标准格式文件,文件最大为 {{ parameter.fileSize }}M
|
||||
</div>
|
||||
</slot>
|
||||
</template>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="parameter.showCover" label="数据覆盖 :">
|
||||
<el-switch v-model="isCover" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang='ts' name='ImportExcel'>
|
||||
<script setup lang="ts" name="ImportExcel">
|
||||
import { ref } from 'vue'
|
||||
import { useDownload } from '@/hooks/useDownload'
|
||||
import { Download } from '@element-plus/icons-vue'
|
||||
import { ElNotification, UploadRequestOptions, UploadRawFile, ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElNotification, UploadRawFile, UploadRequestOptions } from 'element-plus'
|
||||
|
||||
export interface ExcelParameterProps {
|
||||
title: string; // 标题
|
||||
showCover?: boolean; // 是否显示”数据覆盖“选项
|
||||
patternId?: string; // 模式ID
|
||||
planId?: string | null ;//计划ID
|
||||
fileSize?: number; // 上传文件的大小
|
||||
fileType?: File.ExcelMimeType[]; // 上传文件的类型
|
||||
tempApi?: (params: any) => Promise<any>; // 下载模板的Api
|
||||
importApi?: (params: any) => Promise<any>; // 批量导入的Api
|
||||
getTableList?: () => void; // 获取表格数据的Api
|
||||
title: string // 标题
|
||||
showCover?: boolean // 是否显示”数据覆盖“选项
|
||||
patternId?: string // 模式ID
|
||||
planId?: string | null //计划ID
|
||||
fileSize?: number // 上传文件的大小
|
||||
fileType?: File.ExcelMimeType[] // 上传文件的类型
|
||||
tempApi?: (params: any) => Promise<any> // 下载模板的Api
|
||||
importApi?: (params: any) => Promise<any> // 批量导入的Api
|
||||
getTableList?: () => void // 获取表格数据的Api
|
||||
}
|
||||
|
||||
// 是否覆盖数据
|
||||
@@ -64,71 +74,77 @@ const excelLimit = ref(1)
|
||||
const dialogVisible = ref(false)
|
||||
// 父组件传过来的参数
|
||||
const parameter = ref<ExcelParameterProps>({
|
||||
title: '',
|
||||
fileSize: 5,
|
||||
fileType: ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
||||
title: '',
|
||||
fileSize: 5,
|
||||
fileType: ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'result', data: boolean): void
|
||||
}>()
|
||||
// 接收父组件参数
|
||||
const acceptParams = (params: ExcelParameterProps) => {
|
||||
parameter.value = { ...parameter.value, ...params }
|
||||
dialogVisible.value = true
|
||||
parameter.value = { ...parameter.value, ...params }
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
// Excel 导入模板下载
|
||||
const downloadTemp = () => {
|
||||
if (!parameter.value.tempApi) return
|
||||
useDownload(parameter.value.tempApi, `${parameter.value.title}模板`, {'pattern':parameter.value.patternId}, false)
|
||||
if (!parameter.value.tempApi) return
|
||||
useDownload(parameter.value.tempApi, `${parameter.value.title}模板`, { pattern: parameter.value.patternId }, false)
|
||||
}
|
||||
|
||||
// 文件上传
|
||||
const uploadExcel = async (param: UploadRequestOptions) => {
|
||||
let excelFormData = new FormData()
|
||||
excelFormData.append('file', param.file)
|
||||
if (parameter.value.patternId) {
|
||||
excelFormData.append('patternId', parameter.value.patternId)
|
||||
}
|
||||
let excelFormData = new FormData()
|
||||
excelFormData.append('file', param.file)
|
||||
if (parameter.value.patternId) {
|
||||
excelFormData.append('patternId', parameter.value.patternId)
|
||||
}
|
||||
|
||||
excelFormData.append('planId', parameter.value.planId)
|
||||
|
||||
isCover.value && excelFormData.append('isCover', isCover.value as unknown as Blob)
|
||||
//await parameter.value.importApi!(excelFormData);
|
||||
await parameter.value.importApi!(excelFormData)
|
||||
.then(res => handleImportResponse(res))
|
||||
parameter.value.getTableList && parameter.value.getTableList()
|
||||
dialogVisible.value = false
|
||||
excelFormData.append('planId', parameter.value.planId)
|
||||
|
||||
isCover.value && excelFormData.append('isCover', isCover.value as unknown as Blob)
|
||||
//await parameter.value.importApi!(excelFormData);
|
||||
await parameter.value.importApi!(excelFormData).then(res => handleImportResponse(res))
|
||||
|
||||
parameter.value.getTableList && parameter.value.getTableList()
|
||||
dialogVisible.value = false
|
||||
}
|
||||
|
||||
|
||||
async function handleImportResponse(res: any) {
|
||||
console.log(res)
|
||||
|
||||
if (res.type === 'application/json') {
|
||||
const fileReader = new FileReader()
|
||||
fileReader.onloadend = () => {
|
||||
try {
|
||||
const jsonData = JSON.parse(fileReader.result)
|
||||
if (jsonData.code === 'A0000') {
|
||||
ElMessage.success('导入成功')
|
||||
} else {
|
||||
ElMessage.error(jsonData.message)
|
||||
|
||||
if (res.type === 'application/json') {
|
||||
const fileReader = new FileReader()
|
||||
fileReader.onloadend = () => {
|
||||
try {
|
||||
const jsonData = JSON.parse(fileReader.result)
|
||||
if (jsonData.code === 'A0000') {
|
||||
ElMessage.success('导入成功')
|
||||
} else {
|
||||
ElMessageBox.alert(jsonData.message, {
|
||||
title: '导入结果',
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
emit('result', jsonData.data)
|
||||
} catch (err) {
|
||||
//console.log(err)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
fileReader.readAsText(res)
|
||||
} else {
|
||||
emit('result', false)
|
||||
ElMessage.error('导入失败,请查看下载附件!')
|
||||
let blob = new Blob([res], { type: 'application/vnd.ms-excel' })
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = '导入失败数据'
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
}
|
||||
fileReader.readAsText(res)
|
||||
} else {
|
||||
ElMessage.error('导入失败,请查看下载附件!')
|
||||
let blob = new Blob([res], { type: 'application/vnd.ms-excel' })
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = '导入失败数据'
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,32 +152,32 @@ async function handleImportResponse(res: any) {
|
||||
* @param file 上传的文件
|
||||
* */
|
||||
const beforeExcelUpload = (file: UploadRawFile) => {
|
||||
const isExcel = parameter.value.fileType!.includes(file.type as File.ExcelMimeType)
|
||||
const fileSize = file.size / 1024 / 1024 < parameter.value.fileSize!
|
||||
if (!isExcel)
|
||||
ElNotification({
|
||||
title: '温馨提示',
|
||||
message: '上传文件只能是 xls / xlsx 格式!',
|
||||
type: 'warning',
|
||||
})
|
||||
if (!fileSize)
|
||||
setTimeout(() => {
|
||||
ElNotification({
|
||||
title: '温馨提示',
|
||||
message: `上传文件大小不能超过 ${parameter.value.fileSize}MB!`,
|
||||
type: 'warning',
|
||||
})
|
||||
}, 0)
|
||||
return isExcel && fileSize
|
||||
const isExcel = parameter.value.fileType!.includes(file.type as File.ExcelMimeType)
|
||||
const fileSize = file.size / 1024 / 1024 < parameter.value.fileSize!
|
||||
if (!isExcel)
|
||||
ElNotification({
|
||||
title: '温馨提示',
|
||||
message: '上传文件只能是 xls / xlsx 格式!',
|
||||
type: 'warning'
|
||||
})
|
||||
if (!fileSize)
|
||||
setTimeout(() => {
|
||||
ElNotification({
|
||||
title: '温馨提示',
|
||||
message: `上传文件大小不能超过 ${parameter.value.fileSize}MB!`,
|
||||
type: 'warning'
|
||||
})
|
||||
}, 0)
|
||||
return isExcel && fileSize
|
||||
}
|
||||
|
||||
// 文件数超出提示
|
||||
const handleExceed = () => {
|
||||
ElNotification({
|
||||
title: '温馨提示',
|
||||
message: '最多只能上传一个文件!',
|
||||
type: 'warning',
|
||||
})
|
||||
ElNotification({
|
||||
title: '温馨提示',
|
||||
message: '最多只能上传一个文件!',
|
||||
type: 'warning'
|
||||
})
|
||||
}
|
||||
|
||||
// 上传错误提示
|
||||
@@ -183,9 +199,9 @@ const handleExceed = () => {
|
||||
// }
|
||||
|
||||
defineExpose({
|
||||
acceptParams,
|
||||
acceptParams
|
||||
})
|
||||
</script>
|
||||
<style lang='scss' scoped>
|
||||
@import "./index.scss";
|
||||
<style lang="scss" scoped>
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
3
frontend/src/components/ImportZip/index.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
.upload {
|
||||
width: 80%;
|
||||
}
|
||||
241
frontend/src/components/ImportZip/index.vue
Normal file
@@ -0,0 +1,241 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="parameter.title"
|
||||
:destroy-on-close="true"
|
||||
width="450px"
|
||||
:close-on-click-modal="!parameter.progressBar"
|
||||
:show-close="!disable"
|
||||
draggable
|
||||
>
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
action="#"
|
||||
class="upload"
|
||||
:limit="1"
|
||||
:http-request="uploadZip"
|
||||
accept=".zip"
|
||||
:auto-upload="!parameter.confirmMessage"
|
||||
:on-change="handleChange"
|
||||
:on-remove="handleRemove"
|
||||
:disabled="fileDisabled"
|
||||
>
|
||||
<slot name="empty">
|
||||
<el-button type="primary" :disabled="fileDisabled" icon="Upload">点击上传</el-button>
|
||||
</slot>
|
||||
<template #tip>
|
||||
<slot name="tip">
|
||||
<div class="el-upload__tip">请上传 .zip 标准格式文件</div>
|
||||
</slot>
|
||||
</template>
|
||||
</el-upload>
|
||||
|
||||
<el-text v-if="parameter.progressBar && progressData.status === 'exception'" size="small" type="danger">
|
||||
{{ progressData.message }}
|
||||
</el-text>
|
||||
<el-text v-if="parameter.progressBar && progressData.status === 'success'" size="small" type="success">
|
||||
{{ progressData.message }}
|
||||
</el-text>
|
||||
<el-text v-if="parameter.progressBar && progressData.status === ''" size="small" type="info">
|
||||
{{ progressData.message }}
|
||||
</el-text>
|
||||
<el-progress
|
||||
style="margin-top: 10px; margin-bottom: 10px"
|
||||
v-if="parameter.progressBar"
|
||||
:status="progressData.status"
|
||||
:percentage="progressData.percentage"
|
||||
:stroke-width="10"
|
||||
striped
|
||||
striped-flow
|
||||
></el-progress>
|
||||
|
||||
<template #footer v-if="parameter.confirmMessage">
|
||||
<el-button :disabled="disable" type="primary" @click="uploadSubmit">开始导入</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="ImportZip">
|
||||
import { ref } from 'vue'
|
||||
import type { UploadInstance, UploadProps, UploadRequestOptions } from 'element-plus'
|
||||
import http from '@/api'
|
||||
|
||||
export interface ZipParameterProps {
|
||||
title: string // 标题
|
||||
patternId?: string // 模式ID
|
||||
planId?: string // 计划ID
|
||||
importApi?: (params: any) => Promise<any> // 批量导入的Api
|
||||
confirmMessage?: string // 提示信息
|
||||
progressBar?: boolean // 进度条
|
||||
}
|
||||
// dialog状态
|
||||
const dialogVisible = ref(false)
|
||||
const disable = ref(true)
|
||||
const fileDisabled = ref(false)
|
||||
const uploadRef = ref<UploadInstance>()
|
||||
|
||||
// 父组件传过来的参数
|
||||
const parameter = ref<ZipParameterProps>({
|
||||
title: ''
|
||||
})
|
||||
const emit = defineEmits<{
|
||||
(e: 'result', data: boolean): void
|
||||
}>()
|
||||
// 接收父组件参数
|
||||
const acceptParams = (params: ZipParameterProps) => {
|
||||
parameter.value = { ...parameter.value, ...params }
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
// 文件上传
|
||||
const uploadZip = (param: UploadRequestOptions) => {
|
||||
let zipFormData = new FormData()
|
||||
zipFormData.append('file', param.file)
|
||||
if (parameter.value.patternId) {
|
||||
zipFormData.append('patternId', parameter.value.patternId)
|
||||
}
|
||||
if (parameter.value.planId) {
|
||||
zipFormData.append('planId', parameter.value.planId)
|
||||
}
|
||||
if (parameter.value.progressBar) {
|
||||
initSSE()
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
parameter.value.importApi!(zipFormData)
|
||||
.then(res => handleImportResponse(res))
|
||||
.catch(err => {
|
||||
fileDisabled.value = false
|
||||
disable.value = false
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const handleImportResponse = (res: any) => {
|
||||
if (!parameter.value.progressBar) {
|
||||
if (res.code === 'A0000') {
|
||||
ElMessage.success('导入成功')
|
||||
emit('result', true)
|
||||
dialogVisible.value = false
|
||||
} else {
|
||||
ElMessage.error(res.message)
|
||||
fileDisabled.value = false
|
||||
disable.value = false
|
||||
}
|
||||
} else {
|
||||
if (res.code !== 'A0000') {
|
||||
ElMessage.error(res.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const uploadSubmit = () => {
|
||||
if (!uploadRef.value) {
|
||||
return ElMessage.warning('请选择文件!')
|
||||
}
|
||||
progressData.value = {
|
||||
percentage: 0,
|
||||
status: '',
|
||||
message: ''
|
||||
}
|
||||
ElMessageBox.confirm(parameter.value.confirmMessage, '温馨提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(() => {
|
||||
disable.value = true
|
||||
fileDisabled.value = true
|
||||
uploadRef.value?.submit()
|
||||
})
|
||||
.catch(() => {
|
||||
disable.value = false
|
||||
fileDisabled.value = false
|
||||
})
|
||||
}
|
||||
const handleChange: UploadProps['onChange'] = (uploadFile, uploadFiles) => {
|
||||
disable.value = uploadFiles.length === 0
|
||||
progressData.value = {
|
||||
percentage: 0,
|
||||
status: '',
|
||||
message: ''
|
||||
}
|
||||
}
|
||||
const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
|
||||
disable.value = uploadFiles.length === 0
|
||||
progressData.value = {
|
||||
percentage: 0,
|
||||
status: '',
|
||||
message: ''
|
||||
}
|
||||
}
|
||||
|
||||
const progressData = ref({
|
||||
percentage: 0,
|
||||
status: '',
|
||||
message: ''
|
||||
})
|
||||
const eventSource = ref<EventSource | null>(null)
|
||||
|
||||
const initSSE = () => {
|
||||
eventSource.value = http.sse('/sse/createSse')
|
||||
|
||||
eventSource.value.onmessage = event => {
|
||||
// console.log('收到消息内容是:', event.data)
|
||||
const res = JSON.parse(event.data)
|
||||
progressData.value.percentage = res.data
|
||||
progressData.value.message = res.message
|
||||
if (res.code === 'A0002') {
|
||||
fileDisabled.value = false
|
||||
disable.value = false
|
||||
progressData.value.status = 'exception'
|
||||
ElMessage.error(res.message)
|
||||
}
|
||||
if (progressData.value.percentage === 100) {
|
||||
progressData.value.status = 'success'
|
||||
eventSource.value!.close()
|
||||
ElMessage.success('导入成功')
|
||||
emit('result', true)
|
||||
dialogVisible.value = false
|
||||
}
|
||||
}
|
||||
|
||||
eventSource.value.onerror = error => {
|
||||
console.warn('SSE 连接出错:', error)
|
||||
eventSource.value!.close()
|
||||
}
|
||||
}
|
||||
// 添加一个手动关闭EventSource的函数
|
||||
const closeEventSource = () => {
|
||||
if (eventSource.value) {
|
||||
eventSource.value.close()
|
||||
eventSource.value = null
|
||||
// console.log('SSE连接已关闭')
|
||||
}
|
||||
}
|
||||
// 监听 dialogVisible 的变化,确保在对话框关闭时清理资源
|
||||
watch(dialogVisible, newVal => {
|
||||
if (!newVal) {
|
||||
// 延迟执行,确保在组件完全关闭后清理
|
||||
setTimeout(() => {
|
||||
closeEventSource()
|
||||
fileDisabled.value = false
|
||||
disable.value = false
|
||||
progressData.value = {
|
||||
percentage: 0,
|
||||
status: '',
|
||||
message: ''
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
})
|
||||
onUnmounted(() => {
|
||||
closeEventSource()
|
||||
})
|
||||
defineExpose({
|
||||
acceptParams
|
||||
})
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@use './index.scss';
|
||||
</style>
|
||||
@@ -9,5 +9,5 @@
|
||||
<script setup lang="ts" name="Loading"></script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use "./index.scss";;
|
||||
</style>
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
<template>
|
||||
<div class='icon-box' >
|
||||
<el-input
|
||||
ref='inputRef'
|
||||
v-model='valueIcon'
|
||||
v-bind='$attrs'
|
||||
:placeholder='placeholder'
|
||||
:clearable='clearable'
|
||||
@clear='clearIcon'
|
||||
@click='openDialog'
|
||||
>
|
||||
<template #append>
|
||||
<el-button :icon='customIcons[iconValue]' />
|
||||
</template>
|
||||
</el-input>
|
||||
<el-dialog v-model='dialogVisible' :title='placeholder' top='5%' width='30%' >
|
||||
<el-input v-model='inputValue' placeholder='搜索图标' size='large' :prefix-icon='Icons.Search' />
|
||||
<el-scrollbar v-if='Object.keys(iconsList).length'>
|
||||
<div class='icon-list'>
|
||||
<div v-for='item in iconsList' :key='item' class='icon-item' @click='selectIcon(item)'>
|
||||
<component :is='item'></component>
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
<el-empty v-else description='未搜索到您要找的图标~' />
|
||||
</el-dialog>
|
||||
</div>
|
||||
<div class="icon-box">
|
||||
<el-input
|
||||
ref="inputRef"
|
||||
v-model="valueIcon"
|
||||
v-bind="$attrs"
|
||||
:placeholder="placeholder"
|
||||
:clearable="clearable"
|
||||
@clear="clearIcon"
|
||||
@click="openDialog"
|
||||
>
|
||||
<template #append>
|
||||
<el-button :icon="customIcons[iconValue]" />
|
||||
</template>
|
||||
</el-input>
|
||||
<el-dialog v-model="dialogVisible" :title="placeholder" top="5%" width="30%">
|
||||
<el-input v-model="inputValue" placeholder="搜索图标" size="large" :prefix-icon="Icons.Search" />
|
||||
<el-scrollbar v-if="Object.keys(iconsList).length">
|
||||
<div class="icon-list">
|
||||
<div v-for="item in iconsList" :key="item" class="icon-item" @click="selectIcon(item)">
|
||||
<component :is="item"></component>
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
<el-empty v-else description="未搜索到您要找的图标~" />
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang='ts' setup name='SelectIcon'>
|
||||
<script lang="ts" setup name="SelectIcon">
|
||||
import * as Icons from '@element-plus/icons-vue'
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
interface SelectIconProps {
|
||||
iconValue: string| undefined;
|
||||
title?: string;
|
||||
clearable?: boolean;
|
||||
placeholder?: string;
|
||||
iconValue: string | undefined
|
||||
title?: string
|
||||
clearable?: boolean
|
||||
placeholder?: string
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<SelectIconProps>(), {
|
||||
iconValue: '',
|
||||
title: '请选择图标',
|
||||
clearable: true,
|
||||
placeholder: '请选择图标',
|
||||
iconValue: '',
|
||||
title: '请选择图标',
|
||||
clearable: true,
|
||||
placeholder: '请选择图标'
|
||||
})
|
||||
|
||||
// 重新接收一下,防止打包后 clearable 报错
|
||||
@@ -55,37 +55,36 @@ const openDialog = () => (dialogVisible.value = true)
|
||||
|
||||
// 选择图标(触发更新父组件数据)
|
||||
const emit = defineEmits<{
|
||||
'update:iconValue': [value: string];
|
||||
'update:iconValue': [value: string]
|
||||
}>()
|
||||
const selectIcon = (item: any) => {
|
||||
dialogVisible.value = false
|
||||
valueIcon.value = item.name
|
||||
emit('update:iconValue', item.name)
|
||||
setTimeout(() => inputRef.value.blur(), 0)
|
||||
dialogVisible.value = false
|
||||
valueIcon.value = item.name
|
||||
emit('update:iconValue', item.name)
|
||||
setTimeout(() => inputRef.value.blur(), 0)
|
||||
}
|
||||
|
||||
// 清空图标
|
||||
const inputRef = ref()
|
||||
const clearIcon = () => {
|
||||
valueIcon.value = ''
|
||||
emit('update:iconValue', '')
|
||||
setTimeout(() => inputRef.value.blur(), 0)
|
||||
valueIcon.value = ''
|
||||
emit('update:iconValue', '')
|
||||
setTimeout(() => inputRef.value.blur(), 0)
|
||||
}
|
||||
|
||||
// 监听搜索框值
|
||||
const inputValue = ref('')
|
||||
const customIcons: { [key: string]: any } = Icons
|
||||
const iconsList = computed((): { [key: string]: any } => {
|
||||
if (!inputValue.value) return Icons
|
||||
let result: { [key: string]: any } = {}
|
||||
for (const key in customIcons) {
|
||||
if (key.toLowerCase().indexOf(inputValue.value.toLowerCase()) > -1) result[key] = customIcons[key]
|
||||
}
|
||||
return result
|
||||
if (!inputValue.value) return Icons
|
||||
let result: { [key: string]: any } = {}
|
||||
for (const key in customIcons) {
|
||||
if (key.toLowerCase().indexOf(inputValue.value.toLowerCase()) > -1) result[key] = customIcons[key]
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang='scss'>
|
||||
@import "./index.scss";
|
||||
<style scoped lang="scss">
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -1,97 +1,84 @@
|
||||
<template>
|
||||
<div class='time-control'>
|
||||
<el-select
|
||||
class='select'
|
||||
v-model='timeUnit'
|
||||
placeholder='选择时间单位'
|
||||
@change='handleChange'
|
||||
>
|
||||
<!-- 采用 v-for 动态渲染 -->
|
||||
<el-option
|
||||
v-for='unit in timeUnits'
|
||||
:key='unit.value'
|
||||
:label='unit.label'
|
||||
:value='unit.value'
|
||||
></el-option>
|
||||
</el-select>
|
||||
<div class="time-control">
|
||||
<el-select class="select" v-model="timeUnit" placeholder="选择时间单位" @change="handleChange">
|
||||
<!-- 采用 v-for 动态渲染 -->
|
||||
<el-option v-for="unit in timeUnits" :key="unit.value" :label="unit.label" :value="unit.value"></el-option>
|
||||
</el-select>
|
||||
|
||||
<!-- 禁用时间选择器 -->
|
||||
<div class='date-display'>
|
||||
<el-date-picker
|
||||
class='date-picker'
|
||||
v-model='startDate'
|
||||
type='date'
|
||||
placeholder='起始时间'
|
||||
@change='emitDateChange'
|
||||
:disabled-date='disableStartDate'
|
||||
:readonly="timeUnit != '自定义'"
|
||||
></el-date-picker>
|
||||
<el-text>~</el-text>
|
||||
<el-date-picker
|
||||
class='date-picker'
|
||||
v-model='endDate'
|
||||
type='date'
|
||||
placeholder='结束时间'
|
||||
@change='emitDateChange'
|
||||
:disabled-date='disableEndDate'
|
||||
:readonly="timeUnit !== '自定义'"
|
||||
></el-date-picker>
|
||||
<!-- 禁用时间选择器 -->
|
||||
<div class="date-display">
|
||||
<el-date-picker
|
||||
class="date-picker"
|
||||
v-model="startDate"
|
||||
type="date"
|
||||
placeholder="起始时间"
|
||||
@change="emitDateChange"
|
||||
:disabled-date="disableStartDate"
|
||||
:readonly="timeUnit != '自定义'"
|
||||
></el-date-picker>
|
||||
<el-text>~</el-text>
|
||||
<el-date-picker
|
||||
class="date-picker"
|
||||
v-model="endDate"
|
||||
type="date"
|
||||
placeholder="结束时间"
|
||||
@change="emitDateChange"
|
||||
:disabled-date="disableEndDate"
|
||||
:readonly="timeUnit !== '自定义'"
|
||||
></el-date-picker>
|
||||
</div>
|
||||
<div class="date-display" v-if="timeUnit !== '自定义'">
|
||||
<el-button
|
||||
style="width: 10px"
|
||||
class="triangle-button"
|
||||
type="primary"
|
||||
@click="prevPeriod"
|
||||
@change="emitDateChange"
|
||||
>
|
||||
<div class="left_triangle"></div>
|
||||
</el-button>
|
||||
<el-button class="triangle-button" type="primary" @click="goToCurrent">当前</el-button>
|
||||
<el-button
|
||||
style="width: 10px"
|
||||
class="triangle-button"
|
||||
type="primary"
|
||||
@click="nextPeriod"
|
||||
:disabled="isNextDisabled"
|
||||
>
|
||||
<div class="right_triangle"></div>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class='date-display' v-if="timeUnit !== '自定义'">
|
||||
<el-button
|
||||
style='width: 10px;'
|
||||
class='triangle-button'
|
||||
type='primary'
|
||||
@click='prevPeriod'
|
||||
@change='emitDateChange'
|
||||
>
|
||||
<div class='left_triangle'></div>
|
||||
</el-button>
|
||||
<el-button class='triangle-button' type='primary' @click='goToCurrent'>
|
||||
当前
|
||||
</el-button>
|
||||
<el-button
|
||||
style='width: 10px;'
|
||||
class='triangle-button'
|
||||
type='primary'
|
||||
@click='nextPeriod'
|
||||
:disabled='isNextDisabled'
|
||||
>
|
||||
<div class='right_triangle'></div>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script setup lang='ts'>
|
||||
import { ref, onMounted, defineProps, defineEmits } from 'vue'
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
// 定义时间单位的类型
|
||||
interface TimeUnit {
|
||||
label: string;
|
||||
value: string;
|
||||
label: string
|
||||
value: string
|
||||
}
|
||||
|
||||
// 定义组件的props,包含包括和排除的时间单位
|
||||
const props = defineProps({
|
||||
include: {
|
||||
type: Array as () => string[],
|
||||
default: () => ['日', '周', '月', '季度', '年', '自定义'],
|
||||
},
|
||||
exclude: {
|
||||
type: Array as () => string[],
|
||||
default: () => [],
|
||||
},
|
||||
default: {
|
||||
type: String,
|
||||
default: '月',
|
||||
},
|
||||
include: {
|
||||
type: Array as () => string[],
|
||||
default: () => ['日', '周', '月', '季度', '年', '自定义']
|
||||
},
|
||||
exclude: {
|
||||
type: Array as () => string[],
|
||||
default: () => []
|
||||
},
|
||||
default: {
|
||||
type: String,
|
||||
default: '月'
|
||||
}
|
||||
})
|
||||
|
||||
// 定义事件
|
||||
const emit = defineEmits<{
|
||||
(e: 'update-dates', startDate: string, endDate: string): void;
|
||||
(e: 'update-dates', startDate: string, endDate: string): void
|
||||
}>()
|
||||
const timeUnit = ref<string>(props.default) // 默认选择
|
||||
const startDate = ref<Date>(new Date()) // 起始日期
|
||||
@@ -100,219 +87,206 @@ const isNextDisabled = ref<boolean>(false) // 控制下一周期按钮的禁用
|
||||
const today = ref<Date>(new Date()) // 当前日期
|
||||
// 过滤出可用的时间单位
|
||||
const timeUnits = ref<TimeUnit[]>(
|
||||
props.include.filter(unit => !props.exclude.includes(unit)).map(unit => ({
|
||||
label: unit,
|
||||
value: unit,
|
||||
})),
|
||||
props.include
|
||||
.filter(unit => !props.exclude.includes(unit))
|
||||
.map(unit => ({
|
||||
label: unit,
|
||||
value: unit
|
||||
}))
|
||||
)
|
||||
|
||||
// 发出日期变化事件
|
||||
const emitDateChange = () => {
|
||||
emit('update-dates', formatDate(startDate.value), formatDate(endDate.value))
|
||||
|
||||
emit('update-dates', formatDate(startDate.value), formatDate(endDate.value))
|
||||
}
|
||||
|
||||
// 在组件挂载时更新日期范围
|
||||
onMounted(() => {
|
||||
updateDateRange()
|
||||
updateDateRange()
|
||||
})
|
||||
const handleChange = (unit: string) => {
|
||||
// 根据选择的时间单位处理日期变化
|
||||
if (unit !== '自定义') {
|
||||
updateDateRange()
|
||||
} else {
|
||||
// 自定义选项逻辑
|
||||
startDate.value = new Date(new Date().setDate(new Date().getDate() - 1))
|
||||
endDate.value = new Date()
|
||||
}
|
||||
timeUnit.value = unit
|
||||
// 根据选择的时间单位处理日期变化
|
||||
if (unit !== '自定义') {
|
||||
updateDateRange()
|
||||
} else {
|
||||
// 自定义选项逻辑
|
||||
startDate.value = new Date(new Date().setDate(new Date().getDate() - 1))
|
||||
endDate.value = new Date()
|
||||
}
|
||||
timeUnit.value = unit
|
||||
|
||||
// 确保开始时间和结束时间不为空
|
||||
if (!startDate.value) {
|
||||
startDate.value = new Date()
|
||||
}
|
||||
if (!endDate.value) {
|
||||
endDate.value = new Date()
|
||||
}
|
||||
startDate.value = new Date()
|
||||
}
|
||||
if (!endDate.value) {
|
||||
endDate.value = new Date()
|
||||
}
|
||||
|
||||
emitDateChange() // 变化时也发出更新事件
|
||||
updateNextButtonStatus()
|
||||
emitDateChange() // 变化时也发出更新事件
|
||||
updateNextButtonStatus()
|
||||
}
|
||||
const updateDateRange = () => {
|
||||
// 根据选择的时间单位计算起始和结束日期
|
||||
if (timeUnit.value === '日') {
|
||||
startDate.value = today.value
|
||||
endDate.value = today.value
|
||||
} else if (timeUnit.value === '周') {
|
||||
startDate.value = getStartOfWeek(today.value)
|
||||
endDate.value = getEndOfWeek(today.value)
|
||||
} else if (timeUnit.value === '月') {
|
||||
// 获取本月的开始和结束日期
|
||||
startDate.value = new Date(today.value.getFullYear(), today.value.getMonth(), 1)
|
||||
endDate.value = new Date(today.value.getFullYear(), today.value.getMonth() + 1, 0)
|
||||
|
||||
// 根据选择的时间单位计算起始和结束日期
|
||||
if (timeUnit.value === '日') {
|
||||
startDate.value = today.value
|
||||
endDate.value = today.value
|
||||
} else if (timeUnit.value === '周') {
|
||||
startDate.value = getStartOfWeek(today.value)
|
||||
endDate.value = getEndOfWeek(today.value)
|
||||
|
||||
} else if (timeUnit.value === '月') {
|
||||
// 获取本月的开始和结束日期
|
||||
startDate.value = new Date(today.value.getFullYear(), today.value.getMonth(), 1);
|
||||
endDate.value = new Date(today.value.getFullYear(), today.value.getMonth() + 1, 0);
|
||||
|
||||
// // 确保结束日期不超过今天
|
||||
// if (endDate.value > today.value) {
|
||||
// endDate.value = new Date(today.value);
|
||||
// endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999
|
||||
// }
|
||||
// // 确保结束日期不超过今天
|
||||
// if (endDate.value > today.value) {
|
||||
// endDate.value = new Date(today.value);
|
||||
// endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999
|
||||
// }
|
||||
} else if (timeUnit.value === '季度') {
|
||||
const quarter = Math.floor(today.value.getMonth() / 3)
|
||||
startDate.value = new Date(today.value.getFullYear(), quarter * 3, 1)
|
||||
endDate.value = new Date(today.value.getFullYear(), quarter * 3 + 3, 0)
|
||||
|
||||
} else if (timeUnit.value === '季度') {
|
||||
const quarter = Math.floor(today.value.getMonth() / 3);
|
||||
startDate.value = new Date(today.value.getFullYear(), quarter * 3, 1);
|
||||
endDate.value = new Date(today.value.getFullYear(), quarter * 3 + 3, 0);
|
||||
// // 确保结束日期不超过今天
|
||||
// if (endDate.value > today.value) {
|
||||
// endDate.value = new Date(today.value);
|
||||
// endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999
|
||||
// }
|
||||
} else if (timeUnit.value === '年') {
|
||||
startDate.value = new Date(today.value.getFullYear(), 0, 1)
|
||||
endDate.value = new Date(today.value.getFullYear(), 11, 31)
|
||||
|
||||
// // 确保结束日期不超过今天
|
||||
// if (endDate.value > today.value) {
|
||||
// endDate.value = new Date(today.value);
|
||||
// endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999
|
||||
// }
|
||||
// // 确保结束日期不超过今天
|
||||
// if (endDate.value > today.value) {
|
||||
|
||||
} else if (timeUnit.value === '年') {
|
||||
startDate.value = new Date(today.value.getFullYear(), 0, 1);
|
||||
endDate.value = new Date(today.value.getFullYear(), 11, 31);
|
||||
// endDate.value = new Date(today.value);
|
||||
// endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999
|
||||
// }
|
||||
}
|
||||
// 确保开始时间和结束时间不为空
|
||||
if (!startDate.value) {
|
||||
startDate.value = new Date()
|
||||
}
|
||||
if (!endDate.value) {
|
||||
endDate.value = new Date()
|
||||
}
|
||||
|
||||
// // 确保结束日期不超过今天
|
||||
// if (endDate.value > today.value) {
|
||||
|
||||
// endDate.value = new Date(today.value);
|
||||
// endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999
|
||||
// }
|
||||
}
|
||||
// 确保开始时间和结束时间不为空
|
||||
if (!startDate.value) {
|
||||
startDate.value = new Date()
|
||||
}
|
||||
if (!endDate.value) {
|
||||
endDate.value = new Date()
|
||||
}
|
||||
|
||||
updateNextButtonStatus()
|
||||
updateNextButtonStatus()
|
||||
}
|
||||
const getStartOfWeek = (date: Date) => {
|
||||
const startOfWeek = new Date(date)
|
||||
const day = startOfWeek.getDay()
|
||||
const diff = day === 0 ? -6 : 1 - day // 星期天的情况
|
||||
startOfWeek.setDate(startOfWeek.getDate() + diff)
|
||||
return startOfWeek
|
||||
const startOfWeek = new Date(date)
|
||||
const day = startOfWeek.getDay()
|
||||
const diff = day === 0 ? -6 : 1 - day // 星期天的情况
|
||||
startOfWeek.setDate(startOfWeek.getDate() + diff)
|
||||
return startOfWeek
|
||||
}
|
||||
const getEndOfWeek = (date: Date) => {
|
||||
const endOfWeek = new Date(date)
|
||||
const day = endOfWeek.getDay()
|
||||
const diff = day === 0 ? 0 : 7 - day // 星期天的情况
|
||||
endOfWeek.setDate(endOfWeek.getDate() + diff)
|
||||
const endOfWeek = new Date(date)
|
||||
const day = endOfWeek.getDay()
|
||||
const diff = day === 0 ? 0 : 7 - day // 星期天的情况
|
||||
endOfWeek.setDate(endOfWeek.getDate() + diff)
|
||||
|
||||
// 获取今天的日期
|
||||
const today = new Date();
|
||||
today.setHours(23, 59, 59, 999); // 设置今天的结束时间(23:59:59.999)
|
||||
// 获取今天的日期
|
||||
const today = new Date()
|
||||
today.setHours(23, 59, 59, 999) // 设置今天的结束时间(23:59:59.999)
|
||||
|
||||
// 返回不超过今天的结束时间
|
||||
//return endOfWeek > today ? today : endOfWeek;
|
||||
return endOfWeek
|
||||
// 返回不超过今天的结束时间
|
||||
//return endOfWeek > today ? today : endOfWeek;
|
||||
return endOfWeek
|
||||
}
|
||||
const prevPeriod = () => {
|
||||
const prevStartDate = new Date(startDate.value)
|
||||
const prevEndDate = new Date(endDate.value)
|
||||
const prevStartDate = new Date(startDate.value)
|
||||
const prevEndDate = new Date(endDate.value)
|
||||
|
||||
if (timeUnit.value === '日') {
|
||||
prevStartDate.setDate(prevStartDate.getDate() - 1)
|
||||
prevEndDate.setDate(prevEndDate.getDate() - 1)
|
||||
} else if (timeUnit.value === '周') {
|
||||
prevStartDate.setDate(prevStartDate.getDate() - 7)
|
||||
prevEndDate.setDate(prevEndDate.getDate() - 7)
|
||||
} else if (timeUnit.value === '月') {
|
||||
if (timeUnit.value === '日') {
|
||||
prevStartDate.setDate(prevStartDate.getDate() - 1)
|
||||
prevEndDate.setDate(prevEndDate.getDate() - 1)
|
||||
} else if (timeUnit.value === '周') {
|
||||
prevStartDate.setDate(prevStartDate.getDate() - 7)
|
||||
prevEndDate.setDate(prevEndDate.getDate() - 7)
|
||||
} else if (timeUnit.value === '月') {
|
||||
prevStartDate.setMonth(prevStartDate.getMonth() - 1)
|
||||
prevEndDate.setMonth(prevEndDate.getMonth() - 1)
|
||||
} else if (timeUnit.value === '季度') {
|
||||
prevStartDate.setMonth(prevStartDate.getMonth() - 3)
|
||||
prevEndDate.setMonth(prevEndDate.getMonth() - 3)
|
||||
} else if (timeUnit.value === '年') {
|
||||
prevStartDate.setFullYear(prevStartDate.getFullYear() - 1)
|
||||
prevEndDate.setFullYear(prevEndDate.getFullYear() - 1)
|
||||
}
|
||||
|
||||
|
||||
prevStartDate.setMonth(prevStartDate.getMonth() - 1)
|
||||
prevEndDate.setMonth(prevEndDate.getMonth() - 1)
|
||||
|
||||
|
||||
|
||||
} else if (timeUnit.value === '季度') {
|
||||
prevStartDate.setMonth(prevStartDate.getMonth() - 3)
|
||||
prevEndDate.setMonth(prevEndDate.getMonth() - 3)
|
||||
} else if (timeUnit.value === '年') {
|
||||
prevStartDate.setFullYear(prevStartDate.getFullYear() - 1)
|
||||
prevEndDate.setFullYear(prevEndDate.getFullYear() - 1)
|
||||
}
|
||||
|
||||
startDate.value = prevStartDate
|
||||
endDate.value = prevEndDate
|
||||
updateNextButtonStatus()
|
||||
startDate.value = prevStartDate
|
||||
endDate.value = prevEndDate
|
||||
updateNextButtonStatus()
|
||||
}
|
||||
const goToCurrent = () => {
|
||||
if (timeUnit.value !== '自定义') {
|
||||
updateDateRange() // 更新为当前选择时间单位的时间范围
|
||||
}
|
||||
if (timeUnit.value !== '自定义') {
|
||||
updateDateRange() // 更新为当前选择时间单位的时间范围
|
||||
}
|
||||
}
|
||||
const nextPeriod = () => {
|
||||
const nextStartDate = new Date(startDate.value)
|
||||
const nextEndDate = new Date(endDate.value)
|
||||
const nextStartDate = new Date(startDate.value)
|
||||
const nextEndDate = new Date(endDate.value)
|
||||
|
||||
if (timeUnit.value === '日') {
|
||||
nextStartDate.setDate(nextStartDate.getDate() + 1)
|
||||
nextEndDate.setDate(nextEndDate.getDate() + 1)
|
||||
} else if (timeUnit.value === '周') {
|
||||
nextStartDate.setDate(nextStartDate.getDate() + 7)
|
||||
nextEndDate.setDate(nextEndDate.getDate() + 7)
|
||||
} else if (timeUnit.value === '月') {
|
||||
nextStartDate.setMonth(nextStartDate.getMonth() + 1)
|
||||
nextEndDate.setMonth(nextEndDate.getMonth() + 1)
|
||||
} else if (timeUnit.value === '季度') {
|
||||
nextStartDate.setMonth(nextStartDate.getMonth() + 3)
|
||||
nextEndDate.setMonth(nextStartDate.getMonth() + 3)
|
||||
} else if (timeUnit.value === '年') {
|
||||
nextStartDate.setFullYear(nextStartDate.getFullYear() + 1)
|
||||
nextEndDate.setFullYear(nextEndDate.getFullYear() + 1)
|
||||
}
|
||||
if (timeUnit.value === '日') {
|
||||
nextStartDate.setDate(nextStartDate.getDate() + 1)
|
||||
nextEndDate.setDate(nextEndDate.getDate() + 1)
|
||||
} else if (timeUnit.value === '周') {
|
||||
nextStartDate.setDate(nextStartDate.getDate() + 7)
|
||||
nextEndDate.setDate(nextEndDate.getDate() + 7)
|
||||
} else if (timeUnit.value === '月') {
|
||||
nextStartDate.setMonth(nextStartDate.getMonth() + 1)
|
||||
nextEndDate.setMonth(nextEndDate.getMonth() + 1)
|
||||
} else if (timeUnit.value === '季度') {
|
||||
nextStartDate.setMonth(nextStartDate.getMonth() + 3)
|
||||
nextEndDate.setMonth(nextStartDate.getMonth() + 3)
|
||||
} else if (timeUnit.value === '年') {
|
||||
nextStartDate.setFullYear(nextStartDate.getFullYear() + 1)
|
||||
nextEndDate.setFullYear(nextEndDate.getFullYear() + 1)
|
||||
}
|
||||
|
||||
startDate.value = nextStartDate
|
||||
endDate.value = nextEndDate
|
||||
updateNextButtonStatus()
|
||||
startDate.value = nextStartDate
|
||||
endDate.value = nextEndDate
|
||||
updateNextButtonStatus()
|
||||
}
|
||||
const updateNextButtonStatus = () => {
|
||||
|
||||
// 更新下一个按钮的禁用状态
|
||||
const maxDate = new Date() // 假设最新日期为今天
|
||||
// 将 maxDate 设置为当天的开始时间
|
||||
maxDate.setHours(0, 0, 0, 0)
|
||||
// 将 endDate 设置为当天的开始时间并进行比较
|
||||
const endDateAdjusted = new Date(endDate.value)
|
||||
endDateAdjusted.setHours(0, 0, 0, 0)
|
||||
// 仅比较日期部分
|
||||
isNextDisabled.value = endDateAdjusted >= maxDate
|
||||
emitDateChange() // 变化时也发出更新事件
|
||||
// 更新下一个按钮的禁用状态
|
||||
const maxDate = new Date() // 假设最新日期为今天
|
||||
// 将 maxDate 设置为当天的开始时间
|
||||
maxDate.setHours(0, 0, 0, 0)
|
||||
// 将 endDate 设置为当天的开始时间并进行比较
|
||||
const endDateAdjusted = new Date(endDate.value)
|
||||
endDateAdjusted.setHours(0, 0, 0, 0)
|
||||
// 仅比较日期部分
|
||||
isNextDisabled.value = endDateAdjusted >= maxDate
|
||||
emitDateChange() // 变化时也发出更新事件
|
||||
}
|
||||
|
||||
|
||||
// 限制开始日期不能选择超过当前日期
|
||||
const disableStartDate = (date: Date) => {
|
||||
return date > today.value
|
||||
return date > today.value
|
||||
}
|
||||
// 限制结束日期不能超过当前日期且必须大于开始日期
|
||||
const disableEndDate = (date: Date) => {
|
||||
if (timeUnit.value !== '自定义') return false // 如果不是自定义时间单位,则不限制
|
||||
const start = new Date(startDate.value)
|
||||
return date > today.value || (start && date <= start)
|
||||
if (timeUnit.value !== '自定义') return false // 如果不是自定义时间单位,则不限制
|
||||
const start = new Date(startDate.value)
|
||||
return date > today.value || (start && date <= start)
|
||||
}
|
||||
|
||||
|
||||
// 格式化日期yyyy-mm-dd
|
||||
function formatDate(date: Date | null): string {
|
||||
if (!date) {
|
||||
return '';
|
||||
}
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
if (!date) {
|
||||
return ''
|
||||
}
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang='scss'>
|
||||
@import "./index.scss";
|
||||
<style scoped lang="scss">
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref, defineExpose, watch, nextTick } from 'vue'
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
// import echarts from './echarts'
|
||||
import * as echarts from 'echarts' // 全引入
|
||||
// import 'echarts/lib/component/dataZoom'
|
||||
|
||||
@@ -6,21 +6,24 @@ import { useAuthStore } from '@/stores/modules/auth'
|
||||
import type { Directive, DirectiveBinding } from 'vue'
|
||||
|
||||
const auth: Directive = {
|
||||
mounted(el: HTMLElement, binding: DirectiveBinding) {
|
||||
const { value } = binding
|
||||
const authStore = useAuthStore()
|
||||
const currentPageRoles = authStore.authButtonListGet[authStore.routeName] ?? []
|
||||
// console.log('1234',authStore.routeName)
|
||||
// console.log('123',currentPageRoles)
|
||||
if (value instanceof Array && value.length) {
|
||||
//console.log('123456',value)
|
||||
const hasPermission = value.every(item => currentPageRoles.includes(item))
|
||||
if (!hasPermission) el.remove()
|
||||
} else {
|
||||
//console.log('12345',value)
|
||||
if (!currentPageRoles.includes(value)) el.remove()
|
||||
mounted(el: HTMLElement, binding: DirectiveBinding) {
|
||||
//console.log('binding',binding)
|
||||
const { value, modifiers } = binding
|
||||
let currentPageRoles = []
|
||||
const authStore = useAuthStore()
|
||||
if (modifiers && Object.keys(modifiers).length) {
|
||||
currentPageRoles = authStore.authButtonListGet[Object.keys(modifiers)[0]] ?? []
|
||||
} else {
|
||||
currentPageRoles = authStore.authButtonListGet[authStore.routeName] ?? []
|
||||
}
|
||||
//console.log('currentPageRoles', currentPageRoles)
|
||||
if (value instanceof Array && value.length) {
|
||||
const hasPermission = value.every(item => currentPageRoles.includes(item))
|
||||
if (!hasPermission) el.remove()
|
||||
} else {
|
||||
if (!currentPageRoles.includes(value)) el.remove()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default auth
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ElNotification } from "element-plus";
|
||||
import type { AxiosResponse } from "axios";
|
||||
|
||||
/**
|
||||
* @description 接收数据流生成 blob,创建链接,下载文件
|
||||
@@ -8,6 +9,55 @@ import { ElNotification } from "element-plus";
|
||||
* @param {Boolean} isNotify 是否有导出消息提示 (默认为 true)
|
||||
* @param {String} fileType 导出的文件格式 (默认为.xlsx)
|
||||
* */
|
||||
/**
|
||||
* 从 Content-Disposition 头解析文件名
|
||||
*/
|
||||
const getFileNameFromContentDisposition = (contentDisposition: string | undefined | null): string | null => {
|
||||
if (!contentDisposition) return null;
|
||||
|
||||
// 优先匹配 filename*=UTF-8'' 格式(RFC 5987)
|
||||
const filenameStarRegex = /filename\*\s*=\s*UTF-8''([^;]+)/i;
|
||||
const starMatches = filenameStarRegex.exec(contentDisposition);
|
||||
|
||||
if (starMatches && starMatches[1]) {
|
||||
try {
|
||||
return decodeURIComponent(starMatches[1]);
|
||||
} catch (e) {
|
||||
console.warn('解码 filename* 失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 其次匹配 filename="文件名" 或 filename=文件名 格式
|
||||
const filenameRegex = /filename\s*=\s*([^;]+)/i;
|
||||
const matches = filenameRegex.exec(contentDisposition);
|
||||
|
||||
if (matches && matches[1]) {
|
||||
let filename = matches[1].trim();
|
||||
|
||||
// 去除引号
|
||||
filename = filename.replace(/^["']|["']$/g, "");
|
||||
|
||||
// 尝试解码 URL 编码的文件名
|
||||
try {
|
||||
// 检查是否包含 URL 编码字符
|
||||
if (filename.includes('%') || filename.includes('UTF-8')) {
|
||||
// 处理可能的 UTF-8 前缀
|
||||
if (filename.startsWith("UTF-8''") || filename.startsWith("utf-8''")) {
|
||||
filename = filename.substring(7);
|
||||
}
|
||||
filename = decodeURIComponent(filename);
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果解码失败,返回原始文件名
|
||||
console.warn('解码文件名失败,使用原始值:', e);
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const useDownload = async (
|
||||
api: (param: any) => Promise<any>,
|
||||
tempName: string,
|
||||
@@ -39,6 +89,73 @@ export const useDownload = async (
|
||||
document.body.removeChild(exportFile);
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
} catch (error) {
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description 支持服务器文件名的下载方法,会从 Content-Disposition 头获取文件名
|
||||
* @param {Function} api 导出表格的api方法 (必传)
|
||||
* @param {String} fallbackName 备用文件名,当服务器未提供时使用 (可选)
|
||||
* @param {Object} params 导出的参数 (默认{})
|
||||
* @param {Boolean} isNotify 是否有导出消息提示 (默认为 true)
|
||||
* @param {String} fallbackFileType 备用文件格式,当服务器未提供时使用 (默认为.xlsx)
|
||||
*/
|
||||
export const useDownloadWithServerFileName = async (
|
||||
api: (param: any) => Promise<AxiosResponse<Blob> | any>,
|
||||
fallbackName: string = "",
|
||||
params: any = {},
|
||||
isNotify: boolean = true,
|
||||
fallbackFileType: string = ".xlsx"
|
||||
) => {
|
||||
if (isNotify) {
|
||||
ElNotification({
|
||||
title: "温馨提示",
|
||||
message: "如果数据庞大会导致下载缓慢哦,请您耐心等待!",
|
||||
type: "info",
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
try {
|
||||
const res = await api(params);
|
||||
|
||||
// 检查响应是否包含 data 属性(AxiosResponse)还是直接是 Blob
|
||||
const blob = res.data ? new Blob([res.data]) : new Blob([res]);
|
||||
|
||||
// 尝试从响应头获取文件名(如果存在)
|
||||
let serverFileName: string | null = null;
|
||||
if (res.headers) {
|
||||
const headers = res.headers || {};
|
||||
const contentDisposition = headers['content-disposition'] || headers['Content-Disposition'];
|
||||
serverFileName = getFileNameFromContentDisposition(contentDisposition);
|
||||
}
|
||||
|
||||
// 确定最终使用的文件名
|
||||
let finalFileName: string;
|
||||
if (serverFileName) {
|
||||
finalFileName = serverFileName;
|
||||
} else if (fallbackName) {
|
||||
finalFileName = `${fallbackName}${fallbackFileType}`;
|
||||
} else {
|
||||
finalFileName = `download${fallbackFileType}`;
|
||||
}
|
||||
|
||||
// 兼容 edge 不支持 createObjectURL 方法
|
||||
if ("msSaveOrOpenBlob" in navigator) {
|
||||
return window.navigator.msSaveOrOpenBlob(blob, finalFileName);
|
||||
}
|
||||
|
||||
const blobUrl = window.URL.createObjectURL(blob);
|
||||
const exportFile = document.createElement("a");
|
||||
exportFile.style.display = "none";
|
||||
exportFile.download = finalFileName;
|
||||
exportFile.href = blobUrl;
|
||||
document.body.appendChild(exportFile);
|
||||
exportFile.click();
|
||||
// 去除下载对 url 的影响
|
||||
document.body.removeChild(exportFile);
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
} catch (error) {
|
||||
console.error('文件下载失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,63 +1,62 @@
|
||||
<!-- 经典布局 -->
|
||||
<template>
|
||||
<el-container class="layout">
|
||||
|
||||
<el-header>
|
||||
<div class="header-lf mask-image">
|
||||
<div class="logo flx-center">
|
||||
<img class="logo-img" src="@/assets/images/logo.svg" alt="logo" />
|
||||
<span class="logo-text">{{ title }}</span>
|
||||
</div>
|
||||
<ToolBarLeft />
|
||||
</div>
|
||||
<div class="header-ri">
|
||||
<ToolBarRight />
|
||||
</div>
|
||||
</el-header>
|
||||
<el-container class="classic-content">
|
||||
<el-aside>
|
||||
<div class="aside-box" :style="{ width: isCollapse ? '65px' : '210px' }">
|
||||
<el-scrollbar>
|
||||
<el-menu
|
||||
:router="false"
|
||||
:default-active="activeMenu"
|
||||
:collapse="isCollapse"
|
||||
:unique-opened="accordion"
|
||||
:collapse-transition="false"
|
||||
>
|
||||
<SubMenu :menu-list="menuList" />
|
||||
</el-menu>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
</el-aside>
|
||||
<el-container class="classic-main">
|
||||
<Main />
|
||||
</el-container>
|
||||
<el-container class="layout">
|
||||
<el-header>
|
||||
<div class="header-lf mask-image">
|
||||
<div class="logo flx-center">
|
||||
<img class="logo-img" src="@/assets/images/logo.svg" alt="logo" />
|
||||
<span class="logo-text">{{ title }}</span>
|
||||
</div>
|
||||
<ToolBarLeft />
|
||||
</div>
|
||||
<div class="header-ri">
|
||||
<ToolBarRight />
|
||||
</div>
|
||||
</el-header>
|
||||
<el-container class="classic-content">
|
||||
<el-aside>
|
||||
<div class="aside-box" :style="{ width: isCollapse ? '65px' : '210px' }">
|
||||
<el-scrollbar>
|
||||
<el-menu
|
||||
:router="false"
|
||||
:default-active="activeMenu"
|
||||
:collapse="isCollapse"
|
||||
:unique-opened="accordion"
|
||||
:collapse-transition="false"
|
||||
>
|
||||
<SubMenu :menu-list="menuList" />
|
||||
</el-menu>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
</el-aside>
|
||||
<el-container class="classic-main">
|
||||
<Main />
|
||||
</el-container>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="layoutClassic">
|
||||
import { computed } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { useAuthStore } from "@/stores/modules/auth";
|
||||
import { useGlobalStore } from "@/stores/modules/global";
|
||||
import Main from "@/layouts/components/Main/index.vue";
|
||||
import SubMenu from "@/layouts/components/Menu/SubMenu.vue";
|
||||
import ToolBarLeft from "@/layouts/components/Header/ToolBarLeft.vue";
|
||||
import ToolBarRight from "@/layouts/components/Header/ToolBarRight.vue";
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
import { useGlobalStore } from '@/stores/modules/global'
|
||||
import Main from '@/layouts/components/Main/index.vue'
|
||||
import SubMenu from '@/layouts/components/Menu/SubMenu.vue'
|
||||
import ToolBarLeft from '@/layouts/components/Header/ToolBarLeft.vue'
|
||||
import ToolBarRight from '@/layouts/components/Header/ToolBarRight.vue'
|
||||
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE;
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE
|
||||
|
||||
const route = useRoute();
|
||||
const authStore = useAuthStore();
|
||||
const globalStore = useGlobalStore();
|
||||
const accordion = computed(() => globalStore.accordion);
|
||||
const isCollapse = computed(() => globalStore.isCollapse);
|
||||
const menuList = computed(() => authStore.showMenuListGet);
|
||||
const activeMenu = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path) as string);
|
||||
const route = useRoute()
|
||||
const authStore = useAuthStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const accordion = computed(() => globalStore.accordion)
|
||||
const isCollapse = computed(() => globalStore.isCollapse)
|
||||
const menuList = computed(() => authStore.showMenuListGet)
|
||||
const activeMenu = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path) as string)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -1,103 +1,105 @@
|
||||
<!-- 分栏布局 -->
|
||||
<template>
|
||||
<el-container class="layout">
|
||||
<div class="aside-split">
|
||||
<div class="logo flx-center">
|
||||
<img class="logo-img" src="@/assets/images/logo.svg" alt="logo" />
|
||||
</div>
|
||||
<el-scrollbar>
|
||||
<div class="split-list">
|
||||
<div
|
||||
v-for="item in menuList"
|
||||
:key="item.path"
|
||||
class="split-item"
|
||||
:class="{ 'split-active': splitActive === item.path || `/${splitActive.split('/')[1]}` === item.path }"
|
||||
@click="changeSubMenu(item)"
|
||||
>
|
||||
<el-icon>
|
||||
<component :is="item.meta.icon"></component>
|
||||
</el-icon>
|
||||
<span class="title">{{ item.meta.title }}</span>
|
||||
</div>
|
||||
<el-container class="layout">
|
||||
<div class="aside-split">
|
||||
<div class="logo flx-center">
|
||||
<img class="logo-img" src="@/assets/images/logo.svg" alt="logo" />
|
||||
</div>
|
||||
<el-scrollbar>
|
||||
<div class="split-list">
|
||||
<div
|
||||
v-for="item in menuList"
|
||||
:key="item.path"
|
||||
class="split-item"
|
||||
:class="{
|
||||
'split-active': splitActive === item.path || `/${splitActive.split('/')[1]}` === item.path
|
||||
}"
|
||||
@click="changeSubMenu(item)"
|
||||
>
|
||||
<el-icon>
|
||||
<component :is="item.meta.icon"></component>
|
||||
</el-icon>
|
||||
<span class="title">{{ item.meta.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
<el-aside :class="{ 'not-aside': !subMenuList.length }" :style="{ width: isCollapse ? '65px' : '210px' }">
|
||||
<div class="logo flx-center">
|
||||
<span v-show="subMenuList.length" class="logo-text">{{ isCollapse ? "G" : title }}</span>
|
||||
</div>
|
||||
<el-scrollbar>
|
||||
<el-menu
|
||||
:router="false"
|
||||
:default-active="activeMenu"
|
||||
:collapse="isCollapse"
|
||||
:unique-opened="accordion"
|
||||
:collapse-transition="false"
|
||||
>
|
||||
<SubMenu :menu-list="subMenuList" />
|
||||
</el-menu>
|
||||
</el-scrollbar>
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-header>
|
||||
<ToolBarLeft />
|
||||
<ToolBarRight />
|
||||
</el-header>
|
||||
<Main />
|
||||
<el-aside :class="{ 'not-aside': !subMenuList.length }" :style="{ width: isCollapse ? '65px' : '210px' }">
|
||||
<div class="logo flx-center">
|
||||
<span v-show="subMenuList.length" class="logo-text">{{ isCollapse ? 'G' : title }}</span>
|
||||
</div>
|
||||
<el-scrollbar>
|
||||
<el-menu
|
||||
:router="false"
|
||||
:default-active="activeMenu"
|
||||
:collapse="isCollapse"
|
||||
:unique-opened="accordion"
|
||||
:collapse-transition="false"
|
||||
>
|
||||
<SubMenu :menu-list="subMenuList" />
|
||||
</el-menu>
|
||||
</el-scrollbar>
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-header>
|
||||
<ToolBarLeft />
|
||||
<ToolBarRight />
|
||||
</el-header>
|
||||
<Main />
|
||||
</el-container>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="layoutColumns">
|
||||
import { ref, computed, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useAuthStore } from "@/stores/modules/auth";
|
||||
import { useGlobalStore } from "@/stores/modules/global";
|
||||
import Main from "@/layouts/components/Main/index.vue";
|
||||
import ToolBarLeft from "@/layouts/components/Header/ToolBarLeft.vue";
|
||||
import ToolBarRight from "@/layouts/components/Header/ToolBarRight.vue";
|
||||
import SubMenu from "@/layouts/components/Menu/SubMenu.vue";
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
import { useGlobalStore } from '@/stores/modules/global'
|
||||
import Main from '@/layouts/components/Main/index.vue'
|
||||
import ToolBarLeft from '@/layouts/components/Header/ToolBarLeft.vue'
|
||||
import ToolBarRight from '@/layouts/components/Header/ToolBarRight.vue'
|
||||
import SubMenu from '@/layouts/components/Menu/SubMenu.vue'
|
||||
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE;
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const authStore = useAuthStore();
|
||||
const globalStore = useGlobalStore();
|
||||
const accordion = computed(() => globalStore.accordion);
|
||||
const isCollapse = computed(() => globalStore.isCollapse);
|
||||
const menuList = computed(() => authStore.showMenuListGet);
|
||||
const activeMenu = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path) as string);
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const authStore = useAuthStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const accordion = computed(() => globalStore.accordion)
|
||||
const isCollapse = computed(() => globalStore.isCollapse)
|
||||
const menuList = computed(() => authStore.showMenuListGet)
|
||||
const activeMenu = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path) as string)
|
||||
|
||||
const subMenuList = ref<Menu.MenuOptions[]>([]);
|
||||
const splitActive = ref("");
|
||||
const subMenuList = ref<Menu.MenuOptions[]>([])
|
||||
const splitActive = ref('')
|
||||
watch(
|
||||
() => [menuList, route],
|
||||
() => {
|
||||
// 当前菜单没有数据直接 return
|
||||
if (!menuList.value.length) return;
|
||||
splitActive.value = route.path;
|
||||
const menuItem = menuList.value.filter((item: Menu.MenuOptions) => {
|
||||
return route.path === item.path || `/${route.path.split("/")[1]}` === item.path;
|
||||
});
|
||||
if (menuItem[0].children?.length) return (subMenuList.value = menuItem[0].children);
|
||||
subMenuList.value = [];
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
);
|
||||
() => [menuList, route],
|
||||
() => {
|
||||
// 当前菜单没有数据直接 return
|
||||
if (!menuList.value.length) return
|
||||
splitActive.value = route.path
|
||||
const menuItem = menuList.value.filter((item: Menu.MenuOptions) => {
|
||||
return route.path === item.path || `/${route.path.split('/')[1]}` === item.path
|
||||
})
|
||||
if (menuItem[0].children?.length) return (subMenuList.value = menuItem[0].children)
|
||||
subMenuList.value = []
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
)
|
||||
|
||||
// change SubMenu
|
||||
const changeSubMenu = (item: Menu.MenuOptions) => {
|
||||
splitActive.value = item.path;
|
||||
if (item.children?.length) return (subMenuList.value = item.children);
|
||||
subMenuList.value = [];
|
||||
router.push(item.path);
|
||||
};
|
||||
splitActive.value = item.path
|
||||
if (item.children?.length) return (subMenuList.value = item.children)
|
||||
subMenuList.value = []
|
||||
router.push(item.path)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -1,85 +1,78 @@
|
||||
<!-- 横向布局 -->
|
||||
<template>
|
||||
<el-container class="layout">
|
||||
<el-header>
|
||||
<div class="logo flx-center">
|
||||
<!-- <img class="logo-img" src="@/assets/images/logo.svg" alt="logo" /> -->
|
||||
<img
|
||||
class="logo-img"
|
||||
src="@/assets/images/cn_pms9100_logo.png"
|
||||
alt="logo"
|
||||
/>
|
||||
<span class="logo-text">{{ title }} </span>
|
||||
</div>
|
||||
<el-menu v-if="showMenuFlag" trigger="click" mode="horizontal" :router="false" :default-active="activeMenu">
|
||||
<!-- 不能直接使用 SubMenu 组件,无法触发 el-menu 隐藏省略功能 -->
|
||||
<template v-for="subItem in menuList" :key="subItem.path">
|
||||
<el-sub-menu
|
||||
v-if="subItem.children?.length"
|
||||
:key="subItem.path"
|
||||
:index="subItem.path + 'el-sub-menu'"
|
||||
>
|
||||
<template #title>
|
||||
<el-icon>
|
||||
<component :is="subItem.meta.icon"></component>
|
||||
</el-icon>
|
||||
<span>{{ subItem.meta.title }}</span>
|
||||
</template>
|
||||
<SubMenu :menu-list="subItem.children" />
|
||||
</el-sub-menu>
|
||||
<el-menu-item
|
||||
v-else
|
||||
:key="subItem.path + 'el-menu-item'"
|
||||
:index="subItem.path"
|
||||
@click="handleClickMenu(subItem)"
|
||||
>
|
||||
<el-icon>
|
||||
<component :is="subItem.meta.icon"></component>
|
||||
</el-icon>
|
||||
<template #title>
|
||||
<span>{{ subItem.meta.title }}</span>
|
||||
</template>
|
||||
</el-menu-item>
|
||||
</template>
|
||||
</el-menu>
|
||||
<ToolBarRight />
|
||||
</el-header>
|
||||
<Main />
|
||||
|
||||
</el-container>
|
||||
<el-container class="layout">
|
||||
<el-header>
|
||||
<div class="logo flx-center">
|
||||
<!-- <img class="logo-img" src="@/assets/images/logo.svg" alt="logo" /> -->
|
||||
<img class="logo-img" src="@/assets/images/cn_pms9100_logo.png" alt="logo" />
|
||||
<span class="logo-text">{{ title }}</span>
|
||||
</div>
|
||||
<el-menu v-if="showMenuFlag" trigger="click" mode="horizontal" :router="false" :default-active="activeMenu">
|
||||
<!-- 不能直接使用 SubMenu 组件,无法触发 el-menu 隐藏省略功能 -->
|
||||
<template v-for="subItem in menuList" :key="subItem.path">
|
||||
<el-sub-menu
|
||||
v-if="subItem.children?.length"
|
||||
:key="subItem.path"
|
||||
:index="subItem.path + 'el-sub-menu'"
|
||||
>
|
||||
<template #title>
|
||||
<el-icon>
|
||||
<component :is="subItem.meta.icon"></component>
|
||||
</el-icon>
|
||||
<span>{{ subItem.meta.title }}</span>
|
||||
</template>
|
||||
<SubMenu :menu-list="subItem.children" />
|
||||
</el-sub-menu>
|
||||
<el-menu-item
|
||||
v-else
|
||||
:key="subItem.path + 'el-menu-item'"
|
||||
:index="subItem.path"
|
||||
@click="handleClickMenu(subItem)"
|
||||
>
|
||||
<el-icon>
|
||||
<component :is="subItem.meta.icon"></component>
|
||||
</el-icon>
|
||||
<template #title>
|
||||
<span>{{ subItem.meta.title }}</span>
|
||||
</template>
|
||||
</el-menu-item>
|
||||
</template>
|
||||
</el-menu>
|
||||
<ToolBarRight />
|
||||
</el-header>
|
||||
<Main />
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="layoutTransverse">
|
||||
import { computed } from "vue";
|
||||
import { useAuthStore } from "@/stores/modules/auth";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import Main from "@/layouts/components/Main/index.vue";
|
||||
import ToolBarRight from "@/layouts/components/Header/ToolBarRight.vue";
|
||||
import SubMenu from "@/layouts/components/Menu/SubMenu.vue";
|
||||
import { computed } from 'vue'
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import Main from '@/layouts/components/Main/index.vue'
|
||||
import ToolBarRight from '@/layouts/components/Header/ToolBarRight.vue'
|
||||
import SubMenu from '@/layouts/components/Menu/SubMenu.vue'
|
||||
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE;
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const authStore = useAuthStore();
|
||||
const menuList = computed(() => authStore.showMenuListGet);
|
||||
const showMenuFlag=computed(()=>authStore.showMenuFlagGet)
|
||||
const activeMenu = computed(
|
||||
() => (route.meta.activeMenu ? route.meta.activeMenu : route.path) as string
|
||||
);
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const authStore = useAuthStore()
|
||||
const menuList = computed(() => authStore.showMenuListGet)
|
||||
const showMenuFlag = computed(() => authStore.showMenuFlagGet)
|
||||
const activeMenu = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path) as string)
|
||||
|
||||
const handleClickMenu = (subItem: Menu.MenuOptions) => {
|
||||
if (subItem.meta.isLink) return window.open(subItem.meta.isLink, "_blank");
|
||||
router.push(subItem.path);
|
||||
};
|
||||
if (subItem.meta.isLink) return window.open(subItem.meta.isLink, '_blank')
|
||||
router.push(subItem.path)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
.logo{
|
||||
margin-right: 0 !important;
|
||||
@use './index.scss';
|
||||
.logo {
|
||||
margin-right: 0 !important;
|
||||
}
|
||||
.logo-text {
|
||||
letter-spacing: 2px;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
<!-- 纵向布局 -->
|
||||
<template>
|
||||
<el-container class="layout">
|
||||
<el-aside>
|
||||
<div class="aside-box" :style="{ width: isCollapse ? '65px' : '210px' }">
|
||||
<div class="logo flx-center">
|
||||
<img class="logo-img" src="@/assets/images/logo.svg" alt="logo" />
|
||||
<span v-show="!isCollapse" class="logo-text">{{ title }}</span>
|
||||
</div>
|
||||
<el-scrollbar>
|
||||
<el-menu
|
||||
:router="false"
|
||||
:default-active="activeMenu"
|
||||
:collapse="isCollapse"
|
||||
:unique-opened="accordion"
|
||||
:collapse-transition="false"
|
||||
>
|
||||
<SubMenu :menu-list="menuList" />
|
||||
</el-menu>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-header>
|
||||
<ToolBarLeft />
|
||||
<ToolBarRight />
|
||||
</el-header>
|
||||
<Main />
|
||||
<el-container class="layout">
|
||||
<el-aside>
|
||||
<div class="aside-box" :style="{ width: isCollapse ? '65px' : '210px' }">
|
||||
<div class="logo flx-center">
|
||||
<img class="logo-img" src="@/assets/images/logo.svg" alt="logo" />
|
||||
<span v-show="!isCollapse" class="logo-text">{{ title }}</span>
|
||||
</div>
|
||||
<el-scrollbar>
|
||||
<el-menu
|
||||
:router="false"
|
||||
:default-active="activeMenu"
|
||||
:collapse="isCollapse"
|
||||
:unique-opened="accordion"
|
||||
:collapse-transition="false"
|
||||
>
|
||||
<SubMenu :menu-list="menuList" />
|
||||
</el-menu>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-header>
|
||||
<ToolBarLeft />
|
||||
<ToolBarRight />
|
||||
</el-header>
|
||||
<Main />
|
||||
</el-container>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="layoutVertical">
|
||||
import { computed } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { useAuthStore } from "@/stores/modules/auth";
|
||||
import { useGlobalStore } from "@/stores/modules/global";
|
||||
import Main from "@/layouts/components/Main/index.vue";
|
||||
import ToolBarLeft from "@/layouts/components/Header/ToolBarLeft.vue";
|
||||
import ToolBarRight from "@/layouts/components/Header/ToolBarRight.vue";
|
||||
import SubMenu from "@/layouts/components/Menu/SubMenu.vue";
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
import { useGlobalStore } from '@/stores/modules/global'
|
||||
import Main from '@/layouts/components/Main/index.vue'
|
||||
import ToolBarLeft from '@/layouts/components/Header/ToolBarLeft.vue'
|
||||
import ToolBarRight from '@/layouts/components/Header/ToolBarRight.vue'
|
||||
import SubMenu from '@/layouts/components/Menu/SubMenu.vue'
|
||||
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE;
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE
|
||||
|
||||
const route = useRoute();
|
||||
const authStore = useAuthStore();
|
||||
const globalStore = useGlobalStore();
|
||||
const accordion = computed(() => globalStore.accordion);
|
||||
const isCollapse = computed(() => globalStore.isCollapse);
|
||||
const menuList = computed(() => authStore.showMenuListGet);
|
||||
const activeMenu = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path) as string);
|
||||
const route = useRoute()
|
||||
const authStore = useAuthStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const accordion = computed(() => globalStore.accordion)
|
||||
const isCollapse = computed(() => globalStore.isCollapse)
|
||||
const menuList = computed(() => authStore.showMenuListGet)
|
||||
const activeMenu = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path) as string)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -1,115 +1,127 @@
|
||||
<template>
|
||||
<div class="footer flx-align-center pl10">
|
||||
<el-dropdown>
|
||||
<!-- <span class="el-dropdown-link">
|
||||
{{ title }}
|
||||
<el-icon class="el-icon--right">
|
||||
<arrow-down />
|
||||
</el-icon>
|
||||
</span> -->
|
||||
<!-- <el-button dictType="primary"> -->
|
||||
<div class="change_mode">
|
||||
{{ title }}
|
||||
<el-icon class="el-icon--right change_mode_down"
|
||||
><arrow-down
|
||||
/></el-icon>
|
||||
<el-icon class="el-icon--right change_mode_up"><arrow-up /></el-icon>
|
||||
</div>
|
||||
<!-- </el-button> -->
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="handelOpen('模拟式')"
|
||||
>模拟式模块</el-dropdown-item
|
||||
>
|
||||
<el-dropdown-item @click="handelOpen('数字式')"
|
||||
>数字式模块</el-dropdown-item
|
||||
>
|
||||
<el-dropdown-item @click="handelOpen('比对式')"
|
||||
>比对式模块</el-dropdown-item
|
||||
>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<p style="margin: 0;" >
|
||||
<a href="http://www.shining-electric.com/" target="_blank">
|
||||
2024 © 南京灿能电力自动化股份有限公司
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="footer flx-align-center pl10">
|
||||
<el-dropdown>
|
||||
<div class="change_mode">
|
||||
{{ title }}
|
||||
<el-icon class="el-icon--right change_mode_down"><arrow-down /></el-icon>
|
||||
<el-icon class="el-icon--right change_mode_up"><arrow-up /></el-icon>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item
|
||||
v-for="item in modeList"
|
||||
:key="item.key"
|
||||
:disabled="!item.activated"
|
||||
@click="handelOpen(item.code, item.key)"
|
||||
>
|
||||
{{ item.name }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<p style="margin: 0">
|
||||
<a href="http://www.shining-electric.com/" target="_blank">2024 © 南京灿能电力自动化股份有限公司</a>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, computed, onMounted, watch } from "vue";
|
||||
import { useAuthStore } from "@/stores/modules/auth";
|
||||
import { useModeStore } from '@/stores/modules/mode'; // 引入模式 store
|
||||
import { useRouter } from "vue-router";
|
||||
const router = useRouter();
|
||||
const authStore = useAuthStore();
|
||||
const modeStore = useModeStore();
|
||||
import { computed } from 'vue'
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
import { useModeStore } from '@/stores/modules/mode' // 引入模式 store
|
||||
const authStore = useAuthStore()
|
||||
const modeStore = useModeStore()
|
||||
|
||||
const title = computed(() => {
|
||||
return modeStore.currentMode=== ''? '模拟式模块' : modeStore.currentMode+'模块';
|
||||
});
|
||||
|
||||
const handelOpen = async (item: string) => {
|
||||
await authStore.setShowMenu();
|
||||
modeStore.setCurrentMode(item); // 将模式code存入 store
|
||||
|
||||
//if (router.currentRoute.value.path === '/home/index') {
|
||||
// 强制刷新页面
|
||||
window.location.reload();
|
||||
//} else {
|
||||
// router.push({ path: '/home/index' });
|
||||
//}
|
||||
|
||||
};
|
||||
|
||||
return modeStore.currentMode === '' ? '选择模块' : modeStore.currentMode + '模块'
|
||||
})
|
||||
const activateInfo = authStore.activateInfo
|
||||
const isActivateOpen = import.meta.env.VITE_ACTIVATE_OPEN
|
||||
const modeList = [
|
||||
{
|
||||
name: '模拟式模块',
|
||||
code: '模拟式',
|
||||
key: 'simulate',
|
||||
activated:
|
||||
isActivateOpen === 'true'
|
||||
? activateInfo.simulate.apply === 1 && activateInfo.simulate.permanently === 1
|
||||
: true
|
||||
},
|
||||
{
|
||||
name: '数字式模块',
|
||||
code: '数字式',
|
||||
key: 'digital',
|
||||
activated:
|
||||
isActivateOpen === 'true'
|
||||
? activateInfo.digital.apply === 1 && activateInfo.digital.permanently === 1
|
||||
: true
|
||||
},
|
||||
{
|
||||
name: '比对式模块',
|
||||
code: '比对式',
|
||||
key: 'contrast',
|
||||
activated:
|
||||
isActivateOpen === 'true'
|
||||
? activateInfo.contrast.apply === 1 && activateInfo.contrast.permanently === 1
|
||||
: true
|
||||
}
|
||||
]
|
||||
const handelOpen = async (item: string, key: string) => {
|
||||
if (isActivateOpen === 'true' && (activateInfo[key].apply !== 1 || activateInfo[key].permanently !== 1)) {
|
||||
ElMessage.warning(`${item}模块未激活`)
|
||||
return
|
||||
}
|
||||
await authStore.setShowMenu()
|
||||
modeStore.setCurrentMode(item) // 将模式code存入 store
|
||||
// 强制刷新页面
|
||||
window.location.reload()
|
||||
}
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use './index.scss';
|
||||
.footer {
|
||||
position: relative;
|
||||
background-color: var(--el-color-primary);
|
||||
// .el-button:hover {
|
||||
// background-color: var(--el-color-primary) !important;
|
||||
// border: none !important;
|
||||
// outline: none !important;
|
||||
// }
|
||||
.change_mode {
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
height: 100%;
|
||||
width: auto;
|
||||
font-size: 14px;
|
||||
.change_mode_down {
|
||||
display: block;
|
||||
position: relative;
|
||||
background-color: var(--el-color-primary);
|
||||
// .el-button:hover {
|
||||
// background-color: var(--el-color-primary) !important;
|
||||
// border: none !important;
|
||||
// outline: none !important;
|
||||
// }
|
||||
.change_mode {
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
height: 100%;
|
||||
width: auto;
|
||||
font-size: 14px;
|
||||
.change_mode_down {
|
||||
display: block;
|
||||
}
|
||||
.change_mode_up {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
.change_mode_up {
|
||||
display: none;
|
||||
.change_mode:hover {
|
||||
.change_mode_down {
|
||||
display: none;
|
||||
}
|
||||
.change_mode_up {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
.change_mode:hover {
|
||||
.change_mode_down {
|
||||
display: none;
|
||||
.el-dropdown {
|
||||
z-index: 1001;
|
||||
}
|
||||
.change_mode_up {
|
||||
display: block;
|
||||
p {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
text-align: right;
|
||||
line-height: 40px;
|
||||
a {
|
||||
color: #fff;
|
||||
margin-right: 25px; // 增加右边距
|
||||
}
|
||||
}
|
||||
}
|
||||
.el-dropdown {
|
||||
z-index: 1001;
|
||||
}
|
||||
p {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
text-align: right;
|
||||
line-height: 40px;
|
||||
a {
|
||||
color: #fff;
|
||||
margin-right: 25px; // 增加右边距
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,218 +1,212 @@
|
||||
<template>
|
||||
<!-- <div class="userInfo">-->
|
||||
<!-- <div class="icon">-->
|
||||
<!-- <Avatar/>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="username">-->
|
||||
<!-- {{ username }}-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<el-dropdown trigger="click">
|
||||
<div class="userInfo">
|
||||
<div class="icon">
|
||||
<Avatar />
|
||||
</div>
|
||||
<div class="username">
|
||||
{{ username }}
|
||||
</div>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="openDialog('themeRef')">
|
||||
<el-icon><Sunny /></el-icon>{{ t("header.changeTheme") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="openDialog('infoRef')">
|
||||
<el-icon><User /></el-icon>{{ t("header.personalData") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="openDialog('passwordRef')">
|
||||
<el-icon><Edit /></el-icon>{{ t("header.changePassword") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="changeMode">
|
||||
<el-icon><Switch /></el-icon>{{ t("header.changeMode") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="openDialog('versionRegisterRef')">
|
||||
<el-icon><SetUp /></el-icon>{{ t("header.versionRegister") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown trigger="hover" placement="left-start" v-if="userStore.userInfo.loginName == 'root'">
|
||||
<div class="custom-dropdown-trigger">
|
||||
<el-icon><Tools /></el-icon>
|
||||
<span>{{ t("header.changeScene") }}</span>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item
|
||||
v-for="item in dictStore.getDictData('app_scene')"
|
||||
:key="item.value"
|
||||
:class="{
|
||||
'custom-dropdown-item': true,
|
||||
active: item.value === appSceneStore.currentScene
|
||||
}"
|
||||
@click="changeScene(item.value?? '')"
|
||||
:disabled = "item.value === appSceneStore.currentScene"
|
||||
>
|
||||
{{ item.name }}
|
||||
</el-dropdown-item>
|
||||
<!-- <div class="userInfo">-->
|
||||
<!-- <div class="icon">-->
|
||||
<!-- <Avatar/>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="username">-->
|
||||
<!-- {{ username }}-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<el-dropdown trigger="click">
|
||||
<div class="userInfo">
|
||||
<div class="icon">
|
||||
<Avatar />
|
||||
</div>
|
||||
<div class="username">
|
||||
{{ username }}
|
||||
</div>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="openDialog('themeRef')">
|
||||
<el-icon><Sunny /></el-icon>
|
||||
{{ t('header.changeTheme') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="openDialog('infoRef')">
|
||||
<el-icon><User /></el-icon>
|
||||
{{ t('header.personalData') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="openDialog('passwordRef')">
|
||||
<el-icon><Edit /></el-icon>
|
||||
{{ t('header.changePassword') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="changeMode" v-if="authStore.showMenuFlag">
|
||||
<el-icon><Switch /></el-icon>
|
||||
{{ t('header.changeMode') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="openDialog('versionRegisterRef')">
|
||||
<el-icon><SetUp /></el-icon>
|
||||
{{ t('header.versionRegister') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown trigger="hover" placement="left-start" v-if="userStore.userInfo.loginName == 'root'">
|
||||
<div class="custom-dropdown-trigger">
|
||||
<el-icon><Tools /></el-icon>
|
||||
<span>{{ t('header.changeScene') }}</span>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item
|
||||
v-for="item in dictStore.getDictData('app_scene')"
|
||||
:key="item.value"
|
||||
:class="{
|
||||
'custom-dropdown-item': true,
|
||||
active: item.value === appSceneStore.currentScene
|
||||
}"
|
||||
@click="changeScene(item.value ?? '')"
|
||||
:disabled="item.value === appSceneStore.currentScene"
|
||||
>
|
||||
{{ item.name }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<div class="avatar">
|
||||
<img src="@/assets/icons/out_login.svg" alt="avatar" @click="logout" />
|
||||
</div>
|
||||
<!-- infoDialog -->
|
||||
<InfoDialog ref="infoRef"></InfoDialog>
|
||||
<!-- passwordDialog -->
|
||||
<PasswordDialog ref="passwordRef"></PasswordDialog>
|
||||
<!-- versionRegisterDialog -->
|
||||
<VersionDialog ref="versionRegisterRef"></VersionDialog>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<div class="avatar">
|
||||
<img src="@/assets/icons/out_login.svg" alt="avatar" @click="logout" />
|
||||
</div>
|
||||
<!-- infoDialog -->
|
||||
<InfoDialog ref="infoRef"></InfoDialog>
|
||||
<!-- passwordDialog -->
|
||||
<PasswordDialog ref="passwordRef"></PasswordDialog>
|
||||
<!-- versionRegisterDialog -->
|
||||
<VersionDialog ref="versionRegisterRef"></VersionDialog>
|
||||
<!-- ThemeDialog -->
|
||||
<ThemeDialog ref="themeRef"></ThemeDialog>
|
||||
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { LOGIN_URL } from "@/config";
|
||||
import { useRouter } from "vue-router";
|
||||
import { logoutApi } from "@/api/user/login";
|
||||
import { useUserStore } from "@/stores/modules/user";
|
||||
import { ElMessageBox, ElMessage, CHANGE_EVENT } from "element-plus";
|
||||
import InfoDialog from "./InfoDialog.vue";
|
||||
import PasswordDialog from "./PasswordDialog.vue";
|
||||
import ThemeDialog from "./ThemeDialog.vue";
|
||||
import VersionDialog from "@/views/system/versionRegister/index.vue";
|
||||
import { computed } from "vue";
|
||||
import { ArrowLeft, Avatar, Delete, Document, Sunny, Switch ,Tools} from "@element-plus/icons-vue";
|
||||
import AssemblySize from "./components/AssemblySize.vue";
|
||||
import Language from "./components/Language.vue";
|
||||
import SearchMenu from "./components/SearchMenu.vue";
|
||||
import ThemeSetting from "./components/ThemeSetting.vue";
|
||||
import Message from "./components/Message.vue";
|
||||
import Fullscreen from "./components/Fullscreen.vue";
|
||||
import { useAuthStore } from "@/stores/modules/auth";
|
||||
import {useDictStore} from "@/stores/modules/dict";
|
||||
import { useModeStore,useAppSceneStore } from "@/stores/modules/mode";
|
||||
const userStore = useUserStore();
|
||||
const dictStore = useDictStore();
|
||||
const username = computed(() => userStore.userInfo.name);
|
||||
import { computed, ref } from 'vue'
|
||||
import { LOGIN_URL } from '@/config'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { logoutApi } from '@/api/user/login'
|
||||
import { useUserStore } from '@/stores/modules/user'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import InfoDialog from './InfoDialog.vue'
|
||||
import PasswordDialog from './PasswordDialog.vue'
|
||||
import ThemeDialog from './ThemeDialog.vue'
|
||||
import VersionDialog from '@/views/system/versionRegister/index.vue'
|
||||
import { Avatar, Sunny, Switch, Tools } from '@element-plus/icons-vue'
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
import { useDictStore } from '@/stores/modules/dict'
|
||||
import { useAppSceneStore, useModeStore } from '@/stores/modules/mode'
|
||||
import { useTheme } from '@/hooks/useTheme'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { updateScene } from '@/api/system/base/index'
|
||||
|
||||
const router = useRouter();
|
||||
const authStore = useAuthStore();
|
||||
const modeStore = useModeStore();
|
||||
const AppSceneStore = useAppSceneStore();
|
||||
import { useTheme } from "@/hooks/useTheme";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import {updateScene} from '@/api/system/base/index'
|
||||
const userStore = useUserStore()
|
||||
const dictStore = useDictStore()
|
||||
const username = computed(() => userStore.userInfo.name)
|
||||
|
||||
const router = useRouter()
|
||||
const authStore = useAuthStore()
|
||||
const modeStore = useModeStore()
|
||||
const AppSceneStore = useAppSceneStore()
|
||||
|
||||
const { changePrimary} = useTheme();
|
||||
const { changePrimary } = useTheme()
|
||||
|
||||
// 初始化 i18n
|
||||
const { t } = useI18n(); // 使用 t 方法替代 $t
|
||||
const { t } = useI18n() // 使用 t 方法替代 $t
|
||||
|
||||
// 退出登录
|
||||
const logout = () => {
|
||||
ElMessageBox.confirm("您是否确认退出登录?", "温馨提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
}).then(async () => {
|
||||
// 1.执行退出登录接口
|
||||
await logoutApi();
|
||||
// 2.清除 Token
|
||||
userStore.setAccessToken("");
|
||||
userStore.setRefreshToken("");
|
||||
userStore.setExp(0)
|
||||
userStore.setUserInfo({id: "", name: ""});
|
||||
userStore.setIsRefreshToken(false)
|
||||
dictStore.setDictData([]);
|
||||
modeStore.setCurrentMode('');
|
||||
AppSceneStore.setCurrentMode('');
|
||||
// 3.重定向到登陆页
|
||||
router.replace(LOGIN_URL);
|
||||
ElMessage.success("退出登录成功!");
|
||||
//重置菜单/导航栏权限
|
||||
authStore.resetAuthStore();
|
||||
});
|
||||
};
|
||||
ElMessageBox.confirm('您是否确认退出登录?', '温馨提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
// 1.执行退出登录接口
|
||||
await logoutApi()
|
||||
// 2.清除 Token
|
||||
userStore.setAccessToken('')
|
||||
userStore.setRefreshToken('')
|
||||
userStore.setExp(0)
|
||||
userStore.setUserInfo({ id: '', name: '' })
|
||||
userStore.setIsRefreshToken(false)
|
||||
dictStore.setDictData([])
|
||||
modeStore.setCurrentMode('')
|
||||
AppSceneStore.setCurrentMode('')
|
||||
// 3.重定向到登陆页
|
||||
ElMessage.success('退出登录成功!')
|
||||
//重置菜单/导航栏权限
|
||||
await authStore.resetAuthStore()
|
||||
await router.push(LOGIN_URL)
|
||||
})
|
||||
}
|
||||
|
||||
// 打开修改密码和个人信息弹窗
|
||||
const infoRef = ref<InstanceType<typeof InfoDialog> | null>(null);
|
||||
const passwordRef = ref<InstanceType<typeof PasswordDialog> | null>(null);
|
||||
const versionRegisterRef = ref<InstanceType<typeof VersionDialog> | null>(null);
|
||||
const themeRef = ref<InstanceType<typeof ThemeDialog> | null>(null);
|
||||
const infoRef = ref<InstanceType<typeof InfoDialog> | null>(null)
|
||||
const passwordRef = ref<InstanceType<typeof PasswordDialog> | null>(null)
|
||||
const versionRegisterRef = ref<InstanceType<typeof VersionDialog> | null>(null)
|
||||
const themeRef = ref<InstanceType<typeof ThemeDialog> | null>(null)
|
||||
const openDialog = (ref: string) => {
|
||||
if (ref == "infoRef") infoRef.value?.openDialog();
|
||||
if (ref == "passwordRef") passwordRef.value?.openDialog();
|
||||
if (ref == "versionRegisterRef") versionRegisterRef.value?.openDialog();
|
||||
if (ref == "themeRef") themeRef.value?.openDialog();
|
||||
|
||||
};
|
||||
if (ref == 'infoRef') infoRef.value?.openDialog()
|
||||
if (ref == 'passwordRef') passwordRef.value?.openDialog()
|
||||
if (ref == 'versionRegisterRef') versionRegisterRef.value?.openDialog()
|
||||
if (ref == 'themeRef') themeRef.value?.openDialog()
|
||||
}
|
||||
|
||||
|
||||
const appSceneStore = useAppSceneStore();
|
||||
const appSceneStore = useAppSceneStore()
|
||||
|
||||
const changeScene = async (value: string) => {
|
||||
appSceneStore.setCurrentMode(value);
|
||||
await updateScene({scene :dictStore.getDictData('app_scene').find(item => item.value == value)?.id});
|
||||
// 强制刷新页面
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
appSceneStore.setCurrentMode(value)
|
||||
await updateScene({ scene: dictStore.getDictData('app_scene').find(item => item.value == value)?.id })
|
||||
// 强制刷新页面
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
//模式切换
|
||||
const changeMode = () => {
|
||||
authStore.changeModel();
|
||||
};
|
||||
authStore.changeModel()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.userInfo {
|
||||
min-width: 80px;
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
.icon {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
color: #fff !important;
|
||||
}
|
||||
.username {
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
min-width: 80px;
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
.icon {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
color: #fff !important;
|
||||
}
|
||||
.username {
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
cursor: pointer;
|
||||
// border-radius: 50%;
|
||||
img {
|
||||
// width: 100%;
|
||||
// height: 100%;
|
||||
}
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
cursor: pointer;
|
||||
// border-radius: 50%;
|
||||
img {
|
||||
// width: 100%;
|
||||
// height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-dropdown-trigger {
|
||||
padding: 8px 15px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 15px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
:deep(.el-dropdown-menu__item.custom-dropdown-item.active),
|
||||
:deep(.el-dropdown-menu__item.custom-dropdown-item.active:hover) {
|
||||
background-color: var(--el-color-primary-light-9) !important;
|
||||
color: var(--el-color-primary)
|
||||
background-color: var(--el-color-primary-light-9) !important;
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,84 +1,81 @@
|
||||
<template>
|
||||
<Maximize v-show="maximize" />
|
||||
<Tabs v-if="tabs && showMenuFlag" />
|
||||
<el-main>
|
||||
<router-view v-slot="{ Component, route }" style="height:100%;">
|
||||
<!-- {{ keepAliveName}} -->
|
||||
<!-- <transition name="slide-right" mode="out-in"> -->
|
||||
<keep-alive :include="tabsMenuList" >
|
||||
<component :is="Component" :key="route.fullPath" />
|
||||
</keep-alive>
|
||||
<!-- </transition> -->
|
||||
</router-view>
|
||||
</el-main>
|
||||
<el-footer>
|
||||
<Footer />
|
||||
</el-footer>
|
||||
<Maximize v-show="maximize" />
|
||||
<Tabs v-if="tabs && showMenuFlag" />
|
||||
<el-main>
|
||||
<router-view v-slot="{ Component, route }" style="height: 100%">
|
||||
<!-- {{ keepAliveName}} -->
|
||||
<!-- <transition name="slide-right" mode="out-in"> -->
|
||||
<keep-alive :include="tabsMenuList">
|
||||
<component :is="Component" :key="route.fullPath" />
|
||||
</keep-alive>
|
||||
<!-- </transition> -->
|
||||
</router-view>
|
||||
</el-main>
|
||||
<el-footer>
|
||||
<Footer />
|
||||
</el-footer>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onBeforeUnmount, provide, watch, computed } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useDebounceFn } from "@vueuse/core";
|
||||
import { useGlobalStore } from "@/stores/modules/global";
|
||||
import { useKeepAliveStore } from "@/stores/modules/keepAlive";
|
||||
import Maximize from "./components/Maximize.vue";
|
||||
import Tabs from "@/layouts/components/Tabs/index.vue";
|
||||
import Footer from "@/layouts/components/Footer/index.vue";
|
||||
import { useAuthStore } from "@/stores/modules/auth";
|
||||
import { computed, onBeforeUnmount, provide, ref, watch } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useDebounceFn } from '@vueuse/core'
|
||||
import { useGlobalStore } from '@/stores/modules/global'
|
||||
import { useKeepAliveStore } from '@/stores/modules/keepAlive'
|
||||
import Maximize from './components/Maximize.vue'
|
||||
import Tabs from '@/layouts/components/Tabs/index.vue'
|
||||
import Footer from '@/layouts/components/Footer/index.vue'
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
import { useTabsStore } from '@/stores/modules/tabs'
|
||||
|
||||
const tabStore = useTabsStore()
|
||||
const globalStore = useGlobalStore();
|
||||
const globalStore = useGlobalStore()
|
||||
const tabsMenuList = computed(() => tabStore.tabsMenuList.map(item => item.name))
|
||||
const authStore = useAuthStore();
|
||||
const { maximize, isCollapse, layout, tabs, footer } = storeToRefs(globalStore);
|
||||
const keepAliveStore = useKeepAliveStore();
|
||||
const { keepAliveName } = storeToRefs(keepAliveStore);
|
||||
// console.log("🚀 ~ keepAliveName:", keepAliveName)
|
||||
const authStore = useAuthStore()
|
||||
const { maximize, isCollapse, layout, tabs, footer } = storeToRefs(globalStore)
|
||||
const keepAliveStore = useKeepAliveStore()
|
||||
const { keepAliveName } = storeToRefs(keepAliveStore)
|
||||
//是否显示导航栏
|
||||
const showMenuFlag = computed(() => authStore.showMenuFlagGet);
|
||||
const showMenuFlag = computed(() => authStore.showMenuFlagGet)
|
||||
// 注入刷新页面方法
|
||||
const isRouterShow = ref(true);
|
||||
const refreshCurrentPage = (val: boolean) => (isRouterShow.value = val);
|
||||
provide("refresh", refreshCurrentPage);
|
||||
const isRouterShow = ref(true)
|
||||
const refreshCurrentPage = (val: boolean) => (isRouterShow.value = val)
|
||||
provide('refresh', refreshCurrentPage)
|
||||
|
||||
// 监听当前页面是否最大化,动态添加 class
|
||||
watch(
|
||||
() => maximize.value,
|
||||
() => {
|
||||
const app = document.getElementById("app") as HTMLElement;
|
||||
if (maximize.value) app.classList.add("main-maximize");
|
||||
else app.classList.remove("main-maximize");
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
() => maximize.value,
|
||||
() => {
|
||||
const app = document.getElementById('app') as HTMLElement
|
||||
if (maximize.value) app.classList.add('main-maximize')
|
||||
else app.classList.remove('main-maximize')
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// 监听布局变化,在 body 上添加相对应的 layout class
|
||||
watch(
|
||||
() => layout.value,
|
||||
() => {
|
||||
const body = document.body as HTMLElement;
|
||||
body.setAttribute("class", layout.value);
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
() => layout.value,
|
||||
() => {
|
||||
const body = document.body as HTMLElement
|
||||
body.setAttribute('class', layout.value)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// 监听窗口大小变化,折叠侧边栏
|
||||
const screenWidth = ref(0);
|
||||
const screenWidth = ref(0)
|
||||
const listeningWindow = useDebounceFn(() => {
|
||||
screenWidth.value = document.body.clientWidth;
|
||||
if (!isCollapse.value && screenWidth.value < 1200)
|
||||
globalStore.setGlobalState("isCollapse", true);
|
||||
if (isCollapse.value && screenWidth.value > 1200)
|
||||
globalStore.setGlobalState("isCollapse", false);
|
||||
}, 100);
|
||||
window.addEventListener("resize", listeningWindow, false);
|
||||
screenWidth.value = document.body.clientWidth
|
||||
if (!isCollapse.value && screenWidth.value < 1200) globalStore.setGlobalState('isCollapse', true)
|
||||
if (isCollapse.value && screenWidth.value > 1200) globalStore.setGlobalState('isCollapse', false)
|
||||
}, 100)
|
||||
window.addEventListener('resize', listeningWindow, false)
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("resize", listeningWindow);
|
||||
});
|
||||
window.removeEventListener('resize', listeningWindow)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -1,81 +1,88 @@
|
||||
<template>
|
||||
<el-dropdown trigger="click" :teleported="false">
|
||||
<div class="more-button">
|
||||
<i :class="'iconfont icon-xiala'"></i>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="refresh">
|
||||
<el-icon><Refresh /></el-icon>{{ $t("tabs.refresh") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="maximize">
|
||||
<el-icon><FullScreen /></el-icon>{{ $t("tabs.maximize") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item divided @click="closeCurrentTab">
|
||||
<el-icon><Remove /></el-icon>{{ $t("tabs.closeCurrent") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="tabStore.closeTabsOnSide(route.fullPath, 'left')">
|
||||
<el-icon><DArrowLeft /></el-icon>{{ $t("tabs.closeLeft") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="tabStore.closeTabsOnSide(route.fullPath, 'right')">
|
||||
<el-icon><DArrowRight /></el-icon>{{ $t("tabs.closeRight") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item divided @click="tabStore.closeMultipleTab(route.fullPath)">
|
||||
<el-icon><CircleClose /></el-icon>{{ $t("tabs.closeOther") }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="closeAllTab">
|
||||
<el-icon><FolderDelete /></el-icon>{{ $t("tabs.closeAll") }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<el-dropdown trigger="click" :teleported="false">
|
||||
<div class="more-button">
|
||||
<i :class="'iconfont icon-xiala'"></i>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="refresh">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
{{ $t('tabs.refresh') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="maximize">
|
||||
<el-icon><FullScreen /></el-icon>
|
||||
{{ $t('tabs.maximize') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item divided @click="closeCurrentTab">
|
||||
<el-icon><Remove /></el-icon>
|
||||
{{ $t('tabs.closeCurrent') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="tabStore.closeTabsOnSide(route.fullPath, 'left')">
|
||||
<el-icon><DArrowLeft /></el-icon>
|
||||
{{ $t('tabs.closeLeft') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="tabStore.closeTabsOnSide(route.fullPath, 'right')">
|
||||
<el-icon><DArrowRight /></el-icon>
|
||||
{{ $t('tabs.closeRight') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item divided @click="tabStore.closeMultipleTab(route.fullPath)">
|
||||
<el-icon><CircleClose /></el-icon>
|
||||
{{ $t('tabs.closeOther') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item @click="closeAllTab">
|
||||
<el-icon><FolderDelete /></el-icon>
|
||||
{{ $t('tabs.closeAll') }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { inject, nextTick } from "vue";
|
||||
import { HOME_URL } from "@/config";
|
||||
import { useTabsStore } from "@/stores/modules/tabs";
|
||||
import { useGlobalStore } from "@/stores/modules/global";
|
||||
import { useKeepAliveStore } from "@/stores/modules/keepAlive";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { inject, nextTick } from 'vue'
|
||||
import { HOME_URL } from '@/config'
|
||||
import { useTabsStore } from '@/stores/modules/tabs'
|
||||
import { useGlobalStore } from '@/stores/modules/global'
|
||||
import { useKeepAliveStore } from '@/stores/modules/keepAlive'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const tabStore = useTabsStore();
|
||||
const globalStore = useGlobalStore();
|
||||
const keepAliveStore = useKeepAliveStore();
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const tabStore = useTabsStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const keepAliveStore = useKeepAliveStore()
|
||||
|
||||
// refresh current page
|
||||
const refreshCurrentPage: Function = inject("refresh") as Function;
|
||||
const refreshCurrentPage: Function = inject('refresh') as Function
|
||||
const refresh = () => {
|
||||
setTimeout(() => {
|
||||
keepAliveStore.removeKeepAliveName(route.name as string);
|
||||
refreshCurrentPage(false);
|
||||
nextTick(() => {
|
||||
keepAliveStore.addKeepAliveName(route.name as string);
|
||||
refreshCurrentPage(true);
|
||||
});
|
||||
}, 0);
|
||||
};
|
||||
setTimeout(() => {
|
||||
keepAliveStore.removeKeepAliveName(route.name as string)
|
||||
refreshCurrentPage(false)
|
||||
nextTick(() => {
|
||||
keepAliveStore.addKeepAliveName(route.name as string)
|
||||
refreshCurrentPage(true)
|
||||
})
|
||||
}, 0)
|
||||
}
|
||||
|
||||
// maximize current page
|
||||
const maximize = () => {
|
||||
globalStore.setGlobalState("maximize", true);
|
||||
};
|
||||
globalStore.setGlobalState('maximize', true)
|
||||
}
|
||||
|
||||
// Close Current
|
||||
const closeCurrentTab = () => {
|
||||
if (route.meta.isAffix) return;
|
||||
tabStore.removeTabs(route.fullPath);
|
||||
};
|
||||
if (route.meta.isAffix) return
|
||||
tabStore.removeTabs(route.fullPath)
|
||||
}
|
||||
|
||||
// Close All
|
||||
const closeAllTab = () => {
|
||||
tabStore.closeMultipleTab();
|
||||
router.push(HOME_URL);
|
||||
};
|
||||
tabStore.closeMultipleTab()
|
||||
router.push(HOME_URL)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "../index.scss";
|
||||
@use '../index.scss';
|
||||
</style>
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import Sortable from 'sortablejs'
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useGlobalStore } from '@/stores/modules/global'
|
||||
import { useTabsStore } from '@/stores/modules/tabs'
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
import { TabsPaneContext, TabPaneName } from 'element-plus'
|
||||
import { TabPaneName, TabsPaneContext } from 'element-plus'
|
||||
import MoreButton from './components/MoreButton.vue'
|
||||
|
||||
const route = useRoute()
|
||||
@@ -105,18 +105,15 @@ const tabsDrop = () => {
|
||||
// Tab Click
|
||||
const tabClick = (tabItem: TabsPaneContext) => {
|
||||
const fullPath = tabItem.props.name as string
|
||||
// console.log("🚀 ~ tabClick ~ fullPath:", tabItem)
|
||||
router.push(fullPath)
|
||||
}
|
||||
|
||||
// Remove Tab
|
||||
const tabRemove = (fullPath: TabPaneName) => {
|
||||
|
||||
|
||||
tabStore.removeTabs(fullPath as string, fullPath == route.fullPath || '/machine/testScriptAdd' == route.fullPath)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import './index.scss';
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -1,186 +1,198 @@
|
||||
<template>
|
||||
<el-drawer v-model="drawerVisible" title="布局设置" size="290px">
|
||||
<!-- 布局样式 -->
|
||||
<el-divider class="divider" content-position="center">
|
||||
<el-icon><Notification /></el-icon>
|
||||
布局样式
|
||||
</el-divider>
|
||||
<div class="layout-box">
|
||||
<el-tooltip effect="dark" content="纵向" placement="top" :show-after="200">
|
||||
<div :class="['layout-item layout-vertical', { 'is-active': layout == 'vertical' }]" @click="setLayout('vertical')">
|
||||
<div class="layout-dark"></div>
|
||||
<div class="layout-container">
|
||||
<div class="layout-light"></div>
|
||||
<div class="layout-content"></div>
|
||||
</div>
|
||||
<el-icon v-if="layout == 'vertical'">
|
||||
<CircleCheckFilled />
|
||||
</el-icon>
|
||||
<el-drawer v-model="drawerVisible" title="布局设置" size="290px">
|
||||
<!-- 布局样式 -->
|
||||
<el-divider class="divider" content-position="center">
|
||||
<el-icon><Notification /></el-icon>
|
||||
布局样式
|
||||
</el-divider>
|
||||
<div class="layout-box">
|
||||
<el-tooltip effect="dark" content="纵向" placement="top" :show-after="200">
|
||||
<div
|
||||
:class="['layout-item layout-vertical', { 'is-active': layout == 'vertical' }]"
|
||||
@click="setLayout('vertical')"
|
||||
>
|
||||
<div class="layout-dark"></div>
|
||||
<div class="layout-container">
|
||||
<div class="layout-light"></div>
|
||||
<div class="layout-content"></div>
|
||||
</div>
|
||||
<el-icon v-if="layout == 'vertical'">
|
||||
<CircleCheckFilled />
|
||||
</el-icon>
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" content="经典" placement="top" :show-after="200">
|
||||
<div
|
||||
:class="['layout-item layout-classic', { 'is-active': layout == 'classic' }]"
|
||||
@click="setLayout('classic')"
|
||||
>
|
||||
<div class="layout-dark"></div>
|
||||
<div class="layout-container">
|
||||
<div class="layout-light"></div>
|
||||
<div class="layout-content"></div>
|
||||
</div>
|
||||
<el-icon v-if="layout == 'classic'">
|
||||
<CircleCheckFilled />
|
||||
</el-icon>
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" content="横向" placement="top" :show-after="200">
|
||||
<div
|
||||
:class="['layout-item layout-transverse', { 'is-active': layout == 'transverse' }]"
|
||||
@click="setLayout('transverse')"
|
||||
>
|
||||
<div class="layout-dark"></div>
|
||||
<div class="layout-content"></div>
|
||||
<el-icon v-if="layout == 'transverse'">
|
||||
<CircleCheckFilled />
|
||||
</el-icon>
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" content="分栏" placement="top" :show-after="200">
|
||||
<div
|
||||
:class="['layout-item layout-columns', { 'is-active': layout == 'columns' }]"
|
||||
@click="setLayout('columns')"
|
||||
>
|
||||
<div class="layout-dark"></div>
|
||||
<div class="layout-light"></div>
|
||||
<div class="layout-content"></div>
|
||||
<el-icon v-if="layout == 'columns'">
|
||||
<CircleCheckFilled />
|
||||
</el-icon>
|
||||
</div>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" content="经典" placement="top" :show-after="200">
|
||||
<div :class="['layout-item layout-classic', { 'is-active': layout == 'classic' }]" @click="setLayout('classic')">
|
||||
<div class="layout-dark"></div>
|
||||
<div class="layout-container">
|
||||
<div class="layout-light"></div>
|
||||
<div class="layout-content"></div>
|
||||
</div>
|
||||
<el-icon v-if="layout == 'classic'">
|
||||
<CircleCheckFilled />
|
||||
</el-icon>
|
||||
<div class="theme-item">
|
||||
<span>
|
||||
侧边栏反转色
|
||||
<el-tooltip effect="dark" content="侧边栏颜色变为深色模式" placement="top">
|
||||
<el-icon><QuestionFilled /></el-icon>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-switch v-model="asideInverted" @change="setAsideTheme" />
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" content="横向" placement="top" :show-after="200">
|
||||
<div :class="['layout-item layout-transverse', { 'is-active': layout == 'transverse' }]" @click="setLayout('transverse')">
|
||||
<div class="layout-dark"></div>
|
||||
<div class="layout-content"></div>
|
||||
<el-icon v-if="layout == 'transverse'">
|
||||
<CircleCheckFilled />
|
||||
</el-icon>
|
||||
<div class="theme-item mb50">
|
||||
<span>
|
||||
头部反转色
|
||||
<el-tooltip effect="dark" content="头部颜色变为深色模式" placement="top">
|
||||
<el-icon><QuestionFilled /></el-icon>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-switch v-model="headerInverted" @change="setHeaderTheme" />
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" content="分栏" placement="top" :show-after="200">
|
||||
<div :class="['layout-item layout-columns', { 'is-active': layout == 'columns' }]" @click="setLayout('columns')">
|
||||
<div class="layout-dark"></div>
|
||||
<div class="layout-light"></div>
|
||||
<div class="layout-content"></div>
|
||||
<el-icon v-if="layout == 'columns'">
|
||||
<CircleCheckFilled />
|
||||
</el-icon>
|
||||
</div>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>
|
||||
侧边栏反转色
|
||||
<el-tooltip effect="dark" content="侧边栏颜色变为深色模式" placement="top">
|
||||
<el-icon><QuestionFilled /></el-icon>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-switch v-model="asideInverted" @change="setAsideTheme" />
|
||||
</div>
|
||||
<div class="theme-item mb50">
|
||||
<span>
|
||||
头部反转色
|
||||
<el-tooltip effect="dark" content="头部颜色变为深色模式" placement="top">
|
||||
<el-icon><QuestionFilled /></el-icon>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-switch v-model="headerInverted" @change="setHeaderTheme" />
|
||||
</div>
|
||||
|
||||
<!-- 全局主题 -->
|
||||
<el-divider class="divider" content-position="center">
|
||||
<el-icon><ColdDrink /></el-icon>
|
||||
全局主题
|
||||
</el-divider>
|
||||
<div class="theme-item">
|
||||
<span>主题颜色</span>
|
||||
<el-color-picker v-model="primary" :predefine="colorList" @change="changePrimary" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>暗黑模式</span>
|
||||
<SwitchDark />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>灰色模式</span>
|
||||
<el-switch v-model="isGrey" @change="changeGreyOrWeak('grey', !!$event)" />
|
||||
</div>
|
||||
<div class="theme-item mb40">
|
||||
<span>色弱模式</span>
|
||||
<el-switch v-model="isWeak" @change="changeGreyOrWeak('weak', !!$event)" />
|
||||
</div>
|
||||
<!-- 全局主题 -->
|
||||
<el-divider class="divider" content-position="center">
|
||||
<el-icon><ColdDrink /></el-icon>
|
||||
全局主题
|
||||
</el-divider>
|
||||
<div class="theme-item">
|
||||
<span>主题颜色</span>
|
||||
<el-color-picker v-model="primary" :predefine="colorList" @change="changePrimary" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>暗黑模式</span>
|
||||
<SwitchDark />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>灰色模式</span>
|
||||
<el-switch v-model="isGrey" @change="changeGreyOrWeak('grey', !!$event)" />
|
||||
</div>
|
||||
<div class="theme-item mb40">
|
||||
<span>色弱模式</span>
|
||||
<el-switch v-model="isWeak" @change="changeGreyOrWeak('weak', !!$event)" />
|
||||
</div>
|
||||
|
||||
<!-- 界面设置 -->
|
||||
<el-divider class="divider" content-position="center">
|
||||
<el-icon><Setting /></el-icon>
|
||||
界面设置
|
||||
</el-divider>
|
||||
<div class="theme-item">
|
||||
<span>菜单折叠</span>
|
||||
<el-switch v-model="isCollapse" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>菜单手风琴</span>
|
||||
<el-switch v-model="accordion" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>面包屑</span>
|
||||
<el-switch v-model="breadcrumb" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>面包屑图标</span>
|
||||
<el-switch v-model="breadcrumbIcon" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>标签栏</span>
|
||||
<el-switch v-model="tabs" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>标签栏图标</span>
|
||||
<el-switch v-model="tabsIcon" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>页脚</span>
|
||||
<el-switch v-model="footer" />
|
||||
</div>
|
||||
</el-drawer>
|
||||
<!-- 界面设置 -->
|
||||
<el-divider class="divider" content-position="center">
|
||||
<el-icon><Setting /></el-icon>
|
||||
界面设置
|
||||
</el-divider>
|
||||
<div class="theme-item">
|
||||
<span>菜单折叠</span>
|
||||
<el-switch v-model="isCollapse" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>菜单手风琴</span>
|
||||
<el-switch v-model="accordion" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>面包屑</span>
|
||||
<el-switch v-model="breadcrumb" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>面包屑图标</span>
|
||||
<el-switch v-model="breadcrumbIcon" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>标签栏</span>
|
||||
<el-switch v-model="tabs" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>标签栏图标</span>
|
||||
<el-switch v-model="tabsIcon" />
|
||||
</div>
|
||||
<div class="theme-item">
|
||||
<span>页脚</span>
|
||||
<el-switch v-model="footer" />
|
||||
</div>
|
||||
</el-drawer>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useTheme } from "@/hooks/useTheme";
|
||||
import { useGlobalStore } from "@/stores/modules/global";
|
||||
import { LayoutType } from "@/stores/interface";
|
||||
import { DEFAULT_PRIMARY } from "@/config";
|
||||
import mittBus from "@/utils/mittBus";
|
||||
import SwitchDark from "@/components/SwitchDark/index.vue";
|
||||
import { ref } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useTheme } from '@/hooks/useTheme'
|
||||
import { useGlobalStore } from '@/stores/modules/global'
|
||||
import { LayoutType } from '@/stores/interface'
|
||||
import { DEFAULT_PRIMARY } from '@/config'
|
||||
import mittBus from '@/utils/mittBus'
|
||||
import SwitchDark from '@/components/SwitchDark/index.vue'
|
||||
|
||||
const { changePrimary, changeGreyOrWeak, setAsideTheme, setHeaderTheme } = useTheme();
|
||||
const { changePrimary, changeGreyOrWeak, setAsideTheme, setHeaderTheme } = useTheme()
|
||||
|
||||
const globalStore = useGlobalStore();
|
||||
const globalStore = useGlobalStore()
|
||||
const {
|
||||
layout,
|
||||
primary,
|
||||
isGrey,
|
||||
isWeak,
|
||||
asideInverted,
|
||||
headerInverted,
|
||||
isCollapse,
|
||||
accordion,
|
||||
breadcrumb,
|
||||
breadcrumbIcon,
|
||||
tabs,
|
||||
tabsIcon,
|
||||
footer
|
||||
} = storeToRefs(globalStore);
|
||||
layout,
|
||||
primary,
|
||||
isGrey,
|
||||
isWeak,
|
||||
asideInverted,
|
||||
headerInverted,
|
||||
isCollapse,
|
||||
accordion,
|
||||
breadcrumb,
|
||||
breadcrumbIcon,
|
||||
tabs,
|
||||
tabsIcon,
|
||||
footer
|
||||
} = storeToRefs(globalStore)
|
||||
|
||||
// 预定义主题颜色
|
||||
const colorList = [
|
||||
DEFAULT_PRIMARY,
|
||||
"#daa96e",
|
||||
"#0c819f",
|
||||
"#409eff",
|
||||
"#27ae60",
|
||||
"#ff5c93",
|
||||
"#e74c3c",
|
||||
"#fd726d",
|
||||
"#f39c12",
|
||||
"#9b59b6"
|
||||
];
|
||||
DEFAULT_PRIMARY,
|
||||
'#daa96e',
|
||||
'#0c819f',
|
||||
'#409eff',
|
||||
'#27ae60',
|
||||
'#ff5c93',
|
||||
'#e74c3c',
|
||||
'#fd726d',
|
||||
'#f39c12',
|
||||
'#9b59b6'
|
||||
]
|
||||
|
||||
// 设置布局方式
|
||||
const setLayout = (val: LayoutType) => {
|
||||
globalStore.setGlobalState("layout", val);
|
||||
setAsideTheme();
|
||||
};
|
||||
globalStore.setGlobalState('layout', val)
|
||||
setAsideTheme()
|
||||
}
|
||||
|
||||
// 打开主题设置
|
||||
const drawerVisible = ref(false);
|
||||
mittBus.on("openThemeDrawer", () => (drawerVisible.value = true));
|
||||
const drawerVisible = ref(false)
|
||||
mittBus.on('openThemeDrawer', () => (drawerVisible.value = true))
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "./index.scss";
|
||||
@use './index.scss';
|
||||
</style>
|
||||
|
||||
@@ -3,14 +3,14 @@ import { useUserStore } from '@/stores/modules/user'
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
import { LOGIN_URL, ROUTER_WHITE_LIST } from '@/config'
|
||||
import { initDynamicRouter } from '@/routers/modules/dynamicRouter'
|
||||
import { staticRouter, errorRouter } from '@/routers/modules/staticRouter'
|
||||
import { staticRouter } from '@/routers/modules/staticRouter'
|
||||
import NProgress from '@/config/nprogress'
|
||||
|
||||
const mode = import.meta.env.VITE_ROUTER_MODE
|
||||
|
||||
const routerMode = {
|
||||
hash: () => createWebHashHistory(),
|
||||
history: () => createWebHistory(),
|
||||
hash: () => createWebHashHistory(),
|
||||
history: () => createWebHistory()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,76 +30,80 @@ const routerMode = {
|
||||
* @param meta.isKeepAlive ==> 当前路由是否缓存
|
||||
* */
|
||||
const router = createRouter({
|
||||
|
||||
history: routerMode[mode](),
|
||||
routes: [...staticRouter],
|
||||
// 不区分路由大小写,非严格模式下提供了更宽松的路径匹配
|
||||
strict: false,
|
||||
// 页面刷新时,滚动条位置还原
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
history: routerMode[mode](),
|
||||
routes: [...staticRouter],
|
||||
// 不区分路由大小写,非严格模式下提供了更宽松的路径匹配
|
||||
strict: false,
|
||||
// 页面刷新时,滚动条位置还原
|
||||
scrollBehavior: () => ({ left: 0, top: 0 })
|
||||
})
|
||||
|
||||
/**
|
||||
* @description 路由拦截 beforeEach
|
||||
* */
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
const userStore = useUserStore()
|
||||
const authStore = useAuthStore()
|
||||
// 1.NProgress 开始
|
||||
NProgress.start()
|
||||
// 2.动态设置标题
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE
|
||||
document.title = to.meta.title ? `${to.meta.title} - ${title}` : title
|
||||
const userStore = useUserStore()
|
||||
const authStore = useAuthStore()
|
||||
// 1.NProgress 开始
|
||||
NProgress.start()
|
||||
// 2.动态设置标题
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE
|
||||
document.title = to.meta.title ? `${to.meta.title} - ${title}` : title
|
||||
|
||||
// 3.判断是访问登陆页,有 Token 就在当前页面,没有 Token 重置路由到登陆页
|
||||
if (to.path.toLocaleLowerCase() === LOGIN_URL) {
|
||||
if (userStore.accessToken) return next(from.fullPath)
|
||||
resetRouter()
|
||||
return next()
|
||||
}
|
||||
// 3.判断是访问登陆页,有 Token 就在当前页面,没有 Token 重置路由到登陆页
|
||||
if (to.path.toLocaleLowerCase() === LOGIN_URL) {
|
||||
if (userStore.accessToken) return next(from.fullPath)
|
||||
resetRouter()
|
||||
return next()
|
||||
}
|
||||
|
||||
// 4.判断访问页面是否在路由白名单地址(静态路由)中,如果存在直接放行
|
||||
if (ROUTER_WHITE_LIST.includes(to.path)) return next()
|
||||
// 4.判断访问页面是否在路由白名单地址(静态路由)中,如果存在直接放行
|
||||
if (ROUTER_WHITE_LIST.includes(to.path)) return next()
|
||||
|
||||
// 5.判断是否有 Token,没有重定向到 login 页面
|
||||
if (!userStore.accessToken) return next({ path: LOGIN_URL, replace: true })
|
||||
// 5.判断是否有 Token,没有重定向到 login 页面
|
||||
if (!userStore.accessToken) return next({ path: LOGIN_URL, replace: true })
|
||||
|
||||
// 6.如果没有菜单列表,就重新请求菜单列表并添加动态路由
|
||||
if (!authStore.authMenuListGet.length) {
|
||||
await initDynamicRouter()
|
||||
return next({ ...to, replace: true })
|
||||
}
|
||||
// 6.如果没有菜单列表,就重新请求菜单列表并添加动态路由
|
||||
if (!authStore.authMenuListGet.length) {
|
||||
await initDynamicRouter()
|
||||
return next({ ...to, replace: true })
|
||||
}
|
||||
|
||||
// 7.存储 routerName 做按钮权限筛选
|
||||
authStore.setRouteName(to.name as string)
|
||||
// 8.正常访问页面
|
||||
next()
|
||||
// 7.存储 routerName 做按钮权限筛选
|
||||
await authStore.setRouteName(to.name as string)
|
||||
// 8. 当前页面是否有激活信息,没有就刷新
|
||||
const activateInfo = authStore.activateInfo
|
||||
if (!Object.keys(activateInfo).length) {
|
||||
await authStore.setActivateInfo()
|
||||
}
|
||||
// 9.正常访问页面
|
||||
next()
|
||||
})
|
||||
|
||||
/**
|
||||
* @description 重置路由
|
||||
* */
|
||||
export const resetRouter = () => {
|
||||
const authStore = useAuthStore()
|
||||
authStore.flatMenuListGet.forEach(route => {
|
||||
const { name } = route
|
||||
if (name && router.hasRoute(name)) router.removeRoute(name)
|
||||
})
|
||||
const authStore = useAuthStore()
|
||||
authStore.flatMenuListGet.forEach(route => {
|
||||
const { name } = route
|
||||
if (name && router.hasRoute(name)) router.removeRoute(name)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 路由跳转错误
|
||||
* */
|
||||
router.onError(error => {
|
||||
NProgress.done()
|
||||
//console.warn('路由错误', error.message)
|
||||
NProgress.done()
|
||||
//console.warn('路由错误', error.message)
|
||||
})
|
||||
|
||||
/**
|
||||
* @description 路由跳转结束
|
||||
* */
|
||||
router.afterEach(() => {
|
||||
NProgress.done()
|
||||
NProgress.done()
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { type RouteRecordRaw } from 'vue-router'
|
||||
import { HOME_URL, LOGIN_URL } from '@/config'
|
||||
|
||||
export const Layout = () => import('@/layouts/index.vue')
|
||||
/**
|
||||
* staticRouter (静态路由)
|
||||
|
||||
@@ -1,97 +1,103 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { AuthState } from "@/stores/interface";
|
||||
import { getAuthButtonListApi, getAuthMenuListApi } from "@/api/user/login";
|
||||
import {
|
||||
getFlatMenuList,
|
||||
getShowMenuList,
|
||||
getAllBreadcrumbList,
|
||||
} from "@/utils";
|
||||
import { useRouter } from "vue-router";
|
||||
import { AUTH_STORE_KEY } from "@/stores/constant";
|
||||
import {useModeStore} from '@/stores/modules/mode'
|
||||
|
||||
import { defineStore } from 'pinia'
|
||||
import { AuthState } from '@/stores/interface'
|
||||
import { getAuthButtonListApi, getAuthMenuListApi } from '@/api/user/login'
|
||||
import { getAllBreadcrumbList, getFlatMenuList, getShowMenuList } from '@/utils'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { AUTH_STORE_KEY } from '@/stores/constant'
|
||||
import { useModeStore } from '@/stores/modules/mode'
|
||||
import { getLicense } from '@/api/activate'
|
||||
import type { Activate } from '@/api/activate/interface'
|
||||
|
||||
export const useAuthStore = defineStore({
|
||||
id: AUTH_STORE_KEY,
|
||||
state: (): AuthState => ({
|
||||
// 按钮权限列表
|
||||
authButtonList: {},
|
||||
// 菜单权限列表
|
||||
authMenuList: [],
|
||||
// 当前页面的 router name,用来做按钮权限筛选
|
||||
routeName: "",
|
||||
//登录不显示菜单栏和导航栏,点击进入测试的时候显示
|
||||
showMenuFlag: JSON.parse(localStorage.getItem("showMenuFlag")),
|
||||
router: useRouter(),
|
||||
}),
|
||||
getters: {
|
||||
// 按钮权限列表
|
||||
authButtonListGet: (state) => state.authButtonList,
|
||||
// 菜单权限列表 ==> 这里的菜单没有经过任何处理
|
||||
authMenuListGet: (state) => state.authMenuList,
|
||||
// 菜单权限列表 ==> 左侧菜单栏渲染,需要剔除 isHide == true
|
||||
showMenuListGet: (state) => getShowMenuList(state.authMenuList),
|
||||
// 菜单权限列表 ==> 扁平化之后的一维数组菜单,主要用来添加动态路由
|
||||
flatMenuListGet: (state) => getFlatMenuList(state.authMenuList),
|
||||
// 递归处理后的所有面包屑导航列表
|
||||
breadcrumbListGet: (state) => getAllBreadcrumbList(state.authMenuList),
|
||||
//是否显示菜单和导航栏
|
||||
showMenuFlagGet: (state) => state.showMenuFlag,
|
||||
},
|
||||
actions: {
|
||||
// Get AuthButtonList
|
||||
async getAuthButtonList() {
|
||||
const { data } = await getAuthButtonListApi();
|
||||
this.authButtonList = data;
|
||||
id: AUTH_STORE_KEY,
|
||||
state: (): AuthState => ({
|
||||
// 按钮权限列表
|
||||
authButtonList: {},
|
||||
// 菜单权限列表
|
||||
authMenuList: [],
|
||||
// 当前页面的 router name,用来做按钮权限筛选
|
||||
routeName: '',
|
||||
//登录不显示菜单栏和导航栏,点击进入测试的时候显示
|
||||
showMenuFlag: JSON.parse(localStorage.getItem('showMenuFlag') as string),
|
||||
router: useRouter(),
|
||||
activateInfo: {}
|
||||
}),
|
||||
getters: {
|
||||
// 按钮权限列表
|
||||
authButtonListGet: state => state.authButtonList,
|
||||
// 菜单权限列表 ==> 这里的菜单没有经过任何处理
|
||||
authMenuListGet: state => state.authMenuList,
|
||||
// 菜单权限列表 ==> 左侧菜单栏渲染,需要剔除 isHide == true
|
||||
showMenuListGet: state => getShowMenuList(state.authMenuList),
|
||||
// 菜单权限列表 ==> 扁平化之后的一维数组菜单,主要用来添加动态路由
|
||||
flatMenuListGet: state => getFlatMenuList(state.authMenuList),
|
||||
// 递归处理后的所有面包屑导航列表
|
||||
breadcrumbListGet: state => getAllBreadcrumbList(state.authMenuList),
|
||||
//是否显示菜单和导航栏
|
||||
showMenuFlagGet: state => state.showMenuFlag,
|
||||
// 获取激活信息
|
||||
activateInfoGet: state => state.activateInfo
|
||||
},
|
||||
// Get AuthMenuList
|
||||
async getAuthMenuList() {
|
||||
const modeStore = useModeStore()
|
||||
|
||||
const { data: menuData } = await getAuthMenuListApi();
|
||||
let data = menuData; // 新增变量接收并操作
|
||||
if(modeStore.currentMode === '比对式'){
|
||||
data = filterMenuTree(data);
|
||||
}
|
||||
this.authMenuList = data;
|
||||
|
||||
},
|
||||
// Set RouteName
|
||||
async setRouteName(name: string) {
|
||||
this.routeName = name;
|
||||
},
|
||||
//重置权限
|
||||
async resetAuthStore() {
|
||||
this.showMenuFlag = false;
|
||||
localStorage.removeItem("showMenuFlag");
|
||||
},
|
||||
//修改判断菜单栏/导航栏显示条件
|
||||
async setShowMenu() {
|
||||
this.showMenuFlag = true;
|
||||
localStorage.setItem("showMenuFlag", true);
|
||||
},
|
||||
//更改模式
|
||||
async changeModel() {
|
||||
this.showMenuFlag = !this.showMenuFlag;
|
||||
if (this.showMenuFlag) {
|
||||
localStorage.setItem("showMenuFlag", true);
|
||||
} else {
|
||||
localStorage.removeItem("showMenuFlag");
|
||||
}
|
||||
this.router.push({ path: "/home/index" });
|
||||
},
|
||||
},
|
||||
});
|
||||
actions: {
|
||||
// Get AuthButtonList
|
||||
async getAuthButtonList() {
|
||||
const { data } = await getAuthButtonListApi()
|
||||
this.authButtonList = data
|
||||
},
|
||||
// Get AuthMenuList
|
||||
async getAuthMenuList() {
|
||||
const modeStore = useModeStore()
|
||||
|
||||
const { data: menuData } = await getAuthMenuListApi()
|
||||
// 根据不同模式过滤菜单
|
||||
const filteredMenu =
|
||||
modeStore.currentMode === '比对式'
|
||||
? filterMenuByExcludedNames(menuData, ['testSource', 'testScript', 'controlSource'])
|
||||
: filterMenuByExcludedNames(menuData, ['standardDevice'])
|
||||
|
||||
// 工具函数:递归过滤掉 name == 'test' 的菜单项
|
||||
function filterMenuTree(menuList: any[]) {
|
||||
return menuList.filter(menu => {
|
||||
// 如果当前项有 children,递归处理子项
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
menu.children = filterMenuTree(menu.children);
|
||||
this.authMenuList = filteredMenu
|
||||
},
|
||||
// Set RouteName
|
||||
async setRouteName(name: string) {
|
||||
this.routeName = name
|
||||
},
|
||||
//重置权限
|
||||
async resetAuthStore() {
|
||||
this.showMenuFlag = false
|
||||
localStorage.removeItem('showMenuFlag')
|
||||
},
|
||||
//修改判断菜单栏/导航栏显示条件
|
||||
async setShowMenu() {
|
||||
this.showMenuFlag = true
|
||||
localStorage.setItem('showMenuFlag', 'true')
|
||||
},
|
||||
//更改模式
|
||||
async changeModel() {
|
||||
this.showMenuFlag = false
|
||||
localStorage.removeItem('showMenuFlag')
|
||||
this.router.push({ path: '/home/index' })
|
||||
},
|
||||
async setActivateInfo() {
|
||||
const license_result = await getLicense()
|
||||
const licenseData = license_result.data as unknown as Activate.ActivationCodePlaintext
|
||||
this.activateInfo = licenseData
|
||||
}
|
||||
}
|
||||
// 过滤掉 name 是 testSource、testScript 或 controlSource 的菜单项
|
||||
return !['testSource', 'testScript', 'controlSource'].includes(menu.name);
|
||||
});
|
||||
})
|
||||
|
||||
/**
|
||||
* 通用菜单过滤函数
|
||||
* @param menuList 菜单列表
|
||||
* @param excludedNames 需要排除的菜单名称数组
|
||||
* @returns 过滤后的菜单列表
|
||||
*/
|
||||
function filterMenuByExcludedNames(menuList: any[], excludedNames: string[]): any[] {
|
||||
return menuList.filter(menu => {
|
||||
// 如果当前项有 children,递归处理子项
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
menu.children = filterMenuByExcludedNames(menu.children, excludedNames)
|
||||
}
|
||||
// 过滤掉在排除列表中的菜单项
|
||||
return !excludedNames.includes(menu.name)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,25 +3,21 @@ import {CHECK_STORE_KEY} from "@/stores/constant";
|
||||
import type {CheckData} from "@/api/check/interface";
|
||||
import type {Plan} from '@/api/plan/interface'
|
||||
import {useAppSceneStore} from "@/stores/modules/mode";
|
||||
import { set } from "lodash";
|
||||
|
||||
const AppSceneStore = useAppSceneStore()
|
||||
export const useCheckStore = defineStore("check", {
|
||||
id: CHECK_STORE_KEY,
|
||||
|
||||
export const useCheckStore = defineStore(CHECK_STORE_KEY, {
|
||||
state: () => ({
|
||||
devices: Array<CheckData.Device>(),
|
||||
plan: Object<Plan.ResPlan>(),
|
||||
selectTestItems: Object<CheckData.SelectTestItem>({preTest: true, timeTest: false, channelsTest: false, test: true}),
|
||||
checkType:1, // 0:手动检测 1:自动检测
|
||||
devices: [] as CheckData.Device[],
|
||||
plan: {} as Plan.ResPlan,
|
||||
selectTestItems: {preTest: true, timeTest: false, channelsTest: false, test: true} as CheckData.SelectTestItem,
|
||||
checkType: 1, // 0:手动检测 1:自动检测
|
||||
reCheckType: 1, // 0:不合格项复检 1:全部复检
|
||||
showDetailType: 0 ,// 0:数据查询 1:误差体系跟换 2:正式检测
|
||||
showDetailType: 0, // 0:数据查询 1:误差体系跟换 2:正式检测
|
||||
temperature: 0,
|
||||
humidity: 0
|
||||
humidity: 0,
|
||||
chnNumList: [],//连线数据
|
||||
nodesConnectable: true,//设置是能可以连线
|
||||
}),
|
||||
|
||||
getters: {},
|
||||
|
||||
actions: {
|
||||
addDevices(device: CheckData.Device[]) {
|
||||
this.devices.push(...device);
|
||||
@@ -33,8 +29,9 @@ export const useCheckStore = defineStore("check", {
|
||||
this.devices = [];
|
||||
},
|
||||
initSelectTestItems() {
|
||||
const appSceneStore = useAppSceneStore()
|
||||
this.selectTestItems.preTest = true
|
||||
if (AppSceneStore.currentScene === '1') {
|
||||
if (appSceneStore.currentScene === '1') {
|
||||
this.selectTestItems.channelsTest = true
|
||||
} else {
|
||||
this.selectTestItems.channelsTest = false
|
||||
@@ -58,6 +55,13 @@ export const useCheckStore = defineStore("check", {
|
||||
},
|
||||
setHumidity(humidity: number) {
|
||||
this.humidity = humidity
|
||||
}
|
||||
},
|
||||
setChnNum(chnNumList: string[]) {
|
||||
this.chnNumList = chnNumList
|
||||
},
|
||||
setNodesConnectable(nodesConnectable: boolean) {
|
||||
this.nodesConnectable = nodesConnectable
|
||||
},
|
||||
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { GlobalState } from "@/stores/interface";
|
||||
import { type GlobalState } from "@/stores/interface";
|
||||
import { DEFAULT_PRIMARY} from "@/config";
|
||||
import piniaPersistConfig from "@/stores/helper/persist";
|
||||
import {GLOBAL_STORE_KEY} from "@/stores/constant";
|
||||
@@ -49,7 +49,6 @@ export const useGlobalStore = defineStore({
|
||||
// Set GlobalState
|
||||
setGlobalState(...args: ObjToKeyValArray<GlobalState>) {
|
||||
this.$patch({ [args[0]]: args[1] });
|
||||
console.log(DEFAULT_PRIMARY);
|
||||
}
|
||||
},
|
||||
persist: piniaPersistConfig(GLOBAL_STORE_KEY)
|
||||
|
||||
@@ -342,6 +342,17 @@
|
||||
overflow-y: auto;
|
||||
padding: 10px 15px;
|
||||
|
||||
|
||||
|
||||
// 隐藏滚动条的CSS
|
||||
scrollbar-width: none; /* Firefox */
|
||||
-ms-overflow-style: none; /* IE 10+ */
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 0px;
|
||||
background: transparent; /* Chrome Safari */
|
||||
}
|
||||
|
||||
//设置dialog内部form样式
|
||||
.el-form {
|
||||
.el-form-item {
|
||||
@@ -379,6 +390,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//全局el-form-item间距
|
||||
.el-form-item {
|
||||
margin-right: 10px !important;
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
export const dialogSmall = {
|
||||
width:'500px',
|
||||
width:'26vw',
|
||||
maxWidth:'500px',
|
||||
minWidth:'300px',
|
||||
closeOnClickModal:false,
|
||||
draggable:true,
|
||||
class:'dialog-small'
|
||||
}
|
||||
export const dialogMiddle = {
|
||||
width:'800px',
|
||||
width:'42vw',
|
||||
maxWidth:'800px',
|
||||
minWidth:'600px',
|
||||
closeOnClickModal:false,
|
||||
draggable:true,
|
||||
class:'dialog-middle'
|
||||
}
|
||||
export const dialogBig = {
|
||||
width:'1200px',
|
||||
width:'62vw',
|
||||
maxWidth:'1200px',
|
||||
minWidth:'800px',
|
||||
closeOnClickModal:false,
|
||||
draggable:true,
|
||||
class:'dialog-big',
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
const Renderer =
|
||||
(window.require && window.require('electron')) || window.electron || {}
|
||||
|
||||
/**
|
||||
* ipc
|
||||
* 官方api说明:https://www.electronjs.org/zh/docs/latest/api/ipc-renderer
|
||||
*
|
||||
* 属性/方法
|
||||
* ipc.invoke(channel, param) - 发送异步消息(invoke/handle 模型)
|
||||
* ipc.sendSync(channel, param) - 发送同步消息(send/on 模型)
|
||||
* ipc.on(channel, listener) - 监听 channel, 当新消息到达,调用 listener
|
||||
* ipc.once(channel, listener) - 添加一次性 listener 函数
|
||||
* ipc.removeListener(channel, listener) - 为特定的 channel 从监听队列中删除特定的 listener 监听者
|
||||
* ipc.removeAllListeners(channel) - 移除所有的监听器,当指定 channel 时只移除与其相关的所有监听器
|
||||
* ipc.send(channel, ...args) - 通过channel向主进程发送异步消息
|
||||
* ipc.postMessage(channel, message, [transfer]) - 发送消息到主进程
|
||||
* ipc.sendTo(webContentsId, channel, ...args) - 通过 channel 发送消息到带有 webContentsId 的窗口
|
||||
* ipc.sendToHost(channel, ...args) - 消息会被发送到 host 页面上的 <webview> 元素
|
||||
*/
|
||||
|
||||
/**
|
||||
* ipc
|
||||
*/
|
||||
const ipc = Renderer.ipcRenderer || undefined
|
||||
|
||||
/**
|
||||
* 是否为EE环境
|
||||
*/
|
||||
const isEE = ipc ? true : false
|
||||
|
||||
export { Renderer, ipc, isEE }
|
||||
119
frontend/src/utils/ipcRenderer.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Electron IPC Renderer 类型定义
|
||||
*/
|
||||
|
||||
interface IpcRenderer {
|
||||
/**
|
||||
* 发送异步消息(invoke/handle 模型)
|
||||
* @param channel 通道名称
|
||||
* @param param 传递的参数
|
||||
* @returns Promise<T> 返回结果
|
||||
*/
|
||||
invoke<T = any>(channel: string, param?: any): Promise<T>;
|
||||
|
||||
/**
|
||||
* 发送同步消息(send/on 模型)
|
||||
* @param channel 通道名称
|
||||
* @param param 传递的参数
|
||||
* @returns 返回结果
|
||||
*/
|
||||
sendSync(channel: string, param?: any): any;
|
||||
|
||||
/**
|
||||
* 监听 channel,当新消息到达,调用 listener
|
||||
* @param channel 通道名称
|
||||
* @param listener 监听器函数
|
||||
*/
|
||||
on(channel: string, listener: (event: any, ...args: any[]) => void): void;
|
||||
|
||||
/**
|
||||
* 添加一次性 listener 函数
|
||||
* @param channel 通道名称
|
||||
* @param listener 监听器函数
|
||||
*/
|
||||
once(channel: string, listener: (event: any, ...args: any[]) => void): void;
|
||||
|
||||
/**
|
||||
* 为特定的 channel 从监听队列中删除特定的 listener 监听者
|
||||
* @param channel 通道名称
|
||||
* @param listener 要移除的监听器函数
|
||||
*/
|
||||
removeListener(channel: string, listener: (event: any, ...args: any[]) => void): void;
|
||||
|
||||
/**
|
||||
* 移除所有的监听器,当指定 channel 时只移除与其相关的所有监听器
|
||||
* @param channel 通道名称(可选)
|
||||
*/
|
||||
removeAllListeners(channel?: string): void;
|
||||
|
||||
/**
|
||||
* 通过 channel 向主进程发送异步消息
|
||||
* @param channel 通道名称
|
||||
* @param args 传递的参数
|
||||
*/
|
||||
send(channel: string, ...args: any[]): void;
|
||||
|
||||
/**
|
||||
* 发送消息到主进程
|
||||
* @param channel 通道名称
|
||||
* @param message 消息内容
|
||||
* @param transfer 传输对象(可选)
|
||||
*/
|
||||
postMessage(channel: string, message: any, transfer?: MessagePort[]): void;
|
||||
|
||||
/**
|
||||
* 通过 channel 发送消息到带有 webContentsId 的窗口
|
||||
* @param webContentsId 目标窗口的 ID
|
||||
* @param channel 通道名称
|
||||
* @param args 传递的参数
|
||||
*/
|
||||
sendTo(webContentsId: number, channel: string, ...args: any[]): void;
|
||||
|
||||
/**
|
||||
* 消息会被发送到 host 页面上的 <webview> 元素
|
||||
* @param channel 通道名称
|
||||
* @param args 传递的参数
|
||||
*/
|
||||
sendToHost(channel: string, ...args: any[]): void;
|
||||
}
|
||||
|
||||
interface Electron {
|
||||
ipcRenderer?: IpcRenderer;
|
||||
}
|
||||
|
||||
const Renderer = (window.require && window.require('electron')) || (window as any).electron || {};
|
||||
|
||||
/**
|
||||
* ipc
|
||||
* 官方api说明:https://www.electronjs.org/zh/docs/latest/api/ipc-renderer
|
||||
*
|
||||
* 属性/方法
|
||||
* ipc.invoke(channel, param) - 发送异步消息(invoke/handle 模型)
|
||||
* ipc.sendSync(channel, param) - 发送同步消息(send/on 模型)
|
||||
* ipc.on(channel, listener) - 监听 channel, 当新消息到达,调用 listener
|
||||
* ipc.once(channel, listener) - 添加一次性 listener 函数
|
||||
* ipc.removeListener(channel, listener) - 为特定的 channel 从监听队列中删除特定的 listener 监听者
|
||||
* ipc.removeAllListeners(channel) - 移除所有的监听器,当指定 channel 时只移除与其相关的所有监听器
|
||||
* ipc.send(channel, ...args) - 通过channel向主进程发送异步消息
|
||||
* ipc.postMessage(channel, message, [transfer]) - 发送消息到主进程
|
||||
* ipc.sendTo(webContentsId, channel, ...args) - 通过 channel 发送消息到带有 webContentsId 的窗口
|
||||
* ipc.sendToHost(channel, ...args) - 消息会被发送到 host 页面上的 <webview> 元素
|
||||
*/
|
||||
|
||||
/**
|
||||
* ipc
|
||||
*/
|
||||
const ipc: IpcRenderer | undefined = Renderer.ipcRenderer;
|
||||
|
||||
/**
|
||||
* 是否为EE环境
|
||||
*/
|
||||
const isEE: boolean = ipc ? true : false;
|
||||
|
||||
export {
|
||||
type IpcRenderer,
|
||||
type Electron,
|
||||
Renderer,
|
||||
ipc,
|
||||
isEE
|
||||
};
|
||||
234
frontend/src/utils/jwtUtil.ts
Normal file
@@ -0,0 +1,234 @@
|
||||
import { useUserStore } from "@/stores/modules/user";
|
||||
|
||||
// JWT Token解析后的载荷接口
|
||||
export interface JwtPayload {
|
||||
userId?: string;
|
||||
loginName?: string;
|
||||
exp?: number;
|
||||
iat?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// Token信息摘要接口
|
||||
export interface TokenInfo {
|
||||
userId: string | null;
|
||||
loginName: string | null;
|
||||
expiration: string | null;
|
||||
isExpired: boolean;
|
||||
remainingTime: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* JWT工具类
|
||||
* 提供JWT token的解析、验证等功能
|
||||
*/
|
||||
export class JwtUtil {
|
||||
/**
|
||||
* Base64URL解码
|
||||
* @param str Base64URL编码的字符串
|
||||
*/
|
||||
private static base64UrlDecode(str: string): string {
|
||||
try {
|
||||
// Base64URL转Base64
|
||||
let base64 = str.replace(/-/g, '+').replace(/_/g, '/');
|
||||
|
||||
// 补齐padding
|
||||
while (base64.length % 4) {
|
||||
base64 += '=';
|
||||
}
|
||||
|
||||
// Base64解码
|
||||
const decoded = atob(base64);
|
||||
|
||||
// 处理UTF-8编码
|
||||
return decodeURIComponent(
|
||||
decoded
|
||||
.split('')
|
||||
.map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
||||
.join('')
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error('Base64URL解码失败: ' + error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析JWT Token获取载荷信息
|
||||
* @param token JWT token字符串,如果不传则从store中获取
|
||||
*/
|
||||
static parseToken(token?: string): JwtPayload | null {
|
||||
try {
|
||||
let targetToken = token;
|
||||
|
||||
// 如果没有传入token,从store中获取
|
||||
if (!targetToken) {
|
||||
const userStore = useUserStore();
|
||||
targetToken = userStore.accessToken;
|
||||
}
|
||||
|
||||
if (!targetToken) {
|
||||
console.warn('Token不存在');
|
||||
return null;
|
||||
}
|
||||
|
||||
// JWT token由三部分组成,用.分割:header.payload.signature
|
||||
const parts = targetToken.split('.');
|
||||
if (parts.length !== 3) {
|
||||
console.error('无效的JWT token格式');
|
||||
return null;
|
||||
}
|
||||
|
||||
// 解码payload部分(第二部分)
|
||||
const payload = parts[1];
|
||||
const decodedPayload = this.base64UrlDecode(payload);
|
||||
const tokenData: JwtPayload = JSON.parse(decodedPayload);
|
||||
|
||||
return tokenData;
|
||||
} catch (error) {
|
||||
console.error('解析JWT Token失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定字段的值
|
||||
* @param field 字段名
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static getField<T = any>(field: string, token?: string): T | null {
|
||||
const tokenData = this.parseToken(token);
|
||||
return tokenData?.[field] || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户ID
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static getUserId(token?: string): string | null {
|
||||
return this.getField<string>('userId', token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录名
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static getLoginName(token?: string): string | null {
|
||||
return this.getField<string>('loginName', token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Token过期时间戳(秒)
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static getExpiration(token?: string): number | null {
|
||||
return this.getField<number>('exp', token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Token签发时间戳(秒)
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static getIssuedAt(token?: string): number | null {
|
||||
return this.getField<number>('iat', token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查Token是否过期
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static isExpired(token?: string): boolean {
|
||||
const exp = this.getExpiration(token);
|
||||
if (!exp) return true;
|
||||
|
||||
// JWT中的exp是秒级时间戳,需要转换为毫秒
|
||||
const expTime = exp * 1000;
|
||||
return Date.now() >= expTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Token剩余有效时间(毫秒)
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static getRemainingTime(token?: string): number {
|
||||
const exp = this.getExpiration(token);
|
||||
if (!exp) return 0;
|
||||
|
||||
const expTime = exp * 1000;
|
||||
const remaining = expTime - Date.now();
|
||||
return Math.max(0, remaining);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化剩余时间为可读字符串
|
||||
* @param ms 毫秒数
|
||||
*/
|
||||
static formatRemainingTime(ms: number): string {
|
||||
if (ms <= 0) return '已过期';
|
||||
|
||||
const seconds = Math.floor(ms / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const days = Math.floor(hours / 24);
|
||||
|
||||
if (days > 0) return `${days}天 ${hours % 24}小时`;
|
||||
if (hours > 0) return `${hours}小时 ${minutes % 60}分钟`;
|
||||
if (minutes > 0) return `${minutes}分钟 ${seconds % 60}秒`;
|
||||
return `${seconds}秒`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取完整的Token信息摘要
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static getTokenInfo(token?: string): TokenInfo {
|
||||
const exp = this.getExpiration(token);
|
||||
const remainingMs = this.getRemainingTime(token);
|
||||
|
||||
return {
|
||||
userId: this.getUserId(token),
|
||||
loginName: this.getLoginName(token),
|
||||
expiration: exp ? new Date(exp * 1000).toLocaleString() : null,
|
||||
isExpired: this.isExpired(token),
|
||||
remainingTime: this.formatRemainingTime(remainingMs)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证Token是否有效(格式正确且未过期)
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static isValid(token?: string): boolean {
|
||||
const tokenData = this.parseToken(token);
|
||||
return tokenData !== null && !this.isExpired(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Token的头部信息
|
||||
* @param token JWT token字符串,可选
|
||||
*/
|
||||
static getHeader(token?: string): any | null {
|
||||
try {
|
||||
let targetToken = token;
|
||||
|
||||
if (!targetToken) {
|
||||
const userStore = useUserStore();
|
||||
targetToken = userStore.accessToken;
|
||||
}
|
||||
|
||||
if (!targetToken) return null;
|
||||
|
||||
const parts = targetToken.split('.');
|
||||
if (parts.length !== 3) return null;
|
||||
|
||||
const header = parts[0];
|
||||
const decodedHeader = this.base64UrlDecode(header);
|
||||
return JSON.parse(decodedHeader);
|
||||
} catch (error) {
|
||||
console.error('解析JWT Header失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导出单例方法,方便直接调用
|
||||
export const jwtUtil = JwtUtil;
|
||||
@@ -1,185 +1,697 @@
|
||||
import {ElMessage} from "element-plus";
|
||||
/**
|
||||
* WebSocket客户端服务
|
||||
* 提供WebSocket连接管理、心跳机制、消息处理等功能
|
||||
* 集成JWT token解析,支持自动获取用户登录名
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 2.0
|
||||
*/
|
||||
|
||||
import { ElMessage } from "element-plus";
|
||||
import { jwtUtil } from "./jwtUtil";
|
||||
|
||||
// ============================================================================
|
||||
// 类型定义 (Types & Interfaces)
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* WebSocket消息接口定义(对应后端WebSocketVO结构)
|
||||
*/
|
||||
interface WebSocketMessage<T = any> {
|
||||
type: string; // 消息类型
|
||||
requestId?: string; // 请求ID
|
||||
operateCode?: string; // 操作代码
|
||||
code?: number; // 状态码
|
||||
desc?: string; // 描述信息
|
||||
data?: T; // 泛型数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调函数类型定义
|
||||
*/
|
||||
type CallbackFunction<T = any> = (message: WebSocketMessage<T>) => void;
|
||||
|
||||
/**
|
||||
* WebSocket配置接口
|
||||
*/
|
||||
interface SocketConfig {
|
||||
url: string; // WebSocket服务器地址
|
||||
heartbeatInterval?: number; // 心跳间隔时间(ms)
|
||||
reconnectDelay?: number; // 重连延迟时间(ms)
|
||||
maxReconnectAttempts?: number; // 最大重连次数
|
||||
timeout?: number; // 超时时间(ms)
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接状态枚举
|
||||
*/
|
||||
enum ConnectionStatus {
|
||||
DISCONNECTED = 'disconnected', // 未连接
|
||||
CONNECTING = 'connecting', // 连接中
|
||||
CONNECTED = 'connected', // 已连接
|
||||
RECONNECTING = 'reconnecting', // 重连中
|
||||
ERROR = 'error' // 连接错误
|
||||
}
|
||||
|
||||
/**
|
||||
* 常用的WebSocket消息类型定义命名空间
|
||||
*/
|
||||
namespace WebSocketMessageTypes {
|
||||
/**
|
||||
* 预检测相关消息
|
||||
*/
|
||||
export interface PreTestMessage {
|
||||
deviceId?: string;
|
||||
status?: string;
|
||||
progress?: number;
|
||||
errorInfo?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 系数校准相关消息
|
||||
*/
|
||||
export interface CoefficientMessage {
|
||||
deviceId: string;
|
||||
channel: number;
|
||||
voltage?: string;
|
||||
current?: string;
|
||||
calibrationResult?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 正式检测相关消息
|
||||
*/
|
||||
export interface TestMessage {
|
||||
deviceId: string;
|
||||
testType: string;
|
||||
testResult?: 'success' | 'failed' | 'processing';
|
||||
testData?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用响应消息
|
||||
*/
|
||||
export interface CommonResponse {
|
||||
success: boolean;
|
||||
message?: string;
|
||||
timestamp?: number;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 导出类型
|
||||
// ============================================================================
|
||||
|
||||
export type {
|
||||
WebSocketMessage,
|
||||
CallbackFunction,
|
||||
SocketConfig,
|
||||
WebSocketMessageTypes
|
||||
};
|
||||
|
||||
export {
|
||||
ConnectionStatus
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// 主要服务类
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* WebSocket服务类
|
||||
* 单例模式实现,提供完整的WebSocket连接管理功能
|
||||
*/
|
||||
export default class SocketService {
|
||||
static instance = null;
|
||||
static get Instance() {
|
||||
// ========================================================================
|
||||
// 静态属性和方法 (Static)
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 单例实例
|
||||
*/
|
||||
private static instance: SocketService | null = null;
|
||||
|
||||
/**
|
||||
* 获取单例实例
|
||||
* @returns SocketService实例
|
||||
*/
|
||||
static get Instance(): SocketService {
|
||||
if (!this.instance) {
|
||||
this.instance = new SocketService();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
// 和服务端连接的socket对象
|
||||
ws = null;
|
||||
// 存储回调函数
|
||||
callBackMapping = {};
|
||||
// 标识是否连接成功
|
||||
connected = false;
|
||||
// 记录重试的次数
|
||||
sendRetryCount = 0;
|
||||
// 重新连接尝试的次数
|
||||
connectRetryCount = 0;
|
||||
work:any;
|
||||
workerBlobUrl:any;
|
||||
lastActivityTime= 0; // 上次活动时间戳
|
||||
lastResponseHeartTime = Date.now();//最后一次收到心跳回复时间
|
||||
|
||||
reconnectDelay= 5000; // 重新连接延迟,单位毫秒
|
||||
// ========================================================================
|
||||
// 实例属性 (Properties)
|
||||
// ========================================================================
|
||||
|
||||
// 定义连接服务器的方法
|
||||
connect() {
|
||||
/**
|
||||
* WebSocket连接实例
|
||||
*/
|
||||
private ws: WebSocket | null = null;
|
||||
|
||||
/**
|
||||
* 消息回调函数映射表
|
||||
*/
|
||||
private callBackMapping: Record<string, CallbackFunction<any>> = {};
|
||||
|
||||
/**
|
||||
* 当前连接状态
|
||||
*/
|
||||
private connectionStatus: ConnectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
|
||||
/**
|
||||
* 发送消息重试计数器
|
||||
*/
|
||||
private sendRetryCount: number = 0;
|
||||
|
||||
/**
|
||||
* 连接重试计数器
|
||||
*/
|
||||
private connectRetryCount: number = 0;
|
||||
|
||||
/**
|
||||
* 心跳Worker实例
|
||||
*/
|
||||
private heartbeatWorker: Worker | null = null;
|
||||
|
||||
/**
|
||||
* Worker脚本的Blob URL
|
||||
*/
|
||||
private workerBlobUrl: string | null = null;
|
||||
|
||||
/**
|
||||
* 最后一次收到心跳响应的时间戳
|
||||
*/
|
||||
private lastResponseHeartTime: number = Date.now();
|
||||
|
||||
/**
|
||||
* WebSocket连接配置
|
||||
*/
|
||||
private config: SocketConfig = {
|
||||
url: 'ws://127.0.0.1:7777/hello',
|
||||
// url: 'ws://192.168.1.124:7777/hello',
|
||||
heartbeatInterval: 9000, // 9秒心跳间隔
|
||||
reconnectDelay: 5000, // 5秒重连延迟
|
||||
maxReconnectAttempts: 5, // 最多重连5次
|
||||
timeout: 30000 // 30秒超时
|
||||
};
|
||||
|
||||
// 连接服务器
|
||||
// ========================================================================
|
||||
// 构造函数 (Constructor)
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 私有构造函数,防止外部直接实例化
|
||||
*/
|
||||
private constructor() {
|
||||
this.initializeProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化属性
|
||||
*/
|
||||
private initializeProperties(): void {
|
||||
this.lastResponseHeartTime = Date.now();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Getter属性 (Computed)
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 获取连接状态
|
||||
* @returns 是否已连接
|
||||
*/
|
||||
get connected(): boolean {
|
||||
return this.connectionStatus === ConnectionStatus.CONNECTED;
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 公共方法 (Public Methods)
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 配置WebSocket连接参数
|
||||
* @param config 部分配置对象
|
||||
*/
|
||||
public configure(config: Partial<SocketConfig>): void {
|
||||
this.config = { ...this.config, ...config };
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接WebSocket服务器(同步方式,保持向后兼容)
|
||||
*/
|
||||
public connect(): Promise<void> | void {
|
||||
// 检查浏览器支持
|
||||
if (!window.WebSocket) {
|
||||
return console.log('您的浏览器不支持WebSocket');
|
||||
// console.log('您的浏览器不支持WebSocket');
|
||||
return;
|
||||
}
|
||||
|
||||
// let token = $.cookie('123');
|
||||
// let token = '4E6EF539AAF119D82AC4C2BC84FBA21F';
|
||||
// 防止重复连接
|
||||
if (this.connectionStatus === ConnectionStatus.CONNECTING || this.connected) {
|
||||
// console.warn('WebSocket已连接或正在连接中');
|
||||
return;
|
||||
}
|
||||
|
||||
this.connectionStatus = ConnectionStatus.CONNECTING;
|
||||
|
||||
try {
|
||||
this.ws = new WebSocket(this.buildWebSocketUrl());
|
||||
this.setupEventHandlersLegacy();
|
||||
} catch (error) {
|
||||
this.connectionStatus = ConnectionStatus.ERROR;
|
||||
//console.error('WebSocket连接失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步连接WebSocket服务器
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
public connectAsync(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 检查浏览器支持
|
||||
if (!window.WebSocket) {
|
||||
const error = '您的浏览器不支持WebSocket';
|
||||
//console.error(error);
|
||||
reject(new Error(error));
|
||||
return;
|
||||
}
|
||||
|
||||
// 防止重复连接
|
||||
if (this.connectionStatus === ConnectionStatus.CONNECTING || this.connected) {
|
||||
//console.warn('WebSocket已连接或正在连接中');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
this.connectionStatus = ConnectionStatus.CONNECTING;
|
||||
|
||||
try {
|
||||
this.ws = new WebSocket(this.buildWebSocketUrl());
|
||||
this.setupEventHandlers(resolve, reject);
|
||||
} catch (error) {
|
||||
this.connectionStatus = ConnectionStatus.ERROR;
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册消息回调函数(支持泛型)
|
||||
* @param messageType 消息类型
|
||||
* @param callback 回调函数
|
||||
*/
|
||||
public registerCallBack<T = any>(messageType: string, callback: CallbackFunction<T>): void {
|
||||
if (!messageType || typeof callback !== 'function') {
|
||||
//console.error('注册回调函数参数无效');
|
||||
return;
|
||||
}
|
||||
this.callBackMapping[messageType] = callback;
|
||||
// console.log(`注册消息处理器: ${messageType}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销消息回调函数
|
||||
* @param messageType 消息类型
|
||||
*/
|
||||
public unRegisterCallBack(messageType: string): void {
|
||||
if (this.callBackMapping[messageType]) {
|
||||
delete this.callBackMapping[messageType];
|
||||
//console.log(`注销消息处理器: ${messageType}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送数据到WebSocket服务器
|
||||
* @param data 要发送的数据
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
public send(data: any): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.connected || !this.ws) {
|
||||
// 未连接时的重试机制
|
||||
if (this.sendRetryCount < 3) {
|
||||
this.sendRetryCount++;
|
||||
setTimeout(() => {
|
||||
this.send(data).then(resolve).catch(reject);
|
||||
}, this.sendRetryCount * 500);
|
||||
return;
|
||||
} else {
|
||||
reject(new Error('WebSocket未连接且重试失败'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 重置重试计数
|
||||
this.sendRetryCount = 0;
|
||||
|
||||
// 尝试发送JSON数据,失败则发送原始数据
|
||||
const message = typeof data === 'string' ? data : JSON.stringify(data);
|
||||
this.ws.send(message);
|
||||
|
||||
//console.log('发送消息:', message);
|
||||
resolve();
|
||||
} catch (error) {
|
||||
//console.error('发送消息失败:', error);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭WebSocket连接
|
||||
*/
|
||||
public closeWs(): void {
|
||||
//console.log('正在关闭WebSocket连接...');
|
||||
|
||||
// 清理心跳
|
||||
this.clearHeartbeat();
|
||||
|
||||
// 关闭连接
|
||||
if (this.ws) {
|
||||
this.ws.close(1000, '主动关闭连接');
|
||||
this.ws = null;
|
||||
}
|
||||
|
||||
// 更新状态
|
||||
this.connectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
this.connectRetryCount = 0;
|
||||
this.sendRetryCount = 0;
|
||||
|
||||
//console.log('WebSocket连接已关闭');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前连接状态
|
||||
* @returns 连接状态枚举值
|
||||
*/
|
||||
public getConnectionStatus(): ConnectionStatus {
|
||||
return this.connectionStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取连接统计信息
|
||||
* @returns 连接统计对象
|
||||
*/
|
||||
public getConnectionStats(): {
|
||||
status: ConnectionStatus;
|
||||
connectRetryCount: number;
|
||||
lastResponseHeartTime: number;
|
||||
} {
|
||||
return {
|
||||
status: this.connectionStatus,
|
||||
connectRetryCount: this.connectRetryCount,
|
||||
lastResponseHeartTime: this.lastResponseHeartTime
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const url = 'ws://127.0.0.1:7777/hello?name=cdf'
|
||||
this.ws = new WebSocket(url);
|
||||
// 连接成功的事件
|
||||
// ========================================================================
|
||||
// 私有方法 (Private Methods)
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 构建完整的WebSocket URL
|
||||
* 自动从JWT token中获取loginName作为name参数
|
||||
* @returns 完整的WebSocket URL
|
||||
*/
|
||||
private buildWebSocketUrl(): string {
|
||||
const { url } = this.config;
|
||||
|
||||
// 直接从JWT token中获取loginName作为name参数
|
||||
const loginName = jwtUtil.getLoginName();
|
||||
|
||||
if (loginName) {
|
||||
const separator = url.includes('?') ? '&' : '?';
|
||||
return `${url}${separator}name=${encodeURIComponent(loginName)}`;
|
||||
}
|
||||
|
||||
// 如果无法获取loginName,返回原始URL并输出警告
|
||||
console.warn('无法从JWT token中获取loginName,WebSocket连接可能会失败');
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置WebSocket事件处理器(异步版本)
|
||||
* @param resolve Promise resolve回调
|
||||
* @param reject Promise reject回调
|
||||
*/
|
||||
private setupEventHandlers(resolve: () => void, reject: (error: Error) => void): void {
|
||||
if (!this.ws) return;
|
||||
|
||||
// 连接成功事件
|
||||
this.ws.onopen = () => {
|
||||
ElMessage.success("WebSocket连接服务端成功");
|
||||
// console.log('WebSocket连接成功');
|
||||
this.connectionStatus = ConnectionStatus.CONNECTED;
|
||||
this.connectRetryCount = 0;
|
||||
this.startHeartbeat();
|
||||
resolve();
|
||||
};
|
||||
|
||||
// 连接关闭事件
|
||||
this.ws.onclose = (event: CloseEvent) => {
|
||||
//console.log('WebSocket连接关闭', event.code, event.reason);
|
||||
this.connectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
this.clearHeartbeat();
|
||||
|
||||
// 非正常关闭且未超过最大重连次数,尝试重连
|
||||
if (event.code !== 1000 && this.connectRetryCount < this.config.maxReconnectAttempts!) {
|
||||
this.attemptReconnect();
|
||||
}
|
||||
};
|
||||
|
||||
// 连接错误事件
|
||||
this.ws.onerror = (error: Event) => {
|
||||
console.error('WebSocket连接错误:', error);
|
||||
ElMessage.error("WebSocket连接异常");
|
||||
this.connectionStatus = ConnectionStatus.ERROR;
|
||||
reject(new Error('WebSocket连接失败'));
|
||||
};
|
||||
|
||||
// 消息接收事件
|
||||
this.ws.onmessage = (event: MessageEvent) => {
|
||||
this.handleMessage(event);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置WebSocket事件处理器(兼容版本)
|
||||
*/
|
||||
private setupEventHandlersLegacy(): void {
|
||||
if (!this.ws) return;
|
||||
|
||||
// 连接成功事件
|
||||
this.ws.onopen = () => {
|
||||
ElMessage.success("webSocket连接服务端成功了");
|
||||
console.log('连接服务端成功了');
|
||||
this.connected = true;
|
||||
// 重置重新连接的次数
|
||||
// console.log('连接服务端成功了');
|
||||
this.connectionStatus = ConnectionStatus.CONNECTED;
|
||||
this.connectRetryCount = 0;
|
||||
this.updateLastActivityTime();
|
||||
this.startHeartbeat();
|
||||
};
|
||||
// 1.连接服务端失败
|
||||
// 2.当连接成功之后, 服务器关闭的情况
|
||||
this.ws.onclose = () => {
|
||||
console.log('连接webSocket服务端关闭');
|
||||
this.connected = false;
|
||||
this.connectRetryCount++;
|
||||
|
||||
// 连接关闭事件
|
||||
this.ws.onclose = (event: CloseEvent) => {
|
||||
// console.log('连接webSocket服务端关闭');
|
||||
this.connectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
this.clearHeartbeat();
|
||||
/* setTimeout(() => {
|
||||
|
||||
// 保持原有的重连逻辑(被注释掉的)
|
||||
// this.connectRetryCount++;
|
||||
/* setTimeout(() => {
|
||||
this.connect();
|
||||
}, 500 * this.connectRetryCount);*/
|
||||
|
||||
|
||||
};
|
||||
|
||||
// 连接错误事件
|
||||
this.ws.onerror = () => {
|
||||
ElMessage.error("webSocket连接异常!");
|
||||
|
||||
|
||||
this.connectionStatus = ConnectionStatus.ERROR;
|
||||
};
|
||||
|
||||
// 消息接收事件
|
||||
this.ws.onmessage = (event: MessageEvent) => {
|
||||
this.handleMessage(event);
|
||||
};
|
||||
}
|
||||
|
||||
// 得到服务端发送过来的数据
|
||||
this.ws.onmessage = (event) => {
|
||||
// console.log('🚀 ~ SocketService ~ connect ~ event:', event)
|
||||
if(event.data == 'over') {
|
||||
//心跳消息处理
|
||||
this.lastResponseHeartTime = Date.now();
|
||||
this.updateLastActivityTime(); // 收到心跳响应时更新活动时间
|
||||
}else {
|
||||
let message: { [key: string]: any };
|
||||
try {
|
||||
console.log('Received message:',event.data)
|
||||
message = JSON.parse(event.data);
|
||||
} catch (e) {
|
||||
return console.error("消息解析失败", event.data, e);
|
||||
}
|
||||
/**
|
||||
* 处理接收到的消息
|
||||
* 支持心跳响应、JSON消息和普通文本消息
|
||||
* @param event WebSocket消息事件
|
||||
*/
|
||||
private handleMessage(event: MessageEvent): void {
|
||||
// console.log('Received message:', event.data);
|
||||
|
||||
// 心跳响应处理
|
||||
if (event.data === 'over') {
|
||||
// console.log(`${new Date().toLocaleTimeString()} - 收到心跳响应`);
|
||||
this.lastResponseHeartTime = Date.now();
|
||||
return;
|
||||
}
|
||||
|
||||
/* 通过接受服务端发送的type字段来回调函数 */
|
||||
// 检查消息是否为空或无效
|
||||
if (!event.data || event.data.trim() === '') {
|
||||
console.warn('收到空消息,跳过处理');
|
||||
return;
|
||||
}
|
||||
|
||||
// 业务消息处理
|
||||
try {
|
||||
// 检查是否为JSON格式
|
||||
if (typeof event.data === 'string' && (event.data.startsWith('{') || event.data.startsWith('['))) {
|
||||
const message: WebSocketMessage = JSON.parse(event.data);
|
||||
if (message?.type && this.callBackMapping[message.type]) {
|
||||
this.callBackMapping[message.type](message);
|
||||
} else {
|
||||
console.log("抛弃====>")
|
||||
console.log(event.data)
|
||||
/* 丢弃或继续写你的逻辑 */
|
||||
console.warn('未找到对应的消息处理器:', message.type);
|
||||
}
|
||||
} else {
|
||||
// 非JSON格式的消息,作为普通文本处理
|
||||
// console.log('收到非JSON格式消息:', event.data);
|
||||
// 可以添加文本消息的处理逻辑
|
||||
if (this.callBackMapping['text']) {
|
||||
this.callBackMapping['text']({
|
||||
type: 'text',
|
||||
data: event.data
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
startHeartbeat() {
|
||||
this.lastResponseHeartTime = Date.now();
|
||||
const _this = this
|
||||
_this.workerBlobUrl = window.URL.createObjectURL(new Blob(['(function(e){setInterval(function(){this.postMessage(null)},9000)})()']));
|
||||
|
||||
this.work = new Worker(_this.workerBlobUrl);
|
||||
this.work.onmessage = function(e){
|
||||
//判断多久没收到心跳响应
|
||||
|
||||
if(_this.lastActivityTime - _this.lastResponseHeartTime > 30000){
|
||||
//说明已经三轮心跳没收到回复了,关闭检测,提示用户。
|
||||
ElMessage.error("业务主体模块发生未知异常,请尝试重新启动!");
|
||||
_this.clearHeartbeat();
|
||||
return;
|
||||
}
|
||||
_this.sendHeartbeat();
|
||||
}
|
||||
|
||||
}
|
||||
sendHeartbeat() {
|
||||
console.log(new Date()+"进入心跳消息发送。。。。。。。。。。。。。")
|
||||
this.ws.send('alive');
|
||||
this.updateLastActivityTime(); // 发送心跳后更新活动时间
|
||||
}
|
||||
|
||||
|
||||
updateLastActivityTime() {
|
||||
this.lastActivityTime = Date.now();
|
||||
}
|
||||
|
||||
clearHeartbeat() {
|
||||
const _this = this
|
||||
if (_this.work) {
|
||||
_this.work.terminate();
|
||||
_this.work = null;
|
||||
}
|
||||
if (_this.workerBlobUrl) {
|
||||
window.URL.revokeObjectURL(_this.workerBlobUrl); // 释放临时的Blob URL
|
||||
_this.workerBlobUrl = null;
|
||||
|
||||
} catch (error) {
|
||||
console.error('消息解析失败:', event.data, error);
|
||||
console.error('消息类型:', typeof event.data);
|
||||
console.error('消息长度:', event.data?.length || 0);
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 重连机制相关方法
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 尝试重新连接WebSocket
|
||||
*/
|
||||
private attemptReconnect(): void {
|
||||
if (this.connectionStatus === ConnectionStatus.RECONNECTING) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 回调函数的注册
|
||||
registerCallBack(socketType, callBack) {
|
||||
this.callBackMapping[socketType] = callBack;
|
||||
}
|
||||
// 取消某一个回调函数
|
||||
unRegisterCallBack(socketType) {
|
||||
this.callBackMapping[socketType] = null;
|
||||
}
|
||||
// 发送数据的方法
|
||||
send(data) {
|
||||
// 判断此时此刻有没有连接成功
|
||||
if (this.connected) {
|
||||
this.sendRetryCount = 0;
|
||||
this.connectionStatus = ConnectionStatus.RECONNECTING;
|
||||
this.connectRetryCount++;
|
||||
|
||||
const delay = this.config.reconnectDelay! * this.connectRetryCount;
|
||||
|
||||
// console.log(`尝试第${this.connectRetryCount}次重连,${delay}ms后开始...`);
|
||||
|
||||
setTimeout(() => {
|
||||
try {
|
||||
this.ws.send(JSON.stringify(data));
|
||||
} catch (e) {
|
||||
this.ws.send(data);
|
||||
const result = this.connect();
|
||||
if (result instanceof Promise) {
|
||||
result.catch((error: any) => {
|
||||
console.error('重连失败:', error);
|
||||
});
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('重连失败:', error);
|
||||
}
|
||||
} else {
|
||||
this.sendRetryCount++;
|
||||
setTimeout(() => {
|
||||
this.send(data);
|
||||
}, this.sendRetryCount * 500);
|
||||
}, delay);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 心跳机制相关方法
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 启动心跳机制
|
||||
*/
|
||||
private startHeartbeat(): void {
|
||||
this.lastResponseHeartTime = Date.now();
|
||||
this.createHeartbeatWorker();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建心跳Worker
|
||||
* 使用Worker在独立线程中处理心跳定时器,避免主线程阻塞
|
||||
*/
|
||||
private createHeartbeatWorker(): void {
|
||||
try {
|
||||
// 创建Worker脚本
|
||||
const workerScript = `
|
||||
setInterval(function() {
|
||||
postMessage('heartbeat');
|
||||
}, ${this.config.heartbeatInterval});
|
||||
`;
|
||||
|
||||
this.workerBlobUrl = window.URL.createObjectURL(
|
||||
new Blob([workerScript], { type: 'application/javascript' })
|
||||
);
|
||||
|
||||
this.heartbeatWorker = new Worker(this.workerBlobUrl);
|
||||
|
||||
// 心跳Worker消息处理
|
||||
this.heartbeatWorker.onmessage = (event: MessageEvent) => {
|
||||
this.handleHeartbeatTick();
|
||||
};
|
||||
|
||||
// Worker错误处理
|
||||
this.heartbeatWorker.onerror = (error: ErrorEvent) => {
|
||||
console.error('心跳Worker错误:', error);
|
||||
this.clearHeartbeat();
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.error('创建心跳Worker失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 断开方法
|
||||
closeWs() {
|
||||
if (this.connected) {
|
||||
this.ws.close()
|
||||
/**
|
||||
* 处理心跳定时器事件
|
||||
* 检查连接超时并发送心跳消息
|
||||
*/
|
||||
private handleHeartbeatTick(): void {
|
||||
// 检查是否超时(距离上次收到心跳响应的时间)
|
||||
const timeSinceLastResponse = Date.now() - this.lastResponseHeartTime;
|
||||
|
||||
if (timeSinceLastResponse > this.config.timeout!) {
|
||||
console.error(`WebSocket心跳超时: ${timeSinceLastResponse}ms > ${this.config.timeout}ms`);
|
||||
ElMessage.error("WebSocket连接超时,请检查网络连接!");
|
||||
this.clearHeartbeat();
|
||||
this.closeWs();
|
||||
return;
|
||||
}
|
||||
console.log('执行WS关闭命令..');
|
||||
|
||||
this.sendHeartbeat();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送心跳消息到服务器
|
||||
*/
|
||||
private sendHeartbeat(): void {
|
||||
if (this.connected && this.ws) {
|
||||
// console.log(`${new Date().toLocaleTimeString()} - 发送心跳消息`);
|
||||
this.ws.send('alive');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理心跳机制
|
||||
* 终止Worker并清理相关资源
|
||||
*/
|
||||
private clearHeartbeat(): void {
|
||||
if (this.heartbeatWorker) {
|
||||
this.heartbeatWorker.terminate();
|
||||
this.heartbeatWorker = null;
|
||||
}
|
||||
|
||||
if (this.workerBlobUrl) {
|
||||
window.URL.revokeObjectURL(this.workerBlobUrl);
|
||||
this.workerBlobUrl = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,222 +1,224 @@
|
||||
<template>
|
||||
<el-dialog :title="dialogTitle" :model-value="dialogVisible" @close="close" v-bind="dialogMiddle" align-center>
|
||||
<el-form :model="formContent" ref='dialogFormRef' :rules='rules' class="form-two">
|
||||
<el-form-item label="上级菜单" prop="pid" :label-width="100">
|
||||
<el-tree-select
|
||||
v-model="displayPid"
|
||||
:data="functionList"
|
||||
check-strictly
|
||||
:render-after-expand="false"
|
||||
show-checkbox
|
||||
check-on-click-node
|
||||
node-key="id"
|
||||
:props="defaultProps"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name" :label-width="100">
|
||||
<el-input v-model="formContent.name" maxlength="32" show-word-limit/>
|
||||
</el-form-item>
|
||||
<el-form-item label="编码" prop="code" :label-width="100">
|
||||
<el-input v-model="formContent.code" maxlength="32" show-word-limit/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!formContent.type" label="图标" prop="icon" :label-width="100">
|
||||
<IconSelect
|
||||
v-model="formContent.icon"
|
||||
:iconValue="formContent.icon"
|
||||
@update:icon-value="iconValue => formContent.icon = iconValue"
|
||||
placeholder="选择一个图标"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!formContent.type" label="路由地址" prop="path" :label-width="100" >
|
||||
<el-input v-model="formContent.path" maxlength="32" show-word-limit/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!formContent.type" label="组件地址" prop="component" :label-width="100">
|
||||
<el-input v-model="formContent.component" maxlength="32" show-word-limit/>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort" :label-width="100">
|
||||
<el-input-number v-model="formContent.sort" :min='1' :max='999' />
|
||||
</el-form-item>
|
||||
<el-form-item label='类型' prop='type' :label-width="100">
|
||||
<el-select v-model="formContent.type" clearable placeholder="请选择资源类型">
|
||||
<el-option label="菜单" :value="0"></el-option>
|
||||
<el-option label="按钮" :value="1"></el-option>
|
||||
<!-- <el-option label="公共资源" :value="2"></el-option>
|
||||
<el-form :model="formContent" ref="dialogFormRef" :rules="rules" class="form-two">
|
||||
<el-form-item label="上级菜单" prop="pid" :label-width="100">
|
||||
<el-tree-select
|
||||
v-model="displayPid"
|
||||
:data="functionList"
|
||||
check-strictly
|
||||
:render-after-expand="false"
|
||||
show-checkbox
|
||||
check-on-click-node
|
||||
node-key="id"
|
||||
:props="defaultProps"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name" :label-width="100">
|
||||
<el-input v-model="formContent.name" maxlength="32" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item label="编码" prop="code" :label-width="100">
|
||||
<el-input v-model="formContent.code" maxlength="32" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!formContent.type" label="图标" prop="icon" :label-width="100">
|
||||
<IconSelect
|
||||
v-model="formContent.icon"
|
||||
:iconValue="formContent.icon"
|
||||
@update:icon-value="iconValue => (formContent.icon = iconValue)"
|
||||
placeholder="选择一个图标"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!formContent.type" label="路由地址" prop="path" :label-width="100">
|
||||
<el-input v-model="formContent.path" maxlength="32" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!formContent.type" label="组件地址" prop="component" :label-width="100">
|
||||
<el-input v-model="formContent.component" maxlength="32" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort" :label-width="100">
|
||||
<el-input-number v-model="formContent.sort" :min="1" :max="999" />
|
||||
</el-form-item>
|
||||
<el-form-item label="类型" prop="type" :label-width="100">
|
||||
<el-select v-model="formContent.type" clearable placeholder="请选择资源类型">
|
||||
<el-option label="菜单" :value="0"></el-option>
|
||||
<el-option label="按钮" :value="1"></el-option>
|
||||
<!-- <el-option label="公共资源" :value="2"></el-option>
|
||||
<el-option label="服务间调用资源" :value="3"></el-option> -->
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述" prop="remark" :label-width="100">
|
||||
<el-input v-model="formContent.remark" :rows="2" type="textarea"/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="close()">取 消</el-button>
|
||||
<el-button type="primary" @click="save()">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述" prop="remark" :label-width="100">
|
||||
<el-input v-model="formContent.remark" :rows="2" type="textarea" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="close()">取 消</el-button>
|
||||
<el-button type="primary" @click="save()">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="ResourceDialog">
|
||||
import { defineProps, defineEmits,watch,ref, type Ref, computed } from 'vue';
|
||||
import { dialogMiddle } from '@/utils/elementBind'
|
||||
import { ElMessage, type FormInstance, type FormItemRule } from 'element-plus'
|
||||
import { useDictStore } from '@/stores/modules/dict'
|
||||
import type { Function } from "@/api/user/interface/function"
|
||||
import {addFunction,updateFunction,getFunctionListNoButton} from '@/api/user/function/index'
|
||||
import IconSelect from '@/components/SelectIcon/index.vue'
|
||||
const value = ref()
|
||||
// 树形节点配置
|
||||
const defaultProps = {
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="ResourceDialog">
|
||||
import { computed, type Ref, ref, watch } from 'vue'
|
||||
import { dialogMiddle } from '@/utils/elementBind'
|
||||
import { ElMessage, type FormInstance, type FormItemRule } from 'element-plus'
|
||||
import { useDictStore } from '@/stores/modules/dict'
|
||||
import type { Function } from '@/api/user/interface/function'
|
||||
import { addFunction, getFunctionListNoButton, updateFunction } from '@/api/user/function/index'
|
||||
import IconSelect from '@/components/SelectIcon/index.vue'
|
||||
|
||||
const value = ref()
|
||||
// 树形节点配置
|
||||
const defaultProps = {
|
||||
children: 'children',
|
||||
label: 'name',
|
||||
value: 'id'
|
||||
};
|
||||
const functionList = ref<Function.ResFunction[]>([])
|
||||
const dictStore = useDictStore()
|
||||
// 定义弹出组件元信息
|
||||
const dialogFormRef = ref()
|
||||
function useMetaInfo() {
|
||||
}
|
||||
const functionList = ref<Function.ResFunction[]>([])
|
||||
const dictStore = useDictStore()
|
||||
// 定义弹出组件元信息
|
||||
const dialogFormRef = ref()
|
||||
function useMetaInfo() {
|
||||
const dialogVisible = ref(false)
|
||||
const titleType = ref('add')
|
||||
const formContent = ref<Function.ResFunction>({
|
||||
id: '',//资源表Id
|
||||
pid:'',//节点(0为根节点)
|
||||
pids:'',//节点上层所有节点
|
||||
name: '',//名称
|
||||
code:'',//资源标识
|
||||
path:'',//路径
|
||||
component:'',
|
||||
icon:undefined as string | undefined, // 图标
|
||||
sort:100,//排序
|
||||
type:0,//资源类型0-菜单、1-按钮、2-公共资源、3-服务间调用资源
|
||||
remark: '',//权限资源描述
|
||||
state:1,//权限资源状态
|
||||
id: '', //资源表Id
|
||||
pid: '', //节点(0为根节点)
|
||||
pids: '', //节点上层所有节点
|
||||
name: '', //名称
|
||||
code: '', //资源标识
|
||||
path: '', //路径
|
||||
component: '',
|
||||
icon: undefined as string | undefined, // 图标
|
||||
sort: 100, //排序
|
||||
type: 0, //资源类型0-菜单、1-按钮、2-公共资源、3-服务间调用资源
|
||||
remark: '', //权限资源描述
|
||||
state: 1 //权限资源状态
|
||||
})
|
||||
return { dialogVisible, titleType, formContent }
|
||||
}
|
||||
}
|
||||
|
||||
const { dialogVisible, titleType, formContent } = useMetaInfo()
|
||||
const { dialogVisible, titleType, formContent } = useMetaInfo()
|
||||
// 清空formContent
|
||||
const resetFormContent = () => {
|
||||
formContent.value = {
|
||||
id: '',//资源表Id
|
||||
pid:'',//节点(0为根节点)
|
||||
pids:'',//节点上层所有节点
|
||||
name: '',//名称
|
||||
code:'',//资源标识
|
||||
path:'',//路径
|
||||
component:'',
|
||||
icon:undefined,//图标
|
||||
sort:100,//排序
|
||||
type:0,//资源类型0-菜单、1-按钮、2-公共资源、3-服务间调用资源
|
||||
remark:'',//权限资源描述
|
||||
state:1,//权限资源状态
|
||||
id: '', //资源表Id
|
||||
pid: '', //节点(0为根节点)
|
||||
pids: '', //节点上层所有节点
|
||||
name: '', //名称
|
||||
code: '', //资源标识
|
||||
path: '', //路径
|
||||
component: '',
|
||||
icon: undefined, //图标
|
||||
sort: 100, //排序
|
||||
type: 0, //资源类型0-菜单、1-按钮、2-公共资源、3-服务间调用资源
|
||||
remark: '', //权限资源描述
|
||||
state: 1 //权限资源状态
|
||||
}
|
||||
}
|
||||
|
||||
let dialogTitle = computed(() => {
|
||||
}
|
||||
|
||||
let dialogTitle = computed(() => {
|
||||
return titleType.value === 'add' ? '新增菜单' : '编辑菜单'
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
// 定义规则
|
||||
const formRuleRef = ref<FormInstance>()
|
||||
const rules: Ref<Record<string, Array<FormItemRule>>> = ref({
|
||||
name: [{ required: true, trigger: 'blur', message: '菜单名称必填!' }],
|
||||
code: [{ required: true, trigger: 'blur', message: '编码必填!' }],
|
||||
path : [{ required: true, trigger: 'blur', message: '路由地址必填!' }],
|
||||
component :[{ required: true, trigger: 'blur', message: '组件地址必填!' }]
|
||||
})
|
||||
|
||||
// 定义规则
|
||||
const formRuleRef = ref<FormInstance>()
|
||||
const rules : Ref<Record<string, Array<FormItemRule>>> = ref({
|
||||
name :[{required:true,trigger:'blur',message:'菜单名称必填!'}],
|
||||
code :[{required:true,trigger:'blur',message:'编码必填!'}]
|
||||
})
|
||||
// watch(
|
||||
// () => formContent.value.type,
|
||||
// newVal => {
|
||||
// if (newVal === 1) {
|
||||
// // 选择按钮时,路由地址和组件地址无需校验
|
||||
// rules.value.path = []
|
||||
// rules.value.component = []
|
||||
// } else {
|
||||
// // 其他情况下,路由地址和组件地址需要校验
|
||||
// rules.value.path = [{ required: true, trigger: 'blur', message: '路由地址必填!' }]
|
||||
// rules.value.component = [{ required: true, trigger: 'blur', message: '组件地址必填!' }]
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
|
||||
watch(() => formContent.value.type, (newVal) => {
|
||||
if (newVal === 1) {
|
||||
// 选择按钮时,路由地址和组件地址无需校验
|
||||
rules.value.path = [];
|
||||
rules.value.component = [];
|
||||
} else {
|
||||
// 其他情况下,路由地址和组件地址需要校验
|
||||
rules.value.path = [{ required: true, trigger: 'blur', message: '路由地址必填!' }];
|
||||
rules.value.component = [{ required: true, trigger: 'blur', message: '组件地址必填!' }];
|
||||
}
|
||||
});
|
||||
|
||||
// 关闭弹窗
|
||||
// 关闭弹窗
|
||||
const close = () => {
|
||||
dialogVisible.value = false
|
||||
// 清空dialogForm中的值
|
||||
resetFormContent()
|
||||
// 重置表单
|
||||
dialogFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 计算属性,用于控制显示的 pid
|
||||
const displayPid = computed({
|
||||
get: () => {
|
||||
return formContent.value.pid === '0' ? '' : formContent.value.pid;
|
||||
},
|
||||
set: (value) => {
|
||||
formContent.value.pid = value;
|
||||
}
|
||||
});
|
||||
get: () => {
|
||||
return formContent.value.pid === '0' ? '' : formContent.value.pid
|
||||
},
|
||||
set: value => {
|
||||
formContent.value.pid = value
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// 保存数据
|
||||
const save = () => {
|
||||
// 保存数据
|
||||
const save = () => {
|
||||
try {
|
||||
dialogFormRef.value?.validate(async (valid: boolean) => {
|
||||
|
||||
if (formContent.value.pid === undefined || formContent.value.pid === null || formContent.value.pid === '') {
|
||||
formContent.value.pid = '0';
|
||||
}
|
||||
if (formContent.value.pids === undefined || formContent.value.pids === null || formContent.value.pids === '') {
|
||||
formContent.value.pids = '0';
|
||||
}
|
||||
if (valid) {
|
||||
if (formContent.value.id) {
|
||||
await updateFunction(formContent.value);
|
||||
} else {
|
||||
await addFunction(formContent.value);
|
||||
}
|
||||
ElMessage.success({ message: `${dialogTitle.value}成功!` })
|
||||
close()
|
||||
// 刷新表格
|
||||
await props.refreshTable!()
|
||||
|
||||
}
|
||||
})
|
||||
if (formContent.value.pid === undefined || formContent.value.pid === null || formContent.value.pid === '') {
|
||||
formContent.value.pid = '0'
|
||||
}
|
||||
if (
|
||||
formContent.value.pids === undefined ||
|
||||
formContent.value.pids === null ||
|
||||
formContent.value.pids === ''
|
||||
) {
|
||||
formContent.value.pids = '0'
|
||||
}
|
||||
if (valid) {
|
||||
if (formContent.value.id) {
|
||||
await updateFunction(formContent.value)
|
||||
} else {
|
||||
await addFunction(formContent.value)
|
||||
}
|
||||
ElMessage.success({ message: `${dialogTitle.value}成功!` })
|
||||
close()
|
||||
// 刷新表格
|
||||
await props.refreshTable!()
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('验证过程中出现错误', err)
|
||||
console.error('验证过程中出现错误', err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 打开弹窗,可能是新增,也可能是编辑
|
||||
const open = async (sign: string, data: Function.ResFunction) => {
|
||||
// 打开弹窗,可能是新增,也可能是编辑
|
||||
const open = async (sign: string, data: Function.ResFunction) => {
|
||||
// 重置表单
|
||||
dialogFormRef.value?.resetFields()
|
||||
// 清空表单校验
|
||||
dialogFormRef.value?.clearValidate()
|
||||
const response = await getFunctionListNoButton()
|
||||
functionList.value = response.data as unknown as Function.ResFunction[]
|
||||
titleType.value = sign
|
||||
dialogVisible.value = true
|
||||
rules.value.path = [{ required: true, trigger: 'blur', message: '路由地址必填!' }];
|
||||
rules.value.component = [{ required: true, trigger: 'blur', message: '组件地址必填!' }];
|
||||
|
||||
if (formContent.value.pid ==='0') {
|
||||
formContent.value.pid = '';
|
||||
|
||||
if (formContent.value.pid === '0') {
|
||||
formContent.value.pid = ''
|
||||
}
|
||||
|
||||
if (data.id) {
|
||||
formContent.value = { ...data }
|
||||
formContent.value = { ...data }
|
||||
} else {
|
||||
resetFormContent()
|
||||
resetFormContent()
|
||||
}
|
||||
}
|
||||
|
||||
// 对外映射
|
||||
defineExpose({ open })
|
||||
const props = defineProps<{
|
||||
refreshTable: (() => Promise<void>) | undefined;
|
||||
}>()
|
||||
</script>
|
||||
|
||||
}
|
||||
|
||||
// 对外映射
|
||||
defineExpose({ open })
|
||||
const props = defineProps<{
|
||||
refreshTable: (() => Promise<void>) | undefined
|
||||
}>()
|
||||
</script>
|
||||