fix: bug#16436
This commit is contained in:
parent
3fdd6da033
commit
3577a57c29
|
@ -109,6 +109,7 @@ const emit = defineEmits(['change']);
|
||||||
const bindDeviceRef = ref<Record<string, any>>({});
|
const bindDeviceRef = ref<Record<string, any>>({});
|
||||||
const params = ref<Record<string, any>>({});
|
const params = ref<Record<string, any>>({});
|
||||||
const _selectedRowKeys = ref<string[]>([]);
|
const _selectedRowKeys = ref<string[]>([]);
|
||||||
|
const _selectedRowMap = ref<any[]>([]);
|
||||||
const btnLoading = ref<boolean>(false);
|
const btnLoading = ref<boolean>(false);
|
||||||
|
|
||||||
const statusMap = new Map();
|
const statusMap = new Map();
|
||||||
|
@ -175,10 +176,13 @@ const handleSearch = (e: any) => {
|
||||||
|
|
||||||
const onSelectChange = (keys: string[], rows: string[]) => {
|
const onSelectChange = (keys: string[], rows: string[]) => {
|
||||||
_selectedRowKeys.value = [...keys];
|
_selectedRowKeys.value = [...keys];
|
||||||
|
console.log(rows)
|
||||||
|
_selectedRowMap.value = rows.map(item => ({ deviceId: item.id, deviceName: item.name}))
|
||||||
};
|
};
|
||||||
|
|
||||||
const cancelSelect = () => {
|
const cancelSelect = () => {
|
||||||
_selectedRowKeys.value = [];
|
_selectedRowKeys.value = [];
|
||||||
|
_selectedRowMap.value = []
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOk = () => {
|
const handleOk = () => {
|
||||||
|
@ -187,28 +191,36 @@ const handleOk = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
btnLoading.value = true;
|
btnLoading.value = true;
|
||||||
queryDeviceMapping(instanceStore.current.id, )
|
if (instanceStore.current.accessProvider === 'official-edge-gateway') { // 网关设备
|
||||||
.then(res => {
|
queryDeviceMapping(instanceStore.current.id)
|
||||||
const arr = bindDeviceRef.value?._dataSource.filter(item => {
|
.then(res => {
|
||||||
return !res.result?.[0]?.find(val => val.deviceId === item.id) && _selectedRowKeys.value.includes(item.id);
|
const arr = bindDeviceRef.value?._dataSource.filter(item => {
|
||||||
}).map(item => {
|
return !res.result?.[0]?.find(val => val.deviceId === item.id) && _selectedRowKeys.value.includes(item.id);
|
||||||
return {
|
}).map(item => {
|
||||||
deviceId: item.id,
|
return {
|
||||||
deviceName: item.name
|
deviceId: item.id,
|
||||||
}
|
deviceName: item.name
|
||||||
})
|
}
|
||||||
return saveDeviceMapping(instanceStore.current.id, {info: arr})
|
})
|
||||||
})
|
return saveDeviceMapping(instanceStore.current.id, {info: arr})
|
||||||
.then(res => {
|
}).then(res => {
|
||||||
return bindDevice(detail.value.id, _selectedRowKeys.value)
|
emit('change', true);
|
||||||
}).then(res => {
|
cancelSelect();
|
||||||
emit('change', true);
|
onlyMessage('操作成功');
|
||||||
cancelSelect();
|
})
|
||||||
onlyMessage('操作成功');
|
.finally(() => {
|
||||||
})
|
btnLoading.value = false;
|
||||||
.finally(() => {
|
});
|
||||||
|
} else {
|
||||||
|
bindDevice(detail.value.id, _selectedRowKeys.value).then(res => {
|
||||||
|
emit('change', true);
|
||||||
|
cancelSelect();
|
||||||
|
onlyMessage('操作成功');
|
||||||
|
}).finally(() => {
|
||||||
btnLoading.value = false;
|
btnLoading.value = false;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
|
|
|
@ -4,7 +4,12 @@
|
||||||
<div class="import-content">
|
<div class="import-content">
|
||||||
<p class="import-tip">
|
<p class="import-tip">
|
||||||
<AIcon type="ExclamationCircleOutlined" style="margin-right: 5px" />
|
<AIcon type="ExclamationCircleOutlined" style="margin-right: 5px" />
|
||||||
导入的物模型会覆盖原来的属性、功能、事件、标签,请谨慎操作。
|
<template v-if="type === 'product'">
|
||||||
|
导入的物模型会覆盖原来的属性、功能、事件、标签,请谨慎操作。
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
导入时会根据标识跳过继承自产品物模型的属性、功能、事件、标签。
|
||||||
|
</template>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<j-form layout="vertical" v-model="formModel">
|
<j-form layout="vertical" v-model="formModel">
|
||||||
|
@ -66,6 +71,8 @@ import { useProductStore } from '@/store/product';
|
||||||
import { FILE_UPLOAD } from '@/api/comm';
|
import { FILE_UPLOAD } from '@/api/comm';
|
||||||
import { getToken, onlyMessage } from '@/utils/comm';
|
import { getToken, onlyMessage } from '@/utils/comm';
|
||||||
import { useMetadataStore } from '@/store/metadata';
|
import { useMetadataStore } from '@/store/metadata';
|
||||||
|
import {omit} from "lodash-es";
|
||||||
|
import { Modal } from 'jetlinks-ui-components'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const instanceStore = useInstanceStore()
|
const instanceStore = useInstanceStore()
|
||||||
|
@ -142,6 +149,7 @@ const rules = reactive({
|
||||||
})
|
})
|
||||||
const { validate, validateInfos } = useForm(formModel, rules);
|
const { validate, validateInfos } = useForm(formModel, rules);
|
||||||
const fileList = ref<UploadFile[]>([])
|
const fileList = ref<UploadFile[]>([])
|
||||||
|
const hasVirtualRule = ref(false)
|
||||||
|
|
||||||
const productList = ref<DefaultOptionType[]>([])
|
const productList = ref<DefaultOptionType[]>([])
|
||||||
|
|
||||||
|
@ -177,6 +185,7 @@ const fileChange = (info: UploadChangeParam) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const operateLimits = (mdata: DeviceMetadata) => {
|
const operateLimits = (mdata: DeviceMetadata) => {
|
||||||
|
hasVirtualRule.value = false
|
||||||
const obj: DeviceMetadata = { ...mdata };
|
const obj: DeviceMetadata = { ...mdata };
|
||||||
const old = JSON.parse(instanceStore.detail?.metadata || '{}');
|
const old = JSON.parse(instanceStore.detail?.metadata || '{}');
|
||||||
const fid = instanceStore.detail?.features?.map(item => item.id);
|
const fid = instanceStore.detail?.features?.map(item => item.id);
|
||||||
|
@ -190,6 +199,10 @@ const operateLimits = (mdata: DeviceMetadata) => {
|
||||||
return { ...item, sortsIndex: index };
|
return { ...item, sortsIndex: index };
|
||||||
});
|
});
|
||||||
(obj?.properties || []).map((item, index) => {
|
(obj?.properties || []).map((item, index) => {
|
||||||
|
if (item.expands?.virtualRule) {
|
||||||
|
hasVirtualRule.value = true
|
||||||
|
item.expands = omit(item.expands, ['virtualRule'])
|
||||||
|
}
|
||||||
return { ...item, sortsIndex: index };
|
return { ...item, sortsIndex: index };
|
||||||
});
|
});
|
||||||
(obj?.functions || []).map((item, index) => {
|
(obj?.functions || []).map((item, index) => {
|
||||||
|
@ -244,11 +257,14 @@ const handleImport = async () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { id } = route.params || {}
|
const { id } = route.params || {}
|
||||||
|
const copyOperateLimits = operateLimits(_object as DeviceMetadata)
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
id,
|
id,
|
||||||
metadata: JSON.stringify(operateLimits(_object as DeviceMetadata)),
|
metadata: JSON.stringify(copyOperateLimits),
|
||||||
};
|
};
|
||||||
const paramsDevice = operateLimits(_object as DeviceMetadata)
|
const paramsDevice = copyOperateLimits
|
||||||
|
|
||||||
let resp = undefined
|
let resp = undefined
|
||||||
if (props?.type === 'device') {
|
if (props?.type === 'device') {
|
||||||
resp = await saveMetadata(id as string, paramsDevice)
|
resp = await saveMetadata(id as string, paramsDevice)
|
||||||
|
@ -258,6 +274,12 @@ const handleImport = async () => {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
if (resp.success) {
|
if (resp.success) {
|
||||||
onlyMessage('导入成功')
|
onlyMessage('导入成功')
|
||||||
|
if (hasVirtualRule.value) {
|
||||||
|
Modal.info({
|
||||||
|
title: '导入数据存在虚拟属性,请及时添加虚拟属性计算规则。',
|
||||||
|
okText: '确认'
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (props?.type === 'device') {
|
if (props?.type === 'device') {
|
||||||
await instanceStore.refresh(id as string)
|
await instanceStore.refresh(id as string)
|
||||||
|
@ -265,8 +287,6 @@ const handleImport = async () => {
|
||||||
await productStore.getDetail(id as string)
|
await productStore.getDetail(id as string)
|
||||||
}
|
}
|
||||||
metadataStore.set('importMetadata', true)
|
metadataStore.set('importMetadata', true)
|
||||||
// Store.set(SystemConst.GET_METADATA, true)
|
|
||||||
// Store.set(SystemConst.REFRESH_METADATA_TABLE, true)
|
|
||||||
close();
|
close();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
|
|
Loading…
Reference in New Issue