adtec-core-package 3.1.3 → 3.1.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adtec-core-package",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -63,3 +63,69 @@ export function mergeRouteMetaParams(existing: unknown, incoming: unknown): unkn
63
63
  export function shouldPushRouteQueryParams(params: unknown): params is Record<string, unknown> {
64
64
  return isPlainObject(params) && Object.keys(params).length > 0
65
65
  }
66
+
67
+ function extractParameterArray(value: unknown): IParameter[] | undefined {
68
+ if (isParameterArray(value)) return value
69
+ if (isPlainObject(value)) {
70
+ const vals = Object.values(value)
71
+ if (vals.length > 0 && vals.every(isParameterItem)) {
72
+ return vals as IParameter[]
73
+ }
74
+ }
75
+ return undefined
76
+ }
77
+
78
+ /**
79
+ * 从 route.meta.params(数组 / 对象 / 历史 spread 损坏)或 route.query 读取单个参数。
80
+ * 页面侧请用此函数替代 params.find(c => c.code === 'xxx')?.value
81
+ */
82
+ export function getRouteMetaParam(
83
+ params: unknown,
84
+ code: string,
85
+ query?: Record<string, unknown>,
86
+ ): unknown {
87
+ const paramList = extractParameterArray(params)
88
+ if (paramList) {
89
+ const item = paramList.find((c) => c.code === code)
90
+ if (item && item.value !== undefined && item.value !== null && item.value !== '') {
91
+ return item.value
92
+ }
93
+ }
94
+ if (isPlainObject(params) && code in params) {
95
+ const direct = params[code]
96
+ if (direct !== undefined && direct !== null && direct !== '') return direct
97
+ }
98
+ if (query && code in query) {
99
+ const q = query[code]
100
+ if (q !== undefined && q !== null && q !== '') return q
101
+ }
102
+ return undefined
103
+ }
104
+
105
+ /** 将 meta.params + query 归一为键值对象(替代 params.reduce / forEach 灌 taskVo) */
106
+ export function routeMetaParamsToRecord(
107
+ params: unknown,
108
+ query?: Record<string, unknown>,
109
+ ): Record<string, unknown> {
110
+ const record: Record<string, unknown> = {}
111
+ const paramList = extractParameterArray(params)
112
+ if (paramList) {
113
+ for (const item of paramList) {
114
+ if (item?.code != null) record[String(item.code)] = item.value
115
+ }
116
+ } else if (isPlainObject(params) && !isEmptyPlainObject(params)) {
117
+ Object.assign(record, params)
118
+ }
119
+ if (query) {
120
+ for (const [key, value] of Object.entries(query)) {
121
+ if (value !== undefined && value !== null && value !== '' && !(key in record)) {
122
+ record[key] = value
123
+ }
124
+ }
125
+ }
126
+ return record
127
+ }
128
+
129
+ export function hasRouteMetaParams(params: unknown, query?: Record<string, unknown>): boolean {
130
+ return Object.keys(routeMetaParamsToRecord(params, query)).length > 0
131
+ }