官网改版上线:关于我们与联系我们页重构、首页AI主视觉v4、品牌标识与导航交互;同步测试与设计文档
这个提交包含在:
@@ -0,0 +1,108 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var form = document.querySelector('.ct-form');
|
||||
if (!form) return;
|
||||
var submit = form.querySelector('.ct-submit');
|
||||
var status = form.querySelector('.ct-submit-status');
|
||||
var topics = Array.from(form.querySelectorAll('[data-topic]'));
|
||||
var refresh = form.querySelector('.ct-captcha-refresh');
|
||||
var fields = Array.from(form.querySelectorAll('input[required],textarea[required]'));
|
||||
var pending = false;
|
||||
var messages = {title: '请填写需求主题。', name: '请填写您的称呼。', phone: '请填写联系电话。', content: '请简要说明您的需求。', captcha: '请填写图片验证码。'};
|
||||
|
||||
function showStatus(message, state) {
|
||||
status.textContent = message;
|
||||
status.dataset.state = state;
|
||||
status.hidden = false;
|
||||
}
|
||||
function validate(field) {
|
||||
var value = field.value.trim();
|
||||
var message = value ? '' : messages[field.name];
|
||||
if (!message && field.name === 'phone' && (!/^[+\d\s().-]+$/.test(value) || value.replace(/\D/g, '').length < 7)) {
|
||||
message = '请填写可联系的手机或固定电话,固定电话请包含区号。';
|
||||
}
|
||||
var error = document.getElementById(field.id + '-error');
|
||||
field.setAttribute('aria-invalid', String(!!message));
|
||||
error.textContent = message;
|
||||
error.hidden = !message;
|
||||
return !message;
|
||||
}
|
||||
function resetCaptcha() {
|
||||
if (!refresh) return;
|
||||
var url = refresh.dataset.captchaUrl;
|
||||
refresh.querySelector('img').src = url + (url.indexOf('?') === -1 ? '?' : '&') + 'r=' + Date.now();
|
||||
form.elements.captcha.value = '';
|
||||
}
|
||||
async function request(url, options) {
|
||||
var controller = new AbortController();
|
||||
var timer = setTimeout(function () { controller.abort(); }, 20000);
|
||||
try {
|
||||
var response = await fetch(url, Object.assign({credentials: 'same-origin', cache: 'no-store', signal: controller.signal}, options));
|
||||
if (!response.ok) throw new Error('http');
|
||||
return await response.json();
|
||||
} finally { clearTimeout(timer); }
|
||||
}
|
||||
topics.forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
if (pending) return;
|
||||
form.elements.title.value = button.dataset.topic;
|
||||
topics.forEach(function (item) { item.setAttribute('aria-pressed', String(item === button)); });
|
||||
validate(form.elements.title);
|
||||
});
|
||||
});
|
||||
form.elements.title.addEventListener('input', function () {
|
||||
topics.forEach(function (item) { item.setAttribute('aria-pressed', String(item.dataset.topic === form.elements.title.value)); });
|
||||
});
|
||||
fields.forEach(function (field) {
|
||||
field.addEventListener('blur', function () { validate(field); });
|
||||
field.addEventListener('input', function () { if (field.getAttribute('aria-invalid') === 'true') validate(field); });
|
||||
});
|
||||
if (refresh) refresh.addEventListener('click', function () { if (!pending) resetCaptcha(); });
|
||||
form.addEventListener('submit', async function (event) {
|
||||
event.preventDefault();
|
||||
if (pending) return;
|
||||
var invalid = fields.filter(function (field) { return !validate(field); });
|
||||
if (invalid.length) {
|
||||
showStatus('请检查标注的必填内容后再提交。', 'error');
|
||||
invalid[0].focus();
|
||||
return;
|
||||
}
|
||||
pending = true;
|
||||
fields.forEach(function (field) { field.readOnly = true; });
|
||||
submit.disabled = true;
|
||||
form.setAttribute('aria-busy', 'true');
|
||||
submit.textContent = '正在提交…';
|
||||
showStatus('正在提交您的项目需求,请稍候。', 'pending');
|
||||
var payload = new URLSearchParams();
|
||||
fields.forEach(function (field) { payload.set(field.name, field.value.trim()); });
|
||||
var submitted = false;
|
||||
try {
|
||||
// Token is single-use; obtain one for each attempt, including retries.
|
||||
var token = await request(form.dataset.tokenUrl);
|
||||
if (Number(token.code) !== 1 || !token.data) throw new Error('token');
|
||||
form.elements.__token__.value = token.data;
|
||||
payload.set('__token__', token.data);
|
||||
submitted = true;
|
||||
var result = await request(form.action, {method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest'}, body: payload.toString()});
|
||||
if (Number(result.code) === 1) {
|
||||
form.reset();
|
||||
topics.forEach(function (item) { item.setAttribute('aria-pressed', 'false'); });
|
||||
fields.forEach(function (field) { field.removeAttribute('aria-invalid'); document.getElementById(field.id + '-error').hidden = true; });
|
||||
showStatus('您的需求已提交。我们将根据您留下的联系方式与您沟通,请保持电话畅通。', 'success');
|
||||
} else {
|
||||
var message = result.msg === '请先登录!' ? '页面校验已失效,请重试提交。' : String(result.msg || '暂未提交成功,请稍后重试或通过电话联系。');
|
||||
showStatus(message, 'error');
|
||||
}
|
||||
resetCaptcha();
|
||||
} catch (error) {
|
||||
showStatus(submitted ? '暂时无法确认提交结果。为避免重复提交,请稍后通过电话或邮箱确认;您填写的内容已保留。' : '暂时无法连接提交服务,请稍后重试或通过电话、邮箱联系。您填写的内容已保留。', 'error');
|
||||
} finally {
|
||||
pending = false;
|
||||
fields.forEach(function (field) { field.readOnly = false; });
|
||||
submit.disabled = false;
|
||||
submit.textContent = '提交项目需求 ↗';
|
||||
form.setAttribute('aria-busy', 'false');
|
||||
status.focus();
|
||||
}
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,22 @@
|
||||
/* Keep the public navigation readable while content passes beneath it. */
|
||||
(function () {
|
||||
'use strict';
|
||||
var root = document.documentElement;
|
||||
var pending = false;
|
||||
|
||||
function update() {
|
||||
root.classList.toggle('nhc-nav-scrolled', window.scrollY > 40);
|
||||
pending = false;
|
||||
}
|
||||
|
||||
function onScroll() {
|
||||
if (!pending) {
|
||||
pending = true;
|
||||
window.requestAnimationFrame(update);
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
window.addEventListener('scroll', onScroll, { passive: true });
|
||||
window.addEventListener('pageshow', update);
|
||||
}());
|
||||
在新工单中引用
屏蔽一个用户