yuang-framework-ui-common 1.0.106 → 1.0.108

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.
@@ -29,7 +29,7 @@ const http = axios.create({
29
29
  timeout: 10000,
30
30
  headers: {},
31
31
  // 允许跨域请求携带凭证(Cookie等),在本地开发与网关api不是同域,访问api会报错:各种跨域访问,比如:http://localhost:8000/gateway-server/sso-api/client/sso-user/getSsoIdentity
32
- withCredentials: import.meta.env.VITE_PROFILES_ACTIVE === 'dev' ? true : false,
32
+ withCredentials: import.meta.env.VITE_PROFILE_ID === 'dev' ? true : false,
33
33
  })
34
34
 
35
35
 
@@ -251,15 +251,11 @@ import { ElMessage } from 'element-plus';
251
251
  import { http } from '../../../lib/config/httpConfig';
252
252
  import { application } from '../../../lib/config/applicationConfig';
253
253
 
254
- export interface SseMessage {
255
- time: string;
256
- content: string;
257
- }
258
254
 
259
255
  // 🔥 扩展 Hook 参数:新增 moduleCode 模块标识
260
256
  export interface UseSseResult {
261
257
  sseClientId: Ref<string>;
262
- sseMessageList: Ref<SseMessage[]>;
258
+ sseMessageList: Ref<Object[]>;
263
259
  isSseConnected: Ref<boolean>;
264
260
  connectSse: (options?: FrameworkSseClientOptions) => void;
265
261
  disconnectSse: () => void;
@@ -274,14 +270,13 @@ export interface UseSseResult {
274
270
  * @param moduleCode 模块标识(必填,用于隔离 clientId)
275
271
  */
276
272
  export function useSse(
277
- apiBaseUrl: string = '/framework-api',
273
+ connectSseUrl: string = '/framework-api/standard/framework-sse/connect',
274
+ sendSseMessageUrl: string = '/framework-api/standard/framework-sse/sendMessage',
278
275
  moduleCode: string = 'default'
279
276
  ): UseSseResult {
280
- const sseUrl: string = apiBaseUrl + '/standard/framework-sse/connect';
281
- const sendSseMessageUrl: string = apiBaseUrl + '/standard/framework-sse/sendMessage';
282
277
  // 🔥 核心修复2:初始化时读取模块专属的 sseClientId
283
278
  const sseClientId = ref<string>(getLocalStorageItem(getSseClientIdKey(moduleCode)) || '');
284
- const sseMessageList = ref<SseMessage[]>([]);
279
+ const sseMessageList = ref<Object[]>([]);
285
280
  const isSseConnected = ref<boolean>(false);
286
281
  let sseClient: FrameworkSseClient | null = null;
287
282
 
@@ -290,10 +285,7 @@ export function useSse(
290
285
  console.log(`[SSE Hook] [${moduleCode}] 接收消息:`, data, event);
291
286
  // 业务消息才加入列表,避免 clientId 事件混入
292
287
  if (event?.type !== 'sseClientId') {
293
- sseMessageList.value.push({
294
- time: new Date().toLocaleTimeString(),
295
- content: data
296
- });
288
+ sseMessageList.value.push(data);
297
289
  }
298
290
  };
299
291
 
@@ -368,7 +360,7 @@ export function useSse(
368
360
  };
369
361
 
370
362
  sseClient = new FrameworkSseClient(
371
- application.gatewayServerBaseUrl + sseUrl,
363
+ application.gatewayServerBaseUrl + connectSseUrl,
372
364
  messageHandler,
373
365
  finalOptions
374
366
  );
@@ -0,0 +1,62 @@
1
+
2
+
3
+ /**
4
+ * 字符串编码为 Base64
5
+ * @param str 原始字符串(支持中文)
6
+ */
7
+ const base64Encode = (str: string): string => {
8
+ try {
9
+ const utf8Bytes = unescape(encodeURIComponent(str));
10
+ return btoa(utf8Bytes);
11
+ } catch (e) {
12
+ console.error('Base64 encode error:', e);
13
+ return '';
14
+ }
15
+ };
16
+
17
+ /**
18
+ * Base64 解码为字符串
19
+ * @param base64 Base64 字符串
20
+ */
21
+ const base64Decode = (base64: string): string => {
22
+ try {
23
+ const utf8Bytes = atob(base64);
24
+ return decodeURIComponent(escape(utf8Bytes));
25
+ } catch (e) {
26
+ console.error('Base64 decode error:', e);
27
+ return '';
28
+ }
29
+ };
30
+
31
+ /**
32
+ * Uint8Array 转 Base64
33
+ */
34
+ const base64EncodeUint8Array = (uint8Array: Uint8Array): string => {
35
+ let binary = '';
36
+ const len = uint8Array.byteLength;
37
+ for (let i = 0; i < len; i++) {
38
+ binary += String.fromCharCode(uint8Array[i]);
39
+ }
40
+ return btoa(binary);
41
+ };
42
+
43
+ /**
44
+ * Base64 转 Uint8Array
45
+ */
46
+ const base64DecodeToUint8Array = (base64: string): Uint8Array => {
47
+ const binary = atob(base64);
48
+ const len = binary.length;
49
+ const uint8Array = new Uint8Array(len);
50
+ for (let i = 0; i < len; i++) {
51
+ uint8Array[i] = binary.charCodeAt(i);
52
+ }
53
+ return uint8Array;
54
+ }
55
+
56
+ export {
57
+ base64Encode,
58
+ base64Decode,
59
+
60
+ base64EncodeUint8Array,
61
+ base64DecodeToUint8Array
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.106",
3
+ "version": "1.0.108",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -23,6 +23,10 @@ const router = createRouter({
23
23
  path: '/example/utils/rsa-aes-utils',
24
24
  component: () => import('@/views/example/utils/rsa-aes-utils.vue')
25
25
  },
26
+ {
27
+ path: '/example/utils/base64-utils',
28
+ component: () => import('@/views/example/utils/base64-utils.vue')
29
+ },
26
30
  {
27
31
  path: '/example/utils/sso-utils',
28
32
  component: () => import('@/views/example/utils/sso-utils.vue')
@@ -51,14 +51,14 @@ http://localhost:8020/framework-ui-common/example/hooks/framework/framework-sse-
51
51
  <h4 class="title">SSE 接收消息列表</h4>
52
52
  <div class="message-list">
53
53
  <div
54
- v-for="(msg, index) in sseMessageList"
54
+ v-for="(msg, index) in messageList"
55
55
  :key="index"
56
56
  class="message-item"
57
57
  >
58
58
  <span class="time">[{{ msg.time }}]</span>
59
59
  <span class="content">{{ msg.content }}</span>
60
60
  </div>
61
- <div v-if="sseMessageList.length === 0" class="empty-tip">
61
+ <div v-if="messageList.length === 0" class="empty-tip">
62
62
  暂无消息,请先建立连接并等待服务端推送
63
63
  </div>
64
64
  </div>
@@ -67,7 +67,7 @@ http://localhost:8020/framework-ui-common/example/hooks/framework/framework-sse-
67
67
  </template>
68
68
 
69
69
  <script setup lang="ts">
70
- import { ref } from 'vue';
70
+ import { ref, computed } from 'vue';
71
71
  // 1. 引入需要的图标
72
72
  import { Connection, CircleClose, Refresh, Promotion } from '@element-plus/icons-vue';
73
73
  // 2. 引入 ElMessage(之前漏了,导致提示也会报错)
@@ -83,11 +83,23 @@ const {
83
83
  disconnectSse,
84
84
  sendSseMessage,
85
85
  reconnectSse
86
- } = useSse('/framework-api', 'example');
86
+ } = useSse('/framework-api/standard/framework-sse/connect', '/framework-api/standard/framework-sse/sendMessage', 'example');
87
+
88
+
87
89
 
88
90
  // 发送消息输入框绑定值
89
91
  const inputMessage = ref<string>('测试消息 - ' + new Date().getTime());
90
92
 
93
+ const messageList = computed(()=>{
94
+ let list = sseMessageList.value.map(item =>{
95
+ return {
96
+ time: new Date().toLocaleTimeString(),
97
+ content: item
98
+ }
99
+ });
100
+ return list;
101
+ })
102
+
91
103
  // 发送消息处理函数
92
104
  const handleSendMessage = () => {
93
105
  if (!inputMessage.value.trim()) {
@@ -1,3 +1,6 @@
1
+ <!--
2
+ http://localhost:8020/framework-ui-common/example/utils/aes-utils
3
+ -->
1
4
  <template>
2
5
  <div>encryptData:{{encryptData }}</div>
3
6
  <div>decryptData:{{decryptData }}</div>
@@ -5,7 +8,7 @@
5
8
 
6
9
  <script setup lang="ts">
7
10
  import { onMounted, ref } from 'vue';
8
- import {getAesRandomKey, aesEncrypt, aesDecrypt} from '../../../lib/utils/aesUtils';
11
+ import {getAesRandomKey, aesEncrypt, aesDecrypt} from '../../../../lib/utils/aesUtils';
9
12
 
10
13
  let encryptData = ref('');
11
14
  let decryptData = ref('');
@@ -0,0 +1,24 @@
1
+ <!--
2
+ http://localhost:8020/framework-ui-common/example/utils/base64-utils
3
+ -->
4
+ <template>
5
+ <div>encodeData:{{encodeData }}</div>
6
+ <div>decodeData:{{decodeData }}</div>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import { onMounted, ref } from 'vue';
11
+ import { base64Encode, base64Decode} from '../../../../lib/utils/base64Utils';
12
+
13
+ let encodeData = ref('');
14
+ let decodeData = ref('');
15
+ onMounted(() => {
16
+
17
+ encodeData.value = base64Encode( '测试');
18
+ decodeData.value = base64Decode( encodeData.value);
19
+ })
20
+ </script>
21
+
22
+ <style scoped>
23
+
24
+ </style>
@@ -1,3 +1,6 @@
1
+ <!--
2
+ http://localhost:8020/framework-ui-common/example/utils/gateway-utils
3
+ -->
1
4
  <template>
2
5
  <div>
3
6
  <el-button @click="sendRequest">发送请求</el-button>
@@ -5,7 +8,7 @@
5
8
  </template>
6
9
 
7
10
  <script setup lang="ts">
8
- import { http } from "../../../lib/config/httpConfig";
11
+ import { http } from "../../../../lib/config/httpConfig";
9
12
  import { ElMessage } from 'element-plus/es';
10
13
 
11
14
  const sendRequest = () => {
@@ -1,3 +1,6 @@
1
+ <!--
2
+ http://localhost:8020/framework-ui-common/example/utils/http-utils
3
+ -->
1
4
  <template>
2
5
  <div>http</div>
3
6
  </template>
@@ -6,7 +9,7 @@
6
9
  import { onMounted, ref } from 'vue';
7
10
  import { ElLoading } from 'element-plus';
8
11
 
9
- import { http } from '../../../lib/config/httpConfig';
12
+ import { http } from '../../../../lib/config/httpConfig';
10
13
 
11
14
 
12
15
  onMounted(async () => {
@@ -1,3 +1,6 @@
1
+ <!--
2
+ http://localhost:8020/framework-ui-common/example/utils/message-utils
3
+ -->
1
4
  <template>
2
5
  <el-button @click="showSuccessMessage('成功')">成功</el-button>
3
6
  <el-button @click="showInfoMessage('信息')">信息</el-button>
@@ -7,7 +10,7 @@
7
10
  </template>
8
11
 
9
12
  <script setup lang="ts">
10
- import {showSuccessMessage, showInfoMessage, showWarningMessage, showErrorMessage} from '../../../lib/utils/messageUtils';
13
+ import {showSuccessMessage, showInfoMessage, showWarningMessage, showErrorMessage} from '../../../../lib/utils/messageUtils';
11
14
  </script>
12
15
 
13
16
  <style scoped>
@@ -1,5 +1,5 @@
1
1
  <!--
2
- http://localhost:8020/framework-ui-common/utils/rsa-aes-utils
2
+ http://localhost:8020/framework-ui-common/example/utils/rsa-aes-utils
3
3
  -->
4
4
  <template>
5
5
  <div>encryptData:{{ encryptData }}</div>
@@ -8,8 +8,8 @@ http://localhost:8020/framework-ui-common/utils/rsa-aes-utils
8
8
 
9
9
  <script setup lang="ts">
10
10
  import {onMounted, ref} from 'vue';
11
- import { rsaAesDecrypt, rsaAesEncrypt } from '../../../lib/utils/rsaAesUtils';
12
- import { getAesRandomKey } from "../../../lib/utils/aesUtils";
11
+ import { rsaAesDecrypt, rsaAesEncrypt } from '../../../../lib/utils/rsaAesUtils';
12
+ import { getAesRandomKey } from "../../../../lib/utils/aesUtils";
13
13
 
14
14
  let encryptData = ref({});
15
15
  let decryptData = ref('');
@@ -1,3 +1,6 @@
1
+ <!--
2
+ http://localhost:8020/framework-ui-common/example/utils/rsa-utils
3
+ -->
1
4
  <template>
2
5
  <div>encryptData:{{ encryptData }}</div>
3
6
  <div>decryptData:{{ decryptData }}</div>
@@ -5,7 +8,7 @@
5
8
 
6
9
  <script setup lang="ts">
7
10
  import {onMounted, ref} from 'vue';
8
- import {getRsaKeys, rsaEncrypt, rsaDecrypt} from '../../../lib/utils/rsaUtils';
11
+ import {getRsaKeys, rsaEncrypt, rsaDecrypt} from '../../../../lib/utils/rsaUtils';
9
12
 
10
13
  let encryptData = ref('');
11
14
  let decryptData = ref('');
@@ -1,3 +1,6 @@
1
+ <!--
2
+ http://localhost:8020/framework-ui-common/example/utils/sso-utils
3
+ -->
1
4
  <template>
2
5
  <div> </div>
3
6
  </template>