fix: 修改jetlinks-store
This commit is contained in:
parent
e3ef99cbe1
commit
b03dd8846e
|
@ -0,0 +1,17 @@
|
|||
import { defineStore } from "pinia";
|
||||
|
||||
export const useTypeStore = defineStore({
|
||||
id: 'type',
|
||||
state: () => ({
|
||||
configRef: [] as any,
|
||||
resourcesClusters: {} as any,
|
||||
}),
|
||||
actions: {
|
||||
setConfigRef(current: any[]) {
|
||||
this.configRef = current
|
||||
},
|
||||
setResourcesClusters(current: any) {
|
||||
this.resourcesClusters = current
|
||||
}
|
||||
}
|
||||
})
|
|
@ -156,13 +156,10 @@
|
|||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { save, update } from '@/api/data-collect/collector';
|
||||
import { Store } from 'jetlinks-store';
|
||||
import { LeftTreeRules } from '../../data';
|
||||
import type { FormInstance } from 'ant-design-vue';
|
||||
|
||||
const loading = ref(false);
|
||||
const channelListAll = ref();
|
||||
const channelList = ref();
|
||||
const visibleEndian = ref(false);
|
||||
const visibleUnitId = ref(false);
|
||||
|
||||
|
@ -171,6 +168,10 @@ const props = defineProps({
|
|||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
channelListAll: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['change']);
|
||||
|
@ -178,6 +179,16 @@ const emit = defineEmits(['change']);
|
|||
const id = props.data.id;
|
||||
const formRef = ref<FormInstance>();
|
||||
|
||||
const _channelListAll = computed(() => {
|
||||
return props.channelListAll || [];
|
||||
})
|
||||
const channelList = computed(() => {
|
||||
return _channelListAll.value.map((item: any) => ({
|
||||
value: item.id,
|
||||
label: item.name,
|
||||
}));
|
||||
})
|
||||
|
||||
|
||||
const endianData = computed(() => {
|
||||
const { endian, endianIn } = formData.value.configuration;
|
||||
|
@ -213,7 +224,7 @@ const formData = ref({
|
|||
const handleOk = async () => {
|
||||
const data = await formRef.value?.validate();
|
||||
|
||||
const { provider, name } = channelListAll.value.find(
|
||||
const { provider, name } = _channelListAll.value.find(
|
||||
(item: any) => item.id === formData.value.channelId,
|
||||
);
|
||||
const params = {
|
||||
|
@ -252,14 +263,6 @@ const changeCardSelectEndian = (value: Array<string>) => {
|
|||
const changeCardSelectEndianIn = (value: Array<string>) => {
|
||||
formData.value.configuration.endianIn = value[0];
|
||||
};
|
||||
const getChannelNoPaging = async () => {
|
||||
channelListAll.value = Store.get('channelListAll');
|
||||
channelList.value = channelListAll.value.map((item) => ({
|
||||
value: item.id,
|
||||
label: item.name,
|
||||
}));
|
||||
};
|
||||
getChannelNoPaging();
|
||||
|
||||
const filterOption = (input: string, option: any) => {
|
||||
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
|
||||
|
@ -268,7 +271,7 @@ const filterOption = (input: string, option: any) => {
|
|||
watch(
|
||||
() => formData.value.channelId,
|
||||
(value) => {
|
||||
const dt = channelListAll.value.find((item) => item.id === value);
|
||||
const dt = _channelListAll.value.find((item) => item.id === value);
|
||||
visibleUnitId.value = visibleEndian.value =
|
||||
dt?.provider && dt?.provider === 'MODBUS_TCP';
|
||||
},
|
||||
|
|
|
@ -111,7 +111,7 @@
|
|||
</j-tree>
|
||||
<j-empty v-else description="暂无数据" />
|
||||
</j-spin>
|
||||
<Save v-if="visible" :data="current" @change="saveChange" />
|
||||
<Save :channelListAll="channelListAll" v-if="visible" :data="current" @change="saveChange" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -124,7 +124,6 @@ import {
|
|||
} from '@/api/data-collect/collector';
|
||||
import Save from './Save/index.vue';
|
||||
import { onlyMessage } from '@/utils/comm';
|
||||
import { Store } from 'jetlinks-store';
|
||||
import _ from 'lodash';
|
||||
import { colorMap } from '../data.ts';
|
||||
|
||||
|
@ -144,6 +143,7 @@ const searchValue = ref();
|
|||
const visible = ref(false);
|
||||
const current = ref({});
|
||||
const collectorAll = ref();
|
||||
const channelListAll = ref<any[]>([])
|
||||
|
||||
const root = [
|
||||
{
|
||||
|
@ -274,8 +274,8 @@ const handleSearch = async (value: any) => {
|
|||
};
|
||||
const getChannelNoPaging = async () => {
|
||||
|
||||
const res = await queryChannelNoPaging();
|
||||
Store.set('channelListAll', res.result);
|
||||
const res: any = await queryChannelNoPaging();
|
||||
channelListAll.value = res.result;
|
||||
};
|
||||
|
||||
const treeSelect = (keys: string, e: any) => {
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
:bodyStyle="{ padding: 0 }"
|
||||
:defaultParams="defaultParams"
|
||||
>
|
||||
<template #rightExtraRender>
|
||||
<!-- <template #rightExtraRender>
|
||||
<j-popconfirm title="确认全部已读?" @confirm="onAllRead">
|
||||
<j-button type="primary">全部已读</j-button>
|
||||
</j-popconfirm>
|
||||
</template>
|
||||
</template> -->
|
||||
<template #topicProvider="slotProps">
|
||||
{{ slotProps.topicName }}
|
||||
</template>
|
||||
|
@ -240,14 +240,14 @@ watchEffect(() => {
|
|||
}
|
||||
});
|
||||
|
||||
const onAllRead = async () => {
|
||||
const resp = await changeAllStatus('_read', getType.value);
|
||||
if (resp.status === 200) {
|
||||
onlyMessage('操作成功!');
|
||||
refresh();
|
||||
user.updateAlarm();
|
||||
}
|
||||
};
|
||||
// const onAllRead = async () => {
|
||||
// const resp = await changeAllStatus('_read', getType.value);
|
||||
// if (resp.status === 200) {
|
||||
// onlyMessage('操作成功!');
|
||||
// refresh();
|
||||
// user.updateAlarm();
|
||||
// }
|
||||
// };
|
||||
|
||||
onMounted(() => {
|
||||
if (routerParams.params?.value.row) {
|
||||
|
|
|
@ -59,7 +59,6 @@ import { DataTypeList, FileTypeList } from '@/views/device/data';
|
|||
import { DefaultOptionType, SelectValue } from 'ant-design-vue/es/select';
|
||||
import { PropType } from 'vue'
|
||||
import { getUnit } from '@/api/device/instance';
|
||||
import { Store } from 'jetlinks-store';
|
||||
import InputSelect from '@/components/InputSelect/index.vue';
|
||||
import BooleanParam from '@/components/Metadata/BooleanParam/index.vue'
|
||||
import EnumParam from '@/components/Metadata/EnumParam/index.vue'
|
||||
|
@ -140,7 +139,6 @@ const unit = reactive({
|
|||
value: item.id,
|
||||
}));
|
||||
// 缓存单位数据
|
||||
Store.set('units', _data);
|
||||
unit.unitOptions = _data;
|
||||
})
|
||||
},
|
||||
|
|
|
@ -12,8 +12,13 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { Store } from "jetlinks-store"
|
||||
import { resourceClustersById } from "@/api/link/type"
|
||||
import { useTypeStore } from "@/store/type"
|
||||
import { cloneDeep } from "lodash-es"
|
||||
import { storeToRefs } from "pinia"
|
||||
|
||||
const _typeStore = useTypeStore()
|
||||
const { resourcesClusters } = storeToRefs(_typeStore)
|
||||
|
||||
const props = defineProps({
|
||||
value: {
|
||||
|
@ -36,7 +41,7 @@ const host = ref<string>()
|
|||
const options = ref<any[]>([])
|
||||
|
||||
const getResourcesClustersById = async (id: string) => {
|
||||
const _value = Store.get('resourcesClusters')?.[id]
|
||||
const _value = resourcesClusters.value?.[id]
|
||||
if(!_value){
|
||||
const resp = await resourceClustersById(id)
|
||||
if (resp.status === 200) {
|
||||
|
@ -44,15 +49,15 @@ const getResourcesClustersById = async (id: string) => {
|
|||
const checkedHost = [{ value: checked?.host, label: checked?.host }];
|
||||
options.value = checked ? checkedHost : []
|
||||
|
||||
const resourcesClusters = Store.get('resourcesClusters') || {}
|
||||
resourcesClusters[id] = resp.result
|
||||
Store.set('resourcesClusters', resourcesClusters)
|
||||
const _resourcesClusters = cloneDeep(resourcesClusters.value)
|
||||
_resourcesClusters[id] = resp.result
|
||||
_typeStore.setResourcesClusters(_resourcesClusters)
|
||||
emit('valueChange', props.value)
|
||||
} else {
|
||||
options.value = []
|
||||
}
|
||||
} else {
|
||||
const checked = Store.get('resourcesClusters')?.[id]?.[0]
|
||||
const checked = resourcesClusters.value?.[id]?.[0]
|
||||
const checkedHost = [{ value: checked?.host, label: checked?.host }];
|
||||
options.value = checked ? checkedHost : []
|
||||
}
|
||||
|
|
|
@ -1143,9 +1143,10 @@ import {
|
|||
} from '../data';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import type { FormData2Type, FormDataType } from '../type';
|
||||
import { Store } from 'jetlinks-store';
|
||||
import LocalAddressSelect from './LocalAddressSelect.vue';
|
||||
import { isNoCommunity } from '@/utils/utils';
|
||||
import { useTypeStore } from '@/store/type';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
const route = useRoute();
|
||||
const NetworkType = route.query.type as string;
|
||||
|
@ -1157,6 +1158,9 @@ const formRef1 = ref<FormInstance>();
|
|||
const formRef2 = ref<FormInstance>();
|
||||
const shareCluster = ref(true);
|
||||
|
||||
const _typeStore = useTypeStore()
|
||||
const { configRef, resourcesClusters } = storeToRefs(_typeStore)
|
||||
|
||||
const formData = ref<FormDataType>({
|
||||
...FormStates,
|
||||
});
|
||||
|
@ -1198,7 +1202,7 @@ const filterPortOption = (input: string, option: any) => {
|
|||
|
||||
const getPortList = (list: any[], id: string) => {
|
||||
const keys = dynamicValidateForm?.cluster?.map?.(item => item.configuration?.port) || []
|
||||
console.log(dynamicValidateForm?.cluster, id, keys)
|
||||
// console.log(dynamicValidateForm?.cluster, id, keys)
|
||||
return (list || []).filter(item => item.value === id || !keys.includes(item.value) )
|
||||
}
|
||||
|
||||
|
@ -1251,7 +1255,7 @@ const changeType = (value: string) => {
|
|||
const updateClustersListIndex = () => {
|
||||
const { cluster } = dynamicValidateForm;
|
||||
const filters = cluster?.map((item) => item.serverId);
|
||||
const newConfigRef = shareCluster.value ? Store.get('configRef')?.filter(
|
||||
const newConfigRef = shareCluster.value ? (configRef.value || [])?.filter(
|
||||
(item: any) => !filters.includes(item.clusterNodeId),
|
||||
) : configClustersList.value?.filter(
|
||||
(item: any) => !filters.includes(item.id),
|
||||
|
@ -1299,7 +1303,7 @@ const changeHost = (
|
|||
if(!flag){
|
||||
configuration.port = undefined;
|
||||
}
|
||||
const checked = Store.get('resourcesClusters')?.[serverId || '']
|
||||
const checked = resourcesClusters.value?.[serverId || '']
|
||||
if(checked){
|
||||
getPortOptions(checked, index)
|
||||
}
|
||||
|
@ -1387,14 +1391,15 @@ const getCertificates = async () => {
|
|||
};
|
||||
|
||||
const getResourcesCurrent = () => {
|
||||
resourcesCurrent().then((resp) => {
|
||||
resourcesCurrent().then((resp: any) => {
|
||||
if (resp.status === 200) {
|
||||
_typeStore.setConfigRef(resp.result || [])
|
||||
|
||||
const clusterNodeId = resp.result?.[0]?.clusterNodeId
|
||||
const resourcesClusters = Store.get('resourcesClusters') || {}
|
||||
resourcesClusters[clusterNodeId] = resp.result
|
||||
Store.set('resourcesClusters', resourcesClusters)
|
||||
Store.set('configRef', resp.result);
|
||||
getPortOptions(Store.get('resourcesClusters')?.[clusterNodeId]);
|
||||
const _resourcesClusters = cloneDeep(resourcesClusters.value || {})
|
||||
_resourcesClusters[clusterNodeId] = resp.result
|
||||
_typeStore.setResourcesClusters(_resourcesClusters)
|
||||
getPortOptions(resp.result);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -1422,11 +1427,6 @@ const getDetail = () => {
|
|||
...cloneDeep(Configuration), //防止编辑时,表单字段不完善,导致输入/选择框新出现时找不到
|
||||
...configuration,
|
||||
};
|
||||
|
||||
// const configRef = Store.get('configRef').filter(
|
||||
// (item: any) => item.host === '0.0.0.0',
|
||||
// );
|
||||
// getPortOptions(configRef); //更新端口
|
||||
} else {
|
||||
dynamicValidateForm.cluster = cluster;
|
||||
// const arr = cluster.map((item: any) => item.configuration.serverId)
|
||||
|
@ -1479,7 +1479,7 @@ watch(
|
|||
(value) => {
|
||||
formData.value.shareCluster = value;
|
||||
value
|
||||
? getPortOptions(Store.get('configRef'))
|
||||
? getPortOptions(configRef.value)
|
||||
: (portOptionsIndex.value[0] = []);
|
||||
updateClustersListIndex();
|
||||
},
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
告警级别
|
||||
</div>
|
||||
<div>
|
||||
{{ (Store.get('default-level') || []).find((item: any) => item?.level === slotProps.level)?.title ||
|
||||
{{ (defaultLevel || []).find((item: any) => item?.level === slotProps.level)?.title ||
|
||||
slotProps.level }}
|
||||
</div>
|
||||
</j-col>
|
||||
|
@ -124,11 +124,11 @@
|
|||
<template #level="slotProps">
|
||||
<j-tooltip
|
||||
placement="topLeft"
|
||||
:title="(Store.get('default-level') || []).find((item) => item?.level === slotProps.level)?.title ||
|
||||
:title="(defaultLevel || []).find((item) => item?.level === slotProps.level)?.title ||
|
||||
slotProps.level"
|
||||
>
|
||||
<div class="ellipsis">
|
||||
{{ (Store.get('default-level') || []).find((item) => item?.level === slotProps.level)?.title ||
|
||||
{{ (defaultLevel || []).find((item) => item?.level === slotProps.level)?.title ||
|
||||
slotProps.level }}
|
||||
</div>
|
||||
</j-tooltip>
|
||||
|
@ -196,7 +196,6 @@ import {
|
|||
getScene,
|
||||
} from '@/api/rule-engine/configuration';
|
||||
import { queryLevel } from '@/api/rule-engine/config';
|
||||
import { Store } from 'jetlinks-store';
|
||||
import type { ActionsType } from '@/components/Table/index.vue';
|
||||
import { getImage, onlyMessage } from '@/utils/comm';
|
||||
import { useMenuStore } from '@/store/menu';
|
||||
|
@ -352,6 +351,8 @@ const columns = [
|
|||
const visible = ref<boolean>(false);
|
||||
const current = ref<any>({});
|
||||
|
||||
const defaultLevel = ref<any[]>([]);
|
||||
|
||||
const map = {
|
||||
product: '产品',
|
||||
device: '设备',
|
||||
|
@ -380,7 +381,7 @@ const handleSearch = (e: any) => {
|
|||
const queryDefaultLevel = () => {
|
||||
queryLevel().then((res) => {
|
||||
if (res.status === 200) {
|
||||
Store.set('default-level', res.result?.levels || []);
|
||||
defaultLevel.value = res.result?.levels || [];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -30,13 +30,11 @@
|
|||
<j-descriptions-item label="告警级别" :span="1">
|
||||
<j-tooltip
|
||||
placement="topLeft"
|
||||
:title="(Store.get('default-level') || []).find((item: any) => item?.level === data?.level)
|
||||
?.title || props.data?.level"
|
||||
:title="_level"
|
||||
>
|
||||
<Ellipsis>
|
||||
<span>
|
||||
{{(Store.get('default-level') || []).find((item: any) => item?.level === data?.level)
|
||||
?.title || props.data?.level}}
|
||||
{{_level}}
|
||||
</span>
|
||||
</Ellipsis>
|
||||
</j-tooltip>
|
||||
|
@ -60,8 +58,8 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { queryLevel } from '@/api/rule-engine/config';
|
||||
import dayjs from 'dayjs';
|
||||
import { Store } from 'jetlinks-store';
|
||||
import JsonViewer from 'vue-json-viewer';
|
||||
const props = defineProps({
|
||||
data: Object,
|
||||
|
@ -70,11 +68,24 @@ const props = defineProps({
|
|||
const data = computed(()=>{
|
||||
return JSON.parse(props.data?.alarmInfo);
|
||||
})
|
||||
const defaultLevel = ref<any[]>([])
|
||||
|
||||
const emit = defineEmits(['close']);
|
||||
const closeModal = () => {
|
||||
emit('close');
|
||||
};
|
||||
|
||||
const _level = computed(() => {
|
||||
return (defaultLevel.value || []).find((item: any) => item?.level === props.data?.level)?.title || props.data?.level
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
queryLevel().then((res)=>{
|
||||
if(res.status === 200 ){
|
||||
defaultLevel.value = res.result?.levels || [];
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
</style>
|
|
@ -138,7 +138,6 @@ import { queryLevel } from '@/api/rule-engine/config';
|
|||
import Search from '@/components/Search';
|
||||
import { useAlarmStore } from '@/store/alarm';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { Store } from 'jetlinks-store';
|
||||
import dayjs from 'dayjs';
|
||||
import type { ActionsType } from '@/components/Table';
|
||||
import SolveComponent from '../SolveComponent/index.vue';
|
||||
|
@ -149,10 +148,10 @@ const menuStory = useMenuStore();
|
|||
const tableRef = ref();
|
||||
const alarmStore = useAlarmStore();
|
||||
const { data } = storeToRefs(alarmStore);
|
||||
|
||||
const getDefaulitLevel = () => {
|
||||
queryLevel().then((res) => {
|
||||
if (res.status === 200) {
|
||||
Store.set('default-level', res.result?.levels || []);
|
||||
data.value.defaultLevel = res.result?.levels || [];
|
||||
}
|
||||
});
|
||||
|
|
|
@ -9,7 +9,6 @@ import { isNoCommunity } from '@/utils/utils';
|
|||
import { useAlarmStore } from '@/store/alarm';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { queryLevel } from '@/api/rule-engine/config';
|
||||
import { Store } from 'jetlinks-store';
|
||||
import TableComponents from './TabComponent/index.vue';
|
||||
const list = [
|
||||
{
|
||||
|
@ -56,7 +55,6 @@ const { data } = storeToRefs(alarmStore);
|
|||
const getDefaulitLevel = () => {
|
||||
queryLevel().then((res)=>{
|
||||
if(res.status === 200 ){
|
||||
Store.set('default-level', res.result?.levels || []);
|
||||
data.value.defaultLevel = res.result?.levels || [];
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue