当前登录人不是超级用户,是默认添加当前登录人的手机号或者账号传给后端。

This commit is contained in:
zhonghua1
2026-01-10 11:51:50 +08:00
parent 03c0fe8375
commit a0bc13f960

View File

@@ -63,6 +63,15 @@
confirm-type="search"
@confirm="onServiceStatusSearch"
/>
<input
v-if="isAdmin"
class="toolbar-input"
v-model="serviceStatusQuery.salesPhone"
placeholder="销售电话"
placeholder-style="color: #b0b0b0"
confirm-type="search"
@confirm="onServiceStatusSearch"
/>
<view class="toolbar-actions">
<view class="toolbar-btn toolbar-btn--refresh" @click="onServiceStatusRefresh">
<uni-icons type="refresh" size="18" color="#2A68FF"></uni-icons>
@@ -438,8 +447,11 @@ import CommonBeginReception from "./common_begin_reception.vue";
},
serviceStatusQuery: {
salesName: '',
customerName: ''
customerName: '',
salesPhone: ''
},
isAdmin: false,
currentUserPhone: '',
receptionForm: {
id: "",
customerName: "",
@@ -499,9 +511,13 @@ import CommonBeginReception from "./common_begin_reception.vue";
}
},
onLoad() {
this.fetchServiceStatusList();
// 加载当前登录用户信息,填充销售姓名和电话
this.loadCurrentUserInfo();
// 检查用户角色
this.checkUserRole();
// 获取当前用户手机号
this.loadCurrentUserPhone();
this.fetchServiceStatusList();
},
methods: {
/**
@@ -533,6 +549,51 @@ import CommonBeginReception from "./common_begin_reception.vue";
console.error('加载当前登录用户信息失败:', e);
}
},
/**
* 检查用户角色判断是否包含admin
* 只要角色中包含admin字符串如admin_furniture就视为admin角色
*/
checkUserRole() {
try {
const normalize = (val) =>
typeof val === 'string'
? val
.split(',')
.map((s) => s.trim().toLowerCase())
.filter(Boolean)
: [];
const storedRole = uni.getStorageSync('backend-role-name') || '';
const loginResp = uni.getStorageSync('backend-login-response') || {};
const respRole = loginResp.roleName || '';
const roles = [...normalize(storedRole), ...normalize(respRole)];
// 检查角色数组中是否有任何角色包含 'admin' 字符串
this.isAdmin = roles.some(role => role.includes('admin'));
console.log('用户角色检查:', { storedRole, respRole, roles, isAdmin: this.isAdmin });
} catch (e) {
console.error('检查用户角色失败:', e);
this.isAdmin = false;
}
},
/**
* 加载当前用户手机号或登录账户
* 优先使用手机号,如果没有手机号则使用登录账户
*/
loadCurrentUserPhone() {
try {
const loginResponse = uni.getStorageSync('backend-login-response') || {};
// 优先使用手机号如果没有手机号则使用登录账户userName
if (loginResponse.phone) {
this.currentUserPhone = loginResponse.phone;
} else if (loginResponse.userName) {
this.currentUserPhone = loginResponse.userName;
} else {
this.currentUserPhone = '';
}
} catch (e) {
console.error('加载当前用户手机号或登录账户失败:', e);
this.currentUserPhone = '';
}
},
goBack() {
uni.navigateBack();
},
@@ -612,6 +673,20 @@ import CommonBeginReception from "./common_begin_reception.vue";
queryParams.customerName = trimmedCustomerName;
}
// 根据角色处理销售电话查询条件
if (this.isAdmin) {
// 如果是admin使用搜索框中的销售电话
const trimmedSalesPhone = this.serviceStatusQuery?.salesPhone?.trim();
if (trimmedSalesPhone) {
queryParams.salesPhone = trimmedSalesPhone;
}
} else {
// 如果不是admin默认添加当前登录人的手机号或登录账户
if (this.currentUserPhone) {
queryParams.salesPhone = this.currentUserPhone;
}
}
// 确保 serviceStatus 始终存在
queryParams.serviceStatus = '服务中';