wui-components-v2 1.1.70 → 1.1.72
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/api/feishu.ts +20 -20
- package/api/index.ts +4 -4
- package/api/login.ts +51 -51
- package/api/tree.ts +28 -28
- package/components/action-popup/action-popup.vue +116 -116
- package/components/add-address-list/add-address-list.vue +187 -187
- package/components/add-address-page/config.ts +297 -297
- package/components/audio-play/audio-play.vue +220 -220
- package/components/batch-upload-file/batch-upload-file.vue +75 -75
- package/components/card-botom-buttons/card-botom-buttons.vue +279 -279
- package/components/demo-card/demo-card.vue +44 -44
- package/components/fold-card/fold-card.vue +2 -2
- package/components/form-control/form-control.vue +9 -1
- package/components/global-loading/GlobalLoading.md +366 -366
- package/components/global-loading/global-loading.vue +55 -55
- package/components/global-message/GlobalMessage.md +570 -570
- package/components/global-toast/GlobalToast.md +261 -261
- package/components/global-toast/global-toast.vue +56 -56
- package/components/label-value/open-value-more.vue +56 -56
- package/components/loading/loading.vue +5 -5
- package/components/login-form-box/login-form-box.vue +65 -65
- package/components/phone-login-form/phone-login-form.vue +204 -204
- package/components/privacy-popup/privacy-popup.vue +191 -191
- package/components/scan-input/scan-input.vue +406 -406
- package/components/select-col-picker/select-col-picker.vue +168 -168
- package/components/tab-search/tab-search.vue +73 -73
- package/components/tree-select/components/TreeNode.vue +200 -200
- package/components/tree-select/components/index.vue +471 -471
- package/components/tree-select/components/tree-select.vue +56 -56
- package/components/tree-select/index.vue +93 -93
- package/components/user-choose/user-choose.vue +169 -151
- package/components/video-play/video-play.vue +56 -56
- package/components/wui-auto-update-component/wui-auto-update-component.vue +132 -132
- package/components/wui-default/wui-default.vue +49 -49
- package/components/wui-details-page/wui-details-page.vue +147 -147
- package/components/wui-edit-page/wui-edit-page-copy.vue +757 -757
- package/components/wui-edit-page/wui-edit-page.vue +793 -793
- package/components/wui-login/wui-login.vue +43 -43
- package/components/wui-login1/wui-login.vue +41 -41
- package/components/wui-menus/wui-menus-top.vue +137 -137
- package/components/wui-menus/wui-menus-top1.vue +8 -8
- package/components/wui-menus1/components/banner-carousel.vue +320 -320
- package/components/wui-menus1/components/quick-panel.vue +55 -55
- package/components/wui-menus1/components/search-bar.vue +49 -49
- package/components/wui-menus1/components/section-menus.vue +208 -208
- package/components/wui-menus1/wui-menus-top.vue +718 -718
- package/components/wui-menus1/wui-menus-top1.vue +398 -398
- package/components/wui-notify-info/notify-handle.vue +53 -53
- package/components/wui-scan-binding-sensor/wui-scan-binding-sensor.vue +75 -75
- package/components/wui-search-history-babbar/components/SearchBar.vue +70 -70
- package/components/wui-select-list/wui-select-list.vue +1 -9
- package/components/wui-select-popup/wui-select-popup.vue +1 -0
- package/components/wui-tree-page/wui-tree-page.vue +297 -297
- package/components/wui-update-component/wui-update-component.vue +221 -221
- package/composables/types/theme.ts +65 -65
- package/composables/types/user.ts +5 -5
- package/composables/useColorGenerator.ts +221 -221
- package/composables/useCompanyFieldFilter.ts +26 -24
- package/composables/useEnumes.ts +43 -43
- package/composables/useEventBus.ts +37 -37
- package/composables/useGlobalLoading.ts +47 -47
- package/composables/useGlobalMessage.ts +53 -53
- package/composables/useGlobalToast.ts +63 -63
- package/composables/useLocale.ts +54 -54
- package/composables/useManualTheme.ts +179 -179
- package/composables/useSectionMenus.ts +120 -120
- package/composables/useTabbar.ts +50 -50
- package/composables/useTheme.ts +74 -74
- package/composables/useUser.ts +24 -24
- package/index.d.ts +90 -90
- package/package.json +24 -24
- package/store/manualThemeStore.ts +143 -143
- package/store/persist.ts +41 -41
- package/store/themeStore.ts +74 -74
- package/store/userStore.ts +22 -22
- package/styles/dark-mode.scss +498 -498
- package/type.ts +154 -154
- package/utils/control-tree.ts +353 -353
- package/utils/eventBus.ts +36 -36
- package/utils/idata-scan.ts +99 -99
- package/utils/index.ts +979 -979
- package/utils/rsaEncrypt.ts +10 -10
|
@@ -1,179 +1,179 @@
|
|
|
1
|
-
import { computed, onBeforeMount, onUnmounted, ref } from 'vue'
|
|
2
|
-
import { onShow } from '@dcloudio/uni-app'
|
|
3
|
-
import { useManualThemeStore } from '../store/manualThemeStore'
|
|
4
|
-
import { useLocale } from './useLocale'
|
|
5
|
-
import type { LocaleOption, ThemeColorOption, ThemeMode } from './types/theme'
|
|
6
|
-
|
|
7
|
-
import { LocaleOptions, themeColorOptions } from './types/theme'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 完整版主题管理组合式API
|
|
11
|
-
*
|
|
12
|
-
* 功能特性:
|
|
13
|
-
* - 支持手动切换暗黑模式
|
|
14
|
-
* - 支持主题色选择
|
|
15
|
-
* - 支持跟随系统主题
|
|
16
|
-
* - 自动同步导航栏颜色
|
|
17
|
-
* - 持久化用户设置
|
|
18
|
-
*
|
|
19
|
-
* 适用场景:
|
|
20
|
-
* - 需要用户手动控制主题的应用
|
|
21
|
-
* - 需要主题色自定义的应用
|
|
22
|
-
* - 需要完整主题管理功能的复杂应用
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```vue
|
|
26
|
-
* <script setup>
|
|
27
|
-
* import { useManualTheme } from '@/composables/useManualTheme'
|
|
28
|
-
*
|
|
29
|
-
* const {
|
|
30
|
-
* theme,
|
|
31
|
-
* isDark,
|
|
32
|
-
* toggleTheme,
|
|
33
|
-
* openThemeColorPicker,
|
|
34
|
-
* currentThemeColor,
|
|
35
|
-
* themeVars
|
|
36
|
-
* } = useManualTheme()
|
|
37
|
-
* </script>
|
|
38
|
-
*
|
|
39
|
-
* <template>
|
|
40
|
-
* <wd-config-provider :theme-vars="themeVars">
|
|
41
|
-
* <view :class="{ 'dark-mode': isDark }">
|
|
42
|
-
* <wd-button @click="toggleTheme">切换主题</wd-button>
|
|
43
|
-
* <wd-button @click="openThemeColorPicker">选择主题色</wd-button>
|
|
44
|
-
* </view>
|
|
45
|
-
* </wd-config-provider>
|
|
46
|
-
* </template>
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export function useManualTheme() {
|
|
50
|
-
const store = useManualThemeStore()
|
|
51
|
-
const showThemeColorSheet = ref(false)
|
|
52
|
-
const showLanguageSheet = ref(false)
|
|
53
|
-
const language = useLocale()
|
|
54
|
-
/**
|
|
55
|
-
* 切换暗黑模式
|
|
56
|
-
* @param mode 指定主题模式,不传则自动切换
|
|
57
|
-
*/
|
|
58
|
-
function toggleTheme(mode?: ThemeMode) {
|
|
59
|
-
store.toggleTheme(mode)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 打开主题色选择器
|
|
64
|
-
*/
|
|
65
|
-
function openThemeColorPicker() {
|
|
66
|
-
showThemeColorSheet.value = true
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 关闭主题色选择器
|
|
71
|
-
*/
|
|
72
|
-
function closeThemeColorPicker() {
|
|
73
|
-
showThemeColorSheet.value = false
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 选择主题色
|
|
78
|
-
* @param option 主题色选项
|
|
79
|
-
*/
|
|
80
|
-
function selectThemeColor(option: ThemeColorOption) {
|
|
81
|
-
store.setCurrentThemeColor(option)
|
|
82
|
-
store.setNavigationBarColor()
|
|
83
|
-
closeThemeColorPicker()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 选择语言
|
|
88
|
-
*
|
|
89
|
-
*/
|
|
90
|
-
function selectLanguage(option: LocaleOption) {
|
|
91
|
-
store.setLocale(option)
|
|
92
|
-
closeLanguagePicker()
|
|
93
|
-
language.changeSystemLocale()
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 打开语言选择器
|
|
98
|
-
*/
|
|
99
|
-
function openLanguagePicker() {
|
|
100
|
-
showLanguageSheet.value = true
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 关闭语言选择器
|
|
105
|
-
*/
|
|
106
|
-
function closeLanguagePicker() {
|
|
107
|
-
showLanguageSheet.value = false
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 初始化主题
|
|
112
|
-
*/
|
|
113
|
-
function initTheme() {
|
|
114
|
-
store.initTheme()
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// 组件挂载前初始化主题
|
|
118
|
-
onBeforeMount(() => {
|
|
119
|
-
initTheme()
|
|
120
|
-
|
|
121
|
-
// 监听系统主题变化
|
|
122
|
-
if (typeof uni !== 'undefined' && uni.onThemeChange) {
|
|
123
|
-
uni.onThemeChange((res) => {
|
|
124
|
-
if (store.followSystem) {
|
|
125
|
-
toggleTheme(res.theme as ThemeMode)
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
// 页面显示时更新导航栏颜色,确保每次切换页面时导航栏颜色都是正确的
|
|
132
|
-
onShow(() => {
|
|
133
|
-
store.setNavigationBarColor()
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
// 组件卸载时清理监听
|
|
137
|
-
onUnmounted(() => {
|
|
138
|
-
if (typeof uni !== 'undefined' && uni.offThemeChange) {
|
|
139
|
-
uni.offThemeChange((res) => {
|
|
140
|
-
if (store.followSystem) {
|
|
141
|
-
toggleTheme(res.theme as ThemeMode)
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
// 状态
|
|
149
|
-
theme: computed(() => store.theme),
|
|
150
|
-
// 主题色
|
|
151
|
-
primary: computed(() => store.themeVars.colorTheme),
|
|
152
|
-
isDark: computed(() => store.isDark),
|
|
153
|
-
followSystem: computed(() => store.followSystem),
|
|
154
|
-
hasUserSet: computed(() => store.hasUserSet),
|
|
155
|
-
currentThemeColor: computed(() => store.currentThemeColor),
|
|
156
|
-
currentLocale: computed(() => store.Locale),
|
|
157
|
-
themeVars: computed(() => store.themeVars),
|
|
158
|
-
showThemeColorSheet,
|
|
159
|
-
showLanguageSheet,
|
|
160
|
-
// 常量
|
|
161
|
-
themeColorOptions,
|
|
162
|
-
LocaleOptions,
|
|
163
|
-
|
|
164
|
-
// 方法
|
|
165
|
-
initTheme,
|
|
166
|
-
toggleTheme,
|
|
167
|
-
setFollowSystem: store.setFollowSystem,
|
|
168
|
-
openThemeColorPicker,
|
|
169
|
-
closeThemeColorPicker,
|
|
170
|
-
selectThemeColor,
|
|
171
|
-
openLanguagePicker,
|
|
172
|
-
closeLanguagePicker,
|
|
173
|
-
selectLanguage,
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// 导出类型和常量供外部使用
|
|
178
|
-
export type { ThemeColorOption, ThemeMode, LocaleOption }
|
|
179
|
-
export { themeColorOptions }
|
|
1
|
+
import { computed, onBeforeMount, onUnmounted, ref } from 'vue'
|
|
2
|
+
import { onShow } from '@dcloudio/uni-app'
|
|
3
|
+
import { useManualThemeStore } from '../store/manualThemeStore'
|
|
4
|
+
import { useLocale } from './useLocale'
|
|
5
|
+
import type { LocaleOption, ThemeColorOption, ThemeMode } from './types/theme'
|
|
6
|
+
|
|
7
|
+
import { LocaleOptions, themeColorOptions } from './types/theme'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 完整版主题管理组合式API
|
|
11
|
+
*
|
|
12
|
+
* 功能特性:
|
|
13
|
+
* - 支持手动切换暗黑模式
|
|
14
|
+
* - 支持主题色选择
|
|
15
|
+
* - 支持跟随系统主题
|
|
16
|
+
* - 自动同步导航栏颜色
|
|
17
|
+
* - 持久化用户设置
|
|
18
|
+
*
|
|
19
|
+
* 适用场景:
|
|
20
|
+
* - 需要用户手动控制主题的应用
|
|
21
|
+
* - 需要主题色自定义的应用
|
|
22
|
+
* - 需要完整主题管理功能的复杂应用
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```vue
|
|
26
|
+
* <script setup>
|
|
27
|
+
* import { useManualTheme } from '@/composables/useManualTheme'
|
|
28
|
+
*
|
|
29
|
+
* const {
|
|
30
|
+
* theme,
|
|
31
|
+
* isDark,
|
|
32
|
+
* toggleTheme,
|
|
33
|
+
* openThemeColorPicker,
|
|
34
|
+
* currentThemeColor,
|
|
35
|
+
* themeVars
|
|
36
|
+
* } = useManualTheme()
|
|
37
|
+
* </script>
|
|
38
|
+
*
|
|
39
|
+
* <template>
|
|
40
|
+
* <wd-config-provider :theme-vars="themeVars">
|
|
41
|
+
* <view :class="{ 'dark-mode': isDark }">
|
|
42
|
+
* <wd-button @click="toggleTheme">切换主题</wd-button>
|
|
43
|
+
* <wd-button @click="openThemeColorPicker">选择主题色</wd-button>
|
|
44
|
+
* </view>
|
|
45
|
+
* </wd-config-provider>
|
|
46
|
+
* </template>
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function useManualTheme() {
|
|
50
|
+
const store = useManualThemeStore()
|
|
51
|
+
const showThemeColorSheet = ref(false)
|
|
52
|
+
const showLanguageSheet = ref(false)
|
|
53
|
+
const language = useLocale()
|
|
54
|
+
/**
|
|
55
|
+
* 切换暗黑模式
|
|
56
|
+
* @param mode 指定主题模式,不传则自动切换
|
|
57
|
+
*/
|
|
58
|
+
function toggleTheme(mode?: ThemeMode) {
|
|
59
|
+
store.toggleTheme(mode)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 打开主题色选择器
|
|
64
|
+
*/
|
|
65
|
+
function openThemeColorPicker() {
|
|
66
|
+
showThemeColorSheet.value = true
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 关闭主题色选择器
|
|
71
|
+
*/
|
|
72
|
+
function closeThemeColorPicker() {
|
|
73
|
+
showThemeColorSheet.value = false
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 选择主题色
|
|
78
|
+
* @param option 主题色选项
|
|
79
|
+
*/
|
|
80
|
+
function selectThemeColor(option: ThemeColorOption) {
|
|
81
|
+
store.setCurrentThemeColor(option)
|
|
82
|
+
store.setNavigationBarColor()
|
|
83
|
+
closeThemeColorPicker()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 选择语言
|
|
88
|
+
*
|
|
89
|
+
*/
|
|
90
|
+
function selectLanguage(option: LocaleOption) {
|
|
91
|
+
store.setLocale(option)
|
|
92
|
+
closeLanguagePicker()
|
|
93
|
+
language.changeSystemLocale()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 打开语言选择器
|
|
98
|
+
*/
|
|
99
|
+
function openLanguagePicker() {
|
|
100
|
+
showLanguageSheet.value = true
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 关闭语言选择器
|
|
105
|
+
*/
|
|
106
|
+
function closeLanguagePicker() {
|
|
107
|
+
showLanguageSheet.value = false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 初始化主题
|
|
112
|
+
*/
|
|
113
|
+
function initTheme() {
|
|
114
|
+
store.initTheme()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 组件挂载前初始化主题
|
|
118
|
+
onBeforeMount(() => {
|
|
119
|
+
initTheme()
|
|
120
|
+
|
|
121
|
+
// 监听系统主题变化
|
|
122
|
+
if (typeof uni !== 'undefined' && uni.onThemeChange) {
|
|
123
|
+
uni.onThemeChange((res) => {
|
|
124
|
+
if (store.followSystem) {
|
|
125
|
+
toggleTheme(res.theme as ThemeMode)
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
// 页面显示时更新导航栏颜色,确保每次切换页面时导航栏颜色都是正确的
|
|
132
|
+
onShow(() => {
|
|
133
|
+
store.setNavigationBarColor()
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
// 组件卸载时清理监听
|
|
137
|
+
onUnmounted(() => {
|
|
138
|
+
if (typeof uni !== 'undefined' && uni.offThemeChange) {
|
|
139
|
+
uni.offThemeChange((res) => {
|
|
140
|
+
if (store.followSystem) {
|
|
141
|
+
toggleTheme(res.theme as ThemeMode)
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
// 状态
|
|
149
|
+
theme: computed(() => store.theme),
|
|
150
|
+
// 主题色
|
|
151
|
+
primary: computed(() => store.themeVars.colorTheme),
|
|
152
|
+
isDark: computed(() => store.isDark),
|
|
153
|
+
followSystem: computed(() => store.followSystem),
|
|
154
|
+
hasUserSet: computed(() => store.hasUserSet),
|
|
155
|
+
currentThemeColor: computed(() => store.currentThemeColor),
|
|
156
|
+
currentLocale: computed(() => store.Locale),
|
|
157
|
+
themeVars: computed(() => store.themeVars),
|
|
158
|
+
showThemeColorSheet,
|
|
159
|
+
showLanguageSheet,
|
|
160
|
+
// 常量
|
|
161
|
+
themeColorOptions,
|
|
162
|
+
LocaleOptions,
|
|
163
|
+
|
|
164
|
+
// 方法
|
|
165
|
+
initTheme,
|
|
166
|
+
toggleTheme,
|
|
167
|
+
setFollowSystem: store.setFollowSystem,
|
|
168
|
+
openThemeColorPicker,
|
|
169
|
+
closeThemeColorPicker,
|
|
170
|
+
selectThemeColor,
|
|
171
|
+
openLanguagePicker,
|
|
172
|
+
closeLanguagePicker,
|
|
173
|
+
selectLanguage,
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 导出类型和常量供外部使用
|
|
178
|
+
export type { ThemeColorOption, ThemeMode, LocaleOption }
|
|
179
|
+
export { themeColorOptions }
|
|
@@ -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
|
+
}
|