fix:AP设备错误提示修复
This commit is contained in:
@@ -33,12 +33,12 @@
|
||||
|
||||
|
||||
<TableHeaderOperation
|
||||
v-model:columns="columnChecks"
|
||||
:loading="loading"
|
||||
:show-delete="false"
|
||||
@add="handleAdd"
|
||||
@refresh="getData"
|
||||
/>
|
||||
v-model:columns="columnChecks"
|
||||
:loading="loading"
|
||||
:show-delete="false"
|
||||
@add="handleAdd"
|
||||
@refresh="getData"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -108,7 +108,6 @@
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
</template>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
@@ -164,17 +163,17 @@
|
||||
</a-radio-group>
|
||||
</a-form-item>
|
||||
|
||||
<!-- <a-form-item name="tagIds" :label="t('page.apdevice.deviceTags')">-->
|
||||
<!-- <a-select-->
|
||||
<!-- v-model:value="configForm.tagIds"-->
|
||||
<!-- mode="multiple"-->
|
||||
<!-- :placeholder="t('page.apdevice.selectTags')"-->
|
||||
<!-- >-->
|
||||
<!-- <a-select-option v-for="tag in tagsList" :key="tag.id" :value="tag.id">-->
|
||||
<!-- {{ tag.name }}-->
|
||||
<!-- </a-select-option>-->
|
||||
<!-- </a-select>-->
|
||||
<!-- </a-form-item>-->
|
||||
<!-- <a-form-item name="tagIds" :label="t('page.apdevice.deviceTags')">-->
|
||||
<!-- <a-select-->
|
||||
<!-- v-model:value="configForm.tagIds"-->
|
||||
<!-- mode="multiple"-->
|
||||
<!-- :placeholder="t('page.apdevice.selectTags')"-->
|
||||
<!-- >-->
|
||||
<!-- <a-select-option v-for="tag in tagsList" :key="tag.id" :value="tag.id">-->
|
||||
<!-- {{ tag.name }}-->
|
||||
<!-- </a-select-option>-->
|
||||
<!-- </a-select>-->
|
||||
<!-- </a-form-item>-->
|
||||
|
||||
<a-form-item name="longitude" :label="t('page.apdevice.longitude')">
|
||||
<a-input-number
|
||||
@@ -229,11 +228,11 @@ import { useTable } from '@/hooks/common/table';
|
||||
import { SimpleScrollbar } from '~/packages/materials/src';
|
||||
import { computed, shallowRef } from 'vue';
|
||||
import { useElementSize } from '@vueuse/core';
|
||||
import { fetchApDeviceList,forgetApDevice, addApDevice } from '@/service/api/auth';
|
||||
import { fetchApDeviceList,forgetApDevice, addApDevice, adoptApDevice } from '@/service/api/auth';
|
||||
import {Card as ACard, Table as ATable, Tag as ATag, Modal, message } from 'ant-design-vue';
|
||||
import DeviceSearch from './modules/device-search.vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { SettingOutlined, DeleteOutlined, ReloadOutlined,PlusOutlined } from '@ant-design/icons-vue';
|
||||
import { SettingOutlined, DeleteOutlined, ReloadOutlined, PlusOutlined } from '@ant-design/icons-vue';
|
||||
import {Rule} from "ant-design-vue/es/form";
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -252,28 +251,22 @@ const siteLoading = ref(false);
|
||||
|
||||
// 获取站点列表
|
||||
const getSiteList = async () => {
|
||||
try {
|
||||
siteLoading.value = true;
|
||||
const { data, error } = await fetchSiteList({
|
||||
pageNum: 1,
|
||||
pageSize: 100
|
||||
});
|
||||
siteLoading.value = true;
|
||||
const { data, error } = await fetchSiteList({
|
||||
pageNum: 1,
|
||||
pageSize: 100
|
||||
});
|
||||
|
||||
if (!error) {
|
||||
siteList.value = data.rows || [];
|
||||
|
||||
// 如果有站点数据,默认选择第一个
|
||||
if (siteList.value.length > 0) {
|
||||
selectedSiteId.value = siteList.value[0].siteId;
|
||||
await getData();
|
||||
}
|
||||
if (!error) {
|
||||
siteList.value = data.rows || [];
|
||||
// 如果有站点数据,默认选择第一个
|
||||
if (siteList.value.length > 0) {
|
||||
selectedSiteId.value = siteList.value[0].siteId;
|
||||
// 获取第一个站点的数据
|
||||
await getData();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Get site list error:', error);
|
||||
message.error(t('page.apdevice.getSiteError'));
|
||||
} finally {
|
||||
siteLoading.value = false;
|
||||
}
|
||||
siteLoading.value = false;
|
||||
};
|
||||
|
||||
// 处理站点变更
|
||||
@@ -415,65 +408,40 @@ const handleReset = () => {
|
||||
// 添加相关的处理函数
|
||||
// 处理打开配置对话框
|
||||
const handleEditConfig = async (record: Api.Device.ApDevice) => {
|
||||
try {
|
||||
if (!selectedSiteId.value) {
|
||||
throw new Error('No site selected');
|
||||
}
|
||||
currentDevice.value = record;
|
||||
configVisible.value = true;
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
|
||||
// 先获取设备当前的配置
|
||||
const response = await getApDeviceConfig(selectedSiteId.value, record.mac);
|
||||
// 获取设备当前的配置
|
||||
const { data, error } = await getApDeviceConfig(selectedSiteId.value, record.mac);
|
||||
|
||||
hide();
|
||||
|
||||
// 保存当前编辑的设备信息
|
||||
currentDevice.value = record;
|
||||
|
||||
// 使用获取到的配置更新表单,处理 null 和嵌套对象
|
||||
hide();
|
||||
if (!error && data) {
|
||||
configForm.value = {
|
||||
name: response.data?.name || record.name,
|
||||
ledSetting: response.data?.ledSetting ?? 2, // 如果没有设置,默认使用站点设置
|
||||
// tagIds: response.data?.tagIds || [], // 暂时注释掉
|
||||
longitude: response.data?.location?.longitude,
|
||||
latitude: response.data?.location?.latitude,
|
||||
address: response.data?.location?.address || ''
|
||||
name: data.name || '',
|
||||
ledSetting: data.ledSetting || 2,
|
||||
longitude: data.longitude,
|
||||
latitude: data.latitude,
|
||||
address: data.address || ''
|
||||
};
|
||||
|
||||
// 显示配置对话框
|
||||
configVisible.value = true;
|
||||
} catch (error) {
|
||||
console.error('Get device config error:', error);
|
||||
message.error(t('page.apdevice.getConfigError'));
|
||||
}
|
||||
};
|
||||
|
||||
const handleForgetDevice = (record: Api.Device.ApDevice) => {
|
||||
Modal.confirm({
|
||||
title: t('common.confirm'),
|
||||
content: t('page.apdevice.forgetConfirm'),
|
||||
title: t('page.apdevice.confirmForget'),
|
||||
content: t('page.apdevice.forgetConfirmContent', { name: record.name || record.mac }),
|
||||
okText: t('common.confirm'),
|
||||
cancelText: t('common.cancel'),
|
||||
onOk: async () => {
|
||||
try {
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
console.log('Forgetting device:', record);
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
const { error } = await forgetApDevice(selectedSiteId.value, record.mac);
|
||||
hide();
|
||||
|
||||
if (!selectedSiteId.value || !record.mac) {
|
||||
throw new Error('Missing required parameters: siteId or mac');
|
||||
}
|
||||
|
||||
// 使用当前选中的 siteId
|
||||
const response = await forgetApDevice(selectedSiteId.value, record.mac);
|
||||
console.log('Forget device response:', response);
|
||||
|
||||
hide();
|
||||
if (!error) {
|
||||
message.success(t('page.apdevice.forgetSuccess'));
|
||||
|
||||
// 重新获取列表数据
|
||||
getData();
|
||||
} catch (error) {
|
||||
console.error('Forget device error:', error);
|
||||
message.error(t('page.apdevice.forgetError'));
|
||||
throw error;
|
||||
getData(); // 刷新列表
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -491,61 +459,54 @@ const handleRestart = (record: Api.Device.ApDevice) => {
|
||||
});
|
||||
};
|
||||
|
||||
// 纳管表单数据
|
||||
// 添加纳管表单的引用
|
||||
const adoptFormRef = ref();
|
||||
|
||||
// 添加纳管表单的数据
|
||||
const adoptForm = ref({
|
||||
username: '',
|
||||
password: ''
|
||||
});
|
||||
|
||||
// 纳管对话框可见性
|
||||
// 添加纳管表单的验证规则
|
||||
const adoptRules = {
|
||||
username: [
|
||||
{ required: false }
|
||||
],
|
||||
password: [
|
||||
{ required: false }
|
||||
]
|
||||
};
|
||||
|
||||
// 添加纳管对话框的可见性控制
|
||||
const adoptVisible = ref(false);
|
||||
|
||||
// 当前要纳管的设备
|
||||
const adoptingDevice = ref<Api.Device.ApDevice | null>(null);
|
||||
|
||||
// 处理纳管按钮点击
|
||||
const handleAdopt = (record: Api.Device.ApDevice) => {
|
||||
adoptingDevice.value = record;
|
||||
adoptForm.value = {
|
||||
username: '',
|
||||
password: ''
|
||||
};
|
||||
const handleAdopt = async (record: Api.Device.ApDevice) => {
|
||||
currentDevice.value = record;
|
||||
adoptVisible.value = true;
|
||||
};
|
||||
|
||||
// 处理纳管确认
|
||||
const handleAdoptConfirm = async () => {
|
||||
try {
|
||||
if (!adoptingDevice.value || !selectedSiteId.value) {
|
||||
throw new Error('Missing device or site information');
|
||||
}
|
||||
await adoptFormRef.value?.validate();
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
|
||||
// 构造请求参数,只有在有值时才包含
|
||||
const params: { username?: string; password?: string } = {};
|
||||
if (adoptForm.value.username) {
|
||||
params.username = adoptForm.value.username;
|
||||
}
|
||||
if (adoptForm.value.password) {
|
||||
params.password = adoptForm.value.password;
|
||||
}
|
||||
const { error } = await adoptApDevice(
|
||||
selectedSiteId.value,
|
||||
currentDevice.value?.mac || '',
|
||||
adoptForm.value
|
||||
);
|
||||
|
||||
await adoptApDevice(selectedSiteId.value, adoptingDevice.value.mac, params);
|
||||
|
||||
hide();
|
||||
hide();
|
||||
if (!error) {
|
||||
message.success(t('page.apdevice.adoptSuccess'));
|
||||
adoptVisible.value = false;
|
||||
|
||||
// 重新获取列表数据
|
||||
getData();
|
||||
} catch (error) {
|
||||
console.error('Adopt device error:', error);
|
||||
message.error(t('page.apdevice.adoptError'));
|
||||
getData(); // 刷新列表
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 修改表单验证规则的定义
|
||||
const addDeviceRules = {
|
||||
sn: [
|
||||
@@ -555,14 +516,14 @@ const addDeviceRules = {
|
||||
message: t('page.apdevice.snFormatError'),
|
||||
trigger: 'blur'
|
||||
}
|
||||
] ,
|
||||
] as Rule[],
|
||||
name: [
|
||||
{
|
||||
pattern: /^[^ \+\-\@\=]$|^[^ \+\-\@\=].{0,126}[^ ]$/,
|
||||
message: t('page.apdevice.nameFormatError', { test: '@' }),
|
||||
message: t('page.apdevice.nameFormatError'),
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
] as Rule[]
|
||||
};
|
||||
|
||||
// 添加设备的表单数据
|
||||
@@ -583,32 +544,30 @@ const handleAdd = () => {
|
||||
|
||||
// 处理添加设备的确认
|
||||
const handleAddConfirm = async () => {
|
||||
try {
|
||||
// 先验证表单
|
||||
await formRef.value?.validate();
|
||||
await formRef.value?.validate();
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
|
||||
// 构造请求参数,即使所有字段都为空也要发送一个空对象
|
||||
// 构造请求参数,确保 sn 字段存在
|
||||
const deviceParams: Api.Device.AddApDeviceItem = {
|
||||
sn: addDeviceForm.value.sn // sn 是必填的
|
||||
};
|
||||
// 构造请求参数
|
||||
const deviceParams: Api.Device.AddApDeviceItem = {
|
||||
sn: addDeviceForm.value.sn // sn 是必填的
|
||||
};
|
||||
|
||||
// 只添加其他有值的字段
|
||||
if (addDeviceForm.value.name) {
|
||||
deviceParams.name = addDeviceForm.value.name;
|
||||
}
|
||||
if (addDeviceForm.value.username) {
|
||||
deviceParams.username = addDeviceForm.value.username;
|
||||
}
|
||||
if (addDeviceForm.value.password) {
|
||||
deviceParams.password = addDeviceForm.value.password;
|
||||
}
|
||||
// 只添加其他有值的字段
|
||||
if (addDeviceForm.value.name) {
|
||||
deviceParams.name = addDeviceForm.value.name;
|
||||
}
|
||||
if (addDeviceForm.value.username) {
|
||||
deviceParams.username = addDeviceForm.value.username;
|
||||
}
|
||||
if (addDeviceForm.value.password) {
|
||||
deviceParams.password = addDeviceForm.value.password;
|
||||
}
|
||||
|
||||
await addApDevice(selectedSiteId.value, deviceParams);
|
||||
const { error } = await addApDevice(selectedSiteId.value, deviceParams);
|
||||
|
||||
hide();
|
||||
hide();
|
||||
if (!error) {
|
||||
message.success(t('page.apdevice.addSuccess'));
|
||||
addDeviceVisible.value = false;
|
||||
|
||||
@@ -622,9 +581,6 @@ const handleAddConfirm = async () => {
|
||||
|
||||
// 重新获取列表数据
|
||||
getData();
|
||||
} catch (error) {
|
||||
console.error('Add device error:', error);
|
||||
message.error(t('page.apdevice.addError'));
|
||||
}
|
||||
};
|
||||
// 添加表单引用
|
||||
@@ -676,30 +632,25 @@ const currentDevice = ref<Api.Device.ApDevice | null>(null);
|
||||
|
||||
// 处理配置确认
|
||||
const handleConfigConfirm = async () => {
|
||||
try {
|
||||
await configFormRef.value?.validate();
|
||||
await configFormRef.value?.validate();
|
||||
|
||||
if (!currentDevice.value || !selectedSiteId.value) {
|
||||
throw new Error('Missing device or site information');
|
||||
}
|
||||
if (!currentDevice.value || !selectedSiteId.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
const hide = message.loading(t('common.loading'), 0);
|
||||
|
||||
await updateApDeviceConfig(
|
||||
selectedSiteId.value,
|
||||
currentDevice.value.mac,
|
||||
configForm.value
|
||||
);
|
||||
const { error } = await updateApDeviceConfig(
|
||||
selectedSiteId.value,
|
||||
currentDevice.value.mac,
|
||||
configForm.value
|
||||
);
|
||||
|
||||
hide();
|
||||
hide();
|
||||
if (!error) {
|
||||
message.success(t('page.apdevice.configSuccess'));
|
||||
configVisible.value = false;
|
||||
|
||||
// 重新获取列表数据
|
||||
getData();
|
||||
} catch (error) {
|
||||
console.error('Update config error:', error);
|
||||
message.error(t('page.apdevice.configError'));
|
||||
getData(); // 刷新列表
|
||||
}
|
||||
};
|
||||
|
||||
@@ -709,6 +660,7 @@ const configFormRef = ref();
|
||||
onMounted(() => {
|
||||
getSiteList();
|
||||
});
|
||||
|
||||
// 获取状态对应的颜色
|
||||
const getStatusColor = (status: number) => {
|
||||
switch (status) {
|
||||
|
||||
Reference in New Issue
Block a user