import { escapeHtml } from '/static/portal/common/formatters.js';
import { ERR_CODES } from '/static/portal/common/error-codes.js';
export function renderLoading(container, count = 3) {
container.innerHTML = Array.from({ length: count }, () => '
').join('');
container.setAttribute('aria-busy', 'true');
}
export function renderEmpty(container, title, message) {
container.removeAttribute('aria-busy');
container.innerHTML = `${escapeHtml(title)}
${escapeHtml(message)}
`;
}
export function renderError(container, error, retry) {
container.removeAttribute('aria-busy');
if (error.code === ERR_CODES.AUTHENTICATION_REQUIRED || error.status === 401) {
const next = encodeURIComponent(`${window.location.pathname}${window.location.search}`);
const loginPath = window.location.pathname.includes('/employee-') ? '/portal/employee-console/login/' : '/portal/customer/login/';
container.innerHTML = ``;
return;
}
if (error.code === ERR_CODES.AGENT_PERMISSION_DENIED || error.status === 403) {
const needsQuestionnaire = String(error.message || '').includes('风险测评问卷');
const action = needsQuestionnaire
? '开始风险测评'
: '浏览基金产品';
container.innerHTML = `当前账户暂不可访问
${escapeHtml(error.message || '该账号尚未开通此项权限')}
${action}
`;
return;
}
container.innerHTML = `数据暂时不可用
${escapeHtml(error.message || '请求未完成')}
`;
container.querySelector('[data-retry]')?.addEventListener('click', retry, { once: true });
}