user5 9 mesi fa
parent
commit
06e1b163a4
1 ha cambiato i file con 27 aggiunte e 2 eliminazioni
  1. 27 2
      pages/workbench/workbench.vue

+ 27 - 2
pages/workbench/workbench.vue

@@ -134,7 +134,8 @@
 
 		<!-- 页脚区域 -->
 		<view class="footer-div">
-			<u-button type="primary" text="创建工单" @click="openPatrolWorkOrderForm()"></u-button>
+			<u-button v-if="userInfo.roleNames == '巡视员' " type="primary" text="巡视工单" @click="openPatrolWorkOrderForm()"></u-button>
+			<u-button v-if="userInfo.roleNames == '村负责人' " type="primary" text="清运工单" @click="openPatrolWorkOrderForm()"></u-button>
 		</view>
 	</view>
 </template>
@@ -249,8 +250,21 @@
 				userId: (state) => state.user.id
 			}),
 			dynamicStyle() {
+				// 增加空值检查
+				if (!this.userInfo || !this.userInfo.roleNames) {
+					// 如果 userInfo 或 roleNames 不存在,返回一个默认样式
+					return {
+						height: '130px',
+						borderRadius: '15px',
+						backgroundImage: 'linear-gradient(to right, #3cb54b 0%, #88c546 100%)'
+					};
+				}
+
+				// 直接通过 this.userInfo 访问 userInfo 中的属性
+				// 如果 userInfo 存在,继续执行原来的逻辑
+				const roleNames = this.userInfo.roleNames;
 				// 根据从 Vuex 获取的状态来判断样式
-				switch (this.userInfo.roleNames) {
+				switch (roleNames) {
 					case '过磅专员':
 						return {
 							height: '130px',
@@ -283,6 +297,7 @@
 		async mounted() {
 			this.loadmore()
 			//获取当前人对应的负责流程的信息
+			this.fetchUserInfo(); // 模拟获取用户信息
 
 
 			/*let res = await actCategoryService.treeData()
@@ -314,6 +329,16 @@
 		},
 
 		methods: {
+			async fetchUserInfo() {
+				try {
+					// 这里调用获取数据的 API 或者 Vuex action
+					await this.$store.dispatch('fetchUserInfo');  // 示例
+					this.isLoading = false;  // 数据加载完成,关闭加载状态
+				} catch (error) {
+					console.error('获取用户信息失败:', error);
+					this.isLoading = false;  // 即使加载失败也需要关闭加载状态
+				}
+			},
 			tabSelect(index) {
 				this.tabIndex = index;
 			},