|
@@ -48,7 +48,7 @@ const pagePermissionsTree = ref<DataNode[]>([
|
|
|
},
|
|
|
]);
|
|
|
const addCharacterName = async () => {
|
|
|
- if (characterList.value.some((item) => item.name === '')) {
|
|
|
+ if (characterList.value.some((item) => !isValidString(item.name))) {
|
|
|
return;
|
|
|
}
|
|
|
characterList.value.push({
|
|
@@ -61,14 +61,14 @@ const addCharacterName = async () => {
|
|
|
inputRef.value[0].focus();
|
|
|
};
|
|
|
const clickCharacter = (id: number) => {
|
|
|
- if (characterList.value.some((item) => item.name === '')) {
|
|
|
+ if (characterList.value.some((item) => !isValidString(item.name))) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
characterListId.value = id;
|
|
|
};
|
|
|
const addEditor = async (index: number) => {
|
|
|
- if (characterList.value.some((item) => item.name === '')) {
|
|
|
+ if (characterList.value.some((item) => !isValidString(item.name))) {
|
|
|
return;
|
|
|
}
|
|
|
characterList.value[index].show = true;
|
|
@@ -79,6 +79,9 @@ const addDelete = (id: number | undefined) => {
|
|
|
if (!id) {
|
|
|
return message.warning(t('deviceList.pleaseSelectItemDelete'));
|
|
|
}
|
|
|
+ if (characterList.value.some((item) => !isValidString(item.name))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
characterId.value = id;
|
|
|
modalComponentRef.value?.showView();
|
|
|
};
|
|
@@ -100,16 +103,17 @@ const editorCharacterBlur = (index: number, name: string) => {
|
|
|
}
|
|
|
};
|
|
|
/**
|
|
|
- * 检查字符串是否包含任何空白字符(包括空格、制表符、换行等)
|
|
|
+ * 校验字符串是否非空且不包含任何空白字符
|
|
|
* @param str 待检测的字符串
|
|
|
- * @returns 是否包含空白字符
|
|
|
+ * @returns 是否有效(非空且无空白)
|
|
|
*/
|
|
|
-const hasWhitespace = (str: string): boolean => {
|
|
|
- return /\s/.test(str);
|
|
|
+const isValidString = (str: string): boolean => {
|
|
|
+ return /^[\S]+$/.test(str);
|
|
|
+ // ^ 开头 | \S 非空白字符 | + 至少一个 | $ 结尾
|
|
|
};
|
|
|
const editorCharacter = (index: number, name: string) => {
|
|
|
if (name) {
|
|
|
- if (!hasWhitespace(name)) {
|
|
|
+ if (isValidString(name)) {
|
|
|
enterShow.value = true;
|
|
|
characterList.value[index].show = false;
|
|
|
const id = characterList.value[index].id;
|