information.vue
9.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<template>
<view class="page">
<!-- 自定义导航栏 -->
<custom-navbar :title="currentNavbarTitle" :show-background="false" titleColor="#1f2937"
@height-change="handleNavbarHeightChange" backgroundColor="#fff"></custom-navbar>
<!-- 内容区域 -->
<view class="content-wrapper" :style="{ marginTop: contentTopMargin }">
<!-- 集团驾驶舱组件 -->
<dashboard-page v-if="currentComponent === 'dashboard'" ref="dashboardPage" />
<!-- 门店数据组件 -->
<store-dashboard-page v-if="currentComponent === 'store-dashboard'" ref="storeDashboardPage" />
<!-- 科技部数据组件 -->
<tech-department-dashboard-page v-if="currentComponent === 'tech-department-dashboard'" ref="techDepartmentDashboardPage" />
<!-- 事业部数据组件 -->
<business-unit-dashboard-page v-if="currentComponent === 'business-unit-dashboard'" ref="businessUnitDashboardPage" />
<!-- 拓客报表组件 -->
<daily-report-page v-if="currentComponent === 'daily-report'" ref="dailyReportPage" />
</view>
<!-- 悬浮切换按钮 -->
<view class="floating-switch-btn" @click="showSwitchMenu = !showSwitchMenu">
<u-icon name="grid" size="24" color="#fff"></u-icon>
</view>
<!-- 切换菜单 -->
<view class="switch-menu" v-if="showSwitchMenu">
<view
class="menu-item"
v-for="item in componentList"
:key="item.key"
:class="{ active: currentComponent === item.key }"
@click="switchComponent(item.key)">
<u-icon :name="item.icon" size="18" :color="currentComponent === item.key ? '#409EFF' : '#666'"></u-icon>
<text class="menu-text">{{ item.label }}</text>
</view>
</view>
<!-- 遮罩层,点击关闭菜单 -->
<view class="mask" v-if="showSwitchMenu" @click="showSwitchMenu = false"></view>
<!-- 自定义 tabBar -->
<custom-tab-bar />
</view>
</template>
<script>
import CustomTabBar from '@/components/custom-tab-bar/index.vue'
import CustomNavbar from '@/components/custom-navbar/custom-navbar.vue'
// 引入页面组件
import DashboardPage from '@/pagesA/dashboard/dashboard.vue'
import StoreDashboardPage from '@/pagesA/store-dashboard/store-dashboard.vue'
import TechDepartmentDashboardPage from '@/pagesA/tech-department-dashboard/tech-department-dashboard.vue'
import BusinessUnitDashboardPage from '@/pagesA/business-unit-dashboard/business-unit-dashboard.vue'
import DailyReportPage from '@/pagesA/dailyReport/dailyReport.vue'
export default {
components: {
CustomTabBar,
CustomNavbar,
DashboardPage,
StoreDashboardPage,
TechDepartmentDashboardPage,
BusinessUnitDashboardPage,
DailyReportPage
},
data() {
return {
navbarHeightRpx: 0,
currentComponent: '', // 当前显示的组件,根据权限动态设置
showSwitchMenu: false, // 是否显示切换菜单
menuData: [], // 从 API 获取的菜单数据
componentListData: [] // 解析后的组件列表数据
}
},
computed: {
// 内容区域顶部间距
contentTopMargin() {
if (this.navbarHeightRpx > 0) {
return (this.navbarHeightRpx + 20) + 'rpx'
}
return '100rpx'
},
// 组件列表(从动态数据获取)
componentList() {
return this.componentListData
},
// 根据当前组件动态返回导航栏标题
currentNavbarTitle() {
const component = this.componentList.find(item => item.key === this.currentComponent)
return component ? component.label : '数据中心'
}
},
onLoad() {
// 加载菜单数据
// this.loadMenuData()
},
onShow() {
// 重新加载菜单数据
this.loadMenuData()
// 页面加载时初始化默认组件
this.$nextTick(() => {
this.initCurrentComponent()
})
// this.switchComponent('tech-department-dashboard')
},
watch: {
// 监听组件切换,调用子组件的初始化方法
currentComponent(newVal) {
if (newVal) {
this.$nextTick(() => {
this.initCurrentComponent()
})
}
},
// 监听组件列表变化,设置默认组件
componentList(newList) {
if (newList.length > 0 && !this.currentComponent) {
this.currentComponent = newList[0].key
}
}
},
methods: {
// 加载菜单数据
loadMenuData() {
// 先从本地存储读取
const cachedData = uni.getStorageSync('appMenuData')
if (cachedData && Array.isArray(cachedData) && cachedData.length > 0) {
this.menuData = cachedData
this.parseMenuData()
return
}
// 如果本地没有,则调用 API
const userInfo = uni.getStorageSync('userInfo')
if (!userInfo || !userInfo.userId) {
return
}
this.API.getAppAuthorize().then(res => {
if (res.code === 200 && res.data) {
this.menuData = res.data
uni.setStorageSync('appMenuData', res.data)
this.parseMenuData()
}
}).catch(err => {
console.error('获取菜单数据失败:', err)
})
},
// 解析菜单数据
parseMenuData() {
if (!this.menuData || this.menuData.length === 0) {
return
}
// 找到根节点(fullName 为 "app数据中心" 的节点)
const rootNode = this.menuData.find(item => item.fullName === 'app数据中心')
if (!rootNode || !rootNode.children) {
return
}
// 解析每个子节点,转换为组件列表
this.componentListData = rootNode.children
.filter(item => item.isLeaf && item.children === null) // 只取叶子节点
.map(item => {
// description 字段包含图标名称
const icon = (item.description || '').trim()
// 根据 fullName 获取对应的 component key
const key = this.getComponentKeyByFullName(item.fullName)
return {
key: key,
label: item.fullName,
icon: icon,
sortCode: item.sortCode || 0
}
})
.sort((a, b) => a.sortCode - b.sortCode) // 按 sortCode 排序
// 如果列表不为空且当前组件为空,设置默认组件
if (this.componentListData.length > 0 && !this.currentComponent) {
this.currentComponent = this.componentListData[0].key
}
},
// 根据 fullName 获取对应的 component key
getComponentKeyByFullName(fullName) {
const keyMap = {
'集团驾驶舱': 'dashboard',
'门店数据': 'store-dashboard',
'科技部数据': 'tech-department-dashboard',
'事业部数据': 'business-unit-dashboard',
'拓客报表': 'daily-report'
}
return keyMap[fullName] || ''
},
// 处理导航栏高度变化
handleNavbarHeightChange(heightInfo) {
this.navbarHeightRpx = heightInfo.rpx || 0
},
// 切换组件
switchComponent(key) {
this.currentComponent = key
this.showSwitchMenu = false
},
// 初始化当前组件
initCurrentComponent() {
const refMap = {
'dashboard': 'dashboardPage',
'store-dashboard': 'storeDashboardPage',
'tech-department-dashboard': 'techDepartmentDashboardPage',
'business-unit-dashboard': 'businessUnitDashboardPage',
'daily-report': 'dailyReportPage'
}
const refName = refMap[this.currentComponent]
if (refName && this.$refs[refName]) {
const component = this.$refs[refName]
if (component && typeof component.init === 'function') {
component.init()
}
}
}
}
}
</script>
<style lang="scss" scoped>
.content-wrapper {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: calc(100% - 100rpx); // 减去 tabBar 高度
overflow-y: auto;
overflow-x: hidden;
// 确保子组件占满容器
> view {
width: 100%;
min-height: 100%;
}
}
// 悬浮切换按钮
.floating-switch-btn {
position: fixed;
right: 50rpx;
bottom: 200rpx; // 在 tabBar 上方
width: 100rpx;
height: 100rpx;
background: linear-gradient(135deg, #409EFF 0%, #67C23A 100%);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 24rpx rgba(64, 158, 255, 0.4);
z-index: 1001; // 确保在 tabBar (z-index: 999) 上方
transition: all 0.3s ease;
&:active {
transform: scale(0.95);
}
}
// 切换菜单
.switch-menu {
position: fixed;
right: 30rpx;
bottom: 270rpx;
background: #fff;
border-radius: 24rpx;
padding: 20rpx 0;
box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.15);
z-index: 1002; // 确保在按钮上方
min-width: 240rpx;
animation: slideUp 0.3s ease;
.menu-item {
display: flex;
align-items: center;
padding: 24rpx 32rpx;
transition: all 0.2s ease;
&:active {
background-color: #f5f7fa;
}
&.active {
background-color: #ecf5ff;
.menu-text {
color: #409EFF;
font-weight: 600;
}
}
.menu-text {
margin-left: 16rpx;
font-size: 28rpx;
color: #333;
}
}
}
// 遮罩层
.mask {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
z-index: 1000; // 在 tabBar 上方,但在按钮和菜单下方
animation: fadeIn 0.3s ease;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(20rpx);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
</style>