wui-components-v2 1.1.69 → 1.1.71

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.
Files changed (117) hide show
  1. package/api/core/index.ts +74 -74
  2. package/api/feishu.ts +20 -20
  3. package/api/index.ts +4 -4
  4. package/api/login.ts +51 -51
  5. package/api/menu.ts +45 -45
  6. package/api/page.ts +114 -114
  7. package/api/sys.ts +12 -12
  8. package/api/tree.ts +28 -28
  9. package/components/action-popup/action-popup.vue +116 -116
  10. package/components/add-address-list/add-address-list.vue +187 -187
  11. package/components/add-address-page/add-address-page.vue +77 -77
  12. package/components/add-address-page/config.ts +297 -297
  13. package/components/audio-play/audio-play.vue +220 -220
  14. package/components/batch-upload-file/batch-upload-file.vue +75 -75
  15. package/components/card-botom-buttons/card-botom-buttons.vue +279 -279
  16. package/components/custom-date-picker/custom-date-picker.vue +106 -106
  17. package/components/custom-select-picker/custom-select-picker.vue +95 -95
  18. package/components/demo-block/demo-block.vue +63 -63
  19. package/components/demo-card/demo-card.vue +44 -44
  20. package/components/detail-popup/detail-popup.vue +99 -99
  21. package/components/evaluation-page/evaluation-page.vue +196 -196
  22. package/components/fold-card/fold-card.vue +171 -171
  23. package/components/form-control/form-control.vue +661 -661
  24. package/components/global-loading/GlobalLoading.md +366 -366
  25. package/components/global-loading/global-loading.vue +55 -55
  26. package/components/global-message/GlobalMessage.md +570 -570
  27. package/components/global-message/global-message.vue +68 -68
  28. package/components/global-toast/GlobalToast.md +261 -261
  29. package/components/global-toast/global-toast.vue +56 -56
  30. package/components/label-value/label-value.vue +144 -144
  31. package/components/label-value/open-value-more.vue +56 -56
  32. package/components/list-top-buttons/list-top-buttons.vue +19 -19
  33. package/components/loading/loading.vue +5 -5
  34. package/components/login-form/login-form.vue +126 -126
  35. package/components/login-form-box/login-form-box.vue +65 -65
  36. package/components/mulselect-picker/mulselect-picker.vue +86 -86
  37. package/components/phone-login-form/phone-login-form.vue +204 -204
  38. package/components/privacy-popup/privacy-popup.vue +191 -191
  39. package/components/product-card/product-card.vue +201 -201
  40. package/components/scan-input/scan-input.vue +406 -406
  41. package/components/search/search.vue +128 -128
  42. package/components/select-col-picker/select-col-picker.vue +168 -168
  43. package/components/tab-search/tab-search.vue +73 -73
  44. package/components/tree-select/components/TreeNode.vue +200 -200
  45. package/components/tree-select/components/index.vue +471 -471
  46. package/components/tree-select/components/tree-select.vue +56 -56
  47. package/components/tree-select/index.vue +93 -93
  48. package/components/user-choose/user-choose.vue +169 -151
  49. package/components/video-play/video-play.vue +56 -56
  50. package/components/wui-auto-update-component/wui-auto-update-component.vue +132 -132
  51. package/components/wui-default/wui-default.vue +49 -49
  52. package/components/wui-details-page/wui-details-page.vue +147 -147
  53. package/components/wui-edit-page/wui-edit-page-copy.vue +757 -757
  54. package/components/wui-edit-page/wui-edit-page.vue +793 -793
  55. package/components/wui-enume-select-control/wui-enume-select-control.vue +92 -92
  56. package/components/wui-list/wui-list.vue +235 -235
  57. package/components/wui-login/wui-login.vue +43 -43
  58. package/components/wui-login1/wui-login.vue +41 -41
  59. package/components/wui-menus/wui-menus-top.vue +137 -137
  60. package/components/wui-menus/wui-menus-top1.vue +8 -8
  61. package/components/wui-menus/wui-menus.vue +247 -247
  62. package/components/wui-menus1/components/banner-carousel.vue +320 -320
  63. package/components/wui-menus1/components/navbar.vue +43 -43
  64. package/components/wui-menus1/components/quick-panel.vue +55 -55
  65. package/components/wui-menus1/components/search-bar.vue +49 -49
  66. package/components/wui-menus1/components/section-menus.vue +208 -208
  67. package/components/wui-menus1/wui-menus-top.vue +718 -718
  68. package/components/wui-menus1/wui-menus-top1.vue +398 -398
  69. package/components/wui-menus1/wui-menus.vue +564 -564
  70. package/components/wui-notify-info/notify-handle.vue +53 -53
  71. package/components/wui-notify-info/wui-notify-info.vue +280 -280
  72. package/components/wui-scan-binding-sensor/wui-scan-binding-sensor.vue +75 -75
  73. package/components/wui-search-history-babbar/components/SearchBar.vue +70 -70
  74. package/components/wui-search-history-babbar/wui-search-history-babbar.vue +204 -204
  75. package/components/wui-select-list/wui-select-list.vue +310 -310
  76. package/components/wui-select-popup/wui-select-popup.vue +613 -612
  77. package/components/wui-system-settings/wui-system-settings.vue +144 -144
  78. package/components/wui-tabbar/wui-tabbar.vue +106 -106
  79. package/components/wui-tree-page/components/tree-item.vue +238 -238
  80. package/components/wui-tree-page/wui-tree-page.vue +297 -297
  81. package/components/wui-update-component/wui-update-component.vue +221 -221
  82. package/components/wui-user/wui-user.vue +202 -202
  83. package/composables/types/theme.ts +65 -65
  84. package/composables/types/user.ts +5 -5
  85. package/composables/useColorGenerator.ts +221 -221
  86. package/composables/useCompanyFieldFilter.ts +91 -91
  87. package/composables/useEnumes.ts +43 -43
  88. package/composables/useEventBus.ts +37 -37
  89. package/composables/useGlobalLoading.ts +47 -47
  90. package/composables/useGlobalMessage.ts +53 -53
  91. package/composables/useGlobalToast.ts +63 -63
  92. package/composables/useLocale.ts +54 -54
  93. package/composables/useManualTheme.ts +179 -179
  94. package/composables/useMenus.ts +193 -193
  95. package/composables/useSectionMenus.ts +120 -120
  96. package/composables/useTabbar.ts +50 -50
  97. package/composables/useTheme.ts +74 -74
  98. package/composables/useUser.ts +24 -24
  99. package/index.d.ts +90 -90
  100. package/index.ts +83 -83
  101. package/package.json +24 -24
  102. package/static/iconfont/iconfont.css +63 -63
  103. package/store/language.ts +151 -151
  104. package/store/manualThemeStore.ts +143 -143
  105. package/store/persist.ts +41 -41
  106. package/store/themeStore.ts +74 -74
  107. package/store/userStore.ts +22 -22
  108. package/styles/dark-mode.css +523 -523
  109. package/styles/dark-mode.min.css +1 -1
  110. package/styles/dark-mode.scss +498 -498
  111. package/type.ts +154 -154
  112. package/utils/control-tree.ts +353 -353
  113. package/utils/control-type-supportor.ts +148 -148
  114. package/utils/eventBus.ts +36 -36
  115. package/utils/idata-scan.ts +99 -99
  116. package/utils/index.ts +979 -979
  117. package/utils/rsaEncrypt.ts +10 -10
@@ -1,193 +1,193 @@
1
- import { computed, ref } from 'vue'
2
- import { useRouter } from 'uni-mini-router'
3
- import { fastmenu, menu } from '../api/menu'
4
- import { useManualTheme } from '../composables/useManualTheme'
5
- import { useGlobalToast } from '../composables/useGlobalToast'
6
- import { RainbowColorGenerator } from '../utils/index'
7
- // 类型
8
- export interface Icon {
9
- id: string
10
- path: string
11
- }
12
- interface Props {
13
- icons: Icon[]
14
- load: () => void
15
- menuTopType: string
16
- }
17
- export interface MenuItem {
18
- id: string
19
- title: string
20
- icon: string
21
- color: string
22
- tip: string
23
- pageType: string
24
- children?: MenuItem[]
25
- }
26
- export function useMenus(props?: Props, pagingRef?: Ref<any>) {
27
- const router = useRouter()
28
- const toast = useGlobalToast()
29
- const { currentThemeColor } = useManualTheme()
30
- const colorGenerator = new RainbowColorGenerator()
31
- const menuList = ref<MenuItem[]>([])
32
- const title = ref('')
33
- const navTitle = ref('')
34
- const filtermenu = computed<MenuItem[]>(() => {
35
- let arr = []
36
- if (currentThemeColor.value.primary) {
37
- arr = filterHiddenTree(menuList.value, 'items', true)
38
- }
39
- return arr
40
- })
41
- const sheetShow = ref(false)
42
- const actions = ref([])
43
- // 点击菜单跳转页面
44
- function gotoPage(item: MenuItem) {
45
- // 跳转页面
46
- if (goto(item)) return
47
- // 打开动作面板
48
- openSheet(item)
49
- }
50
-
51
- // 点击动作面板跳转页面
52
- function sheetGotoPage(item: MenuItem) {
53
- // 跳转页面
54
- if (goto(item)) return
55
- // 打开动作面板
56
- openSheet(item, 300)
57
- }
58
-
59
- // 跳转页面
60
- function goto(item: MenuItem) {
61
- console.log(item.pageType)
62
- switch (item.pageType) {
63
- case '列表':
64
- console.log(item, 'item ')
65
- router.push(`/pages/list/index?sourceId=${item.id}&title=${item.title}`)
66
- return true
67
- case '树':
68
- router.push(`/pages/tree-page/index?sourceId=${item.id}&title=${item.title}`)
69
- return true
70
- case '报表':
71
- // uni.navigateTo({
72
- // url: `/pages/report-table/report-table?sourceId=${item.id}&title=${item.title}`,
73
- // })
74
- return true
75
-
76
- default:
77
- return false
78
- }
79
- }
80
-
81
- // 打开wd-action-sheet动作面板
82
- function openSheet(item: any, s = 0) {
83
- if (item.items) {
84
- title.value = item.title
85
- actions.value = item.items
86
- ? item.items.map((item: any) => {
87
- return {
88
- name: item.title,
89
- // color: '#00000073',
90
- ...item,
91
- }
92
- })
93
- : []
94
-
95
- // 设置二次打开的过渡时间
96
- const id = setTimeout(() => {
97
- sheetShow.value = true
98
- clearTimeout(id)
99
- }, s)
100
- }
101
- }
102
-
103
- /**
104
- * 根据 `disabled: true` 过滤树形数组(支持自定义子节点字段)
105
- * @param {Array} tree 原始树形数据
106
- * @param {string} [childKey] 子节点字段名
107
- * @param {boolean} [deepClone] 是否深拷贝原数据
108
- * @returns {Array} 过滤后的新树形数据
109
- */
110
- function filterHiddenTree(tree: any, childKey = 'children', deepClone = false) {
111
- // 深拷贝处理(可选)
112
- const clone = (data: any) => {
113
- if (!deepClone) return data
114
- return JSON.parse(JSON.stringify(data))
115
- }
116
-
117
- return clone(tree)
118
- .filter((node: any) => !node.disabled) // 过滤当前层隐藏节点
119
- .map((node: any) => {
120
- // 递归处理子节点
121
- if (Array.isArray(node[childKey])) {
122
- node[childKey] = filterHiddenTree(node[childKey], childKey, deepClone)
123
- }
124
- const icon = props?.icons.find((item: any) => {
125
- return item.id === node.id
126
- })
127
- const color = colorGenerator.getNextColor()
128
- return {
129
- ...node,
130
- iconPath: (icon as any)?.path,
131
- color,
132
- }
133
- })
134
- }
135
-
136
- // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用this.$refs.paging.reload()即可
137
- function queryList() {
138
- // 此处请求仅为演示,请替换为自己项目中的请求
139
- menu()
140
- .then((res: any) => {
141
- // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
142
- if (!res?.blocks?.length) {
143
- toast.warning('暂无权限,请重新登录或联系管理员')
144
- }
145
- navTitle.value = res?.programName || ''
146
- uni.setNavigationBarTitle({ title: res?.programName || '' }) // 设置标题
147
- pagingRef?.value.complete(res?.blocks || [])
148
- })
149
- .catch((res: any) => {
150
- console.log(res)
151
- // 如果请求失败写this.$refs.paging.complete(false),会自动展示错误页面
152
- // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
153
- // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
154
- pagingRef?.value.complete(false)
155
- })
156
- }
157
-
158
- // 快速访问菜单
159
- const sectionmenu = ref<MenuItem[]>([])
160
- const filersectiomenus = computed(() => {
161
- // 截取数组前4项
162
- return sectionmenu.value.slice(0, 4)
163
- })
164
-
165
- const getSectionMenu = async () => {
166
- try {
167
- const res = await fastmenu()
168
- if (res.fastMenu) {
169
- sectionmenu.value = res.fastMenu.QuickQueryBar || []
170
- } else {
171
- sectionmenu.value = []
172
- }
173
- } catch (error) {
174
- console.log(error)
175
- }
176
- }
177
-
178
- return {
179
- gotoPage,
180
- sheetGotoPage,
181
- filtermenu,
182
- sheetShow,
183
- actions,
184
- title,
185
- navTitle,
186
- queryList,
187
- menuList,
188
- currentThemeColor,
189
- getSectionMenu,
190
- filersectiomenus,
191
- sectionmenu,
192
- }
193
- }
1
+ import { computed, ref } from 'vue'
2
+ import { useRouter } from 'uni-mini-router'
3
+ import { fastmenu, menu } from '../api/menu'
4
+ import { useManualTheme } from '../composables/useManualTheme'
5
+ import { useGlobalToast } from '../composables/useGlobalToast'
6
+ import { RainbowColorGenerator } from '../utils/index'
7
+ // 类型
8
+ export interface Icon {
9
+ id: string
10
+ path: string
11
+ }
12
+ interface Props {
13
+ icons: Icon[]
14
+ load: () => void
15
+ menuTopType: string
16
+ }
17
+ export interface MenuItem {
18
+ id: string
19
+ title: string
20
+ icon: string
21
+ color: string
22
+ tip: string
23
+ pageType: string
24
+ children?: MenuItem[]
25
+ }
26
+ export function useMenus(props?: Props, pagingRef?: Ref<any>) {
27
+ const router = useRouter()
28
+ const toast = useGlobalToast()
29
+ const { currentThemeColor } = useManualTheme()
30
+ const colorGenerator = new RainbowColorGenerator()
31
+ const menuList = ref<MenuItem[]>([])
32
+ const title = ref('')
33
+ const navTitle = ref('')
34
+ const filtermenu = computed<MenuItem[]>(() => {
35
+ let arr = []
36
+ if (currentThemeColor.value.primary) {
37
+ arr = filterHiddenTree(menuList.value, 'items', true)
38
+ }
39
+ return arr
40
+ })
41
+ const sheetShow = ref(false)
42
+ const actions = ref([])
43
+ // 点击菜单跳转页面
44
+ function gotoPage(item: MenuItem) {
45
+ // 跳转页面
46
+ if (goto(item)) return
47
+ // 打开动作面板
48
+ openSheet(item)
49
+ }
50
+
51
+ // 点击动作面板跳转页面
52
+ function sheetGotoPage(item: MenuItem) {
53
+ // 跳转页面
54
+ if (goto(item)) return
55
+ // 打开动作面板
56
+ openSheet(item, 300)
57
+ }
58
+
59
+ // 跳转页面
60
+ function goto(item: MenuItem) {
61
+ console.log(item.pageType)
62
+ switch (item.pageType) {
63
+ case '列表':
64
+ console.log(item, 'item ')
65
+ router.push(`/pages/list/index?sourceId=${item.id}&title=${item.title}`)
66
+ return true
67
+ case '树':
68
+ router.push(`/pages/tree-page/index?sourceId=${item.id}&title=${item.title}`)
69
+ return true
70
+ case '报表':
71
+ // uni.navigateTo({
72
+ // url: `/pages/report-table/report-table?sourceId=${item.id}&title=${item.title}`,
73
+ // })
74
+ return true
75
+
76
+ default:
77
+ return false
78
+ }
79
+ }
80
+
81
+ // 打开wd-action-sheet动作面板
82
+ function openSheet(item: any, s = 0) {
83
+ if (item.items) {
84
+ title.value = item.title
85
+ actions.value = item.items
86
+ ? item.items.map((item: any) => {
87
+ return {
88
+ name: item.title,
89
+ // color: '#00000073',
90
+ ...item,
91
+ }
92
+ })
93
+ : []
94
+
95
+ // 设置二次打开的过渡时间
96
+ const id = setTimeout(() => {
97
+ sheetShow.value = true
98
+ clearTimeout(id)
99
+ }, s)
100
+ }
101
+ }
102
+
103
+ /**
104
+ * 根据 `disabled: true` 过滤树形数组(支持自定义子节点字段)
105
+ * @param {Array} tree 原始树形数据
106
+ * @param {string} [childKey] 子节点字段名
107
+ * @param {boolean} [deepClone] 是否深拷贝原数据
108
+ * @returns {Array} 过滤后的新树形数据
109
+ */
110
+ function filterHiddenTree(tree: any, childKey = 'children', deepClone = false) {
111
+ // 深拷贝处理(可选)
112
+ const clone = (data: any) => {
113
+ if (!deepClone) return data
114
+ return JSON.parse(JSON.stringify(data))
115
+ }
116
+
117
+ return clone(tree)
118
+ .filter((node: any) => !node.disabled) // 过滤当前层隐藏节点
119
+ .map((node: any) => {
120
+ // 递归处理子节点
121
+ if (Array.isArray(node[childKey])) {
122
+ node[childKey] = filterHiddenTree(node[childKey], childKey, deepClone)
123
+ }
124
+ const icon = props?.icons.find((item: any) => {
125
+ return item.id === node.id
126
+ })
127
+ const color = colorGenerator.getNextColor()
128
+ return {
129
+ ...node,
130
+ iconPath: (icon as any)?.path,
131
+ color,
132
+ }
133
+ })
134
+ }
135
+
136
+ // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用this.$refs.paging.reload()即可
137
+ function queryList() {
138
+ // 此处请求仅为演示,请替换为自己项目中的请求
139
+ menu()
140
+ .then((res: any) => {
141
+ // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
142
+ if (!res?.blocks?.length) {
143
+ toast.warning('暂无权限,请重新登录或联系管理员')
144
+ }
145
+ navTitle.value = res?.programName || ''
146
+ uni.setNavigationBarTitle({ title: res?.programName || '' }) // 设置标题
147
+ pagingRef?.value.complete(res?.blocks || [])
148
+ })
149
+ .catch((res: any) => {
150
+ console.log(res)
151
+ // 如果请求失败写this.$refs.paging.complete(false),会自动展示错误页面
152
+ // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
153
+ // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
154
+ pagingRef?.value.complete(false)
155
+ })
156
+ }
157
+
158
+ // 快速访问菜单
159
+ const sectionmenu = ref<MenuItem[]>([])
160
+ const filersectiomenus = computed(() => {
161
+ // 截取数组前4项
162
+ return sectionmenu.value.slice(0, 4)
163
+ })
164
+
165
+ const getSectionMenu = async () => {
166
+ try {
167
+ const res = await fastmenu()
168
+ if (res.fastMenu) {
169
+ sectionmenu.value = res.fastMenu.QuickQueryBar || []
170
+ } else {
171
+ sectionmenu.value = []
172
+ }
173
+ } catch (error) {
174
+ console.log(error)
175
+ }
176
+ }
177
+
178
+ return {
179
+ gotoPage,
180
+ sheetGotoPage,
181
+ filtermenu,
182
+ sheetShow,
183
+ actions,
184
+ title,
185
+ navTitle,
186
+ queryList,
187
+ menuList,
188
+ currentThemeColor,
189
+ getSectionMenu,
190
+ filersectiomenus,
191
+ sectionmenu,
192
+ }
193
+ }
@@ -1,120 +1,120 @@
1
- import { onUnmounted, ref } from 'vue'
2
- import { fastmenu, menuCount } from '../api/menu'
3
-
4
- export interface MenuCount {
5
- title: string
6
- id: string
7
- count: number
8
- icon: string
9
- pageType: string
10
- }
11
- export function useSectionMenus(isInterval: boolean = false) {
12
- const messageBar = ref<MenuCount | null>(null)
13
- const quickPanel = ref<MenuCount[]>([])
14
- const rightSidebar01 = ref<MenuCount[]>([])
15
- const rightSidebar02 = ref<MenuCount[]>([])
16
- // 手动调用并启动定时器
17
- let intervalId: ReturnType<typeof setInterval> | null = null
18
-
19
- const getmenuCount = async (id: string) => {
20
- try {
21
- if (id) {
22
- const res = await menuCount(id)
23
- return res.count
24
- }
25
- return 0
26
- }
27
- catch (error) {
28
- console.log(error)
29
- return 0
30
- }
31
- }
32
-
33
- // 组件卸载时清理定时器(可选)
34
- onUnmounted(() => {
35
- if (intervalId)
36
- clearInterval(intervalId)
37
- })
38
-
39
- const updateMenuCounts = async () => {
40
- try {
41
- // 立即执行一次
42
- if (messageBar.value?.id) {
43
- const count = await getmenuCount(messageBar.value.id)
44
- messageBar.value = { ...messageBar.value, count }
45
- }
46
-
47
- if (quickPanel.value.length > 0) {
48
- quickPanel.value = await Promise.all(
49
- quickPanel.value.map(async (item) => {
50
- const count = await getmenuCount(item.id)
51
- return { ...item, count }
52
- }),
53
- )
54
- }
55
-
56
- // 设置定时器,每隔 1000*60*2 秒执行一次
57
- const intervalId = setInterval(async () => {
58
- try {
59
- if (messageBar.value?.id) {
60
- const count = await getmenuCount(messageBar.value.id)
61
- messageBar.value = { ...messageBar.value, count }
62
- }
63
-
64
- if (quickPanel.value.length > 0) {
65
- quickPanel.value = await Promise.all(
66
- quickPanel.value.map(async (item) => {
67
- const count = await getmenuCount(item.id)
68
- return { ...item, count }
69
- }),
70
- )
71
- }
72
- }
73
- catch (error) {
74
- console.log(error)
75
- }
76
- }, 1000 * 60 * 2)
77
-
78
- // 返回定时器 ID,方便后续清理
79
- return intervalId
80
- }
81
- catch (error) {
82
- console.log(error)
83
- return null
84
- }
85
- }
86
-
87
- const getSectionMenu = async () => {
88
- try {
89
- const res = await fastmenu()
90
- if (res.fastMenu) {
91
- messageBar.value = res.fastMenu.MessageBar ? res.fastMenu.MessageBar[0] : null
92
- quickPanel.value = res.fastMenu?.QuickPanel || []
93
- rightSidebar01.value = res.fastMenu?.RightSidebar01 || []
94
- rightSidebar02.value = res.fastMenu?.RightSidebar02 || []
95
- // 清除之前的定时器(防止重复创建)
96
- if (intervalId)
97
- clearInterval(intervalId)
98
- // 启动定时器
99
- if (isInterval) {
100
- intervalId = await updateMenuCounts()
101
- }
102
- }
103
- else {
104
- messageBar.value = null
105
- quickPanel.value = []
106
- }
107
- }
108
- catch (error) {
109
- console.log(error)
110
- }
111
- }
112
- getSectionMenu()
113
-
114
- return {
115
- messageBar,
116
- quickPanel,
117
- rightSidebar01,
118
- rightSidebar02,
119
- }
120
- }
1
+ import { onUnmounted, ref } from 'vue'
2
+ import { fastmenu, menuCount } from '../api/menu'
3
+
4
+ export interface MenuCount {
5
+ title: string
6
+ id: string
7
+ count: number
8
+ icon: string
9
+ pageType: string
10
+ }
11
+ export function useSectionMenus(isInterval: boolean = false) {
12
+ const messageBar = ref<MenuCount | null>(null)
13
+ const quickPanel = ref<MenuCount[]>([])
14
+ const rightSidebar01 = ref<MenuCount[]>([])
15
+ const rightSidebar02 = ref<MenuCount[]>([])
16
+ // 手动调用并启动定时器
17
+ let intervalId: ReturnType<typeof setInterval> | null = null
18
+
19
+ const getmenuCount = async (id: string) => {
20
+ try {
21
+ if (id) {
22
+ const res = await menuCount(id)
23
+ return res.count
24
+ }
25
+ return 0
26
+ }
27
+ catch (error) {
28
+ console.log(error)
29
+ return 0
30
+ }
31
+ }
32
+
33
+ // 组件卸载时清理定时器(可选)
34
+ onUnmounted(() => {
35
+ if (intervalId)
36
+ clearInterval(intervalId)
37
+ })
38
+
39
+ const updateMenuCounts = async () => {
40
+ try {
41
+ // 立即执行一次
42
+ if (messageBar.value?.id) {
43
+ const count = await getmenuCount(messageBar.value.id)
44
+ messageBar.value = { ...messageBar.value, count }
45
+ }
46
+
47
+ if (quickPanel.value.length > 0) {
48
+ quickPanel.value = await Promise.all(
49
+ quickPanel.value.map(async (item) => {
50
+ const count = await getmenuCount(item.id)
51
+ return { ...item, count }
52
+ }),
53
+ )
54
+ }
55
+
56
+ // 设置定时器,每隔 1000*60*2 秒执行一次
57
+ const intervalId = setInterval(async () => {
58
+ try {
59
+ if (messageBar.value?.id) {
60
+ const count = await getmenuCount(messageBar.value.id)
61
+ messageBar.value = { ...messageBar.value, count }
62
+ }
63
+
64
+ if (quickPanel.value.length > 0) {
65
+ quickPanel.value = await Promise.all(
66
+ quickPanel.value.map(async (item) => {
67
+ const count = await getmenuCount(item.id)
68
+ return { ...item, count }
69
+ }),
70
+ )
71
+ }
72
+ }
73
+ catch (error) {
74
+ console.log(error)
75
+ }
76
+ }, 1000 * 60 * 2)
77
+
78
+ // 返回定时器 ID,方便后续清理
79
+ return intervalId
80
+ }
81
+ catch (error) {
82
+ console.log(error)
83
+ return null
84
+ }
85
+ }
86
+
87
+ const getSectionMenu = async () => {
88
+ try {
89
+ const res = await fastmenu()
90
+ if (res.fastMenu) {
91
+ messageBar.value = res.fastMenu.MessageBar ? res.fastMenu.MessageBar[0] : null
92
+ quickPanel.value = res.fastMenu?.QuickPanel || []
93
+ rightSidebar01.value = res.fastMenu?.RightSidebar01 || []
94
+ rightSidebar02.value = res.fastMenu?.RightSidebar02 || []
95
+ // 清除之前的定时器(防止重复创建)
96
+ if (intervalId)
97
+ clearInterval(intervalId)
98
+ // 启动定时器
99
+ if (isInterval) {
100
+ intervalId = await updateMenuCounts()
101
+ }
102
+ }
103
+ else {
104
+ messageBar.value = null
105
+ quickPanel.value = []
106
+ }
107
+ }
108
+ catch (error) {
109
+ console.log(error)
110
+ }
111
+ }
112
+ getSectionMenu()
113
+
114
+ return {
115
+ messageBar,
116
+ quickPanel,
117
+ rightSidebar01,
118
+ rightSidebar02,
119
+ }
120
+ }