yuang-framework-ui-common 1.0.112 → 1.0.114
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/lib/hooks/framework/frameworkEnum.ts +46 -32
- package/lib/hooks/sso/ssoUser.ts +45 -30
- package/lib/hooks/uims/uimsUser.ts +22 -18
- package/package.json +1 -1
|
@@ -1,50 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { http } from '../../../lib/config/httpConfig';
|
|
3
|
+
|
|
3
4
|
export interface StatusEnumItem {
|
|
4
|
-
// 根据实际返回的字段补充类型,比如:
|
|
5
5
|
value: string;
|
|
6
6
|
name: string;
|
|
7
|
-
// 兼容对象中未显式定义的任意字段,避免 TS 报错
|
|
8
7
|
[key: string]: any;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
// 全局唯一 KEY
|
|
11
|
+
const CACHE_KEY = '__global_status_enum_list__';
|
|
12
|
+
|
|
13
|
+
// 全局单例(只会初始化一次)
|
|
14
|
+
if (!(window as any)[CACHE_KEY]) {
|
|
15
|
+
(window as any)[CACHE_KEY] = {
|
|
16
|
+
data: ref<StatusEnumItem[]>([]),
|
|
17
|
+
isLoading: ref(false),
|
|
18
|
+
isLoaded: false, // 🔥 核心:标记是否【真正加载完成】
|
|
19
|
+
promise: null as Promise<any> | null,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const cache = (window as any)[CACHE_KEY];
|
|
13
24
|
|
|
14
|
-
/**
|
|
15
|
-
* 提供“获取状态枚举列表”的能力
|
|
16
|
-
*
|
|
17
|
-
* Vue3 官方明确规定,组合式函数必须以 use 开头(参考:Vue3 组合式函数文档),目的是让开发者一眼识别:“这是一个可复用的组合式逻辑,返回响应式能力”
|
|
18
|
-
*/
|
|
19
25
|
export const useStatusEnumList = () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const getStatusEnumList = async () => {
|
|
27
|
+
// 1. 已经加载完成 → 直接返回
|
|
28
|
+
if (cache.isLoaded) {
|
|
29
|
+
return cache.data.value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 2. 正在请求中 → 等待同一个请求
|
|
33
|
+
if (cache.promise) {
|
|
34
|
+
await cache.promise;
|
|
35
|
+
return cache.data.value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 3. 真正开始请求
|
|
39
|
+
cache.isLoading.value = true;
|
|
40
|
+
cache.promise = http.get('/framework-api/union/uims-user/getStatusEnumList', {});
|
|
41
|
+
|
|
29
42
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
statusEnumList.value = [];
|
|
43
|
+
const res = await cache.promise;
|
|
44
|
+
cache.data.value = res.data.data || [];
|
|
45
|
+
cache.isLoaded = true; // 🔥 永久标记:已加载完成!
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error('加载枚举失败', err);
|
|
48
|
+
cache.data.value = [];
|
|
37
49
|
} finally {
|
|
38
|
-
|
|
50
|
+
cache.isLoading.value = false;
|
|
51
|
+
cache.promise = null;
|
|
39
52
|
}
|
|
53
|
+
|
|
54
|
+
return cache.data.value;
|
|
40
55
|
};
|
|
41
56
|
|
|
42
|
-
//
|
|
57
|
+
// 自动加载
|
|
43
58
|
getStatusEnumList();
|
|
44
59
|
|
|
45
|
-
// 返回响应式数据和方法,供组件使用
|
|
46
60
|
return {
|
|
47
|
-
statusEnumList,
|
|
48
|
-
isLoadingEnum
|
|
61
|
+
statusEnumList: cache.data,
|
|
62
|
+
isLoadingEnum: cache.isLoading,
|
|
49
63
|
};
|
|
50
64
|
};
|
package/lib/hooks/sso/ssoUser.ts
CHANGED
|
@@ -1,50 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { http } from '../../../lib/config/httpConfig';
|
|
3
|
+
|
|
4
|
+
// 枚举项类型
|
|
3
5
|
export interface StatusEnumItem {
|
|
4
|
-
// 根据实际返回的字段补充类型,比如:
|
|
5
6
|
value: string;
|
|
6
7
|
name: string;
|
|
7
|
-
// 兼容对象中未显式定义的任意字段,避免 TS 报错
|
|
8
8
|
[key: string]: any;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// ==================== 全局单例缓存(核心) ====================
|
|
12
|
+
const GLOBAL_ENUM_CACHE = '__sso_user_status_enum_list__';
|
|
13
|
+
|
|
14
|
+
// 全局唯一初始化
|
|
15
|
+
if (!(window as any)[GLOBAL_ENUM_CACHE]) {
|
|
16
|
+
(window as any)[GLOBAL_ENUM_CACHE] = {
|
|
17
|
+
data: ref<StatusEnumItem[]>([]),
|
|
18
|
+
isLoading: ref(false),
|
|
19
|
+
isLoaded: false,
|
|
20
|
+
promise: null as Promise<any> | null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const cache = (window as any)[GLOBAL_ENUM_CACHE];
|
|
13
25
|
|
|
14
|
-
|
|
15
|
-
* 提供“获取状态枚举列表”的能力
|
|
16
|
-
*
|
|
17
|
-
* Vue3 官方明确规定,组合式函数必须以 use 开头(参考:Vue3 组合式函数文档),目的是让开发者一眼识别:“这是一个可复用的组合式逻辑,返回响应式能力”
|
|
18
|
-
*/
|
|
26
|
+
// ==================== Hook 本体 ====================
|
|
19
27
|
export const useStatusEnumList = () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const getStatusEnumList = async () => {
|
|
29
|
+
// 1. 已经加载过 → 直接返回
|
|
30
|
+
if (cache.isLoaded) return cache.data.value;
|
|
31
|
+
|
|
32
|
+
// 2. 正在请求 → 等待同一个请求
|
|
33
|
+
if (cache.promise) {
|
|
34
|
+
await cache.promise;
|
|
35
|
+
return cache.data.value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 3. 真正发起请求
|
|
39
|
+
cache.isLoading.value = true;
|
|
40
|
+
cache.promise = http.get('/framework-api/union/sso-user/getStatusEnumList', {});
|
|
41
|
+
|
|
29
42
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
statusEnumList.value = res.data.data;
|
|
43
|
+
const res = await cache.promise;
|
|
44
|
+
cache.data.value = res.data.data || [];
|
|
45
|
+
cache.isLoaded = true; // 标记已加载
|
|
34
46
|
} catch (ex) {
|
|
35
47
|
console.error('获取状态枚举列表失败:', ex);
|
|
36
|
-
|
|
48
|
+
cache.data.value = [];
|
|
37
49
|
} finally {
|
|
38
|
-
|
|
50
|
+
cache.isLoading.value = false;
|
|
51
|
+
cache.promise = null;
|
|
39
52
|
}
|
|
53
|
+
|
|
54
|
+
return cache.data.value;
|
|
40
55
|
};
|
|
41
56
|
|
|
42
|
-
//
|
|
57
|
+
// 自动加载
|
|
43
58
|
getStatusEnumList();
|
|
44
59
|
|
|
45
|
-
//
|
|
60
|
+
// 保持你原来的返回结构,不用改业务代码
|
|
46
61
|
return {
|
|
47
|
-
statusEnumList,
|
|
48
|
-
isLoadingEnum
|
|
62
|
+
statusEnumList: cache.data,
|
|
63
|
+
isLoadingEnum: cache.isLoading,
|
|
49
64
|
};
|
|
50
65
|
};
|
|
@@ -1,51 +1,54 @@
|
|
|
1
1
|
import { ref } from 'vue';
|
|
2
2
|
import { http } from '../../../lib/config/httpConfig';
|
|
3
3
|
|
|
4
|
+
// 枚举项类型
|
|
4
5
|
export interface StatusEnumItem {
|
|
5
6
|
value: string;
|
|
6
7
|
name: string;
|
|
7
8
|
[key: string]: any;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
//
|
|
11
|
-
const
|
|
11
|
+
// ==================== 全局单例缓存(核心) ====================
|
|
12
|
+
const GLOBAL_ENUM_CACHE = '__uims_user_status_enum_list__';
|
|
12
13
|
|
|
13
|
-
//
|
|
14
|
-
if (!(window as any)[
|
|
15
|
-
(window as any)[
|
|
14
|
+
// 全局唯一初始化
|
|
15
|
+
if (!(window as any)[GLOBAL_ENUM_CACHE]) {
|
|
16
|
+
(window as any)[GLOBAL_ENUM_CACHE] = {
|
|
16
17
|
data: ref<StatusEnumItem[]>([]),
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
isLoading: ref(false),
|
|
19
|
+
isLoaded: false,
|
|
20
|
+
promise: null as Promise<any> | null,
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
const cache = (window as any)[
|
|
24
|
+
const cache = (window as any)[GLOBAL_ENUM_CACHE];
|
|
23
25
|
|
|
26
|
+
// ==================== Hook 本体 ====================
|
|
24
27
|
export const useStatusEnumList = () => {
|
|
25
28
|
const getStatusEnumList = async () => {
|
|
26
|
-
// 1.
|
|
27
|
-
if (cache.data.value
|
|
28
|
-
return cache.data.value;
|
|
29
|
-
}
|
|
29
|
+
// 1. 已经加载过 → 直接返回
|
|
30
|
+
if (cache.isLoaded) return cache.data.value;
|
|
30
31
|
|
|
31
|
-
// 2. 正在请求 →
|
|
32
|
+
// 2. 正在请求 → 等待同一个请求
|
|
32
33
|
if (cache.promise) {
|
|
33
34
|
await cache.promise;
|
|
34
35
|
return cache.data.value;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// 3. 真正发起请求
|
|
38
|
-
cache.
|
|
39
|
+
cache.isLoading.value = true;
|
|
39
40
|
cache.promise = http.get('/framework-api/union/uims-user/getStatusEnumList', {});
|
|
40
41
|
|
|
41
42
|
try {
|
|
42
43
|
const res = await cache.promise;
|
|
43
44
|
cache.data.value = res.data.data || [];
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
cache.isLoaded = true; // 标记已加载
|
|
46
|
+
} catch (ex) {
|
|
47
|
+
console.error('获取状态枚举列表失败:', ex);
|
|
46
48
|
cache.data.value = [];
|
|
47
49
|
} finally {
|
|
48
|
-
cache.
|
|
50
|
+
cache.isLoading.value = false;
|
|
51
|
+
cache.promise = null;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
return cache.data.value;
|
|
@@ -54,8 +57,9 @@ export const useStatusEnumList = () => {
|
|
|
54
57
|
// 自动加载
|
|
55
58
|
getStatusEnumList();
|
|
56
59
|
|
|
60
|
+
// 保持你原来的返回结构,不用改业务代码
|
|
57
61
|
return {
|
|
58
62
|
statusEnumList: cache.data,
|
|
59
|
-
isLoadingEnum: cache.
|
|
63
|
+
isLoadingEnum: cache.isLoading,
|
|
60
64
|
};
|
|
61
65
|
};
|