diff --git a/src/composables/data/useDataMonitoring.ts b/src/composables/data/useDataMonitoring.ts index e2bb2021..27aa3843 100644 --- a/src/composables/data/useDataMonitoring.ts +++ b/src/composables/data/useDataMonitoring.ts @@ -1,8 +1,7 @@ -import { queryGroupList, queryTagList } from '@/api/config' +import { queryGroupList, queryTagList, querySouthDriverList } from '@/api/config' import { getMonitoringData } from '@/api/data' -import useSouthDriver from '@/composables/config/useSouthDriver' import useWriteDataCheckNParse from '@/composables/data/useWriteDataCheckNParse' -import type { GroupData, TagForm } from '@/types/config' +import type { GroupData, TagForm, RawDriverData } from '@/types/config' import type { TagDataInMonitoring } from '@/types/data' import { TagAttributeType, TagType } from '@/types/enums' import { paginate, listOrderByKey } from '@/utils/utils' @@ -29,7 +28,7 @@ export default () => { const { t } = useI18n() const store = useStore() - const { totalSouthDriverList: nodeList } = useSouthDriver() + const nodeList: Ref> = ref([]) const groupList: Ref> = ref([]) const { findLabelByValue: findTagTypeLabelByValue } = useTagTypeSelect() @@ -105,7 +104,7 @@ export default () => { const reSubAfterReturnError = async () => { const { groupName, lastTimestamp, count } = reSubCount - const { node, groupName: currentGroupName } = currentGroup.value + const { groupName: currentGroupName } = currentGroup.value let canReSubAndRequest = false if (Date.now() - lastTimestamp < 500 && groupName === currentGroupName && count < 3) { canReSubAndRequest = true @@ -228,6 +227,18 @@ export default () => { keywordSearch.value = '' } + const initCurrentGroupName = async () => { + const { node, groupName } = currentGroup.value + + // reset default value when remove a node. + const group = groupList.value.find(({ name }) => name === groupName) + currentGroup.value.groupName = group?.name || '' + + if (node && currentGroup.value.groupName) { + await getTagList() + } + } + // change node const selectedNodeChanged = async (nodeName: string) => { if (nodeName) { @@ -237,10 +248,9 @@ export default () => { totalData.value = [] const data = await queryGroupList(currentGroup.value.node.toString()) - const isExistGroup = data.find((group) => group.name === currentGroup.value.groupName) - currentGroup.value.groupName = isExistGroup?.name || '' - groupList.value = data + + await initCurrentGroupName() } catch (error) { groupList.value = [] } @@ -304,18 +314,40 @@ export default () => { return item.attribute && item.attribute.some((attr) => attr === TagAttributeType.Write) } - const initTagList = async () => { - const { node, groupName } = currentGroup.value - if (node) { - await selectedNodeChanged(node) + const getSouthNodeList = async () => { + try { + nodeList.value = await querySouthDriverList() + return Promise.resolve(nodeList.value) + } catch (error) { + nodeList.value = [] + return Promise.reject(error) } - if (node && groupName) { - await getTagList() + } + + const initCurrentNode = async () => { + const { node } = currentGroup.value + + // reset default value when remove a node. + if (node && !currentNodeName.value) { + currentGroup.value = { + node: '', + groupName: '', + } } + + if (currentGroup.value.node) { + await selectedNodeChanged(node) + } + } + + const initTagList = async () => { + await initCurrentNode() + await initCurrentGroupName() } - onMounted(() => { - initTagList() + onMounted(async () => { + await getSouthNodeList() + await initTagList() }) onUnmounted(() => {