refactor: 限制纯空格名称

This commit is contained in:
wangjiahao 2025-01-20 10:35:17 +08:00 committed by 王嘉豪
parent 303f26dc36
commit ddac238fa0
3 changed files with 11 additions and 4 deletions

View File

@ -585,7 +585,7 @@ export async function canvasSave(callBack) {
ElMessage.error('数据集分组名称已存在')
return
}
nameTrim(dvInfo.value)
nameTrim(dvInfo.value, t('components.length_1_64_characters'))
const method = dvInfo.value.id && dvInfo.value.optType !== 'copy' ? updateCanvas : saveCanvas
if (method === updateCanvas) {
await dvNameCheck({

View File

@ -1,6 +1,9 @@
import { BusiTreeNode } from '@/models/tree/TreeNode'
import { useCache } from '@/hooks/web/useCache'
import { loadScript } from '@/utils/RemoteJs'
import { ElMessage } from 'element-plus-secondary'
import { useI18n } from '@/hooks/web/useI18n'
const { t } = useI18n()
const { wsCache } = useCache()
export function deepCopy(target) {
@ -283,8 +286,12 @@ export const filterFreeFolder = (list, flagText) => {
}
}
}
export const nameTrim = (target: {}) => {
export const nameTrim = (target: {}, msg = '名称字段长度1-64个字符') => {
if (target.name) {
target.name = target.name.trim()
if (target.name.length < 1 || target.name.length > 64) {
ElMessage.warning(msg)
throw new Error(msg)
}
}
}

View File

@ -273,7 +273,7 @@ const saveResource = () => {
params.pid = resourceForm.pid || pid.value || '0'
break
}
nameTrim(params)
nameTrim(params, t('components.length_1_64_characters'))
if (cmd.value === 'move' && !checkParent(params)) {
return
}
@ -291,7 +291,7 @@ const saveResource = () => {
loading.value = false
resourceDialogShow.value = false
emits('finish')
ElMessage.success('保存成功')
ElMessage.success(t('visualization.save_success'))
if (cmd.value === 'copy') {
const openType = wsCache.get('open-backend') === '1' ? '_self' : '_blank'
const baseUrl =