feat(用户认证): 实现基于角色的页面跳转和登录状态检查
- 在App.vue中添加登录状态检查和用户信息获取 - 修改index.vue实现根据用户角色跳转到不同页面 - 更新pages.json调整底部导航栏和页面配置 - 优化user.js中的用户信息存储逻辑
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<view class="production-page">
|
||||
<!-- <view class="production-page">
|
||||
|
||||
<klp-header @lineChange="setActive" class="line-header"></klp-header>
|
||||
|
||||
@@ -10,42 +10,74 @@
|
||||
<Zinc2 v-else-if="active == 3"></Zinc2>
|
||||
<Zinc3 v-else-if="active == 4"></Zinc3>
|
||||
</view>
|
||||
</view>
|
||||
</view> -->
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Acidity from '@/components/lines/acidity.vue'
|
||||
import Paint from '@/components/lines/paint.vue'
|
||||
import Zinc1 from '@/components/lines/zinc1.vue'
|
||||
import Zinc2 from '@/components/lines/zinc2.vue'
|
||||
import Zinc3 from '@/components/lines/zinc3.vue'
|
||||
|
||||
// 根据不同的全责跳转到不同的页面
|
||||
// 如果是工人跳转到扫码页面
|
||||
// 如果是管理员跳转到产线
|
||||
export default {
|
||||
components: {
|
||||
Acidity,
|
||||
Paint,
|
||||
Zinc1,
|
||||
Zinc2,
|
||||
Zinc3
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
active: 0
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
next() {
|
||||
if (this.active >= 5) {
|
||||
this.active = 0
|
||||
} else {
|
||||
this.active += 1
|
||||
created() {
|
||||
// 检查用户角色
|
||||
this.$store.dispatch('GetInfo').then(res => {
|
||||
const roles = res.data.roles;
|
||||
|
||||
if (roles.includes('admin')) {
|
||||
// 管理员角色,跳转到产线页面
|
||||
uni.switchTab({
|
||||
url: '/pages/line/line'
|
||||
});
|
||||
} else if (roles.includes('worker')) {
|
||||
// 工人角色,跳转到扫码页面
|
||||
uni.navigateTo({
|
||||
url: '/pages/easycode/easycode'
|
||||
});
|
||||
}
|
||||
},
|
||||
setActive({ index, line }) {
|
||||
this.active = index;
|
||||
}
|
||||
// else {
|
||||
// // 其他角色,跳转到扫码页面
|
||||
// uni.navigateTo({
|
||||
// url: '/pages/easycode/easycode'
|
||||
// });
|
||||
// }
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// import Acidity from '@/components/lines/acidity.vue'
|
||||
// import Paint from '@/components/lines/paint.vue'
|
||||
// import Zinc1 from '@/components/lines/zinc1.vue'
|
||||
// import Zinc2 from '@/components/lines/zinc2.vue'
|
||||
// import Zinc3 from '@/components/lines/zinc3.vue'
|
||||
|
||||
// export default {
|
||||
// components: {
|
||||
// Acidity,
|
||||
// Paint,
|
||||
// Zinc1,
|
||||
// Zinc2,
|
||||
// Zinc3
|
||||
// },
|
||||
// data() {
|
||||
// return {
|
||||
// active: 0
|
||||
// }
|
||||
// },
|
||||
// methods: {
|
||||
// next() {
|
||||
// if (this.active >= 5) {
|
||||
// this.active = 0
|
||||
// } else {
|
||||
// this.active += 1
|
||||
// }
|
||||
// },
|
||||
// setActive({ index, line }) {
|
||||
// this.active = index;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user