adtec-core-package 2.2.2 → 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.2",
3
+ "version": "2.2.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -40,7 +40,6 @@
40
40
  "vue-focus-lock": "^3.0.0",
41
41
  "vue-img-viewr": "2.0.11",
42
42
  "vue-router": "^4.5.0",
43
- "vxe-pc-ui": "4.6.8",
44
43
  "vxe-table": "4.13.28",
45
44
  "wujie-vue3": "^1.0.24",
46
45
  "xlsx-js-style": "^1.2.0"
@@ -0,0 +1,11 @@
1
+ import VxeTooltipComponent from './src/tooltip'
2
+
3
+ export const VxeTooltip = Object.assign({}, VxeTooltipComponent, {
4
+ install (app: import("vue").App) {
5
+ app.component(VxeTooltipComponent.name as string, VxeTooltipComponent)
6
+ }
7
+ })
8
+
9
+
10
+ export const Tooltip = VxeTooltip
11
+ export default VxeTooltip
@@ -0,0 +1,518 @@
1
+ //@ts-ignore
2
+ import {
3
+ h,
4
+ ref,
5
+ nextTick,
6
+ onBeforeUnmount,
7
+ onMounted,
8
+ computed,
9
+ reactive,
10
+ watch,
11
+ type PropType,
12
+ type VNode
13
+ } from 'vue'
14
+
15
+ // 定义属性类型
16
+ interface VxeTooltipPropTypes {
17
+ modelValue?: boolean
18
+ content?: string | number
19
+ trigger?: 'hover' | 'click'
20
+ theme?: 'dark' | 'light'
21
+ enterDelay?: number
22
+ leaveDelay?: number
23
+ isArrow?: boolean
24
+ enterable?: boolean
25
+ }
26
+
27
+ // 定义响应式数据类型
28
+ interface TooltipReactData {
29
+ target: HTMLElement | null
30
+ isUpdate: boolean
31
+ visible: boolean
32
+ tipContent: string | number
33
+ tipActive: boolean
34
+ tipTarget: HTMLElement | null
35
+ tipZindex: number
36
+ tipStore: {
37
+ style: Record<string, string | number>
38
+ placement: string
39
+ arrowStyle: Record<string, string | number> | null
40
+ }
41
+ }
42
+
43
+ // 定义内部数据类型
44
+ interface TooltipInternalData {
45
+ showDelayTip?: Function
46
+ }
47
+
48
+ // 定义组件方法类型
49
+ interface TooltipMethods {
50
+ open: (target?: HTMLElement | null, content?: string | number) => void
51
+ close: () => void
52
+ updatePlacement: () => Promise<void>
53
+ isActived: () => boolean
54
+ setActived: (active: boolean) => void
55
+ }
56
+
57
+ // 简单的防抖函数
58
+ function debounce(func: Function, wait: number) {
59
+ let timeout: number | null = null
60
+ return function (this: any, ...args: any[]) {
61
+ if (timeout) {
62
+ clearTimeout(timeout)
63
+ }
64
+ timeout = window.setTimeout(() => {
65
+ func.apply(this, args)
66
+ }, wait) as any
67
+ }
68
+ }
69
+
70
+ // 检查值是否为空
71
+ function isNull(value: any): boolean {
72
+ return value === null || value === undefined
73
+ }
74
+
75
+ // 检查值是否相等
76
+ function eqNull(value: any): boolean {
77
+ return value === null || value === undefined || value === ''
78
+ }
79
+
80
+ export default {
81
+ name: 'VxeTooltip',
82
+ props: {
83
+ modelValue: Boolean,
84
+ content: [String, Number],
85
+ trigger: {
86
+ type: String as PropType<'hover' | 'click'>,
87
+ default: 'hover'
88
+ },
89
+ theme: {
90
+ type: String as PropType<'dark' | 'light'>,
91
+ default: 'dark'
92
+ },
93
+ isArrow: {
94
+ type: Boolean,
95
+ default: true
96
+ },
97
+ enterable: {
98
+ type: Boolean,
99
+ default: true
100
+ },
101
+ enterDelay: {
102
+ type: Number,
103
+ default: 0
104
+ },
105
+ leaveDelay: {
106
+ type: Number,
107
+ default: 0
108
+ }
109
+ },
110
+ emits: ['update:modelValue'],
111
+ setup(props: VxeTooltipPropTypes, { slots, emit }: any) {
112
+ // 响应式数据
113
+ const reactData = reactive<TooltipReactData>({
114
+ target: null,
115
+ isUpdate: false,
116
+ visible: false,
117
+ tipContent: '',
118
+ tipActive: false,
119
+ tipTarget: null,
120
+ tipZindex: 0,
121
+ tipStore: {
122
+ style: {},
123
+ placement: '',
124
+ arrowStyle: {}
125
+ }
126
+ })
127
+
128
+ // 内部数据
129
+ const internalData: TooltipInternalData = {}
130
+
131
+ // DOM 引用
132
+ const refElem = ref<HTMLDivElement>()
133
+ const contentWrapperfElem = ref<HTMLDivElement>()
134
+
135
+ // 获取 DOM 位置信息
136
+ const getDomNode = () => {
137
+ return {
138
+ scrollTop: window.scrollY || document.documentElement.scrollTop,
139
+ scrollLeft: window.scrollX || document.documentElement.scrollLeft,
140
+ visibleWidth: document.documentElement.clientWidth
141
+ }
142
+ }
143
+
144
+ // 获取元素绝对位置
145
+ const getAbsolutePos = (element: HTMLElement) => {
146
+ const rect = element.getBoundingClientRect()
147
+ return {
148
+ top: rect.top + getDomNode().scrollTop,
149
+ left: rect.left + getDomNode().scrollLeft
150
+ }
151
+ }
152
+
153
+ // 更新提示框位置
154
+ const updateTipStyle = () => {
155
+ const { tipTarget, tipStore } = reactData
156
+ if (tipTarget) {
157
+ const { scrollTop, scrollLeft, visibleWidth } = getDomNode()
158
+ const { top, left } = getAbsolutePos(tipTarget)
159
+ const el = refElem.value
160
+ if (!el) return
161
+
162
+ const marginSize = 6
163
+ const offsetHeight = el.offsetHeight
164
+ const offsetWidth = el.offsetWidth
165
+
166
+ let tipLeft = left
167
+ let tipTop = top - offsetHeight - marginSize
168
+
169
+ // 水平居中
170
+ tipLeft = Math.max(
171
+ marginSize,
172
+ left + Math.floor((tipTarget.offsetWidth - offsetWidth) / 2)
173
+ )
174
+
175
+ // 检查是否超出右边界
176
+ if (tipLeft + offsetWidth + marginSize > scrollLeft + visibleWidth) {
177
+ tipLeft = scrollLeft + visibleWidth - offsetWidth - marginSize
178
+ }
179
+
180
+ // 检查是否超出上边界,如果超出则显示在底部
181
+ if (top - offsetHeight < scrollTop + marginSize) {
182
+ tipStore.placement = 'bottom'
183
+ tipTop = top + tipTarget.offsetHeight + marginSize
184
+ }
185
+
186
+ tipStore.style.top = `${tipTop}px`
187
+ tipStore.style.left = `${tipLeft}px`
188
+ tipStore.arrowStyle = {
189
+ left: `${left - tipLeft + tipTarget.offsetWidth / 2}px`
190
+ }
191
+ }
192
+ }
193
+
194
+ // 更新值
195
+ const updateValue = (value: boolean) => {
196
+ if (value !== reactData.visible) {
197
+ reactData.visible = value
198
+ reactData.isUpdate = true
199
+ emit('update:modelValue', value)
200
+ }
201
+ }
202
+
203
+ // 显示提示框
204
+ const showTip = () => {
205
+ const el = refElem.value
206
+ if (el) {
207
+ const parentNode = el.parentNode
208
+ if (!parentNode) {
209
+ document.body.appendChild(el)
210
+ }
211
+ }
212
+
213
+ updateValue(true)
214
+ reactData.tipZindex = 1000 // 简化的 z-index
215
+ reactData.tipStore.placement = 'top'
216
+ reactData.tipStore.style = {
217
+ width: 'auto',
218
+ left: 0,
219
+ top: 0,
220
+ zIndex: reactData.tipZindex
221
+ }
222
+ reactData.tipStore.arrowStyle = { left: '50%' }
223
+
224
+ return nextTick().then(() => {
225
+ updateTipStyle()
226
+ return nextTick().then(() => {
227
+ updateTipStyle()
228
+ })
229
+ })
230
+ }
231
+
232
+ // 处理延迟函数
233
+ const handleDelayFn = () => {
234
+ internalData.showDelayTip = debounce(() => {
235
+ if (reactData.tipActive) {
236
+ showTip()
237
+ }
238
+ //@ts-ignore
239
+ }, props.enterDelay)
240
+ }
241
+
242
+ // 处理显示逻辑
243
+ const handleVisible = (target: HTMLElement | null, content?: string | number) => {
244
+ const contentSlot = slots.content
245
+ if (!contentSlot && (content === '' || eqNull(content))) {
246
+ return nextTick()
247
+ }
248
+
249
+ if (target) {
250
+ const { showDelayTip } = internalData
251
+ const { trigger, enterDelay } = props
252
+ reactData.tipActive = true
253
+ reactData.tipTarget = target
254
+ //@ts-ignore
255
+ reactData.tipContent = isNull(content) ? '' : content
256
+
257
+ if (enterDelay && trigger === 'hover') {
258
+ if (showDelayTip) {
259
+ showDelayTip()
260
+ }
261
+ } else {
262
+ return showTip()
263
+ }
264
+ }
265
+ return nextTick()
266
+ }
267
+
268
+ // 事件处理函数
269
+ const targetMouseenterEvent = () => {
270
+ handleVisible(reactData.target, props.content)
271
+ }
272
+
273
+ const targetMouseleaveEvent = () => {
274
+ const { trigger, enterable, leaveDelay } = props
275
+ reactData.tipActive = false
276
+
277
+ if (enterable && trigger === 'hover') {
278
+ setTimeout(() => {
279
+ if (!reactData.tipActive) {
280
+ close()
281
+ }
282
+ }, leaveDelay)
283
+ } else {
284
+ close()
285
+ }
286
+ }
287
+
288
+ const wrapperMouseenterEvent = () => {
289
+ reactData.tipActive = true
290
+ }
291
+
292
+ const wrapperMouseleaveEvent = () => {
293
+ const { trigger, enterable, leaveDelay } = props
294
+ reactData.tipActive = false
295
+
296
+ if (enterable && trigger === 'hover') {
297
+ setTimeout(() => {
298
+ if (!reactData.tipActive) {
299
+ close()
300
+ }
301
+ }, leaveDelay)
302
+ }
303
+ }
304
+
305
+ const clickEvent = () => {
306
+ if (reactData.visible) {
307
+ close()
308
+ } else {
309
+ handleVisible(reactData.target, props.content)
310
+ }
311
+ }
312
+
313
+ // 关闭方法
314
+ const close = () => {
315
+ reactData.tipTarget = null
316
+ reactData.tipActive = false
317
+ Object.assign(reactData.tipStore, {
318
+ style: {},
319
+ placement: '',
320
+ arrowStyle: null
321
+ })
322
+ updateValue(false)
323
+ return nextTick()
324
+ }
325
+
326
+ // 公开方法
327
+ const tooltipMethods: TooltipMethods = {
328
+ open(target?: HTMLElement | null, content?: string | number) {
329
+ return handleVisible(target || reactData.target, content)
330
+ },
331
+ close,
332
+ updatePlacement() {
333
+ return nextTick().then(() => {
334
+ const { tipTarget } = reactData
335
+ const el = refElem.value
336
+ if (tipTarget && el) {
337
+ updateTipStyle()
338
+ return nextTick().then(() => {
339
+ updateTipStyle()
340
+ })
341
+ }
342
+ })
343
+ },
344
+ isActived() {
345
+ return reactData.tipActive
346
+ },
347
+ setActived(active: boolean) {
348
+ reactData.tipActive = !!active
349
+ }
350
+ }
351
+
352
+ // 渲染内容
353
+ const renderContent = () => {
354
+ const { tipContent } = reactData
355
+ const contentSlot = slots.content
356
+
357
+ const contVNs: VNode[] = []
358
+ if (contentSlot) {
359
+ contVNs.push(
360
+ h('div', {}, contentSlot({}))
361
+ )
362
+ } else {
363
+ contVNs.push(
364
+ h('div', {}, `${tipContent}`)
365
+ )
366
+ }
367
+
368
+ return h('div', {
369
+ ref: contentWrapperfElem,
370
+ class: 'vxe-tooltip--content'
371
+ }, contVNs)
372
+ }
373
+
374
+ // 渲染虚拟节点
375
+ const renderVN = () => {
376
+ const { theme, isArrow, enterable } = props
377
+ const { tipActive, visible, tipStore } = reactData
378
+ const defaultSlot = slots.default
379
+
380
+ let ons
381
+ if (enterable) {
382
+ ons = {
383
+ onMouseenter: wrapperMouseenterEvent,
384
+ onMouseleave: wrapperMouseleaveEvent
385
+ }
386
+ }
387
+
388
+ return h('div', {
389
+ ref: refElem,
390
+ class: [
391
+ 'vxe-tooltip--wrapper',
392
+ `theme--${theme}`,
393
+ {
394
+ [`placement--${tipStore.placement}`]: tipStore.placement,
395
+ 'is--enterable': enterable,
396
+ 'is--visible': visible,
397
+ 'is--arrow': isArrow,
398
+ 'is--active': tipActive
399
+ }
400
+ ],
401
+ style: {
402
+ ...tipStore.style,
403
+ // 添加过渡效果
404
+ transition: 'opacity 0.2s ease, transform 0.2s ease',
405
+ opacity: visible ? 1 : 0,
406
+ transform: visible ? 'scale(1)' : 'scale(0.95)'
407
+ },
408
+ ...ons
409
+ }, [
410
+ renderContent(),
411
+ isArrow
412
+ ? h('div', {
413
+ class: 'vxe-tooltip--arrow',
414
+ style: tipStore.arrowStyle
415
+ })
416
+ : null,
417
+ ...(defaultSlot ? defaultSlot({}) : [])
418
+ ])
419
+ }
420
+
421
+ // 监听器
422
+ watch(() => props.enterDelay, () => {
423
+ handleDelayFn()
424
+ })
425
+
426
+ watch(() => props.content, (val) => {
427
+ //@ts-ignore
428
+ reactData.tipContent = isNull(val) ? '' : val
429
+ })
430
+
431
+ watch(() => props.modelValue, (val) => {
432
+ if (!reactData.isUpdate) {
433
+ if (val) {
434
+ handleVisible(reactData.target, props.content)
435
+ } else {
436
+ close()
437
+ }
438
+ }
439
+ reactData.isUpdate = false
440
+ })
441
+
442
+ // 生命周期钩子
443
+ onMounted(() => {
444
+ nextTick(() => {
445
+ const { trigger, content } = props
446
+ const wrapperElem = refElem.value
447
+
448
+ if (wrapperElem) {
449
+ const parentNode = wrapperElem.parentNode
450
+ if (parentNode) {
451
+ //@ts-ignore
452
+ reactData.tipContent = isNull(content) ? '' : content
453
+ reactData.tipZindex = 1000
454
+
455
+ // 将子元素移动到父级
456
+ const children = Array.from(wrapperElem.children)
457
+ children.forEach((elem, index) => {
458
+ if (index > 1) {
459
+ parentNode.insertBefore(elem, wrapperElem)
460
+ if (!reactData.target) {
461
+ reactData.target = elem as HTMLElement
462
+ }
463
+ }
464
+ })
465
+
466
+ parentNode.removeChild(wrapperElem)
467
+
468
+ // 绑定事件
469
+ const { target } = reactData
470
+ if (target) {
471
+ if (trigger === 'hover') {
472
+ target.onmouseenter = targetMouseenterEvent
473
+ target.onmouseleave = targetMouseleaveEvent
474
+ } else if (trigger === 'click') {
475
+ target.onclick = clickEvent
476
+ }
477
+ }
478
+
479
+ // 如果 modelValue 为 true,则显示
480
+ if (props.modelValue) {
481
+ handleVisible(target, content)
482
+ }
483
+ }
484
+ }
485
+ })
486
+ })
487
+
488
+ onBeforeUnmount(() => {
489
+ const { target } = reactData
490
+ const wrapperElem = refElem.value
491
+
492
+ if (target) {
493
+ target.onmouseenter = null
494
+ target.onmouseleave = null
495
+ target.onclick = null
496
+ }
497
+
498
+ if (wrapperElem) {
499
+ const parentNode = wrapperElem.parentNode
500
+ if (parentNode) {
501
+ parentNode.removeChild(wrapperElem)
502
+ }
503
+ }
504
+ })
505
+
506
+ handleDelayFn()
507
+
508
+ return {
509
+ ...tooltipMethods,
510
+ renderVN
511
+ }
512
+ },
513
+ //@ts-ignore
514
+ render() {
515
+ //@ts-ignore
516
+ return this.renderVN()
517
+ }
518
+ }
@@ -1,5 +1,6 @@
1
- import { VxeGrid } from 'vxe-table'
2
- import { VxeUI } from 'vxe-pc-ui'
1
+ import { VxeGrid,VxeUI } from 'vxe-table'
2
+ //@ts-ignore
3
+ import { VxeTooltip } from '../components/tooltip/index.ts'
3
4
 
4
5
  import VxeUIPluginRenderElement from '@vxe-ui/plugin-render-element'
5
6
  import '@vxe-ui/plugin-render-element/dist/style.css'
@@ -15,15 +16,19 @@ import zhCN from 'vxe-table/lib/locale/lang/zh-CN'
15
16
  /**
16
17
  * 局部初始化 vxe-table 插件与配置
17
18
  */
18
- export function initVxeTableInPage(enableExcel: boolean = false, enablePdf: boolean = false) {
19
+ export function initVxeTableInPage(
20
+ enableExcel: boolean = false,
21
+ enablePdf: boolean = false,
22
+ enableElementPlus: boolean = true,
23
+ ) {
19
24
  // 设置语言
20
25
  VxeUI.setI18n('zh-CN', zhCN)
21
26
  VxeUI.setLanguage('zh-CN')
22
-
27
+ VxeUI.component(VxeTooltip)
23
28
  // 局部注册插件
24
- VxeUI.use(VxeUIPluginRenderElement)
25
- if (enableExcel) VxeUI.use(VxeUIPluginExportXLSX, { ExcelJS })
26
- if (enablePdf) VxeUI.use(VxeUIPluginExportPDF, { jsPDF })
29
+ enableElementPlus && VxeUI.use(VxeUIPluginRenderElement)
30
+ enableExcel && VxeUI.use(VxeUIPluginExportXLSX, { ExcelJS })
31
+ enablePdf && VxeUI.use(VxeUIPluginExportPDF, { jsPDF })
27
32
 
28
33
  // 设置表格配置(可复制你在 VxeTableConfig.ts 中的配置)
29
34
  VxeUI.setConfig({
@@ -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
  }