diff --git a/App.vue b/App.vue
index cc1058b..7e7c283 100644
--- a/App.vue
+++ b/App.vue
@@ -1,9 +1,13 @@
+
+
\ No newline at end of file
diff --git a/pages/index/index.vue b/pages/index/index.vue
index b0ba127..9f44d5c 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -94,82 +94,46 @@
-
+
-
-
-
- 请选择您的身份类型:
-
-
-
-
-
-
- {{ role.label }}
- {{ getRoleDesc(role.value) }}
-
-
-
-
-
-
-
-
-
+
+
@@ -427,4 +343,27 @@
color: #333;
margin-right: 8rpx;
}
+
+ .role-float-btn {
+ position: fixed;
+ bottom: 200rpx;
+ right: 30rpx;
+ width: 100rpx;
+ height: 100rpx;
+ background: linear-gradient(135deg, #007AFF 0%, #0056CC 100%);
+ border-radius: 50rpx;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ box-shadow: 0 8rpx 20rpx rgba(0, 122, 255, 0.3);
+ z-index: 999;
+ transition: all 0.3s ease;
+
+ &:active {
+ transform: scale(0.95);
+ box-shadow: 0 4rpx 10rpx rgba(0, 122, 255, 0.2);
+ }
+ }
+
+
\ No newline at end of file
diff --git a/pages/index/order.vue b/pages/index/order.vue
index 2d510c6..276bbeb 100644
--- a/pages/index/order.vue
+++ b/pages/index/order.vue
@@ -27,6 +27,7 @@ import UserHall from '@/components/user/hall.vue'
import StaffHall from '@/components/staff/hall.vue'
import EnterpriseHall from '@/components/enterprise/hall.vue'
import RegionHall from '@/components/region/hall.vue'
+import { mapState, mapGetters, mapMutations } from 'vuex'
export default {
components: {
@@ -42,6 +43,8 @@ export default {
}
},
computed: {
+ ...mapState(['role']),
+ ...mapGetters(['currentRoleText']),
pageTitle() {
const roleNum = Number(this.role);
if (roleNum === 0) {
@@ -58,35 +61,52 @@ export default {
}
},
onShow() {
- this.role = uni.getStorageSync('role') || '1';
+ // 初始化角色
+ this.initRole();
// 设置导航栏标题
uni.setNavigationBarTitle({ title: this.pageTitle });
+ // 监听角色变更事件
+ uni.$on('roleChanged', this.handleRoleChange);
+
// 刷新对应的组件数据
- this.$nextTick(() => {
- try {
- const roleNum = Number(this.role);
- if (roleNum === 0) {
- this.$refs.us && this.$refs.us.loadPage && this.$refs.us.loadPage();
- } else if (roleNum === 1) {
- this.$refs.eh && this.$refs.eh.loadPage && this.$refs.eh.loadPage();
- } else if (roleNum === 2) {
- this.$refs.ss && this.$refs.ss.loadPage && this.$refs.ss.loadPage();
- } else if (roleNum === 3) {
- this.$refs.rh && this.$refs.rh.loadPage && this.$refs.rh.loadPage();
- }
- } catch (e) {
- console.log('组件方法调用失败:', e);
- }
- });
+ this.refreshCurrentComponent();
+ },
+ onHide() {
+ // 移除事件监听
+ uni.$off('roleChanged', this.handleRoleChange);
},
methods: {
- // 切换角色(用于测试)
- switchRole(newRole) {
- this.role = newRole;
- uni.setStorageSync('role', newRole);
+ ...mapMutations(['initRole']),
+ // 处理角色变更
+ handleRoleChange(newRole) {
+ console.log('订单页面收到角色变更:', newRole);
+ // 更新导航栏标题
uni.setNavigationBarTitle({ title: this.pageTitle });
+ // 刷新对应组件
+ this.$nextTick(() => {
+ this.refreshCurrentComponent();
+ });
+ },
+ // 刷新当前角色对应的组件
+ refreshCurrentComponent() {
+ this.$nextTick(() => {
+ try {
+ const roleNum = Number(this.role);
+ if (roleNum === 0) {
+ this.$refs.us && this.$refs.us.loadPage && this.$refs.us.loadPage();
+ } else if (roleNum === 1) {
+ this.$refs.eh && this.$refs.eh.loadPage && this.$refs.eh.loadPage();
+ } else if (roleNum === 2) {
+ this.$refs.ss && this.$refs.ss.loadPage && this.$refs.ss.loadPage();
+ } else if (roleNum === 3) {
+ this.$refs.rh && this.$refs.rh.loadPage && this.$refs.rh.loadPage();
+ }
+ } catch (e) {
+ console.log('组件方法调用失败:', e);
+ }
+ });
}
}
}
diff --git a/store/store.js b/store/store.js
index f1131ab..7b93544 100644
--- a/store/store.js
+++ b/store/store.js
@@ -10,9 +10,24 @@ const store = new Vuex.Store({
state: {
configList: {}, //配置列表
userInfo : {}, //用户信息
- role : 0,
+ role : '0', // 当前角色:0-用户/泵司,1-企业,2-员工,3-区域管理员
+ roleOptions: [
+ { value: '0', label: '用户/泵司' },
+ { value: '1', label: '企业用户' },
+ { value: '2', label: '员工' },
+ { value: '3', label: '区域管理员' }
+ ],
},
getters: {
+ // 获取当前角色文本
+ currentRoleText: (state) => {
+ const role = state.roleOptions.find(r => r.value === state.role);
+ return role ? role.label : '用户/泵司';
+ },
+ // 获取角色选项
+ getRoleOptions: (state) => {
+ return state.roleOptions;
+ }
},
mutations: {
// 初始化配置
@@ -83,6 +98,20 @@ const store = new Vuex.Store({
}
})
},
+ // 切换角色
+ switchRole(state, roleValue) {
+ state.role = roleValue;
+ uni.setStorageSync('role', roleValue);
+ // 触发全局事件通知角色变更
+ uni.$emit('roleChanged', roleValue);
+ },
+ // 初始化角色
+ initRole(state) {
+ const savedRole = uni.getStorageSync('role');
+ if (savedRole) {
+ state.role = savedRole;
+ }
+ },
// 退出登录
logout(state){
uni.showModal({
@@ -90,8 +119,9 @@ const store = new Vuex.Store({
success(r) {
if(r.confirm){
state.userInfo = {}
- state.role = false
+ state.role = '0'
uni.removeStorageSync('token')
+ uni.removeStorageSync('role')
uni.reLaunch({
url: '/pages/index/index'
})