leadal-auth 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -0
- package/babel.config.js +5 -0
- package/jsconfig.json +19 -0
- package/ld-auth/demo.html +1 -0
- package/ld-auth/ld-auth.common.js +44730 -0
- package/ld-auth/ld-auth.css +1 -0
- package/ld-auth/ld-auth.umd.js +44730 -0
- package/ld-auth/ld-auth.umd.min.js +55 -0
- package/package.json +58 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +17 -0
- package/public/models/age_gender_model-shard1 +0 -0
- package/public/models/age_gender_model-weights_manifest.json +1 -0
- package/public/models/face_expression_model-shard1 +0 -0
- package/public/models/face_expression_model-weights_manifest.json +1 -0
- package/public/models/face_landmark_68_model-shard1 +0 -0
- package/public/models/face_landmark_68_model-weights_manifest.json +1 -0
- package/public/models/face_landmark_68_tiny_model-shard1 +0 -0
- package/public/models/face_landmark_68_tiny_model-weights_manifest.json +1 -0
- package/public/models/face_recognition_model-shard1 +0 -0
- package/public/models/face_recognition_model-shard2 +6 -0
- package/public/models/face_recognition_model-weights_manifest.json +1 -0
- package/public/models/mtcnn_model-shard1 +0 -0
- package/public/models/mtcnn_model-weights_manifest.json +1 -0
- package/public/models/ssd_mobilenetv1_model-shard1 +0 -0
- package/public/models/ssd_mobilenetv1_model-shard2 +145 -0
- package/public/models/ssd_mobilenetv1_model-weights_manifest.json +1 -0
- package/public/models/tiny_face_detector_model-shard1 +0 -0
- package/public/models/tiny_face_detector_model-weights_manifest.json +1 -0
- package/src/App.vue +19 -0
- package/src/api/card.js +58 -0
- package/src/api/face.js +37 -0
- package/src/api/finger.js +64 -0
- package/src/api/index.js +100 -0
- package/src/assets/BIN.png +0 -0
- package/src/assets/CLOSE.svg +11 -0
- package/src/assets/blue-left.png +0 -0
- package/src/assets/blue-right.png +0 -0
- package/src/assets/finger-ready.png +0 -0
- package/src/assets/finger-select.png +0 -0
- package/src/assets/finger-status-1-last.png +0 -0
- package/src/assets/finger-status-1.gif +0 -0
- package/src/assets/finger-status-2-last.png +0 -0
- package/src/assets/finger-status-2.gif +0 -0
- package/src/assets/finger-status-3-last.png +0 -0
- package/src/assets/finger-status-3.gif +0 -0
- package/src/assets/finger-status-compeleted.png +0 -0
- package/src/assets/finger-status-start.png +0 -0
- package/src/assets/icon-camera.png +0 -0
- package/src/assets/icon-picture.png +0 -0
- package/src/assets/icon-success.png +0 -0
- package/src/assets/img-camera.png +0 -0
- package/src/assets/img-card.png +0 -0
- package/src/assets/img-loading.png +0 -0
- package/src/assets/left.png +0 -0
- package/src/assets/logo.png +0 -0
- package/src/assets/right.png +0 -0
- package/src/assets/ukey1.png +0 -0
- package/src/assets/ukey2.png +0 -0
- package/src/assets//346/214/207/347/272/271/350/257/206/345/210/2531.png +0 -0
- package/src/assets//346/214/207/347/272/271/350/257/206/345/210/2532.png +0 -0
- package/src/components/auth-com.vue +100 -0
- package/src/components/card-register/components/CardTable.vue +94 -0
- package/src/components/card-register/components/RegisterDialog.vue +137 -0
- package/src/components/card-register/index.vue +110 -0
- package/src/components/edit-user-dialog.vue +141 -0
- package/src/components/empty.vue +13 -0
- package/src/components/face-register/components/ChooseCameraOrPicture.vue +59 -0
- package/src/components/face-register/components/FaceDetected.vue +543 -0
- package/src/components/face-register/components/FaceInfo.vue +171 -0
- package/src/components/face-register/components/FacePicture.vue +85 -0
- package/src/components/face-register/components/UploadPicture.vue +336 -0
- package/src/components/face-register/index.vue +242 -0
- package/src/components/finger-register/index.vue +685 -0
- package/src/components/organ-tree.vue +211 -0
- package/src/components/tree-select.vue +131 -0
- package/src/components/user-drawer.vue +147 -0
- package/src/components/user-info.vue +272 -0
- package/src/components/user-table.vue +405 -0
- package/src/main.js +26 -0
- package/src/package/auth-manage/index.vue +461 -0
- package/src/package/index.js +22 -0
- package/src/store/index.js +39 -0
- package/src/styles/common.scss +183 -0
- package/src/styles/index.scss +38 -0
- package/src/utils/dict.js +47 -0
- package/src/utils/event-bus.js +6 -0
- package/src/utils/request-auth.js +64 -0
- package/src/utils/request.js +64 -0
- package/src/utils/websocket.js +282 -0
- package/vue.config.js +43 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
@import url("./common.scss");
|
|
2
|
+
|
|
3
|
+
body {
|
|
4
|
+
margin: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
span {
|
|
8
|
+
font-size: 14px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.f_center {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.f_around {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: space-around;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.f_between {
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: space-between;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.f_end {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: flex-end;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* 确保 el-message 的 z-index 高于 el-drawer */
|
|
36
|
+
.el-message {
|
|
37
|
+
z-index: 9999 !important;
|
|
38
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const GENDER = {
|
|
2
|
+
0: '男',
|
|
3
|
+
1: '女',
|
|
4
|
+
2: '保密'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const USER_TYPE = {
|
|
8
|
+
0: '系统用户',
|
|
9
|
+
1: '临时用户',
|
|
10
|
+
2: '职员',
|
|
11
|
+
4: '会员'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const SECRET_LEVEL_LIST = [
|
|
15
|
+
{ label: "公开", value: 1 },
|
|
16
|
+
{ label: "内部", value: 2 },
|
|
17
|
+
{ label: "秘密", value: 4 },
|
|
18
|
+
{ label: "机密", value: 8 },
|
|
19
|
+
{ label: "绝密", value: 16 },
|
|
20
|
+
{ label: "核心机密", value: 32 },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
export const SECRET_LEVEL = {
|
|
24
|
+
1: '公开',
|
|
25
|
+
2: '内部',
|
|
26
|
+
4: '秘密',
|
|
27
|
+
8: '机密',
|
|
28
|
+
16: '绝密',
|
|
29
|
+
32: '核心机密'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const AUTH_TYPE = {
|
|
33
|
+
'face': '人脸采集',
|
|
34
|
+
'finger': '指纹采集',
|
|
35
|
+
'idCard': '身份卡绑定',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const dictToArray = (obj, isNum = true) => {
|
|
39
|
+
const dictArr = []
|
|
40
|
+
for(const i in obj) {
|
|
41
|
+
dictArr.push({
|
|
42
|
+
label: obj[i],
|
|
43
|
+
value: isNum ? parseInt(i) : i
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
return dictArr
|
|
47
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { Message } from "element-ui";
|
|
3
|
+
import store from "../store";
|
|
4
|
+
|
|
5
|
+
// create an axios instance
|
|
6
|
+
const service = axios.create({
|
|
7
|
+
timeout: 50000, // request timeout
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// request interceptor
|
|
11
|
+
service.interceptors.request.use(
|
|
12
|
+
(config) => {
|
|
13
|
+
if (process.env.NODE_ENV === "development") {
|
|
14
|
+
config.baseURL = "/plugin"; // 开发环境使用代理,baseURL留空
|
|
15
|
+
} else {
|
|
16
|
+
config.baseURL = store.state.authUrl + "/plugin";
|
|
17
|
+
}
|
|
18
|
+
return config;
|
|
19
|
+
},
|
|
20
|
+
(error) => {
|
|
21
|
+
// do something with request error
|
|
22
|
+
console.log(error); // for debug
|
|
23
|
+
return Promise.reject(error);
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// response interceptor
|
|
28
|
+
service.interceptors.response.use(
|
|
29
|
+
/**
|
|
30
|
+
* If you want to get http information such as headers or status
|
|
31
|
+
* Please return response => response
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Determine the request status by custom code
|
|
36
|
+
* Here is just an example
|
|
37
|
+
* You can also judge the status by HTTP Status Code
|
|
38
|
+
*/
|
|
39
|
+
(response) => {
|
|
40
|
+
const res = response.data;
|
|
41
|
+
// if the custom code is not 20000, it is judged as an error.
|
|
42
|
+
if (res.code && res.code !== 0 && res.code !== 200) {
|
|
43
|
+
Message({
|
|
44
|
+
message: res.message || "请求失败,请稍后再试",
|
|
45
|
+
type: "error",
|
|
46
|
+
duration: 5 * 1000,
|
|
47
|
+
});
|
|
48
|
+
return Promise.reject(new Error(res.message || "Error"));
|
|
49
|
+
} else {
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
(error) => {
|
|
54
|
+
console.log("err" + error); // for debug
|
|
55
|
+
Message({
|
|
56
|
+
message: error.message,
|
|
57
|
+
type: "error",
|
|
58
|
+
duration: 5 * 1000,
|
|
59
|
+
});
|
|
60
|
+
return Promise.reject(error);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
export default service;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { Message } from "element-ui";
|
|
3
|
+
import store from "../store";
|
|
4
|
+
|
|
5
|
+
// create an axios instance
|
|
6
|
+
const service = axios.create({
|
|
7
|
+
timeout: 50000, // request timeout
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// request interceptor
|
|
11
|
+
service.interceptors.request.use(
|
|
12
|
+
(config) => {
|
|
13
|
+
if (process.env.NODE_ENV === "development") {
|
|
14
|
+
config.baseURL = "/auth-component"; // 开发环境使用代理,baseURL留空
|
|
15
|
+
} else {
|
|
16
|
+
config.baseURL = store.state.baseUrl + "/auth-component";
|
|
17
|
+
}
|
|
18
|
+
return config;
|
|
19
|
+
},
|
|
20
|
+
(error) => {
|
|
21
|
+
// do something with request error
|
|
22
|
+
console.log(error); // for debug
|
|
23
|
+
return Promise.reject(error);
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// response interceptor
|
|
28
|
+
service.interceptors.response.use(
|
|
29
|
+
/**
|
|
30
|
+
* If you want to get http information such as headers or status
|
|
31
|
+
* Please return response => response
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Determine the request status by custom code
|
|
36
|
+
* Here is just an example
|
|
37
|
+
* You can also judge the status by HTTP Status Code
|
|
38
|
+
*/
|
|
39
|
+
(response) => {
|
|
40
|
+
const res = response.data;
|
|
41
|
+
// if the custom code is not 20000, it is judged as an error.
|
|
42
|
+
if (res.code && res.code !== 0 && res.code !== 200) {
|
|
43
|
+
Message({
|
|
44
|
+
message: res.message || "请求失败,请稍后再试",
|
|
45
|
+
type: "error",
|
|
46
|
+
duration: 5 * 1000,
|
|
47
|
+
});
|
|
48
|
+
return Promise.reject(new Error(res.message || "Error"));
|
|
49
|
+
} else {
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
(error) => {
|
|
54
|
+
console.log("err" + error); // for debug
|
|
55
|
+
Message({
|
|
56
|
+
message: error.message,
|
|
57
|
+
type: "error",
|
|
58
|
+
duration: 5 * 1000,
|
|
59
|
+
});
|
|
60
|
+
return Promise.reject(error);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
export default service;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket工具类
|
|
3
|
+
* 提供WebSocket连接、发送、接收、重连等功能
|
|
4
|
+
*/
|
|
5
|
+
class WebSocketClient {
|
|
6
|
+
constructor(url, options = {}) {
|
|
7
|
+
this.url = url
|
|
8
|
+
this.options = {
|
|
9
|
+
reconnectInterval: 5000, // 重连间隔时间
|
|
10
|
+
maxReconnectAttempts: 10, // 最大重连次数
|
|
11
|
+
heartbeatInterval: 120000, // 心跳间隔
|
|
12
|
+
...options
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
this.ws = null
|
|
16
|
+
this.reconnectAttempts = 0
|
|
17
|
+
this.isConnected = false
|
|
18
|
+
this.heartbeatTimer = null
|
|
19
|
+
this.eventListeners = new Map()
|
|
20
|
+
|
|
21
|
+
// 绑定方法的this
|
|
22
|
+
this.onOpen = this.onOpen.bind(this)
|
|
23
|
+
this.onMessage = this.onMessage.bind(this)
|
|
24
|
+
this.onError = this.onError.bind(this)
|
|
25
|
+
this.onClose = this.onClose.bind(this)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 连接WebSocket
|
|
30
|
+
*/
|
|
31
|
+
connect() {
|
|
32
|
+
try {
|
|
33
|
+
this.ws = new WebSocket(this.url)
|
|
34
|
+
this.ws.onopen = this.onOpen
|
|
35
|
+
this.ws.onmessage = this.onMessage
|
|
36
|
+
this.ws.onerror = this.onError
|
|
37
|
+
this.ws.onclose = this.onClose
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('WebSocket连接失败:', error)
|
|
40
|
+
this.handleReconnect()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 连接成功处理
|
|
46
|
+
*/
|
|
47
|
+
onOpen(event) {
|
|
48
|
+
console.log('WebSocket连接成功')
|
|
49
|
+
this.isConnected = true
|
|
50
|
+
this.reconnectAttempts = 0
|
|
51
|
+
this.startHeartbeat()
|
|
52
|
+
this.emit('open', event)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 接收消息处理
|
|
57
|
+
*/
|
|
58
|
+
onMessage(event) {
|
|
59
|
+
try {
|
|
60
|
+
const data = JSON.parse(event.data)
|
|
61
|
+
console.log('收到WebSocket消息:', data)
|
|
62
|
+
|
|
63
|
+
// 处理心跳响应
|
|
64
|
+
if (data.type === 'pong') {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.emit('message', data)
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error('解析WebSocket消息失败:', error)
|
|
71
|
+
this.emit('message', event.data)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 错误处理
|
|
77
|
+
*/
|
|
78
|
+
onError(error) {
|
|
79
|
+
console.error('WebSocket错误:', error)
|
|
80
|
+
this.emit('error', error)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 连接关闭处理
|
|
85
|
+
*/
|
|
86
|
+
onClose(event) {
|
|
87
|
+
console.log('WebSocket连接关闭:', event.code, event.reason)
|
|
88
|
+
this.isConnected = false
|
|
89
|
+
this.stopHeartbeat()
|
|
90
|
+
this.emit('close', event)
|
|
91
|
+
|
|
92
|
+
// 如果不是主动关闭,尝试重连
|
|
93
|
+
if (event.code !== 1000) {
|
|
94
|
+
this.handleReconnect()
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 发送消息
|
|
100
|
+
* @param {Object|String} data 要发送的数据
|
|
101
|
+
*/
|
|
102
|
+
send(data) {
|
|
103
|
+
if (!this.isConnected || this.ws.readyState !== WebSocket.OPEN) {
|
|
104
|
+
console.warn('WebSocket未连接,无法发送消息')
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const message = typeof data === 'string' ? data : JSON.stringify(data)
|
|
110
|
+
this.ws.send(message)
|
|
111
|
+
console.log('发送WebSocket消息:', data)
|
|
112
|
+
return true
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error('发送WebSocket消息失败:', error)
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 添加事件监听器
|
|
121
|
+
* @param {String} event 事件名称 (open, message, error, close)
|
|
122
|
+
* @param {Function} callback 回调函数
|
|
123
|
+
*/
|
|
124
|
+
on(event, callback) {
|
|
125
|
+
if (!this.eventListeners.has(event)) {
|
|
126
|
+
this.eventListeners.set(event, [])
|
|
127
|
+
}
|
|
128
|
+
this.eventListeners.get(event).push(callback)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 移除事件监听器
|
|
133
|
+
* @param {String} event 事件名称
|
|
134
|
+
* @param {Function} callback 回调函数
|
|
135
|
+
*/
|
|
136
|
+
off(event, callback) {
|
|
137
|
+
const listeners = this.eventListeners.get(event)
|
|
138
|
+
if (listeners) {
|
|
139
|
+
const index = listeners.indexOf(callback)
|
|
140
|
+
if (index > -1) {
|
|
141
|
+
listeners.splice(index, 1)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 触发事件
|
|
148
|
+
* @param {String} event 事件名称
|
|
149
|
+
* @param {*} data 数据
|
|
150
|
+
*/
|
|
151
|
+
emit(event, data) {
|
|
152
|
+
const listeners = this.eventListeners.get(event)
|
|
153
|
+
if (listeners) {
|
|
154
|
+
listeners.forEach(callback => {
|
|
155
|
+
try {
|
|
156
|
+
callback(data)
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error(`事件监听器执行失败 [${event}]:`, error)
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 处理重连
|
|
166
|
+
*/
|
|
167
|
+
handleReconnect() {
|
|
168
|
+
if (this.reconnectAttempts < this.options.maxReconnectAttempts) {
|
|
169
|
+
this.reconnectAttempts++
|
|
170
|
+
console.log(`尝试重连WebSocket (${this.reconnectAttempts}/${this.options.maxReconnectAttempts})`)
|
|
171
|
+
|
|
172
|
+
setTimeout(() => {
|
|
173
|
+
this.connect()
|
|
174
|
+
}, this.options.reconnectInterval)
|
|
175
|
+
} else {
|
|
176
|
+
console.error('WebSocket重连次数已达上限')
|
|
177
|
+
this.emit('reconnectFailed')
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 开始心跳检测
|
|
183
|
+
*/
|
|
184
|
+
startHeartbeat() {
|
|
185
|
+
this.stopHeartbeat()
|
|
186
|
+
this.heartbeatTimer = setInterval(() => {
|
|
187
|
+
if (this.isConnected) {
|
|
188
|
+
this.send({ type: 'ping', timestamp: Date.now() })
|
|
189
|
+
}
|
|
190
|
+
}, this.options.heartbeatInterval)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 停止心跳检测
|
|
195
|
+
*/
|
|
196
|
+
stopHeartbeat() {
|
|
197
|
+
if (this.heartbeatTimer) {
|
|
198
|
+
clearInterval(this.heartbeatTimer)
|
|
199
|
+
this.heartbeatTimer = null
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 主动关闭连接
|
|
205
|
+
*/
|
|
206
|
+
close() {
|
|
207
|
+
this.stopHeartbeat()
|
|
208
|
+
if (this.ws) {
|
|
209
|
+
this.ws.close(1000, '主动关闭')
|
|
210
|
+
}
|
|
211
|
+
this.isConnected = false
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 获取连接状态
|
|
216
|
+
*/
|
|
217
|
+
getReadyState() {
|
|
218
|
+
return this.ws ? this.ws.readyState : WebSocket.CLOSED
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 是否已连接
|
|
223
|
+
*/
|
|
224
|
+
isOpen() {
|
|
225
|
+
return this.isConnected && this.ws && this.ws.readyState === WebSocket.OPEN
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 创建WebSocket实例的工厂函数
|
|
231
|
+
* @param {String} url WebSocket服务器地址
|
|
232
|
+
* @param {Object} options 配置选项
|
|
233
|
+
* @returns {WebSocketClient} WebSocket客户端实例
|
|
234
|
+
*/
|
|
235
|
+
export function createWebSocket(url, options = {}) {
|
|
236
|
+
return new WebSocketClient(url, options)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 导出类
|
|
240
|
+
export default WebSocketClient
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* 使用示例:
|
|
244
|
+
*
|
|
245
|
+
* import WebSocketClient, { createWebSocket } from '@/utils/websocket'
|
|
246
|
+
*
|
|
247
|
+
* // 方式1: 直接使用类
|
|
248
|
+
* const ws = new WebSocketClient('ws://localhost:8080/ws')
|
|
249
|
+
*
|
|
250
|
+
* // 方式2: 使用工厂函数
|
|
251
|
+
* const ws = createWebSocket('ws://localhost:8080/ws', {
|
|
252
|
+
* reconnectInterval: 5000,
|
|
253
|
+
* maxReconnectAttempts: 10
|
|
254
|
+
* })
|
|
255
|
+
*
|
|
256
|
+
* // 添加事件监听
|
|
257
|
+
* ws.on('open', () => {
|
|
258
|
+
* console.log('连接已建立')
|
|
259
|
+
* })
|
|
260
|
+
*
|
|
261
|
+
* ws.on('message', (data) => {
|
|
262
|
+
* console.log('收到消息:', data)
|
|
263
|
+
* })
|
|
264
|
+
*
|
|
265
|
+
* ws.on('error', (error) => {
|
|
266
|
+
* console.error('连接错误:', error)
|
|
267
|
+
* })
|
|
268
|
+
*
|
|
269
|
+
* ws.on('close', (event) => {
|
|
270
|
+
* console.log('连接已关闭')
|
|
271
|
+
* })
|
|
272
|
+
*
|
|
273
|
+
* // 连接
|
|
274
|
+
* ws.connect()
|
|
275
|
+
*
|
|
276
|
+
* // 发送消息
|
|
277
|
+
* ws.send({ type: 'chat', message: 'Hello World' })
|
|
278
|
+
* ws.send('Hello World')
|
|
279
|
+
*
|
|
280
|
+
* // 关闭连接
|
|
281
|
+
* ws.close()
|
|
282
|
+
*/
|
package/vue.config.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const { defineConfig } = require('@vue/cli-service')
|
|
2
|
+
const version = new Date().getTime();
|
|
3
|
+
module.exports = defineConfig({
|
|
4
|
+
transpileDependencies: true,
|
|
5
|
+
lintOnSave: false,
|
|
6
|
+
productionSourceMap: false,
|
|
7
|
+
// 开发服务器配置
|
|
8
|
+
devServer: {
|
|
9
|
+
client: {
|
|
10
|
+
overlay: false // 关闭错误遮罩层
|
|
11
|
+
},
|
|
12
|
+
port: 8080,
|
|
13
|
+
proxy: {
|
|
14
|
+
// 代理auth相关API
|
|
15
|
+
'/auth-component': {
|
|
16
|
+
target: 'http://dftdm.netiler.com',
|
|
17
|
+
changeOrigin: true,
|
|
18
|
+
secure: false,
|
|
19
|
+
logLevel: 'debug'
|
|
20
|
+
},
|
|
21
|
+
// 代理plugin相关API
|
|
22
|
+
'/plugin': {
|
|
23
|
+
target: 'http://10.1.24.63:8080',
|
|
24
|
+
changeOrigin: true,
|
|
25
|
+
secure: false,
|
|
26
|
+
logLevel: 'debug'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
configureWebpack: {
|
|
31
|
+
output: {
|
|
32
|
+
filename: '[name]/index.js',
|
|
33
|
+
libraryTarget: 'umd',
|
|
34
|
+
libraryExport: 'default',
|
|
35
|
+
library: 'ld-auth'
|
|
36
|
+
},
|
|
37
|
+
plugins: [
|
|
38
|
+
new (require('webpack')).DefinePlugin({
|
|
39
|
+
'process.env.VERSION': JSON.stringify(version)
|
|
40
|
+
})
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
})
|