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