148 lines
3.1 KiB
Vue
148 lines
3.1 KiB
Vue
<template>
|
||
<!-- 模板内容保持不变(注释部分可根据需求保留) -->
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
hasJumped: false // 防止重复跳转的标记
|
||
}
|
||
},
|
||
onShow() {
|
||
// 已跳转过则不再执行逻辑
|
||
if (this.hasJumped) return;
|
||
|
||
// 显示加载状态,提升用户感知
|
||
// uni.showLoading({
|
||
// title: '验证身份中...',
|
||
// mask: true // 防止用户重复操作
|
||
// });
|
||
|
||
// 检查用户角色
|
||
this.$store.dispatch('GetInfo')
|
||
.then(res => {
|
||
// 验证返回数据格式
|
||
if (!res || !res.data || !Array.isArray(res.data.roles)) {
|
||
throw new Error('用户角色信息格式错误');
|
||
}
|
||
|
||
console.log('用户角色信息', res.data.roles)
|
||
|
||
const roles = res.data.roles;
|
||
|
||
if (roles.includes('admin')) {
|
||
// 管理员角色跳转
|
||
uni.switchTab({
|
||
url: '/pages/line/line',
|
||
success: () => {
|
||
this.hasJumped = true; // 标记已跳转
|
||
},
|
||
fail: (err) => {
|
||
console.error('管理员页面跳转失败:', err);
|
||
uni.showToast({
|
||
title: '跳转产线页面失败',
|
||
icon: 'none',
|
||
duration: 2000
|
||
});
|
||
}
|
||
});
|
||
} else if (roles.includes('worker')) {
|
||
// 工人角色跳转
|
||
uni.navigateTo({
|
||
url: '/pages/easycode/easycode',
|
||
success: () => {
|
||
this.hasJumped = true; // 标记已跳转
|
||
},
|
||
fail: (err) => {
|
||
console.error('工人页面跳转失败:', err);
|
||
uni.showToast({
|
||
title: '跳转扫码页面失败',
|
||
icon: 'none',
|
||
duration: 2000
|
||
});
|
||
}
|
||
});
|
||
} else {
|
||
// 处理未定义角色(默认角色)
|
||
uni.showToast({
|
||
title: '检测到未知角色,将跳转至默认页面',
|
||
icon: 'none',
|
||
duration: 2000
|
||
});
|
||
|
||
// 延迟跳转,确保提示被用户看到
|
||
setTimeout(() => {
|
||
uni.navigateTo({
|
||
url: '/pages/easycode/easycode',
|
||
success: () => {
|
||
this.hasJumped = true;
|
||
},
|
||
fail: (err) => {
|
||
console.error('默认角色页面跳转失败:', err);
|
||
uni.showToast({
|
||
title: '跳转默认页面失败',
|
||
icon: 'none',
|
||
duration: 2000
|
||
});
|
||
}
|
||
});
|
||
}, 2000);
|
||
}
|
||
})
|
||
.catch(err => {
|
||
uni.reLaunch({
|
||
url: '/pages/login'
|
||
})
|
||
});
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
/* 样式保持不变 */
|
||
.production-page {
|
||
min-height: 100vh;
|
||
background: #f6f6f6;
|
||
}
|
||
|
||
.page-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 40rpx 30rpx 20rpx;
|
||
background: #fff;
|
||
border-bottom: 1rpx solid #e8e8e8;
|
||
|
||
.header-title {
|
||
font-size: 28rpx;
|
||
font-weight: 500;
|
||
color: #333;
|
||
letter-spacing: 2rpx;
|
||
padding: 0 30rpx;
|
||
}
|
||
|
||
.header-line {
|
||
height: 2rpx;
|
||
background: linear-gradient(90deg, transparent, #ddd, transparent);
|
||
flex: 1;
|
||
max-width: 100rpx;
|
||
|
||
&.line-left {
|
||
background: linear-gradient(90deg, transparent, #ddd);
|
||
}
|
||
|
||
&.line-right {
|
||
background: linear-gradient(90deg, #ddd, transparent);
|
||
}
|
||
}
|
||
}
|
||
|
||
.line-header {
|
||
background: #fff;
|
||
}
|
||
|
||
.content-wrapper {
|
||
padding: 0;
|
||
}
|
||
</style> |