员工入职填写优化

This commit is contained in:
fuenmao
2026-09-14 16:45:50 +08:00
parent 0624710136
commit 40010b5668
5 changed files with 133 additions and 22 deletions
+41
View File
@@ -323,3 +323,44 @@ export function findItemNested(enumData: any, callValue: any, value: string, chi
if (current[children]) return findItemNested(current[children], callValue, value, children);
}, null);
}
/**
* @description 复制文本到剪贴板(兼容安全上下文 HTTPS 与非安全上下文 HTTP/IP 环境)
* @param {String} text 要复制的文本
* @returns {Promise<boolean>} 是否成功复制
*/
export async function copyToClipboard(text: string): Promise<boolean> {
if (!text) return false;
// 1. 现代 Clipboard API (仅在 Secure Context 如 HTTPS 或 localhost 下可用)
if (navigator?.clipboard?.writeText) {
try {
await navigator.clipboard.writeText(text);
return true;
} catch (err) {
console.warn("navigator.clipboard.writeText failed, falling back to execCommand: ", err);
}
}
// 2. 降级方案:创建隐藏 textarea 并调用 document.execCommand('copy')
try {
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
textArea.style.top = "0";
textArea.style.left = "-9999px";
textArea.style.opacity = "0";
textArea.setAttribute("readonly", "");
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
textArea.setSelectionRange(0, text.length);
const successful = document.execCommand("copy");
document.body.removeChild(textArea);
return successful;
} catch (fallbackErr) {
console.error("document.execCommand('copy') failed: ", fallbackErr);
return false;
}
}
+10
View File
@@ -73,6 +73,16 @@ export function getIdCardBirthday(value: unknown) {
return `${text.slice(0, 4)}-${text.slice(4, 6)}-${text.slice(6, 8)}`;
}
export function getIdCardGender(value: unknown) {
const idCardNumber = normalizeIdCardNumber(value);
if (!/^\d{17}[0-9X]$/.test(idCardNumber)) {
return "";
}
const genderCode = Number(idCardNumber.charAt(16));
return genderCode % 2 === 1 ? "男" : "女";
}
export function isNumberInRange(value: unknown, min: number, max: number) {
const text = String(value ?? "").trim();
if (!/^\d+(\.\d+)?$/.test(text)) {