adtec-core-package 2.2.3 → 2.2.4

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": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -0,0 +1,30 @@
1
+ import frameworkUtils from '../utils/FrameworkUtils.ts'
2
+ import usePermissionHooks from '../hooks/usePermissionHooks'
3
+ import { userInfoStore } from '../stores/userInfoStore'
4
+ import commonUtils from '../utils/commonUtils'
5
+
6
+ export default function useOpenNewMenu(menuCode: string, module: { getModules: Function }) {
7
+ const usePermission = usePermissionHooks(module)
8
+ const userInfo = userInfoStore()
9
+ const handleView = async (businessId: string,menuName?: string, params: any = '') => {
10
+ const newId = menuCode + businessId
11
+ let menu = frameworkUtils.getOpenMenuInfoWujie().find((item: any) => item.id === newId)
12
+ if (!menu) {
13
+ menu = JSON.parse(
14
+ JSON.stringify(userInfo.getUserInfo.menuList.find((item) => item.code === menuCode)),
15
+ )
16
+ if (menu) {
17
+ menu.code = menuCode + commonUtils.jsonToUrlQuery(params)
18
+ menu.id = newId
19
+ menu.name = menuName??menu.name
20
+ await usePermission.openMenuByFramework(menu, params)
21
+ }
22
+ } else {
23
+ await usePermission.openMenuByFramework(menu)
24
+ }
25
+ }
26
+
27
+ return {
28
+ handleView,
29
+ }
30
+ }
@@ -0,0 +1,139 @@
1
+ import {useRouter} from 'vue-router'
2
+ import {h} from 'vue'
3
+ import type {ISysMenuInfoVo} from '../interface/ISysMenuInfoVo.ts'
4
+ import {permissionStore} from '../stores/permissionStore.ts'
5
+ import WujieVue from 'wujie-vue3'
6
+ import frameworkUtil from '../utils/FrameworkUtils.ts'
7
+ import { ElMessage } from 'element-plus'
8
+ import { userInfoStore } from '../stores/userInfoStore'
9
+
10
+ export default function usePermissionHooks(module:{getModules:Function}) {
11
+ const router = useRouter()
12
+ const permission = permissionStore()
13
+ /**
14
+ * 获取当前路由菜单信息
15
+ */
16
+ const getRouteMenuInfo = (): ISysMenuInfoVo => {
17
+ return router.currentRoute.value.meta.sysMenuData as ISysMenuInfoVo
18
+ }
19
+ /**
20
+ * 新增菜单路由
21
+ * @param sysMenu
22
+ */
23
+ const addRoute = async (sysMenu: ISysMenuInfoVo,params?:any): Promise<string> => {
24
+ const rootRoute = router.getRoutes().find((c) => c.name === '/')
25
+ if (!rootRoute?.children.find((c: any) => c.name === sysMenu.code)) {
26
+ // const comp = modules[sysMenu.component]
27
+ // console.log(comp, text)
28
+ let comp = null
29
+ if (sysMenu.isLink !== 1 && sysMenu.applicationModule !== 'system') {
30
+ comp = module.getModules(sysMenu.path)
31
+ }
32
+ if (comp) {
33
+ const r = {
34
+ name: sysMenu.code,
35
+ path: '/' + sysMenu.code,
36
+ meta: {
37
+ sysMenuData: sysMenu,
38
+ params:params,
39
+ link: sysMenu.isLink === 1,
40
+ applicationModule: sysMenu.applicationModule,
41
+ },
42
+ component: async () => {
43
+ const cpn = await comp()
44
+ cpn.default.__name = sysMenu.code
45
+ return h(cpn.default)
46
+ },
47
+ }
48
+
49
+ // rootRoute?.children.push(r)
50
+ //@ts-ignore
51
+ // router.addRoute(rootRoute)
52
+ router.addRoute('/', r)
53
+ return sysMenu.code
54
+ } else {
55
+ const r1 = {
56
+ name: sysMenu.code,
57
+ path: '/' + sysMenu.code,
58
+ meta: {
59
+ sysMenuData: sysMenu,
60
+ params:params,
61
+ link: sysMenu.isLink === 1,
62
+ applicationModule: sysMenu.applicationModule,
63
+ },
64
+ component: null,
65
+ }
66
+ //@ts-ignore
67
+ rootRoute?.children.push(r1)
68
+ //@ts-ignore
69
+ router.addRoute(rootRoute)
70
+ return sysMenu.code
71
+ }
72
+ } else {
73
+ return sysMenu.code
74
+ }
75
+ }
76
+ /**
77
+ * 打开菜单
78
+ * @param sysMenu
79
+ */
80
+ const openMenu = async (sysMenu: ISysMenuInfoVo, params?: any) => {
81
+ // permission.setOpenMenuInfo(sysMenu)
82
+ const name = await addRoute(sysMenu,params)
83
+ router.push({ name: name })
84
+ }
85
+ /**
86
+ * 通过框架打开菜单
87
+ * @param sysMenu
88
+ */
89
+ const openMenuByFramework = async (sysMenu: ISysMenuInfoVo,params?: any) => {
90
+ WujieVue.bus.$emit('openMenu', sysMenu,params)
91
+ }
92
+ /**
93
+ * 通过随机数打开菜单
94
+ * @param menuId 菜单id(用于判断是否打开过)
95
+ * @param menuCode 菜单code
96
+ * @param name 菜单tab显示名称
97
+ * @param param 菜单参数 route.meta.params
98
+ */
99
+ const openMenuByRandom = async (menuId: string, menuCode: string, name: string, param?: any) => {
100
+ if (!menuId || !menuCode || !name) {
101
+ ElMessage.error('菜单打开参数缺失')
102
+ return ''
103
+ }
104
+ let menu = frameworkUtil.getOpenMenuInfoWujie().find((item:any)=>item.id === menuId)
105
+ if (!menu) {
106
+ const userInfo = userInfoStore()
107
+ menu = JSON.parse(JSON.stringify(userInfo.getUserInfo.menuList.find(item => item.code === menuCode)))
108
+ if (menu) {
109
+ const random = (Math.random() * 100000).toFixed(0)
110
+ menu.code = menu.code + random
111
+ menu.name = name
112
+ menu.id = menuId
113
+ await openMenuByFramework(menu, param)
114
+ return menu.code
115
+ } else {
116
+ ElMessage.error('无"'+ name +'"权限')
117
+ }
118
+ } else {
119
+ await openMenuByFramework(menu, param)
120
+ return menu.code
121
+ }
122
+ return ''
123
+ }
124
+ /**
125
+ * 关闭当前菜单
126
+ * @param sysMenu
127
+ */
128
+ const closeMenu = (sysMenu: ISysMenuInfoVo) => {
129
+ if (sysMenu.id === permission.getActiveMenuInfo?.id) {
130
+ WujieVue.bus.$emit('close-sonPage')
131
+ }
132
+
133
+ }
134
+ const closeCurrentMenu = () => {
135
+ closeMenu(getRouteMenuInfo())
136
+ }
137
+
138
+ return {openMenu, getRouteMenuInfo, openMenuByFramework, closeMenu, closeCurrentMenu, openMenuByRandom}
139
+ }
@@ -1,3 +1,5 @@
1
+ import {ElMessageBox} from 'element-plus'
2
+
1
3
  export default {
2
4
  /**
3
5
  * 校验身份证号码
@@ -111,5 +113,223 @@ export default {
111
113
  birthday: '',
112
114
  sex: ''
113
115
  }
116
+ },
117
+ /**
118
+ * 判断数组中是否有props相同的对象
119
+ * @param arr
120
+ * @param props
121
+ */
122
+ hasDuplicate(arr: any[], props: string[]): boolean {
123
+ const map = new Map()
124
+ for (const obj of arr) {
125
+ let key = ''
126
+ for (const prop of props) {
127
+ key += obj[prop] + '|'
128
+ }
129
+ if (map.has(key)) {
130
+ return true
131
+ }
132
+ map.set(key, true)
133
+ }
134
+ return false
135
+ },
136
+ /**
137
+ * 删除确认函数
138
+ * @param fun
139
+ * @param args
140
+ */
141
+ deleteFun(fun: Function, ...args: any[]): void {
142
+ ElMessageBox.confirm(`是否确认删除该数据?`, '删除提示', {
143
+ confirmButtonText: '确定',
144
+ cancelButtonText: '取消',
145
+ type: 'warning',
146
+ }).then(async () => {
147
+ fun(...args)
148
+ })
149
+ },
150
+ calculateAge(birthDateStr: string | undefined): number | undefined {
151
+ if (!birthDateStr) return undefined
152
+ const birthDate = new Date(birthDateStr)
153
+ const currentDate = new Date()
154
+
155
+ let age = currentDate.getFullYear() - birthDate.getFullYear()
156
+ const monthDiff = currentDate.getMonth() - birthDate.getMonth()
157
+
158
+ if (monthDiff < 0 || (monthDiff === 0 && currentDate.getDate() < birthDate.getDate())) {
159
+ age--
160
+ }
161
+
162
+ return age
163
+ },
164
+ formatCurrency(amount: number): number {
165
+ return (Math.round(amount * 100) / 100).toFixed(2) as unknown as number;
166
+ },
167
+ stripRichText(html: string): string {
168
+ // 如果输入不是字符串或为空,直接返回空字符串
169
+ if (typeof html !== 'string' || html.trim() === '') {
170
+ return '';
171
+ }
172
+
173
+ // 1. 移除所有HTML标签
174
+ let text = html.replace(/<[^>]*>?/gm, '');
175
+
176
+ // 2. 处理HTML实体(如&nbsp; &amp; &lt; &gt;等)
177
+ const entities: Record<string, string> = {
178
+ '&nbsp;': ' ',
179
+ '&amp;': '&',
180
+ '&lt;': '<',
181
+ '&gt;': '>',
182
+ '&quot;': '"',
183
+ '&#39;': "'",
184
+ '&#160;': ' '
185
+ };
186
+
187
+ text = text.replace(/&[a-zA-Z0-9#]+;/g, match => {
188
+ return entities[match] || match;
189
+ });
190
+
191
+ // 3. 去除多余的空格和空行
192
+ text = text
193
+ .replace(/\s+/g, ' ') // 将多个空格/换行符替换为单个空格
194
+ .trim(); // 去除首尾空格
195
+
196
+ return text;
197
+ },
198
+ isRichTextEmpty(content: string | undefined): boolean {
199
+ if (!content) return true;
200
+ const textContent = this.stripRichText(content);
201
+ return !textContent;
202
+ },
203
+ /**
204
+ * 解析数学不等式规则,判断x是否满足规则
205
+ * @param {string} rule - 不等式规则,如"x=100"、"x≤50"、"10<x<20"等
206
+ * @param {string|number} xValue - 变量x的值,可为字符串或数字
207
+ * @returns {boolean} - x是否满足规则
208
+ */
209
+ isValueValidForRule(rule: string, xValue: number | string): boolean {
210
+ // 去除规则中的空格,统一格式
211
+ rule = rule.replace(/\s/g, '');
212
+
213
+ // 将字符串类型的数值转换为数字,若转换失败则设为NaN
214
+ const x = typeof xValue === 'string' ? parseFloat(xValue) : xValue;
215
+
216
+ // 检查转换后的值是否为有效数字
217
+ if (isNaN(x)) {
218
+ throw new Error(`Invalid xValue: ${xValue}`);
219
+ }
220
+
221
+ // 解析规则中的数值并进行匹配
222
+ try {
223
+ // 处理 "x=a" 类型规则
224
+ if (rule.includes('=')) {
225
+ const match = rule.match(/^x=([+-]?\d+(\.\d+)?)$/);
226
+ if (match) {
227
+ const a = parseFloat(match[1]);
228
+ if (isNaN(a)) {
229
+ throw new Error(`Invalid rule value: ${match[1]}`);
230
+ }
231
+ return x === a;
232
+ }
233
+ }
234
+
235
+ // 处理 "x<a" 类型规则
236
+ if (rule.includes('<') && !rule.includes('≤') && !rule.includes('±')) {
237
+ // 先尝试匹配 "a<x<b" 类型
238
+ const rangeMatch = rule.match(/^([+-]?\d+(\.\d+)?)<x<([+-]?\d+(\.\d+)?)$/);
239
+ if (rangeMatch) {
240
+ const a = parseFloat(rangeMatch[1]);
241
+ const b = parseFloat(rangeMatch[3]);
242
+ if (isNaN(a) || isNaN(b)) {
243
+ throw new Error(`Invalid rule values: ${rangeMatch[1]} or ${rangeMatch[3]}`);
244
+ }
245
+ return x > a && x < b;
246
+ }
247
+
248
+ // 再尝试匹配 "x<a" 类型
249
+ const match = rule.match(/^x<([+-]?\d+(\.\d+)?)$/);
250
+ if (match) {
251
+ const a = parseFloat(match[1]);
252
+ if (isNaN(a)) {
253
+ throw new Error(`Invalid rule value: ${match[1]}`);
254
+ }
255
+ return x < a;
256
+ }
257
+ }
258
+
259
+ // 处理 "x≤a" 类型规则
260
+ if (rule.includes('≤')) {
261
+ const match = rule.match(/^x≤([+-]?\d+(\.\d+)?)$/);
262
+ if (match) {
263
+ const a = parseFloat(match[1]);
264
+ if (isNaN(a)) {
265
+ throw new Error(`Invalid rule value: ${match[1]}`);
266
+ }
267
+ return x <= a;
268
+ }
269
+ }
270
+
271
+ // 处理 "x>a" 类型规则
272
+ if (rule.includes('>') && !rule.includes('≥')) {
273
+ const match = rule.match(/^x>([+-]?\d+(\.\d+)?)$/);
274
+ if (match) {
275
+ const a = parseFloat(match[1]);
276
+ if (isNaN(a)) {
277
+ throw new Error(`Invalid rule value: ${match[1]}`);
278
+ }
279
+ return x > a;
280
+ }
281
+ }
282
+
283
+ // 处理 "x≥a" 类型规则
284
+ if (rule.includes('≥')) {
285
+ const match = rule.match(/^x≥([+-]?\d+(\.\d+)?)$/);
286
+ if (match) {
287
+ const a = parseFloat(match[1]);
288
+ if (isNaN(a)) {
289
+ throw new Error(`Invalid rule value: ${match[1]}`);
290
+ }
291
+ return x >= a;
292
+ }
293
+ }
294
+
295
+ // 处理 "x±a" 类型规则
296
+ if (rule.includes('±')) {
297
+ const match = rule.match(/^x±([+-]?\d+(\.\d+)?)$/);
298
+ if (match) {
299
+ const a = parseFloat(match[1]);
300
+ if (isNaN(a)) {
301
+ throw new Error(`Invalid rule value: ${match[1]}`);
302
+ }
303
+ return x >= a - Math.abs(a) && x <= a + Math.abs(a);
304
+ }
305
+ }
306
+
307
+ // 处理 "a≤x<b" 类型规则
308
+ if (rule.includes('≤x<')) {
309
+ const match = rule.match(/^([+-]?\d+(\.\d+)?)≤x<([+-]?\d+(\.\d+)?)$/);
310
+ if (match) {
311
+ const a = parseFloat(match[1]);
312
+ const b = parseFloat(match[3]);
313
+ if (isNaN(a) || isNaN(b)) {
314
+ throw new Error(`Invalid rule values: ${match[1]} or ${match[3]}`);
315
+ }
316
+ return x >= a && x < b;
317
+ }
318
+ }
319
+
320
+ } catch (error) {
321
+ throw new Error(`Rule parsing error: ${(error as Error).message}`);
322
+ }
323
+
324
+ throw new Error(`Unsupported rule format: ${rule}`);
325
+ },
326
+ parseUrlParams: (queryStr: string):Record<string, any> => {
327
+ return Object.fromEntries(new URLSearchParams(queryStr.slice(queryStr.indexOf('?') + 1)));
328
+ },
329
+ jsonToUrlQuery: (jsonObj: Record<string, string>) => {
330
+ const keyValuePairs = Object.entries(jsonObj).map(([key, value]) => {
331
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
332
+ })
333
+ return keyValuePairs.length > 0 ? `?${keyValuePairs.join('&')}` : ''
114
334
  }
115
335
  }