filament-login-phone.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // 修改登录表单为手机号输入
  2. document.addEventListener('DOMContentLoaded', function() {
  3. // 等待 Livewire 初始化完成
  4. setTimeout(function() {
  5. const emailInput = document.querySelector('#form\\.email');
  6. const emailLabel = document.querySelector('label[for="form.email"]');
  7. if (emailInput && emailLabel) {
  8. // 修改输入框类型为 tel
  9. emailInput.type = 'tel';
  10. emailInput.inputMode = 'numeric';
  11. emailInput.maxLength = 11;
  12. emailInput.placeholder = '请输入11位手机号';
  13. // 修改标签文字
  14. emailLabel.textContent = '手机号';
  15. // 添加提示文字
  16. const hint = document.createElement('p');
  17. hint.className = 'mt-1 text-xs text-slate-500';
  18. hint.textContent = '请输入11位手机号码(以1开头)';
  19. emailLabel.parentNode.insertBefore(hint, emailInput.parentNode.nextSibling);
  20. // 监听输入事件,只允许数字
  21. emailInput.addEventListener('input', function(e) {
  22. let value = e.target.value.replace(/\D/g, '');
  23. if (value.length > 11) {
  24. value = value.substring(0, 11);
  25. }
  26. e.target.value = value;
  27. });
  28. console.log('Login form modified to phone number input');
  29. } else {
  30. console.error('Login form elements not found');
  31. }
  32. }, 1000);
  33. });