Blame view

绿纤uni-app/components/custom-tab-bar/index.vue 9.12 KB
7db17e74   李宇   最新
1
2
  <template>
  	<view class="tab-block">
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
3
4
5
6
7
8
  		<view class='tab-list flex flex-center'
  			:class="showMiddleButton === true ? 'tab-list-middle' : 'tab-list-default'">
  			<!-- 流动选中指示器 - 暂时禁用 -->
  			<!-- <view class="tab-indicator" :style="{ left: indicatorLeft + 'px', width: indicatorWidth + 'px' }"></view> -->
  			<view v-for="(item, index) in tabList" :class="'list-item flex flex-column flex-middle ' + item.middleClass"
  				@tap="handlePush(item, index)" :key="index" :ref="'tabItem' + index">
7db17e74   李宇   最新
9
  				<view class="item-img-box">
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
10
  					<image class="item-img" :src="currentTabIndex == index ? item.selectedIconPath : item.iconPath" />
7db17e74   李宇   最新
11
  				</view>
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
12
13
  				<view class="item-text font-20 color-black" :class="{ specialColor: currentTabIndex == index }">
  					{{ item.text }}
7db17e74   李宇   最新
14
15
16
17
18
19
20
  				</view>
  			</view>
  		</view>
  	</view>
  </template>
  
  <script>
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
21
22
23
24
25
26
27
28
29
30
  export default {
  	props: {
  		// 当前选中的tab项,如果不传则自动根据当前页面路径计算
  		tabIndex: {
  			type: Number,
  			default: null
  		}
  	},
  	data() {
  		return {
6a231974   李宇   最新
31
  			tabList: [],
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
32
33
34
  			showMiddleButton: false,
  			indicatorLeft: 0,
  			indicatorWidth: 0,
6a231974   李宇   最新
35
  			newuserInfo:{},
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
36
37
38
39
40
41
42
43
44
  			isUpdating: false // 防止无限递归的标志
  		};
  	},
  	computed: {
  		// 自动计算当前选中的tab索引
  		currentTabIndex() {
  			// 如果外部传入了 tabIndex,优先使用外部传入的值
  			if (this.tabIndex !== null && this.tabIndex !== undefined) {
  				return this.tabIndex;
7db17e74   李宇   最新
45
  			}
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  			// 否则根据当前页面路径自动计算
  			const pages = getCurrentPages();
  			if (pages.length === 0) return 0;
  
  			const currentPage = pages[pages.length - 1];
  			const currentPath = '/' + currentPage.route;
  
  			// 查找匹配的tab项
  			const matchedIndex = this.tabList.findIndex(item => {
  				return currentPath === item.pagePath || currentPath.startsWith(item.pagePath);
  			});
  
  			return matchedIndex >= 0 ? matchedIndex : 0;
  		}
  	},
  	mounted() {
6a231974   李宇   最新
62
  		this.initTabList()
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
63
64
65
  		// 完全禁用指示器功能,避免无限递归导致堆栈溢出
  		// 指示器功能暂时不启用
  	},
6a231974   李宇   最新
66
67
68
69
  	onShow() {
  		// 每次显示时重新初始化,确保用户信息更新后能正确显示
  		this.initTabList()
  	},
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
70
71
72
73
  	watch: {
  		// 移除所有 watch,避免无限递归
  	},
  	methods: {
ba43caee   李宇   最新
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
  	/**
  	 * 初始化 tab 列表
  	 */
  	async initTabList() {
  		if(uni.getStorageSync('newuserInfo')) {
  			this.newuserInfo = uni.getStorageSync('newuserInfo') 
  		} else{
  			await this.API.getUsers(uni.getStorageSync('userInfo').userId).then(res => {
  				if (res.code === 200) {
  					this.newuserInfo = res.data
  				}
  			})
  		}
  		this.newuserInfo = uni.getStorageSync('newuserInfo') || {}
  		
  		// 通过菜单数据判断是否有"数据中心"菜单
  		const hasDataCenter = await this.hasDataCenterMenu()
  		this.tabList = this.getTabList(hasDataCenter)
  		
  		// 调试信息:打印菜单权限和 tab 数量
  		console.log('[TabBar] 是否有数据中心菜单:', hasDataCenter, 'Tab数量:', this.tabList.length, 'Tab列表:', this.tabList.map(t => t.text))
  	},
  	/**
  	 * 判断是否有"数据中心"菜单权限
  	 * 通过解析菜单数据,查找是否存在 fullName === 'app数据中心' 的节点
  	 * @returns {Boolean} 是否存在数据中心菜单
  	 */
  	async hasDataCenterMenu() {
  		try {
  			// 先从本地存储读取菜单数据
  			const cachedData = uni.getStorageSync('appMenuData')
  			if (cachedData && Array.isArray(cachedData) && cachedData.length > 0) {
  				return this.parseMenuDataForTabBar(cachedData)
6a231974   李宇   最新
107
  			}
6a231974   李宇   最新
108
  			
ba43caee   李宇   最新
109
110
111
112
  			// 如果本地没有,则调用 API
  			const userInfo = uni.getStorageSync('userInfo')
  			if (!userInfo || !userInfo.userId) {
  				return false
6a231974   李宇   最新
113
  			}
6a231974   李宇   最新
114
  			
ba43caee   李宇   最新
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
  			const res = await this.API.getAppAuthorize()
  			if (res.code === 200 && res.data) {
  				const menuData = res.data
  				// 缓存菜单数据
  				uni.setStorageSync('appMenuData', menuData)
  				return this.parseMenuDataForTabBar(menuData)
  			}
  			
  			return false
  		} catch (err) {
  			console.error('[TabBar] 获取菜单数据失败:', err)
  			return false
  		}
  	},
  	
  	/**
  	 * 解析菜单数据,判断是否存在"数据中心"菜单
  	 * 参考 information.vue 中的 parseMenuData() 方法逻辑
  	 * @param {Array} menuData - 菜单数据数组
  	 * @returns {Boolean} 是否存在数据中心菜单
  	 */
  	parseMenuDataForTabBar(menuData) {
  		if (!menuData || !Array.isArray(menuData) || menuData.length === 0) {
  			return false
  		}
  		
  		// 找到根节点(fullName 为 "app数据中心" 的节点)
  		const rootNode = menuData.find(item => item.fullName === 'app数据中心')
  		if (!rootNode || !rootNode.children) {
  			return false
  		}
  		
  		// 如果根节点存在且有子节点,说明有"数据中心"菜单权限
  		return true
  	},
  	
  	/**
  	 * 根据是否有数据中心菜单权限获取对应的 tab 列表
  	 * @param {Boolean} hasDataCenter - 是否有数据中心菜单权限
  	 * @returns {Array} tab 配置列表
  	 */
  	getTabList(hasDataCenter) {
  		// 定义所有 tab 配置项
  		const tabConfigs = {
  			home: {
  				iconPath: "/static/tabBar/icon2.png",
  				selectedIconPath: "/static/tabBar/icon1.png",
  				text: '首页',
  				pagePath: '/pages/home/home',
  				middleClass: ''
  			},
  			dataCenter: {
  				iconPath: "/static/tabBar/icon4.png",
  				selectedIconPath: "/static/tabBar/icon3.png",
  				text: '数据中心',
9854a774   李宇   最新
170
  				pagePath: '/pagesA/information/information',
ba43caee   李宇   最新
171
172
173
174
175
176
  				middleClass: ''
  			},
  			mine: {
  				iconPath: "/static/tabBar/icon6.png",
  				selectedIconPath: "/static/tabBar/icon5.png",
  				text: '我的',
9854a774   李宇   最新
177
  				pagePath: '/pagesA/me/me',
ba43caee   李宇   最新
178
  				middleClass: ''
6a231974   李宇   最新
179
  			}
ba43caee   李宇   最新
180
181
182
183
184
185
186
187
  		}
  
  		// 根据菜单权限组合 tab 列表
  		const tabList = [tabConfigs.home]
  		if (hasDataCenter) {
  			tabList.push(tabConfigs.dataCenter)
  		}
  		tabList.push(tabConfigs.mine)
6a231974   李宇   最新
188
  
ba43caee   李宇   最新
189
190
  		return tabList
  	},
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
191
192
193
194
195
196
197
198
199
  		// 更新流动指示器位置 - 暂时禁用
  		updateIndicator() {
  			// 暂时禁用此功能,避免无限递归
  			return
  
  			// 以下代码暂时禁用
  			/*
  			if (this.isUpdating) {
  				return
4f00d759   “wangming”   优化个人中心页面:实现玻璃态卡片效...
200
  			}
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  			this.isUpdating = true
  			setTimeout(() => {
  				try {
  					const currentIndex = this.currentTabIndex
  					const query = uni.createSelectorQuery().in(this)
  					query.select('.tab-list').boundingClientRect((tabListRect) => {
  						if (!tabListRect) {
  							this.isUpdating = false
  							return
  						}
  						query.selectAll('.list-item').boundingClientRect((rects) => {
  							if (rects && rects.length > 0 && currentIndex >= 0 && currentIndex < rects.length) {
  								const currentRect = rects[currentIndex]
  								if (currentRect && tabListRect) {
  									const newWidth = currentRect.width * 0.6
  									const newLeft = currentRect.left - tabListRect.left + (currentRect.width - newWidth) / 2
  									this.indicatorWidth = newWidth
  									this.indicatorLeft = newLeft
4f00d759   “wangming”   优化个人中心页面:实现玻璃态卡片效...
219
  								}
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
220
221
222
223
  							}
  							setTimeout(() => {
  								this.isUpdating = false
  							}, 100)
4f00d759   “wangming”   优化个人中心页面:实现玻璃态卡片效...
224
  						}).exec()
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
225
226
227
228
  					}).exec()
  				} catch (e) {
  					console.error('更新指示器失败:', e)
  					this.isUpdating = false
7db17e74   李宇   最新
229
  				}
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
230
231
232
233
234
235
236
237
238
  			}, 200)
  			*/
  		},
  		// 点击按钮
  		handlePush(item, index) {
  			if (this.currentTabIndex !== index) {
  				uni.reLaunch({
  					url: item.pagePath
  				})
7db17e74   李宇   最新
239
240
241
  			}
  		}
  	}
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
242
  }
7db17e74   李宇   最新
243
244
245
  </script>
  
  <style lang="scss">
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
246
247
248
  .specialColor {
  	color: #009b4d;
  }
7db17e74   李宇   最新
249
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
250
251
252
253
  .flex {
  	display: flex;
  	flex-flow: row wrap;
  }
7db17e74   李宇   最新
254
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
255
256
257
258
  .flex-center {
  	align-items: center;
  	justify-content: center;
  }
7db17e74   李宇   最新
259
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  .flex-column {
  	flex-direction: column;
  }
  
  .flex-middle {
  	align-items: center;
  }
  
  .font-20 {
  	font-size: 22rpx;
  }
  
  .tab-block {
  	position: fixed;
  	bottom: 32rpx;
  	left: 50%;
  	transform: translateX(-50%);
04f9fdae   李宇   最新
277
  	z-index: 99999;
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
278
279
280
281
  	width: calc(100% - 16rpx);
  	// max-width: 680rpx;
  	padding: 0 24rpx;
  	box-sizing: border-box;
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
282
283
  	.tab-list {
  		height: 120rpx;
7db17e74   李宇   最新
284
  	}
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
285
286
  
  	.tab-list-default {
4f00d759   “wangming”   优化个人中心页面:实现玻璃态卡片效...
287
288
289
290
291
292
293
294
295
  		background: rgba(255, 255, 255, 0.7);
  		backdrop-filter: blur(20px) saturate(180%);
  		-webkit-backdrop-filter: blur(20px) saturate(180%);
  		border-radius: 28rpx;
  		box-shadow: 0rpx 8rpx 32rpx rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(255, 255, 255, 0.3) inset;
  		border: 1px solid rgba(255, 255, 255, 0.4);
  		position: relative;
  		transition: all 0.3s ease;
  	}
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
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
  
  	.tab-list-middle {
  		position: relative;
  		background: url('https://res.paquapp.com/popmartvip/home/nav_bar_bg_2x.png') no-repeat center center;
  		background-size: cover;
  	}
  
  	/* 流动选中指示器 */
  	.tab-indicator {
  		position: absolute;
  		bottom: 8rpx;
  		height: 4rpx;
  		background: linear-gradient(90deg, #43a047 0%, #66bb6a 100%);
  		border-radius: 2rpx;
  		transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  		box-shadow: 0 2rpx 8rpx rgba(67, 160, 71, 0.4);
  		z-index: 1;
  	}
  
  	.list-item {
  		flex: 1;
  		position: relative;
  		z-index: 2;
  		transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  		.item-img-box {
  			width: 40rpx;
  			height: 40rpx;
  			margin-bottom: 6rpx;
7db17e74   李宇   最新
325
  			position: relative;
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
326
  			transition: transform 0.3s ease;
4f00d759   “wangming”   优化个人中心页面:实现玻璃态卡片效...
327
328
  		}
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
329
330
331
332
333
  		.item-img {
  			width: 40rpx;
  			height: 40rpx;
  			transition: transform 0.3s ease;
  		}
7db17e74   李宇   最新
334
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
335
336
337
  		/* 3D悬浮动效 */
  		&:active {
  			transform: translateY(-2rpx) scale(0.95);
4f00d759   “wangming”   优化个人中心页面:实现玻璃态卡片效...
338
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
339
340
  			.item-img-box {
  				transform: scale(1.1);
7db17e74   李宇   最新
341
342
  			}
  		}
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
343
  	}
7db17e74   李宇   最新
344
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
345
346
  	.mid-button {
  		position: relative;
7db17e74   李宇   最新
347
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
348
349
350
351
352
353
354
355
  		.item-img-box {
  			width: 106rpx;
  			height: 106rpx;
  			margin-bottom: 9rpx;
  			position: absolute;
  			z-index: 1002;
  			top: -104rpx;
  		}
7db17e74   李宇   最新
356
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
357
358
359
360
  		.item-img {
  			width: 106rpx;
  			height: 106rpx;
  		}
7db17e74   李宇   最新
361
  
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
362
363
364
365
366
  		.item-text {
  			font-size: 20rpx;
  			position: absolute;
  			z-index: 1002;
  			bottom: -40rpx;
7db17e74   李宇   最新
367
368
  		}
  	}
777dbe40   “wangming”   feat: 实现集团驾驶舱移动端功...
369
  }
7db17e74   李宇   最新
370
  </style>