批量添加设备行数显示

This commit is contained in:
ChenYi 2025-08-05 11:59:00 +08:00
parent 789a16e958
commit 7cf5167728
2 changed files with 136 additions and 38 deletions

View File

@ -178,8 +178,20 @@ const [BatchAddModal, batchAddModalApi] = useVbenModal({
onConfirm: submitBatchAdd,
onBeforeClose: () => {
batchAddFormApi.resetForm();
stopLineCheck();
return true;
},
onOpenChange: (isOpen) => {
if (isOpen) {
//
setTimeout(() => {
startLineCheck();
}, 100);
} else {
//
stopLineCheck();
}
},
});
//
@ -414,6 +426,12 @@ async function submitBatchAdd() {
return;
}
//
if (addressList.length > 100) {
Message.error('设备地址不能超过100行');
return;
}
//
const invalidAddresses = addressList.filter(
(address: string) => !address || address.length < 3,
@ -469,49 +487,123 @@ async function submitBatchAdd() {
const openBatchAddModal = () => {
console.log('打开批量添加模态框');
batchAddFormApi.resetForm();
addressLines.value = 0; //
batchAddModalApi.open();
};
//
const addressLines = ref(0);
//
const getAddressLines = () => {
//
const isOverLineLimit = computed(() => {
return addressLines.value > 100;
});
//
watch(
() => batchAddFormApi.getValues()?.addressList,
(newValue) => {
try {
console.log('监听地址列表变化:', newValue);
if (!newValue || typeof newValue !== 'string') {
addressLines.value = 0;
return;
}
const lines = newValue.split('\n').filter((line: string) => line.trim());
addressLines.value = lines.length;
console.log('更新行数:', addressLines.value);
} catch {
addressLines.value = 0;
}
},
{ immediate: true },
);
//
watch(
() => batchAddFormApi.getValues(),
(formValues) => {
try {
const formValues = batchAddFormApi.getValues();
const addressList = formValues?.addressList;
console.log('监听表单值变化:', addressList);
if (!addressList || typeof addressList !== 'string') {
addressLines.value = 0;
return 0;
return;
}
const lines = addressList.split('\n').filter((line: string) => line.trim());
addressLines.value = lines.length;
return lines.length;
console.log('备用方案更新行数:', addressLines.value);
} catch {
addressLines.value = 0;
return 0;
}
},
{ deep: true, immediate: true },
);
// 使
let lineCheckInterval: NodeJS.Timeout | null = null;
//
const startLineCheck = () => {
if (lineCheckInterval) {
clearInterval(lineCheckInterval);
}
lineCheckInterval = setInterval(() => {
try {
//
let addressList = '';
// 1
const formValues = batchAddFormApi.getValues();
console.log('表单值:', formValues);
addressList = formValues?.addressList || '';
// 21
if (!addressList) {
try {
const rawValues = batchAddFormApi.getValues();
console.log('原始表单值:', rawValues);
addressList = rawValues?.addressList || '';
} catch (e) {
console.log('方式2失败:', e);
}
}
// 3DOM
if (!addressList) {
const textarea = document.querySelector('textarea[name="addressList"]') as HTMLTextAreaElement;
if (textarea) {
addressList = textarea.value;
console.log('从DOM获取的地址列表:', addressList);
}
}
console.log('获取到的地址列表:', addressList);
if (addressList && typeof addressList === 'string') {
const lines = addressList.split('\n').filter((line: string) => line.trim());
const newLineCount = lines.length;
console.log('计算出的行数:', newLineCount, '当前行数:', addressLines.value);
if (newLineCount !== addressLines.value) {
console.log('定时器更新行数:', newLineCount);
addressLines.value = newLineCount;
}
} else {
console.log('地址列表为空或不是字符串');
}
} catch (error) {
console.error('定时器检查行数失败:', error);
}
}, 300);
};
// 使
const computedAddressLines = computed(() => {
try {
const formValues = batchAddFormApi.getValues();
const addressList = formValues?.addressList;
if (!addressList || typeof addressList !== 'string') {
return 0;
//
const stopLineCheck = () => {
if (lineCheckInterval) {
clearInterval(lineCheckInterval);
lineCheckInterval = null;
}
const lines = addressList.split('\n').filter((line: string) => line.trim());
return lines.length;
} catch {
return 0;
}
});
// addressLines
watch(computedAddressLines, (newValue) => {
addressLines.value = newValue;
}, { immediate: true });
};
//
const handleCacheRefresh = async () => {
@ -676,13 +768,19 @@ const toolbarActions = computed(() => [
<div class="text-sm text-gray-500">
<span v-if="addressLines > 0">
{{ addressLines }} 行设备地址
<span v-if="isOverLineLimit" style="color: #ff4d4f;">
(超过100行限制)
</span>
</span>
<span v-else>
当前行数: {{ addressLines }} (调试信息)
</span>
</div>
<div class="flex gap-2">
<Button @click="batchAddModalApi.close()">
{{ $t('common.cancel') }}
</Button>
<Button type="primary" :loading="batchAddModalState?.confirmLoading" @click="submitBatchAdd">
<Button type="primary" :loading="batchAddModalState?.confirmLoading" @click="submitBatchAdd" :disabled="isOverLineLimit">
{{ $t('common.confirm') }}
</Button>
</div>

View File

@ -674,8 +674,8 @@ export const batchAddDeviceFormSchema: any = computed(() => [
componentProps: {
rows: 4,
placeholder: $t('common.pleaseInput') + $t('abp.deviceInfos.deviceAddress') + ',每行一个设备地址',
showCount: true,
maxLength: 2000,
showCount: false,
maxLength: 10000,
style: {
resize: 'vertical',
minHeight: '32px',