feat(auth): 默认登录角色设置(切换角色对话框星标)

- 切换角色对话框每张角色卡片加星标按钮:设为/取消默认登录角色(金色高亮)
- user store 新增 defaultRoleUuid 状态与 setDefaultRole 动作,fetchRoles 同步 IsDefault
- auth.ts 新增 SetDefaultRole 接口(POST /Auth/SetDefaultRole)
This commit is contained in:
TermiNexus committed 2026-08-22 01:23:28 +08:00
1 parent 1d5e406616
commit f61716f215
3 files changed
+72 -1

No files matched your search

+52
View File
@@ -72,6 +72,23 @@ async function confirm(): Promise<void> {
}
}
const settingDefault = ref(false)
/** 切换"默认登录角色":再点已默认的角色 = 取消默认(登录后自动激活该角色) */
async function toggleDefault(role: RoleItem): Promise<void> {
if (settingDefault.value || !isEnabled(role)) return
settingDefault.value = true
try {
const isDefault = userStore.defaultRoleUuid === role.RoleUUID
await userStore.setDefaultRole(isDefault ? null : role)
ElMessage.success(isDefault ? '已取消默认登录角色' : `已设为默认登录角色:"${role.RoleName}"`)
} catch {
ElMessage.error('设置默认角色失败,请重试')
} finally {
settingDefault.value = false
}
}
/** 角色描述:公司全名(公司简称),无公司时显示"无所属公司" */
function roleDesc(role: RoleItem): string {
if (role.CompanyName) {
@@ -123,6 +140,15 @@ function roleDesc(role: RoleItem): string {
<div v-if="selectedRole?.RoleUUID === role.RoleUUID" class="role-check">
<svg viewBox="0 0 1024 1024" width="12" height="12"><path fill="currentColor" d="M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474a32 32 0 0 0-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1.4-12.8-6.3-12.8z" /></svg>
</div>
<!-- 默认登录角色星标(再点取消) -->
<button
class="role-default-btn"
:class="{ 'is-default': userStore.defaultRoleUuid === role.RoleUUID }"
:title="userStore.defaultRoleUuid === role.RoleUUID ? '取消默认登录角色' : '设为默认登录角色'"
@click.stop="toggleDefault(role)"
>
<svg viewBox="0 0 1024 1024" width="16" height="16"><path fill="currentColor" d="M908.1 353.1l-253.9-36.9L540.7 86.1c-3.1-6.3-8.2-11.4-14.5-14.5-15.8-7.8-35-1.3-42.9 14.5L369.8 316.2l-253.9 36.9c-7 1-13.4 4.3-18.3 9.3-12.3 12.7-12.1 32.9.6 45.3l183.7 179.1-43.4 252.9c-1.2 7-0.1 14.1 3.2 20.4 8.1 15.8 27.6 22 43.4 13.9l227.2-119.5 227.2 119.5c6.2 3.3 13.4 4.4 20.4 3.2 17.4-3 29.1-19.5 26.1-36.9l-43.4-252.9 183.7-179.1c5-4.9 8.3-11.3 9.3-18.3 2.7-17.5-9.5-33.7-27-36.3z"/></svg>
</button>
</div>
</div>
</div>
@@ -350,6 +376,32 @@ function roleDesc(role: RoleItem): string {
}
}
/* 默认登录角色星标(右下角,再点取消) */
.role-default-btn {
position: absolute;
right: 10px;
bottom: 10px;
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
border: none;
border-radius: 8px;
background: var(--el-fill-color);
color: var(--el-text-color-placeholder);
cursor: pointer;
transition: all 0.2s;
}
.role-default-btn:hover {
background: rgba(245, 158, 11, 0.15);
color: #f59e0b;
}
.role-default-btn.is-default {
background: rgba(245, 158, 11, 0.18);
color: #f59e0b;
}
/* 底部 */
.role-switcher-footer {
display: flex;