筛选IoTDB设备信息成功
This commit is contained in:
parent
a10acc6613
commit
474f4347ee
File diff suppressed because one or more lines are too long
@ -7104,6 +7104,19 @@ export type PostAggregationBusinessReceiveGetCommandInfoAsyncResponse = (HttpDat
|
||||
|
||||
export type PostAggregationBusinessReceiveGetCommandInfoAsyncError = unknown;
|
||||
|
||||
export type PostAggregationBusinessCallDeviceServiceToOneNetForApiAsyncData = {
|
||||
query?: {
|
||||
/**
|
||||
* 开放接口请求入参,所有外部接口请求参数
|
||||
*/
|
||||
input?: OpenApiRequest;
|
||||
};
|
||||
};
|
||||
|
||||
export type PostAggregationBusinessCallDeviceServiceToOneNetForApiAsyncResponse = (HttpDataResult);
|
||||
|
||||
export type PostAggregationBusinessCallDeviceServiceToOneNetForApiAsyncError = unknown;
|
||||
|
||||
export type GetCommonGetSelectListData = {
|
||||
query?: {
|
||||
input?: SelectResultListInput;
|
||||
@ -7374,6 +7387,16 @@ export type PostAggregationDeviceRepushDeviceInfoToIoTplatformResponse = (Device
|
||||
|
||||
export type PostAggregationDeviceRepushDeviceInfoToIoTplatformError = unknown;
|
||||
|
||||
export type PostAggregationDeviceRecoverDeviceToOneNetData = {
|
||||
query?: {
|
||||
input?: IdInput;
|
||||
};
|
||||
};
|
||||
|
||||
export type PostAggregationDeviceRecoverDeviceToOneNetResponse = (DeviceManagementInfoDto);
|
||||
|
||||
export type PostAggregationDeviceRecoverDeviceToOneNetError = unknown;
|
||||
|
||||
export type PostAggregationDeviceEnableDeviceForApiAsyncData = {
|
||||
query?: {
|
||||
input?: EnableDeviceForApiInput;
|
||||
|
||||
@ -43,6 +43,7 @@ import {
|
||||
postAggregationDeviceDeviceUpgradeForApiAsync,
|
||||
postAggregationDeviceEnableDeviceForApiAsync,
|
||||
postAggregationDeviceGetDevicePropertyValueForApiAsync,
|
||||
postAggregationDeviceRecoverDeviceToOneNet,
|
||||
postAggregationDeviceRepushDeviceInfoToIoTplatform,
|
||||
postAggregationDeviceUpdateDeviceSecKeyForApiAsync,
|
||||
postDeviceInfoCacheDeviceDataToRedis,
|
||||
@ -2165,6 +2166,55 @@ const repushDeviceInfo = async (row: Record<string, any>) => {
|
||||
loadingTip.value = '缓存刷新中...';
|
||||
}
|
||||
};
|
||||
|
||||
/** 物联网平台枚举:2=移动OneNET,3=EMQX */
|
||||
const IOT_PLATFORM_ONENET = 2;
|
||||
const IOT_PLATFORM_EMQX = 3;
|
||||
|
||||
/**
|
||||
* 是否允许"改投 OneNET"(与后端闸门一致):
|
||||
* 已是 OneNET 不显示;EMQX 恒放开(仅本地建档、无外部注册);
|
||||
* 其余平台仅在"未真实推送成功"时放开。
|
||||
*/
|
||||
function canRecoverToOneNET(row: Record<string, any>): boolean {
|
||||
const platform = Number(row?.ioTPlatform);
|
||||
if (platform === IOT_PLATFORM_ONENET) return false;
|
||||
if (platform === IOT_PLATFORM_EMQX) return true;
|
||||
return !row?.isPlatformPushSuccess;
|
||||
}
|
||||
|
||||
// 改投设备平台到 OneNET(平台纠错:主要用于误选 EMQX 的设备)
|
||||
const recoverDeviceToOneNET = (row: Record<string, any>) => {
|
||||
const deviceLabel = row.deviceName || row.deviceAddress || '';
|
||||
Modal.confirm({
|
||||
title: '确认改投 OneNET?',
|
||||
content: `设备:${deviceLabel}。将把平台切换为 OneNET 并向 OneNET 注册(平台若已存在该设备则回填密钥),请确认无误。`,
|
||||
okText: '改投 OneNET',
|
||||
cancelText: $t('common.cancel'),
|
||||
onOk: async () => {
|
||||
try {
|
||||
pageLoading.value = true;
|
||||
loadingTip.value = '改投 OneNET 中...';
|
||||
const result = await postAggregationDeviceRecoverDeviceToOneNet({
|
||||
body: { id: row.id },
|
||||
});
|
||||
if (result.data) {
|
||||
Message.success('改投 OneNET 成功');
|
||||
gridApi.reload();
|
||||
} else {
|
||||
Message.error('改投 OneNET 失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('改投 OneNET 失败:', error);
|
||||
Message.error('改投 OneNET 失败');
|
||||
} finally {
|
||||
pageLoading.value = false;
|
||||
loadingTip.value = '缓存刷新中...';
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const openAddModal = async () => {
|
||||
editRow.value = {};
|
||||
userModalApi.open();
|
||||
@ -3428,6 +3478,11 @@ const [DeviceDataFlowModal, deviceDataFlowModalApi] = useVbenModal({
|
||||
style="padding: 4px 8px; text-align: left">
|
||||
重推设备信息
|
||||
</Button>
|
||||
<Button v-if="canRecoverToOneNET(row)" type="text" size="small"
|
||||
@click="recoverDeviceToOneNET.bind(null, row)()"
|
||||
style="padding: 4px 8px; color: #1677ff; text-align: left">
|
||||
改投 OneNET
|
||||
</Button>
|
||||
<Button type="text" size="small" @click="openDataFlowModal.bind(null, row)()"
|
||||
style="padding: 4px 8px; text-align: left">
|
||||
数据流转配置
|
||||
|
||||
@ -40,6 +40,12 @@ const query = ref({
|
||||
const total = ref(0);
|
||||
const loading = ref<boolean>(false);
|
||||
const searchInput = ref<string>('');
|
||||
// 预设加载(如从设备列表跳转带入地址)后,自动选中返回列表的第一个元素并对外抛出,
|
||||
// 以便父级表单以真实设备标识触发查询;仅由预设/初始路径置位,手动搜索/翻页不置位。
|
||||
const pendingAutoSelectFirst = ref<boolean>(false);
|
||||
// 选中值时 antd Select 会清空搜索框并触发一次 @search(''),用此标志抑制该次“空搜索”,
|
||||
// 避免清掉当前地址过滤、导致 DevicePatchListAsync 丢失设备地址并冲掉已选项。
|
||||
const suppressEmptySearchOnce = ref<boolean>(false);
|
||||
|
||||
// 最大页码
|
||||
const maxPage = computed(() => {
|
||||
@ -74,6 +80,22 @@ const fetchData = async () => {
|
||||
...item,
|
||||
}));
|
||||
total.value = data.totalCount || 0;
|
||||
|
||||
// 预设加载后自动选中第一个:过滤返回的设备标识(item.Device)通常与传入的原始地址不完全相等,
|
||||
// 若不主动选中,值匹配不到选项、表格也无法以真实标识发起查询。
|
||||
if (pendingAutoSelectFirst.value) {
|
||||
pendingAutoSelectFirst.value = false;
|
||||
if (options.value.length > 0) {
|
||||
const first = options.value[0];
|
||||
// 设置值会触发 antd 的空搜索,抑制之,避免清掉刚加载的地址过滤与选项
|
||||
suppressEmptySearchOnce.value = true;
|
||||
if (props.value !== first.value) {
|
||||
emit('update:value', first.value);
|
||||
emit('change', first.value);
|
||||
}
|
||||
emit('device-change', first);
|
||||
}
|
||||
}
|
||||
}
|
||||
loading.value = false;
|
||||
} catch (error) {
|
||||
@ -86,6 +108,11 @@ const fetchData = async () => {
|
||||
* 处理搜索输入
|
||||
*/
|
||||
const handleSearch = useDebounceFn((value: string) => {
|
||||
// 抑制“选中即清空搜索”引发的空搜索,避免清掉地址过滤、丢失设备地址
|
||||
if (!value && suppressEmptySearchOnce.value) {
|
||||
suppressEmptySearchOnce.value = false;
|
||||
return;
|
||||
}
|
||||
query.value.deviceAddress = value;
|
||||
query.value.pageIndex = 1; // 搜索时重置到第一页
|
||||
fetchData();
|
||||
@ -112,8 +139,11 @@ watch(
|
||||
() => props.ioTDataType,
|
||||
(newVal) => {
|
||||
query.value.pageIndex = 1;
|
||||
query.value.deviceAddress = ''; // 重置搜索关键词
|
||||
// 有预设值(如从设备列表跳转带入的设备地址)时按其过滤加载,确保目标设备出现在选项,
|
||||
// 并在加载完成后自动选中第一个;否则按空关键词加载第一页
|
||||
query.value.deviceAddress = props.value || '';
|
||||
searchInput.value = '';
|
||||
pendingAutoSelectFirst.value = !!props.value;
|
||||
if (newVal) {
|
||||
fetchData();
|
||||
} else {
|
||||
@ -124,8 +154,35 @@ watch(
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// 监听预设值(如从设备列表跳转带入的设备地址):当地址在挂载后才到达时,
|
||||
// 兜底把该地址作为过滤参数传给 DevicePatchListAsync,确保目标设备被查出并回显。
|
||||
// 防重复:已按该地址加载或该值已在选项中则跳过。
|
||||
watch(
|
||||
() => props.value,
|
||||
(newVal) => {
|
||||
if (!newVal || !props.ioTDataType) {
|
||||
return;
|
||||
}
|
||||
if (query.value.deviceAddress === newVal) {
|
||||
return;
|
||||
}
|
||||
if (options.value.some((option) => option.value === newVal)) {
|
||||
return;
|
||||
}
|
||||
query.value.pageIndex = 1;
|
||||
query.value.deviceAddress = newVal;
|
||||
pendingAutoSelectFirst.value = true;
|
||||
fetchData();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// 处理值变化
|
||||
const handleValueChange = (value: string) => {
|
||||
// 选中值会触发 antd 的空搜索,抑制之,避免清掉当前地址过滤
|
||||
if (value) {
|
||||
suppressEmptySearchOnce.value = true;
|
||||
}
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
|
||||
|
||||
@ -376,16 +376,19 @@ const initializeGrid = async () => {
|
||||
updatedValues.IoTDataType = IoTDataType as string;
|
||||
}
|
||||
|
||||
if (updatedValues !== currentValues) {
|
||||
await gridApi.formApi.setValues(updatedValues);
|
||||
// 等待表单值更新完成
|
||||
await nextTick();
|
||||
}
|
||||
// 回填路由带来的数据类型与设备地址(触发数据类型选择、设备下拉按类型/地址加载)
|
||||
await gridApi.formApi.setValues(updatedValues);
|
||||
// 等待表单值更新完成
|
||||
await nextTick();
|
||||
|
||||
// 延迟清除初始化标志,让表单值变化监听来处理查询
|
||||
setTimeout(() => {
|
||||
isInitializing.value = false;
|
||||
}, 200);
|
||||
isInitializing.value = false;
|
||||
|
||||
// 初始值不会触发 handleValuesChange,这里显式触发查询表单。
|
||||
// 用无参 reload 读取最新表单值:设备下拉可能已自动选中真实设备标识(与传入原始地址不同);
|
||||
// 若此刻尚未选中,稍后自动选中会再经 handleValuesChange 触发一次查询兜底。
|
||||
if (updatedValues.IoTDataType && updatedValues.DeviceAddress) {
|
||||
await gridApi.reload();
|
||||
}
|
||||
} else {
|
||||
isInitializing.value = false;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user