@gct-paas/core 0.1.6-dev.27 → 0.1.6-dev.28
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/dist/index.esm.min.js +2 -2
- package/dist/{redirect-index-2mXSgnns.js → redirect-index-BFuhimnn.js} +1 -1
- package/es/global/gct/gct.d.ts +3 -3
- package/es/index.d.ts +1 -0
- package/es/index.mjs +5 -2
- package/es/interface/i-pinia-action/i-global-actions.d.ts +6 -0
- package/es/interface/i-pinia-getter/i-global-getters.d.ts +22 -1
- package/es/interface/i-pinia-state/i-global-state.d.ts +9 -2
- package/es/modules/mqtt/interfaces/i-mqtt.d.ts +6 -2
- package/es/modules/mqtt/mqtt-client.d.ts +7 -7
- package/es/modules/mqtt/mqtt-client.mjs +20 -19
- package/es/modules/platform-config/constants/theme.const.d.ts +9 -1
- package/es/modules/platform-config/constants/theme.const.mjs +13 -2
- package/es/modules/platform-config/store.d.ts +3 -3
- package/es/modules/platform-config/useThemeSetting.d.ts +1 -1
- package/es/modules/platform-config/useThemeSetting.mjs +11 -1
- package/es/modules/system-mqtt/index.d.ts +3 -0
- package/es/modules/system-mqtt/index.mjs +2 -0
- package/es/modules/system-mqtt/system-mqtt.const.d.ts +1 -0
- package/es/modules/system-mqtt/system-mqtt.const.mjs +13 -0
- package/es/modules/system-mqtt/system-mqtt.interface.d.ts +71 -0
- package/es/modules/system-mqtt/system-mqtt.service.d.ts +102 -0
- package/es/modules/system-mqtt/system-mqtt.service.mjs +176 -0
- package/es/router/guard/index.d.ts +4 -0
- package/es/router/guard/index.mjs +41 -0
- package/es/router/index.mjs +2 -10
- package/es/state/global-pinia-state/global-pinia-state.d.ts +6 -0
- package/es/state/global-pinia-state/global-pinia-state.mjs +6 -0
- package/es/store/global-store.mjs +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { getTenant } from "../../utils/tools/tools.mjs";
|
|
2
|
+
import { getPageIdentification } from "../../utils/deviceFingerprint.mjs";
|
|
3
|
+
import "../../utils/index.mjs";
|
|
4
|
+
import "../mqtt/index.mjs";
|
|
5
|
+
import { ProjectNameType } from "./system-mqtt.const.mjs";
|
|
6
|
+
//#region src/modules/system-mqtt/system-mqtt.service.ts
|
|
7
|
+
/**
|
|
8
|
+
* 系统级 MQTT 业务
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @class SystemMqttService
|
|
12
|
+
*/
|
|
13
|
+
var SystemMqttService = class {
|
|
14
|
+
static isInitialized = false;
|
|
15
|
+
static client;
|
|
16
|
+
static fingerprint;
|
|
17
|
+
static client_id = "";
|
|
18
|
+
/**
|
|
19
|
+
* 用户登出消息 topic
|
|
20
|
+
*
|
|
21
|
+
* @static
|
|
22
|
+
*/
|
|
23
|
+
static USER_LOGOUT_TOPIC = `users/logout/msg`;
|
|
24
|
+
/**
|
|
25
|
+
* 踢出用户消息 topic
|
|
26
|
+
*
|
|
27
|
+
* @readonly
|
|
28
|
+
* @static
|
|
29
|
+
* @type {string}
|
|
30
|
+
*/
|
|
31
|
+
static get KICK_OUT_TOPIC() {
|
|
32
|
+
return `USER/${_gct.store.userInfo.userId}/KICK_OUT`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 未读消息变化 topic
|
|
36
|
+
*
|
|
37
|
+
* @readonly
|
|
38
|
+
* @static
|
|
39
|
+
* @type {string}
|
|
40
|
+
*/
|
|
41
|
+
static get INTERNAL_MESSAGE_TOPIC() {
|
|
42
|
+
return `${_gct.env.getEnv()}/USER/${getTenant()}/${_gct.store.userInfo.userId}/INTERNAL_MESSAGE`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 待办消息数量 topic
|
|
46
|
+
*
|
|
47
|
+
* @readonly
|
|
48
|
+
* @static
|
|
49
|
+
* @type {string}
|
|
50
|
+
*/
|
|
51
|
+
static get TASK_TODO_COUNT_TOPIC() {
|
|
52
|
+
return `${_gct.env.getEnv()}/USER/${getTenant()}/${_gct.store.userInfo.userId}/TASK_TODO_COUNT`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 强制刷新并清空缓存 topic
|
|
56
|
+
*
|
|
57
|
+
* @static
|
|
58
|
+
*/
|
|
59
|
+
static CLEAN_CACHE_TOPIC = "CLEAN_CACHE";
|
|
60
|
+
/**
|
|
61
|
+
* 初始化系统级 MQTT 客户端,需要在用户信息以及应用信息加载完成后调用
|
|
62
|
+
*
|
|
63
|
+
* @static
|
|
64
|
+
* @return {*} {Promise<void>}
|
|
65
|
+
*/
|
|
66
|
+
static async init() {
|
|
67
|
+
if (this.isInitialized) {
|
|
68
|
+
console.warn("SystemMqttService 已经初始化,请勿重复调用 init 方法");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.isInitialized = true;
|
|
72
|
+
const willDelayInterval = 20;
|
|
73
|
+
const userInfo = _gct.store.userInfo;
|
|
74
|
+
const mqttProperties = userInfo.mqttProperties || {};
|
|
75
|
+
_gct.mqtt.create("USER_LOGOUT", {
|
|
76
|
+
...mqttProperties,
|
|
77
|
+
clientId: "logout" + this.fingerprint + getPageIdentification(),
|
|
78
|
+
protocolVersion: 5,
|
|
79
|
+
clean: false,
|
|
80
|
+
will: {
|
|
81
|
+
topic: this.USER_LOGOUT_TOPIC,
|
|
82
|
+
payload: JSON.stringify({
|
|
83
|
+
appId: _gct.store.appInfo.id,
|
|
84
|
+
ipAddress: userInfo.ip,
|
|
85
|
+
signLog: `${userInfo.userId}.${_gct.env.getEnv()}.${this.fingerprint}.${ProjectNameType[_gct.store.projectName]}.web.${getPageIdentification()}`,
|
|
86
|
+
tenantId: getTenant()
|
|
87
|
+
}),
|
|
88
|
+
qos: 1,
|
|
89
|
+
retain: true,
|
|
90
|
+
properties: {
|
|
91
|
+
willDelayInterval,
|
|
92
|
+
messageExpiryInterval: willDelayInterval * 10
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
properties: { sessionExpiryInterval: willDelayInterval * 2 }
|
|
96
|
+
});
|
|
97
|
+
this.subCleanCache();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 订阅系统级 MQTT 消息
|
|
101
|
+
*
|
|
102
|
+
* @static
|
|
103
|
+
* @param {string} topic
|
|
104
|
+
*/
|
|
105
|
+
static subscribe(topic, callback) {
|
|
106
|
+
if (!this.client) throw new Error("MQTT client is not initialized");
|
|
107
|
+
return this.client.subscribe(topic, (topic, payload) => {
|
|
108
|
+
console.debug(`收到系统级 MQTT 消息,topic: ${topic}, payload:`, payload);
|
|
109
|
+
try {
|
|
110
|
+
callback(JSON.parse(payload.toString()));
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error("解析 MQTT 消息 payload 失败:", error);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 订阅用户被踢出消息
|
|
118
|
+
*
|
|
119
|
+
* @static
|
|
120
|
+
* @param {MqttSubCallback<IKickOutPayload>} callback
|
|
121
|
+
* @return {*} {MqttCancelSub}
|
|
122
|
+
*/
|
|
123
|
+
static subKickOut(callback) {
|
|
124
|
+
return this.subscribe(this.KICK_OUT_TOPIC, callback);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 订阅未读消息变化
|
|
128
|
+
*
|
|
129
|
+
* @static
|
|
130
|
+
* @param {MqttSubCallback<IInternalMessagePayload>} callback
|
|
131
|
+
* @return {*} {MqttCancelSub}
|
|
132
|
+
*/
|
|
133
|
+
static subInternalMessage(callback) {
|
|
134
|
+
return this.subscribe(this.INTERNAL_MESSAGE_TOPIC, callback);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 订阅待办消息数量变化
|
|
138
|
+
*
|
|
139
|
+
* @static
|
|
140
|
+
* @param {MqttSubCallback<IToDoMessagePayload>} callback
|
|
141
|
+
* @return {*} {MqttCancelSub}
|
|
142
|
+
*/
|
|
143
|
+
static subTaskTodoCount(callback) {
|
|
144
|
+
return this.subscribe(this.TASK_TODO_COUNT_TOPIC, callback);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 强制用户界面刷新
|
|
148
|
+
*
|
|
149
|
+
* @static
|
|
150
|
+
* @param {MqttSubCallback<void>} callback
|
|
151
|
+
* @return {*} {MqttCancelSub}
|
|
152
|
+
*/
|
|
153
|
+
static subCleanCache() {
|
|
154
|
+
return this.subscribe(this.CLEAN_CACHE_TOPIC, () => {
|
|
155
|
+
const url = new URL(window.location.href);
|
|
156
|
+
url.searchParams.set("reloadTime", Date.now().toString());
|
|
157
|
+
window.location.replace(url.toString());
|
|
158
|
+
location.reload();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 发送用户登出消息
|
|
163
|
+
*
|
|
164
|
+
* @static
|
|
165
|
+
*/
|
|
166
|
+
static pubLogout() {
|
|
167
|
+
this.client?.publish(this.USER_LOGOUT_TOPIC, JSON.stringify({
|
|
168
|
+
appId: _gct.store.appInfo.id,
|
|
169
|
+
ipAddress: _gct.store.userInfo.ip,
|
|
170
|
+
signLog: `${_gct.store.userInfo.userId}.${_gct.env.getEnv()}.${this.fingerprint}.${ProjectNameType[_gct.store.projectName]}.web.${getPageIdentification()}`,
|
|
171
|
+
tenantId: getTenant()
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
//#endregion
|
|
176
|
+
export { SystemMqttService };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getToken } from "../../utils/tools/tools.mjs";
|
|
2
|
+
import "../../utils/index.mjs";
|
|
3
|
+
import { usePlatformConfigStore } from "../../modules/platform-config/store.mjs";
|
|
4
|
+
import "../../modules/platform-config/index.mjs";
|
|
5
|
+
import nProgress from "nprogress";
|
|
6
|
+
//#region src/router/guard/index.ts
|
|
7
|
+
function createPageLoadingGuard(router) {
|
|
8
|
+
const platformStore = usePlatformConfigStore();
|
|
9
|
+
router.beforeEach(async (to) => {
|
|
10
|
+
if (!getToken() || to.meta.loaded) return true;
|
|
11
|
+
if (platformStore.themeSetting.pageLoading == true) {
|
|
12
|
+
_gct.store.setPageLoading(true);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
});
|
|
17
|
+
router.afterEach(async () => {
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
_gct.store.setPageLoading(false);
|
|
20
|
+
}, 220);
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function createProgressGuard(router) {
|
|
25
|
+
const platformStore = usePlatformConfigStore();
|
|
26
|
+
router.beforeEach(async (to) => {
|
|
27
|
+
if (to.meta.loaded) return true;
|
|
28
|
+
if (platformStore.themeSetting.pageProgress == true) nProgress.start();
|
|
29
|
+
return true;
|
|
30
|
+
});
|
|
31
|
+
router.afterEach(async () => {
|
|
32
|
+
nProgress.done();
|
|
33
|
+
return true;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function createGuard(router) {
|
|
37
|
+
createPageLoadingGuard(router);
|
|
38
|
+
createProgressGuard(router);
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { createGuard };
|
package/es/router/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createGuard } from "./guard/index.mjs";
|
|
2
2
|
import "vue";
|
|
3
3
|
import { createRouter, createWebHashHistory } from "vue-router";
|
|
4
|
-
import nProgress from "nprogress";
|
|
5
4
|
//#region src/router/index.ts
|
|
6
5
|
var REDIRECT_NAME = "Redirect";
|
|
7
6
|
var RouterUtil = class {
|
|
@@ -11,14 +10,7 @@ var RouterUtil = class {
|
|
|
11
10
|
history: createWebHashHistory(),
|
|
12
11
|
routes
|
|
13
12
|
});
|
|
14
|
-
this.router
|
|
15
|
-
if (to.meta.loaded) return true;
|
|
16
|
-
if (usePlatformConfigStore().themeSetting.pageProgress == true) nProgress.start();
|
|
17
|
-
return true;
|
|
18
|
-
});
|
|
19
|
-
this.router.afterEach(() => {
|
|
20
|
-
nProgress.done();
|
|
21
|
-
});
|
|
13
|
+
createGuard(this.router);
|
|
22
14
|
}
|
|
23
15
|
/**
|
|
24
16
|
* 添加路由
|
|
@@ -20,6 +20,9 @@ var useGlobalStore = defineStore("global-store", {
|
|
|
20
20
|
},
|
|
21
21
|
getEmptyDisplay() {
|
|
22
22
|
return nullDisplayEnum[this.globalSetting.emptyDisplay];
|
|
23
|
+
},
|
|
24
|
+
getPageLoading() {
|
|
25
|
+
return this.pageLoading;
|
|
23
26
|
}
|
|
24
27
|
},
|
|
25
28
|
actions: {
|
|
@@ -50,6 +53,9 @@ var useGlobalStore = defineStore("global-store", {
|
|
|
50
53
|
setProjectName(name) {
|
|
51
54
|
this.projectName = name;
|
|
52
55
|
},
|
|
56
|
+
setPageLoading(loading) {
|
|
57
|
+
this.pageLoading = loading;
|
|
58
|
+
},
|
|
53
59
|
updateUserInfo(data) {
|
|
54
60
|
this.userInfo = {
|
|
55
61
|
...this.userInfo,
|