(users, preferredUserId = state.userId)
| 513 | } |
| 514 | |
| 515 | function renderUsers(users, preferredUserId = state.userId) { |
| 516 | const select = $("userSelect"); |
| 517 | select.innerHTML = ""; |
| 518 | if (!users.length) { |
| 519 | const option = document.createElement("option"); |
| 520 | option.value = ""; |
| 521 | option.textContent = "暂无画像"; |
| 522 | select.appendChild(option); |
| 523 | state.userId = ""; |
| 524 | return; |
| 525 | } |
| 526 | const preferred = String(preferredUserId || "").trim(); |
| 527 | const current = users.find((user) => user.is_current); |
| 528 | const selectedUserId = |
| 529 | (preferred && users.some((user) => user.user_id === preferred) && preferred) || |
| 530 | current?.user_id || |
| 531 | users[0].user_id; |
| 532 | |
| 533 | users.forEach((user) => { |
| 534 | const option = document.createElement("option"); |
| 535 | option.value = user.user_id; |
| 536 | option.textContent = user.role_name ? `${user.role_name} (${user.user_id})` : user.user_id; |
| 537 | if (user.user_id === selectedUserId) option.selected = true; |
| 538 | select.appendChild(option); |
| 539 | }); |
| 540 | setActiveUser(select.value || selectedUserId); |
| 541 | } |
| 542 | |
| 543 | async function loadUsers(preferredUserId = state.userId) { |
| 544 | const data = await api("/api/users"); |
no test coverage detected