tsg-web/src/models/runtime/index.ts

294 lines
7.1 KiB
TypeScript

import { createModel } from '@rematch/core'
import { RootModel } from '..'
import {
FeaturePopInfo,
FeatureTipInfo,
RecordId,
RuntimeState,
InfoDlg,
MarkerInfo,
} from '../_'
import { config } from '../../config'
import moment from 'moment'
export const runtime = createModel<RootModel>()({
state: {
calculating: false,
calculatingLoop: false,
mouseCoords: undefined,
featurePops: [], // [{ id, type, data, lgtd, lttd, elev }]
rainDrpData:[],
infoDlg: undefined,
cameraTarget: undefined,
markers: {},
coordsText: '',
viewTick: 1,
layerSetting: {},
layerSettingLoop: {},
hasRightPanel: true,
showGlobalSearch: true,
leftActiveTab: '',
rainLayerTm: '2022070108',
hasAlertBox: false,
badgeBool: {
jy: false,
sh: false,
sk: false,
hd: false,
},
badgejy: false,
hasAlertBoxStyle: {},
alarmActive: false,
warnDataNum0: 0,
mapIn: new Date(),
mapOut: new Date(),
smallSkRiskTime: {
stm: moment().add(-1, 'day').format('YYYY-MM-DD HH:mm:ss'),
etm: moment().format('YYYY-MM-DD HH:mm:ss'),
},
smallSkRiskNums: {
total: 0,
redAlert: 0,
orangeAlert: 0,
yellowAlert: 0,
blueWarning: 0,
},
isReadObject: {},
} as RuntimeState,
reducers: {
setRainDrpData(state, o) {
return { ...state, rainDrpData: o }
},
setIsReadObject(state, o) {
return { ...state, isReadObject: o }
},
setInfoDlg(state, props: InfoDlg | undefined): RuntimeState {
return { ...state, infoDlg: props }
},
// 地图飞行定位, center [lgtd, lttd] | bound [[x1, y1], [x2, y2]]
setCameraTarget(state, o) {
return { ...state, cameraTarget: o }
},
setCalculating(state, val) {
return { ...state, calculating: val }
},
setCalculatingLoop(state, val) {
return { ...state, calculatingLoop: val }
},
setHasRightPanel(state, val) {
return { ...state, hasRightPanel: val }
},
setShowGlobalSearch(state, val) {
return { ...state, showGlobalSearch: val }
},
setLeftActiveTab(state, val) {
return { ...state, leftActiveTab: val }
},
setLayerSetting(state, so) {
const s: any = { ...state }
s.layerSetting = {
...s.layerSetting,
...so,
}
for (const key in s.layerSetting) {
if (s.layerSetting[key] === undefined) {
delete s.layerSetting[key]
}
}
return s
},
setSmallSkRiskTime(state, val) {
return { ...state, smallSkRiskTime: val }
},
setSmallSkRiskNums(state, val) {
return { ...state, smallSkRiskNums: val }
},
setLayerSettingLoop(state, so) {
const s: any = { ...state }
s.layerSettingLoop = {
...s.layerSettingLoop,
...so,
}
for (const key in s.layerSettingLoop) {
if (s.layerSettingLoop[key] === undefined) {
delete s.layerSettingLoop[key]
}
}
return s
},
setRainLayerTm(state, val) {
return { ...state, rainLayerTm: val }
},
setHome(state, o) {
return {
...state,
cameraTarget: {
bound: [
[114.746, 31.479, 0],
[114.776, 31.509, 0],
],
zoom: localStorage.getItem('mapZoom'),
pitch: config.homePitch,
},
}
},
setIn(state, o) {
//console.log(extent);
return {
...state,
mapIn: new Date(),
}
},
mapOut(state, o) {
//console.log(extent);
return {
...state,
mapOut: new Date(),
}
},
setCoordsText(
state,
val: [number, number] | [number, number, number] | undefined
): RuntimeState {
return { ...state, mouseCoords: val }
},
setFeatureTip(state, tip: FeatureTipInfo | null): RuntimeState {
let { text, left, top } = tip || {}
if (!text || !left || !top) {
return { ...state, featureTip: undefined }
} else {
return {
...state,
featureTip: { text, left, top: top + 15 },
}
}
},
setFeaturePop(state, popups: any): RuntimeState {
popups = popups || []
if (!Array.isArray(popups)) {
popups = [popups]
}
//console.log("48++++",popups);
const val = popups.filter(
(o: any) => (o.id && o.lgtd && o.lttd && o.type) || o.data
)
console.log(val)
return {
...state,
featurePops: val,
}
},
setMarkers(
state,
markers: { [layername: string]: MarkerInfo[] }
): RuntimeState {
const s = { ...state }
s.markers = {
...s.markers,
...markers,
}
return s
},
closeFeaturePop(state, id: RecordId): RuntimeState {
const val = state.featurePops?.filter((o) => o.id !== id)
return {
...state,
featurePops: val,
}
},
closeFeaturePopAll(state): RuntimeState {
const val: any = []
return {
...state,
featurePops: val,
}
},
tickViewChanged(state) {
return {
...state,
// @ts-ignore
viewTick: state.viewTick + 1,
}
},
setHasAlertBox(state, val) {
if (val) {
return {
...state,
hasAlertBox: val,
hasAlertBoxStyle: {
height: 'calc(100vh - 142px)',
overflowY: 'hidden',
},
}
} else {
return {
...state,
hasAlertBox: val,
hasAlertBoxStyle: {
height: 'calc(100vh - 120px)',
overflowY: 'hidden',
},
}
}
},
setBadgeBool(state, val) {
return { ...state, badgeBool: val }
},
setBadgejy(state, val) {
return { ...state, badgejy: val }
},
setAlarmActive(state, val) {
return { ...state, alarmActive: val }
},
//warnDataNum0
setWarnDataNum0(state, val) {
return { ...state, warnDataNum0: val }
},
},
effects: (dispatch) => ({
// 增加contour的索引
addContourIndex({ startIndex }, state) {
console.log('138+++++', state)
const index = state.runtime.layerSetting?.contour?.index
const shps = state.runtime.layerSetting?.contour?.shps
if (typeof index === 'number' && Array.isArray(shps)) {
const contour = { ...state.runtime.layerSetting.contour }
contour.index = index + 1
if (contour.index >= shps.length) {
contour.index = startIndex || 0
}
this.setLayerSetting({ contour })
}
},
// 增加contour的索引
addContourIndexLoop({ startIndex }, state) {
console.log('168+++++', state)
const index = state.runtime.layerSettingLoop?.contour?.index
const shps = state.runtime.layerSettingLoop?.contour?.shps
if (typeof index === 'number' && Array.isArray(shps)) {
const contour = { ...state.runtime.layerSettingLoop.contour }
contour.index = index + 1
if (contour.index >= shps.length) {
contour.index = startIndex || 0
}
this.setLayerSettingLoop({ contour })
}
},
}),
})