@gct-paas/core 0.1.6-dev.26 → 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.
Files changed (33) hide show
  1. package/dist/index.esm.min.js +2 -2
  2. package/dist/{redirect-index-CXM17Y16.js → redirect-index-BFuhimnn.js} +1 -1
  3. package/es/enums/page-designer/panel.d.ts +1 -2
  4. package/es/enums/page-designer/panel.mjs +0 -1
  5. package/es/global/gct/gct.d.ts +3 -3
  6. package/es/index.d.ts +1 -0
  7. package/es/index.mjs +5 -2
  8. package/es/interface/i-app-context/i-app-context.d.ts +6 -0
  9. package/es/interface/i-pinia-action/i-global-actions.d.ts +6 -0
  10. package/es/interface/i-pinia-getter/i-global-getters.d.ts +22 -1
  11. package/es/interface/i-pinia-state/i-global-state.d.ts +9 -2
  12. package/es/modules/mqtt/interfaces/i-mqtt.d.ts +6 -2
  13. package/es/modules/mqtt/mqtt-client.d.ts +7 -7
  14. package/es/modules/mqtt/mqtt-client.mjs +20 -19
  15. package/es/modules/platform-config/constants/theme.const.d.ts +9 -1
  16. package/es/modules/platform-config/constants/theme.const.mjs +13 -2
  17. package/es/modules/platform-config/store.d.ts +3 -3
  18. package/es/modules/platform-config/useThemeSetting.d.ts +1 -1
  19. package/es/modules/platform-config/useThemeSetting.mjs +32 -4
  20. package/es/modules/system-mqtt/index.d.ts +3 -0
  21. package/es/modules/system-mqtt/index.mjs +2 -0
  22. package/es/modules/system-mqtt/system-mqtt.const.d.ts +1 -0
  23. package/es/modules/system-mqtt/system-mqtt.const.mjs +13 -0
  24. package/es/modules/system-mqtt/system-mqtt.interface.d.ts +71 -0
  25. package/es/modules/system-mqtt/system-mqtt.service.d.ts +102 -0
  26. package/es/modules/system-mqtt/system-mqtt.service.mjs +176 -0
  27. package/es/router/guard/index.d.ts +4 -0
  28. package/es/router/guard/index.mjs +41 -0
  29. package/es/router/index.mjs +2 -0
  30. package/es/state/global-pinia-state/global-pinia-state.d.ts +6 -0
  31. package/es/state/global-pinia-state/global-pinia-state.mjs +6 -0
  32. package/es/store/global-store.mjs +6 -0
  33. package/package.json +3 -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,4 @@
1
+ import { Router } from 'vue-router';
2
+ export declare function createPageLoadingGuard(router: Router): void;
3
+ export declare function createProgressGuard(router: Router): void;
4
+ export declare function createGuard(router: Router): void;
@@ -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 };
@@ -1,3 +1,4 @@
1
+ import { createGuard } from "./guard/index.mjs";
1
2
  import "vue";
2
3
  import { createRouter, createWebHashHistory } from "vue-router";
3
4
  //#region src/router/index.ts
@@ -9,6 +10,7 @@ var RouterUtil = class {
9
10
  history: createWebHashHistory(),
10
11
  routes
11
12
  });
13
+ createGuard(this.router);
12
14
  }
13
15
  /**
14
16
  * 添加路由
@@ -17,6 +17,12 @@ export declare class GlobalPiniaState implements IGlobalState {
17
17
  /**运行时空值显示 */
18
18
  emptyDisplay: emptyDisplayType;
19
19
  };
20
+ /**
21
+ * 是否出发路由全局设置中开启的 loading
22
+ *
23
+ * @type {boolean}
24
+ */
25
+ pageLoading: boolean;
20
26
  /**
21
27
  * 应用信息
22
28
  *
@@ -23,6 +23,12 @@ var GlobalPiniaState = class {
23
23
  globalSetting = {
24
24
  /**运行时空值显示 */
25
25
  emptyDisplay: "--" };
26
+ /**
27
+ * 是否出发路由全局设置中开启的 loading
28
+ *
29
+ * @type {boolean}
30
+ */
31
+ pageLoading = false;
26
32
  /**
27
33
  * 应用信息
28
34
  *
@@ -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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gct-paas/core",
3
- "version": "0.1.6-dev.26",
3
+ "version": "0.1.6-dev.28",
4
4
  "type": "module",
5
5
  "description": "paas 平台核心包",
6
6
  "loader": "dist/index.esm.min.js",
@@ -43,6 +43,7 @@
43
43
  "lodash-es": "^4.17.23",
44
44
  "mitt": "^3.0.1",
45
45
  "mqtt": "^5.15.0",
46
+ "nprogress": "^0.2.0",
46
47
  "overlayscrollbars": "^2.14.0",
47
48
  "pinia": "^3.0.4",
48
49
  "qs": "^6.15.0",
@@ -53,6 +54,7 @@
53
54
  "wujie": "^1.0.29"
54
55
  },
55
56
  "devDependencies": {
57
+ "@types/nprogress": "^0.2.3",
56
58
  "@vue/test-utils": "^2.4.6",
57
59
  "fs-extra": "^11.3.3",
58
60
  "playwright": "^1.58.0"