Browse Source

feat(contact): 添加表单提交成功提示功能和样式

master
peijunlei 2 weeks ago
parent
commit
f4c78da7f3
  1. 55
      public/themes/website/1/zh/demo/contact.html

55
public/themes/website/1/zh/demo/contact.html

@ -230,6 +230,7 @@ $(function () {
success: function (res) { success: function (res) {
if (res.code === 0 || res.code === 200) { if (res.code === 0 || res.code === 200) {
$form[0].reset(); $form[0].reset();
showFormToast('提交成功,我们会尽快与您联系!');
} else { } else {
alert(res.msg || '提交失败,请稍后重试'); alert(res.msg || '提交失败,请稍后重试');
} }
@ -245,8 +246,62 @@ $(function () {
return false; return false;
}); });
// 表单提交成功提示
var $toast = null;
var toastTimer = null;
function showFormToast(msg) {
if (!$toast) {
$toast = $(
'<div class="form-toast">' +
' <svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg">' +
' <circle cx="12" cy="12" r="10.5" stroke="currentColor" stroke-width="1.5"/>' +
' <path d="M7.5 12.5L10.5 15.5L16.5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>' +
' </svg>' +
' <span class="form-toast__text"></span>' +
'</div>'
);
$('body').append($toast);
}
$toast.find('.form-toast__text').text(msg);
$toast.addClass('form-toast--show');
clearTimeout(toastTimer);
toastTimer = setTimeout(function () {
$toast.removeClass('form-toast--show');
}, 3000);
}
}); });
</script> </script>
<style>
.form-toast {
position: fixed;
left: 50%;
top: 40px;
transform: translate(-50%, -16px);
z-index: 9999;
display: flex;
align-items: center;
gap: 10px;
padding: 14px 24px;
border-radius: 8px;
background: #fff;
color: var(--color-primary);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
font-size: 15px;
opacity: 0;
visibility: hidden;
pointer-events: none;
transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
}
.form-toast--show {
opacity: 1;
visibility: visible;
transform: translate(-50%, 0);
}
.form-toast__text {
color: var(--color-text);
}
</style>
</body> </body>
</html> </html>
Loading…
Cancel
Save