feat(user): Add logic to conditionally display "Add as Ladder User" button
- Implemented a check to hide the "Add as Ladder User" button for users already designated as ladder users in any store. - Enhanced the user retrieval process to include a flag indicating whether a user is a ladder user, optimizing front-end rendering and reducing unnecessary actions.
This commit is contained in:
parent
edd977d5d2
commit
21c5bb9b57
@ -73,7 +73,12 @@
|
|||||||
<el-button type="primary" link @click="handleView(row)"
|
<el-button type="primary" link @click="handleView(row)"
|
||||||
>查看</el-button
|
>查看</el-button
|
||||||
>
|
>
|
||||||
<el-button type="primary" link @click="handleAddLadderUser(row)"
|
<!-- 如果该用户已经是任意门店的天梯用户,则不再展示“添加为天梯用户”按钮 -->
|
||||||
|
<el-button
|
||||||
|
v-if="!row.hasLadderUser"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleAddLadderUser(row)"
|
||||||
>添加为天梯用户</el-button
|
>添加为天梯用户</el-button
|
||||||
>
|
>
|
||||||
<el-button
|
<el-button
|
||||||
|
|||||||
@ -125,6 +125,17 @@ class AdminController {
|
|||||||
offset
|
offset
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 批量查询这些用户是否已是任意门店的天梯用户,避免在前端逐个额外请求
|
||||||
|
const userIds = rows.map(u => u.id);
|
||||||
|
let ladderUserIdSet = new Set();
|
||||||
|
if (userIds.length > 0) {
|
||||||
|
const ladderUsers = await LadderUser.findAll({
|
||||||
|
where: { user_id: { [Op.in]: userIds } },
|
||||||
|
attributes: ['user_id']
|
||||||
|
});
|
||||||
|
ladderUserIdSet = new Set(ladderUsers.map(lu => lu.user_id));
|
||||||
|
}
|
||||||
|
|
||||||
res.json(pageResult(rows.map(user => ({
|
res.json(pageResult(rows.map(user => ({
|
||||||
id: user.id,
|
id: user.id,
|
||||||
nickname: user.nickname,
|
nickname: user.nickname,
|
||||||
@ -134,7 +145,9 @@ class AdminController {
|
|||||||
memberCode: user.member_code,
|
memberCode: user.member_code,
|
||||||
totalPoints: user.total_points,
|
totalPoints: user.total_points,
|
||||||
status: user.status,
|
status: user.status,
|
||||||
createdAt: user.created_at
|
createdAt: user.created_at,
|
||||||
|
// 前端根据该字段隐藏“添加为天梯用户”按钮
|
||||||
|
hasLadderUser: ladderUserIdSet.has(user.id)
|
||||||
})), count, page, pageSize));
|
})), count, page, pageSize));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('获取用户列表失败:', err);
|
console.error('获取用户列表失败:', err);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user