iscs 生成uid代码调整

This commit is contained in:
joylink_cuiweidong 2020-01-19 13:49:55 +08:00
parent 0bb7b11271
commit d957ea049b
8 changed files with 66 additions and 56 deletions

View File

@ -6,6 +6,7 @@ import Painter from './painter';
import deviceType from './constant/deviceType'; import deviceType from './constant/deviceType';
import {calculateDCenter, createBoundingRect, deviceFactory} from './utils/parser'; import {calculateDCenter, createBoundingRect, deviceFactory} from './utils/parser';
import { updateIscsData } from './utils/parser'; import { updateIscsData } from './utils/parser';
import store from '@/store';
const renderer = 'canvas'; const renderer = 'canvas';
const devicePixelRatio = 1; const devicePixelRatio = 1;
@ -120,7 +121,7 @@ class Iscs {
(list || []).forEach(elem => { (list || []).forEach(elem => {
const code = elem.code; const code = elem.code;
const type = elem._type; const type = elem._type;
updateIscsData(elem); // updateIscsData(store.state.iscs, elem);
const oDevice = this.iscsDevice[code] || deviceFactory(type, elem); const oDevice = this.iscsDevice[code] || deviceFactory(type, elem);
const nDevice = deviceFactory(type, Object.assign(oDevice.model || {}, elem)); const nDevice = deviceFactory(type, Object.assign(oDevice.model || {}, elem));
delete this.iscsDevice[code]; delete this.iscsDevice[code];

View File

@ -2,7 +2,7 @@ export function getUID(type, list) {
if (list && list.length > 0) { if (list && list.length > 0) {
const lastCode = list[list.length - 1].code; const lastCode = list[list.length - 1].code;
const num = lastCode.split(type + '_')[1]; const num = lastCode.split(type + '_')[1];
return type + `_${num + 1}`; return type + `_${parseInt(num) + 1}`;
} else { } else {
return type + `_1`; return type + `_1`;
} }

View File

@ -112,85 +112,94 @@ export function parser(data) {
return iscsDevice; return iscsDevice;
} }
function updateIscsListByDevice(iscs, name, device) { function updateIscsListByDevice(state, name, device) {
var list = iscs[name]; // var list = iscs[name];
if (list) { const list = state.iscs[name];
if (list && list instanceof Array) {
const index = list.findIndex(elem => { return elem.code == device.code; }); const index = list.findIndex(elem => { return elem.code == device.code; });
if (index >= 0) { if (device._dispose) {
device._dispose ? list.splice(index, 1) : list[index] = deepClone(device); index >= 0 && list.splice(index, 1); // 删除
} else { } else if (!list[index]) {
list.push(deepClone(device)); list.push(deepClone(device)); // 新增
} else if (index >= 0) {
list[index] = deepClone(device); // item map 数据 model 页面表单数据
} }
// if (index >= 0) {
// device._dispose ? list.splice(index, 1) : list[index] = deepClone(device);
// } else {
// list.push(deepClone(device));
// }
} else { } else {
iscs[name] = [device]; // list[name] = [device];
state.iscs[name] = [device];
} }
return list; // return list;
} }
export function updateIscsData(device) { export function updateIscsData(state, device) {
const iscsData = store.state.iscs; // const state = store.state;
switch (device._type) { switch (device._type) {
case deviceType.vidiconList : case deviceType.Vidicon :
updateIscsListByDevice(iscsData, 'vidiconList', device); updateIscsListByDevice(state, 'vidiconList', device);
break; break;
case deviceType.vidiconCloudList : case deviceType.VidiconCloud :
updateIscsListByDevice(iscsData, 'vidiconCloudList', device); updateIscsListByDevice(state, 'vidiconCloudList', device);
break; break;
case deviceType.ManualAlarmButton : case deviceType.ManualAlarmButton :
updateIscsListByDevice(iscsData, 'manualAlarmButtonList', device); updateIscsListByDevice(state, 'manualAlarmButtonList', device);
break; break;
case deviceType.FireHydranAlarmButton: case deviceType.FireHydranAlarmButton:
updateIscsListByDevice(iscsData, 'fireHydranAlarmButtonList', device); updateIscsListByDevice(state, 'fireHydranAlarmButtonList', device);
break; break;
case deviceType.GasFireControl: case deviceType.GasFireControl:
updateIscsListByDevice(iscsData, 'gasFireControlList', device); updateIscsListByDevice(state, 'gasFireControlList', device);
break; break;
case deviceType.SmokeDetector: case deviceType.SmokeDetector:
updateIscsListByDevice(iscsData, 'smokeDetectorList', device); updateIscsListByDevice(state, 'smokeDetectorList', device);
break; break;
case deviceType.TemperatureDetector: case deviceType.TemperatureDetector:
updateIscsListByDevice(iscsData, 'temperatureDetectorList', device); updateIscsListByDevice(state, 'temperatureDetectorList', device);
break; break;
case deviceType.PlatformScreenDoor: case deviceType.PlatformScreenDoor:
updateIscsListByDevice(iscsData, 'platformScreenDoorList', device); updateIscsListByDevice(state, 'platformScreenDoorList', device);
break; break;
case deviceType.FrozenPump : case deviceType.FrozenPump :
updateIscsListByDevice(iscsData, 'frozenPumpList', device); updateIscsListByDevice(state, 'frozenPumpList', device);
break; break;
case deviceType.Ventilator : case deviceType.Ventilator :
updateIscsListByDevice(iscsData, 'ventilatorList', device); updateIscsListByDevice(state, 'ventilatorList', device);
break; break;
case deviceType.Chiller : case deviceType.Chiller :
updateIscsListByDevice(iscsData, 'chillerList', device); updateIscsListByDevice(state, 'chillerList', device);
break; break;
case deviceType.CoolTower : case deviceType.CoolTower :
updateIscsListByDevice(iscsData, 'coolTowerList', device); updateIscsListByDevice(state, 'coolTowerList', device);
break; break;
case deviceType.EndDoor: case deviceType.EndDoor:
updateIscsListByDevice(iscsData, 'endDoorList', device); updateIscsListByDevice(state, 'endDoorList', device);
break; break;
case deviceType.BorderRadius: case deviceType.BorderRadius:
updateIscsListByDevice(iscsData, 'borderRadius', device); updateIscsListByDevice(state, 'borderRadius', device);
break; break;
case deviceType.AirConditioner: case deviceType.AirConditioner:
updateIscsListByDevice(iscsData, 'airConditionerList', device); updateIscsListByDevice(state, 'airConditionerList', device);
break; break;
case deviceType.OrbitalVentilator: case deviceType.OrbitalVentilator:
updateIscsListByDevice(iscsData, 'orbitalVentilatorList', device); updateIscsListByDevice(state, 'orbitalVentilatorList', device);
break; break;
case deviceType.JetFan: case deviceType.JetFan:
updateIscsListByDevice(iscsData, 'jetFanList', device); updateIscsListByDevice(state, 'jetFanList', device);
break; break;
case deviceType.TunnelFan: case deviceType.TunnelFan:
updateIscsListByDevice(iscsData, 'tunnelFanList', device); updateIscsListByDevice(state, 'tunnelFanList', device);
break; break;
case deviceType.FireDamper: case deviceType.FireDamper:
updateIscsListByDevice(iscsData, 'fireDamperList', device); updateIscsListByDevice(state, 'fireDamperList', device);
break; break;
case deviceType.SmookProofFd: case deviceType.SmookProofFd:
updateIscsListByDevice(iscsData, 'smookProofFdList', device); updateIscsListByDevice(state, 'smookProofFdList', device);
break; break;
} }
store.dispatch('iscs/setIscsData', iscsData); // store.dispatch('iscs/setIscsData', state.iscs);
} }

View File

@ -33,84 +33,84 @@ const iscs = {
return state.updateDeviceData; return state.updateDeviceData;
}, },
vidiconList: (state) => { vidiconList: (state) => {
if (state.iscs && state.iscs.vidiconList) { if (state.iscs) {
return state.iscs.vidiconList; return state.iscs.vidiconList;
} else { } else {
return []; return [];
} }
}, },
vidiconCloudList: (state) => { vidiconCloudList: (state) => {
if (state.iscs && state.iscs.vidiconCloudList) { if (state.iscs.vidiconCloudList) {
return state.iscs.vidiconCloudList; return state.iscs.vidiconCloudList;
} else { } else {
return []; return [];
} }
}, },
frozenPumpList:(state)=>{ frozenPumpList:(state)=>{
if (state.iscs && state.iscs.frozenPumpList) { if (state.iscs.frozenPumpList) {
return state.iscs.frozenPumpList; return state.iscs.frozenPumpList;
} else { } else {
return []; return [];
} }
}, },
airConditionerList:(state)=>{ airConditionerList:(state)=>{
if (state.iscs && state.iscs.airConditionerList) { if (state.iscs.airConditionerList) {
return state.iscs.airConditionerList; return state.iscs.airConditionerList;
} else { } else {
return []; return [];
} }
}, },
tunnelFanList:(state)=>{ tunnelFanList:(state)=>{
if (state.iscs && state.iscs.tunnelFanList) { if (state.iscs.tunnelFanList) {
return state.iscs.tunnelFanList; return state.iscs.tunnelFanList;
} else { } else {
return []; return [];
} }
}, },
orbitalVentilatorList:(state)=>{ orbitalVentilatorList:(state)=>{
if (state.iscs && state.iscs.orbitalVentilatorList) { if (state.iscs.orbitalVentilatorList) {
return state.iscs.orbitalVentilatorList; return state.iscs.orbitalVentilatorList;
} else { } else {
return []; return [];
} }
}, },
smookProofFdList:(state)=>{ smookProofFdList:(state)=>{
if (state.iscs && state.iscs.smookProofFdList) { if (state.iscs.smookProofFdList) {
return state.iscs.smookProofFdList; return state.iscs.smookProofFdList;
} else { } else {
return []; return [];
} }
}, },
chillerList:(state)=>{ chillerList:(state)=>{
if (state.iscs && state.iscs.chillerList) { if (state.iscs.chillerList) {
return state.iscs.chillerList; return state.iscs.chillerList;
} else { } else {
return []; return [];
} }
}, },
coolTowerList:(state)=>{ coolTowerList:(state)=>{
if (state.iscs && state.iscs.coolTowerList) { if (state.iscs.coolTowerList) {
return state.iscs.coolTowerList; return state.iscs.coolTowerList;
} else { } else {
return []; return [];
} }
}, },
fireDamperList:(state)=>{ fireDamperList:(state)=>{
if (state.iscs && state.iscs.fireDamperList) { if (state.iscs.fireDamperList) {
return state.iscs.fireDamperList; return state.iscs.fireDamperList;
} else { } else {
return []; return [];
} }
}, },
jetFanList:(state)=>{ jetFanList:(state)=>{
if (state.iscs && state.iscs.jetFanList) { if (state.iscs.jetFanList) {
return state.iscs.jetFanList; return state.iscs.jetFanList;
} else { } else {
return []; return [];
} }
}, },
ventilatorList:(state)=>{ ventilatorList:(state)=>{
if (state.iscs && state.iscs.ventilatorList) { if (state.iscs.ventilatorList) {
return state.iscs.ventilatorList; return state.iscs.ventilatorList;
} else { } else {
return []; return [];
@ -122,7 +122,7 @@ const iscs = {
iscsRender: (state, devices) => { iscsRender: (state, devices) => {
if (devices && devices.length) { if (devices && devices.length) {
if (state.iscs) { if (state.iscs) {
devices.forEach(elem => { updateIscsData(elem); }); devices.forEach(elem => { updateIscsData(state, elem); });
} }
if (Vue.prototype.$iscs) { if (Vue.prototype.$iscs) {
Vue.prototype.$iscs.render(devices); Vue.prototype.$iscs.render(devices);

View File

@ -43,7 +43,7 @@ export default {
}, },
watch: { watch: {
$route(val) { $route(val) {
this.iscsChange();
} }
}, },
created() { created() {

View File

@ -65,7 +65,7 @@ export default {
}, },
computed:{ computed:{
...mapGetters('iscs', [ ...mapGetters('iscs', [
'frozenPumpList' 'iscs'
]) ])
}, },
watch:{ watch:{
@ -96,7 +96,7 @@ export default {
y: this.form.y y: this.form.y
}, },
_type: 'FrozenPump', _type: 'FrozenPump',
code: this.isUpdate ? this.form.code : getUID('FrozenPump', this.frozenPumpList), code: this.isUpdate ? this.form.code : getUID('FrozenPump', this.iscs.frozenPumpList),
width: this.form.width, width: this.form.width,
color:'#00ff00', color:'#00ff00',
pumpType:this.form.type pumpType:this.form.type

View File

@ -49,14 +49,14 @@ export default {
}, },
computed: { computed: {
...mapGetters('iscs', [ ...mapGetters('iscs', [
'vidiconList' 'iscs'
]) ])
}, },
methods: { methods: {
onSubmit(form) { onSubmit(form) {
this.$refs.form.validate((valid) => { this.$refs.form.validate((valid) => {
if (valid) { if (valid) {
const Uid = getUID('Vidicon', this.vidiconList); const Uid = getUID('Vidicon', this.iscs.vidiconList);
const model = { const model = {
_type: 'Vidicon', _type: 'Vidicon',
code: Uid, code: Uid,

View File

@ -45,14 +45,14 @@ export default {
}, },
computed: { computed: {
...mapGetters('iscs', [ ...mapGetters('iscs', [
'vidiconCloudList' 'iscs'
]) ])
}, },
methods: { methods: {
onSubmit(form) { onSubmit(form) {
this.$refs.form.validate((valid) => { this.$refs.form.validate((valid) => {
if (valid) { if (valid) {
const Uid = getUID('VidiconCloud', this.vidiconCloudList); const Uid = getUID('VidiconCloud', this.iscs.vidiconCloudList);
const model = { const model = {
_type: 'VidiconCloud', _type: 'VidiconCloud',
code: Uid, code: Uid,