feat: ticket create - identity-only for logged-in users

- logged-in users: identity dropdown shown when >=1 identity exists,
  game name input hidden (identity carries the submitter); required
  removed from hidden field
- no identity: fall back to showing the game name input
- anonymous: unchanged, only the input field
- submit: identity selection still overrides reporter name/uid
This commit is contained in:
2026-08-22 02:56:13 +08:00
parent d7fb971f9f
commit bab584f31d

View File

@@ -34,9 +34,22 @@ const TicketCreate = {
API.get('/auth/identities').then(list => { API.get('/auth/identities').then(list => {
this.identities = list || []; this.identities = list || [];
const sel = container.querySelector('#identity-select'); const sel = container.querySelector('#identity-select');
if (sel && this.identities.length > 1) { const nameGroup = container.querySelector('#reporter-name-group');
sel.innerHTML = this.identities.map((it, i) => `<option value="${i}">${U.esc(it.source)}${U.esc(it.game_name)}</option>`).join(''); if (sel) {
sel.closest('.form-group').classList.remove('hidden'); if (this.identities.length > 0) {
// 有身份: 显示身份选择, 隐藏游戏名输入框(身份即代表提交者)
sel.innerHTML = this.identities.map((it, i) => `<option value="${i}">${U.esc(it.source)}${U.esc(it.game_name)}</option>`).join('');
sel.closest('.form-group').classList.remove('hidden');
if (nameGroup) {
nameGroup.classList.add('hidden');
const inp = nameGroup.querySelector('input[name="reporter_game_name"]');
if (inp) inp.required = false; // 隐藏字段不再参与原生必填校验
}
} else {
// 无身份: 保留游戏名输入框兜底
sel.closest('.form-group').classList.add('hidden');
if (nameGroup) nameGroup.classList.remove('hidden');
}
} }
}).catch(() => {}); }).catch(() => {});
} }
@@ -82,11 +95,11 @@ const TicketCreate = {
</div> </div>
${user ? `<div class="form-group hidden" id="identity-group"> ${user ? `<div class="form-group hidden" id="identity-group">
<label>使用身份</label> <label>使用身份 *</label>
<select id="identity-select"></select> <select id="identity-select"></select>
</div>` : ''} </div>` : ''}
<div class="form-group"> <div class="form-group" id="reporter-name-group">
<label>您的游戏名称 *</label> <label>您的游戏名称 *</label>
<input name="reporter_game_name" required placeholder="Minecraft ID" value="${U.esc(prefill?.game_name || user?.game_name || '')}" ${prefill?.game_name ? 'readonly' : ''}> <input name="reporter_game_name" required placeholder="Minecraft ID" value="${U.esc(prefill?.game_name || user?.game_name || '')}" ${prefill?.game_name ? 'readonly' : ''}>
</div> </div>