diff --git a/package.json b/package.json
index bbbe6db..fa5b2fc 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
"moment": "^2.30.1",
"nprogress": "0.2.0",
"pinia": "2.1.7",
+ "pinyin-pro": "^3.27.0",
"splitpanes": "3.1.5",
"tinymce": "^7.9.1",
"vue": "3.4.31",
diff --git a/src/views/qualification/escTask/components/QualificationManage.vue b/src/views/qualification/escTask/components/QualificationManage.vue
index 8edfe0a..9016f3c 100644
--- a/src/views/qualification/escTask/components/QualificationManage.vue
+++ b/src/views/qualification/escTask/components/QualificationManage.vue
@@ -70,7 +70,7 @@
-
+
diff --git a/src/views/qualification/myQualifications/components/QualificationTrain.vue b/src/views/qualification/myQualifications/components/QualificationTrain.vue
index 3e7055c..72394b3 100644
--- a/src/views/qualification/myQualifications/components/QualificationTrain.vue
+++ b/src/views/qualification/myQualifications/components/QualificationTrain.vue
@@ -54,7 +54,7 @@
-
+
@@ -124,7 +124,7 @@ const hasFilesList = [
]
// 选择是否复审
-const handleCheckedHasFileChange = (value) => {
+const handleCheckedHasFileChange = (value) => {
if (value.length > 0) {
// 选中状态
checkedFs.value = true
diff --git a/src/views/register.vue b/src/views/register.vue
index a49e34c..6fc3ea9 100644
--- a/src/views/register.vue
+++ b/src/views/register.vue
@@ -35,7 +35,8 @@
-
+
+
@@ -81,6 +82,7 @@ import systemlogo from '@/assets/logo/systemLogo.png'
import { getCustomerBusDependencyPage } from "@/api/system/dependency"
import { customerDeptTreeSelect } from "@/api/system/user"
import { getCustomerSysSectionPage } from "@/api/system/section"
+import { pinyin } from 'pinyin-pro';
const router = useRouter()
const { proxy } = getCurrentInstance()
@@ -99,6 +101,15 @@ const registerForm = ref({
escEmail: null,
isHasEmail: 1
})
+const isCompoundSurname = ref(false);
+// 常见复姓列表
+const compoundSurnames = [
+ '欧阳', '司马', '上官', '诸葛', '司徒', '司空',
+ '夏侯', '皇甫', '慕容', '端木', '东方', '南宫',
+ '万俟', '闻人', '澹台', '公冶', '宗政', '濮阳',
+ '单于', '太史', '申屠', '公孙', '仲孙', '轩辕',
+ '令狐', '钟离', '宇文', '长孙', '鲜于', '闾丘'
+];
const registerRules = {
isHasEmail: [{ required: true, message: "请选择是否有邮箱", trigger: ["change"] }],
@@ -117,6 +128,11 @@ const registerRules = {
const handleInput = (value) => {
registerForm.value.username = value
}
+// 中文姓名输入后 自动生成英文姓名
+const handleInputNickName = (value) => {
+ registerForm.value.nickName = value
+ convertToEnglishName()
+}
// 属地选择切换
const selectChanged = (value) => {
if (value) {
@@ -184,49 +200,73 @@ const filterDisabledDept = (deptList) => {
return true
})
}
-
+// 首字母大写函数
+const capitalizeFirst = (str) => {
+ if (!str) return '';
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
+};
+// 检测是否为复姓
+const detectCompoundSurname = (name) => {
+ for (const surname of compoundSurnames) {
+ if (name.startsWith(surname)) {
+ return surname;
+ }
+ }
+ return null;
+};
// 中文姓名转英文姓名
const convertToEnglishName = () => {
if (!registerForm.value.nickName.trim()) {
registerForm.value.englishName = '';
+ isCompoundSurname.value = false;
return;
}
- // 去除前后空格
- let name = form.value.nickName.trim();
+ try {
+ const name = registerForm.value.nickName.trim();
- // 检查是否是复姓
- let isCompound = false;
- let surnameParts = [];
+ // 检测复姓
+ const compoundSurname = detectCompoundSurname(name);
+ isCompoundSurname.value = compoundSurname !== null;
- for (const sn of compoundSurnames) {
- if (name.startsWith(sn)) {
- isCompound = true;
- surnameParts = [sn];
- name = name.slice(sn.length);
- break;
+ // 获取拼音数组
+ const pinyinArray = pinyin(name, {
+ toneType: 'none',
+ type: 'array'
+ });
+
+ if (pinyinArray.length === 0) {
+ registerForm.value.englishName = '转换失败';
+ return;
}
+
+ let lastNamePart, firstNamePart;
+
+ if (compoundSurname) {
+ // 复姓:前N个字合并为姓氏
+ const surnameLength = compoundSurname.length;
+ lastNamePart = pinyinArray.slice(0, surnameLength).join('');
+ firstNamePart = pinyinArray.slice(surnameLength).join('');
+ } else {
+ // 单姓:第一个字为姓氏
+ lastNamePart = pinyinArray[0];
+ firstNamePart = pinyinArray.slice(1).join('');
+ }
+
+ // 格式化输出
+ const formattedLastName = capitalizeFirst(lastNamePart);
+ const formattedFirstName = firstNamePart
+ .split(' ')
+ .map(word => capitalizeFirst(word))
+ .join(' ');
+ // 姓在前
+ registerForm.value.englishName = `${formattedLastName} ${formattedFirstName}`;
+ // 名在前
+ // registerForm.value.englishName = `${capitalizeFirst(formattedFirstName)} ${capitalizeFirst(formattedLastName)}`;
+ } catch (error) {
+ console.error('转换错误:', error);
+ registerForm.value.englishName = '转换失败,请检查输入';
}
-
- // 如果不是复姓,则取第一个字作为姓
- if (!isCompound && name.length > 0) {
- surnameParts = [name[0]];
- name = name.slice(1);
- }
-
- // 处理剩余的名字部分
- const givenNameParts = name.split('');
-
- // 构建英文姓氏 (全部大写)
- const engSurname = surnameParts.join('').toUpperCase();
-
- // 构建英文名字 (每个字首字母大写)
- const engGivenName = givenNameParts
- .map(char => char.charAt(0).toUpperCase() + char.slice(1).toLowerCase())
- .join('');
-
- // 组合结果
- registerForm.value.englishName = `${engSurname} ${engGivenName}`;
};
const handleRegister = () => {
@@ -235,7 +275,6 @@ const handleRegister = () => {
loading.value = true
if (registerForm.value.isHasEmail == 0) registerForm.value.email = undefined
register(registerForm.value).then(res => {
- console.log('注册结果', res)
const username = registerForm.value.username
const escName = registerForm.value.escUserName
const _email = registerForm.value.email
diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue
index 82e3281..04f2257 100644
--- a/src/views/system/user/index.vue
+++ b/src/views/system/user/index.vue
@@ -177,8 +177,7 @@
-
+
@@ -329,6 +328,7 @@ import { getSysSectionPage } from "@/api/system/section"
import { getBusDependencyPage } from "@/api/system/dependency"
import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css"
+import { pinyin } from 'pinyin-pro';
const router = useRouter()
const appStore = useAppStore()
@@ -376,12 +376,14 @@ const columns = ref([
{ key: 5, label: `状态`, visible: true },
{ key: 6, label: `创建时间`, visible: true }
])
-// 常见的复姓列表
+const isCompoundSurname = ref(false);
+// 常见复姓列表
const compoundSurnames = [
- '欧阳', '太史', '端木', '上官', '司马',
- '东方', '公孙', '尉迟', '公羊', '澹台',
- '宗政', '濮阳', '闾丘', '子车', '亓官',
- '南宫', '墨夷', '恰喇', '阏氏', '竺联'
+ '欧阳', '司马', '上官', '诸葛', '司徒', '司空',
+ '夏侯', '皇甫', '慕容', '端木', '东方', '南宫',
+ '万俟', '闻人', '澹台', '公冶', '宗政', '濮阳',
+ '单于', '太史', '申屠', '公孙', '仲孙', '轩辕',
+ '令狐', '钟离', '宇文', '长孙', '鲜于', '闾丘'
];
const validateRoles = (rule, value, callback) => {
console.log('选择值', value)
@@ -425,6 +427,11 @@ const { queryParams, form, rules } = toRefs(data)
const handleInput = (value) => {
form.value.userName = value
}
+// 中文姓名输入后 自动生成英文姓名
+const handleInputNickName = (value) => {
+ form.value.nickName = value
+ convertToEnglishName()
+}
// 科室数据
const sectionData = ref([])
// 获取科室数据
@@ -702,49 +709,73 @@ function submitForm() {
}
})
}
-
+// 首字母大写函数
+const capitalizeFirst = (str) => {
+ if (!str) return '';
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
+};
+// 检测是否为复姓
+const detectCompoundSurname = (name) => {
+ for (const surname of compoundSurnames) {
+ if (name.startsWith(surname)) {
+ return surname;
+ }
+ }
+ return null;
+};
// 中文姓名转英文姓名
const convertToEnglishName = () => {
if (!form.value.nickName.trim()) {
form.value.englishName = '';
+ isCompoundSurname.value = false;
return;
}
- // 去除前后空格
- let name = form.value.nickName.trim();
+ try {
+ const name = form.value.nickName.trim();
- // 检查是否是复姓
- let isCompound = false;
- let surnameParts = [];
+ // 检测复姓
+ const compoundSurname = detectCompoundSurname(name);
+ isCompoundSurname.value = compoundSurname !== null;
- for (const sn of compoundSurnames) {
- if (name.startsWith(sn)) {
- isCompound = true;
- surnameParts = [sn];
- name = name.slice(sn.length);
- break;
+ // 获取拼音数组
+ const pinyinArray = pinyin(name, {
+ toneType: 'none',
+ type: 'array'
+ });
+
+ if (pinyinArray.length === 0) {
+ form.value.englishName = '转换失败';
+ return;
}
+
+ let lastNamePart, firstNamePart;
+
+ if (compoundSurname) {
+ // 复姓:前N个字合并为姓氏
+ const surnameLength = compoundSurname.length;
+ lastNamePart = pinyinArray.slice(0, surnameLength).join('');
+ firstNamePart = pinyinArray.slice(surnameLength).join('');
+ } else {
+ // 单姓:第一个字为姓氏
+ lastNamePart = pinyinArray[0];
+ firstNamePart = pinyinArray.slice(1).join('');
+ }
+
+ // 格式化输出
+ const formattedLastName = capitalizeFirst(lastNamePart);
+ const formattedFirstName = firstNamePart
+ .split(' ')
+ .map(word => capitalizeFirst(word))
+ .join(' ');
+ // 姓在前
+ form.value.englishName = `${formattedLastName} ${formattedFirstName}`;
+ // 名在前
+ // form.value.englishName = `${capitalizeFirst(formattedFirstName)} ${capitalizeFirst(formattedLastName)}`;
+ } catch (error) {
+ console.error('转换错误:', error);
+ form.value.englishName = '转换失败,请检查输入';
}
-
- // 如果不是复姓,则取第一个字作为姓
- if (!isCompound && name.length > 0) {
- surnameParts = [name[0]];
- name = name.slice(1);
- }
-
- // 处理剩余的名字部分
- const givenNameParts = name.split('');
-
- // 构建英文姓氏 (全部大写)
- const engSurname = surnameParts.join('').toUpperCase();
-
- // 构建英文名字 (每个字首字母大写)
- const engGivenName = givenNameParts
- .map(char => char.charAt(0).toUpperCase() + char.slice(1).toLowerCase())
- .join('');
-
- // 组合结果
- form.value.englishName = `${engSurname} ${engGivenName}`;
};
onMounted(() => {