feat: 重构扫码与巡检模块,优化页面路由
1. 新增钢卷详情、扫码页面与设备巡检组件 2. 调整首页跳转逻辑至扫码页面,更新tabBar配置 3. 隐藏旧的分条、其他操作模块,替换钢卷详情弹窗为页面跳转 4. 复用巡检组件到扫码页面与设备巡检页
This commit is contained in:
@@ -6,132 +6,26 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
tabVisible: {
|
||||
admin: [true, true, true, false, true, true],
|
||||
canteen: [false, false, false, true, false, true],
|
||||
worker: [false, true, true, false, true, true]
|
||||
},
|
||||
hasJumped: false, // 防止重复跳转的标记
|
||||
hasJumped: false,
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
// 已跳转过则不再执行逻辑
|
||||
if (this.hasJumped) return;
|
||||
|
||||
// 检查用户角色
|
||||
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')) {
|
||||
for (let i = 0; i < this.tabVisible.admin.length; i++) {
|
||||
const v = this.tabVisible.admin[i]
|
||||
uni.setTabBarItem({
|
||||
index: i,
|
||||
visible: v
|
||||
});
|
||||
}
|
||||
// 管理员角色跳转
|
||||
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('canteen')) {
|
||||
for (let i = 0; i < this.tabVisible.canteen.length; i++) {
|
||||
const v = this.tabVisible.canteen[i]
|
||||
uni.setTabBarItem({
|
||||
index: i,
|
||||
visible: v
|
||||
});
|
||||
}
|
||||
// 食堂角色跳转
|
||||
uni.switchTab({
|
||||
url: '/pages/meal/meal',
|
||||
success: () => {
|
||||
this.hasJumped = true; // 标记已跳转
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('管理员页面跳转失败:', err);
|
||||
uni.showToast({
|
||||
title: '跳转产线页面失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (roles.includes('worker')) {
|
||||
// 工人角色跳转
|
||||
// 设置tab内容
|
||||
// 设置产线和复杂扫码不可见
|
||||
for (let i = 0; i < this.tabVisible.worker.length; i++) {
|
||||
const v = this.tabVisible.worker[i]
|
||||
uni.setTabBarItem({
|
||||
index: i,
|
||||
visible: v
|
||||
});
|
||||
}
|
||||
uni.switchTab({
|
||||
url: '/pages/easycode/easycode',
|
||||
success: () => {
|
||||
this.hasJumped = true; // 标记已跳转
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('工人页面跳转失败:', err);
|
||||
uni.showToast({
|
||||
title: '跳转扫码页面失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for (let i = 0; i < this.tabVisible.worker.length; i++) {
|
||||
const v = this.tabVisible.worker[i]
|
||||
uni.setTabBarItem({
|
||||
index: i,
|
||||
visible: v
|
||||
});
|
||||
}
|
||||
// 延迟跳转,确保提示被用户看到
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/easycode/easycode',
|
||||
success: () => {
|
||||
this.hasJumped = true;
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('默认角色页面跳转失败:', err);
|
||||
uni.showToast({
|
||||
title: '跳转默认页面失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
}
|
||||
.then(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/scan/scan',
|
||||
success: () => {
|
||||
this.hasJumped = true;
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('跳转失败:', err);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login'
|
||||
})
|
||||
.catch(() => {
|
||||
uni.reLaunch({ url: '/pages/login' })
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user