operate.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. import Bus from '@/utils/bus'
  2. import bus from '@/utils/bus'
  3. import { useAppStore } from '@/stores/app'
  4. import { useTimeScrollbarStore } from '@/stores/timeScrollbar'
  5. import { useStationStore } from '@/stores/station'
  6. import { extractList } from '../list'
  7. import { stationList } from '@/assets/js/station'
  8. import { slopeCalculation } from '@/utils/slopeCalculation'
  9. import { getYuyanDataList } from '@/api/yuyan'
  10. import { convertDate } from '@/utils/date'
  11. import { useTyphoonStore } from '@/stores/typhoon'
  12. import {
  13. getRainfallForecastRadarMap,
  14. getRainfallForecastRadarMapList,
  15. } from '@/api/typhoon'
  16. import { Layer } from '@/utils/tdInstruction/index'
  17. import { formatd } from '@/utils/ruoyi'
  18. let waterLevel = ''
  19. let waterSpeed = ''
  20. /**
  21. * 设置测站水位
  22. * @param stcd 测站编码
  23. * @param value 水位
  24. */
  25. export async function setWaterLevel(
  26. stcd: any,
  27. value: any = waterLevel,
  28. speed: any = waterSpeed,
  29. ) {
  30. if (value) {
  31. waterLevel = value + ''
  32. } else {
  33. if (!waterLevel) {
  34. const store = useStationStore()
  35. store.setStcd(stcd)
  36. waterLevel = (await store.getZ()) + ''
  37. }
  38. }
  39. if (speed) {
  40. waterSpeed = speed + ''
  41. }
  42. let descriptor = {
  43. command: 'WaterLevel',
  44. data: {
  45. ID: stcd,
  46. code: waterLevel,
  47. wave: waterSpeed,
  48. },
  49. }
  50. Bus.emit('emitUIInteraction', descriptor)
  51. console.log('-- 设置测站水位,流速', JSON.stringify(descriptor))
  52. }
  53. export async function setUnderwaterState(stcd: any, show = true) {
  54. let value = '-5'
  55. if (!show) {
  56. const store = useStationStore()
  57. value = waterLevel ? waterLevel : (await store.getZ()) + ''
  58. }
  59. let descriptor = {
  60. command: 'WaterLevel',
  61. data: {
  62. ID: stcd,
  63. code: value,
  64. },
  65. }
  66. Bus.emit('emitUIInteraction', descriptor)
  67. console.log('-- 水下地形:', JSON.stringify(descriptor))
  68. }
  69. /**
  70. * 设置测站流速
  71. * @param stcd 测站编码
  72. * @param value 水位
  73. */
  74. export function setWaterSpeed(stcd: any, speed: any = waterSpeed) {
  75. let descriptor = {
  76. command: 'WaterLevel',
  77. data: {
  78. ID: stcd,
  79. speed: speed,
  80. },
  81. }
  82. Bus.emit('emitUIInteraction', descriptor)
  83. console.log('-- 设置测站流速', JSON.stringify(descriptor))
  84. }
  85. /**
  86. * 测验模拟
  87. * @param type 播放、暂停、继续、结束
  88. * @param stcd 测站编码
  89. */
  90. export function testSimulation(stcd: any, type: any = '播放') {
  91. let descriptor = {
  92. command: 'InstrumentMovie',
  93. data: {
  94. Type: type,
  95. ID: stcd,
  96. },
  97. }
  98. Bus.emit('emitUIInteraction', descriptor)
  99. console.log('-- 测验模拟:' + type, JSON.stringify(descriptor))
  100. }
  101. /**
  102. * 流量比对
  103. * @param type 播放、暂停、继续、结束
  104. * @param stcd 测站编码
  105. */
  106. export function flowComparative(stcd: any, type: any = '播放') {
  107. let descriptor = {
  108. command: 'ADCPship',
  109. data: {
  110. Type: type,
  111. ID: stcd,
  112. },
  113. }
  114. Bus.emit('emitUIInteraction', descriptor)
  115. console.log('-- 流量比对:' + type, JSON.stringify(descriptor))
  116. }
  117. /**
  118. * 漫游(太师桥)
  119. * @param type 远:河道;近:测站
  120. * @param operate 播放、暂停、继续、结束
  121. */
  122. export function roam(type: any = 'river', operate: any = 'play') {
  123. let descriptor = {
  124. command: 'Roaming',
  125. data: {
  126. tag: type === 'river' ? '太师桥远' : '太师桥近',
  127. Type: operate,
  128. },
  129. }
  130. Bus.emit('emitUIInteraction', descriptor)
  131. console.log(
  132. '-- 漫游:' + (type === 'river' ? '河道' : '测站'),
  133. JSON.stringify(descriptor),
  134. )
  135. }
  136. export function setPointState(stcd: any, name: string, type: string) {
  137. let descriptor = {
  138. command: 'POIwarning',
  139. data: {
  140. ID: stcd,
  141. Name: name,
  142. type: type,
  143. },
  144. }
  145. Bus.emit('emitUIInteraction', descriptor)
  146. console.log('-- 设置设备告警:', JSON.stringify(descriptor))
  147. }
  148. export async function addTyphoonTrack(tfid: string) {
  149. const typhoonStore = useTyphoonStore()
  150. let yuyanData: any[] = await getYuyanDataList('2025041714054696095').then(
  151. res => {
  152. return res.data.map(item => {
  153. return {
  154. ...item,
  155. YMDHM: convertDate(item.YMDHM),
  156. }
  157. })
  158. },
  159. )
  160. const appStore = useAppStore()
  161. const timeScrollbarStore = useTimeScrollbarStore()
  162. appStore.changeCurrentView('Globe')
  163. // 获取台风数据
  164. const typhoonData = await import(`@/assets/json/typhoon/${tfid}.json`).then(
  165. res => res.default,
  166. )
  167. typhoonData.points.length
  168. timeScrollbarStore.setTimeScrollbarShow(true)
  169. timeScrollbarStore.setMax(typhoonData.points.length)
  170. const timeList = typhoonData.points.map((element: any) => element.time)
  171. const timeObj = extractList(timeList, 4)
  172. for (let key in timeObj) {
  173. timeObj[key] = {
  174. style: {
  175. color: '#00c7e3',
  176. 'text-shadow': '0 0 4px #32003C',
  177. },
  178. label: timeObj[key].substring(0, 10) + '\n' + timeObj[key].substring(11),
  179. }
  180. }
  181. timeScrollbarStore.setMarks(timeObj)
  182. let time = ''
  183. timeScrollbarStore.sliderlTooltip = (value: number) => {
  184. if (typhoonStore.isRadar) {
  185. getRainfallForecastRadarMap(timeList[value]).then(res => {
  186. Layer.radarMap(res)
  187. })
  188. }
  189. const date = new Date(timeList[value])
  190. const list = yuyanData.filter(y => y.YMDHM.getTime() === date.getTime())
  191. const data = list.map(d => {
  192. let station: any = stationList.find(s => s.id === d.STCD)
  193. if (!station) {
  194. console.log(`未找到${d.STCD}`)
  195. }
  196. return {
  197. value: `${d.DATA.toFixed(2)}`,
  198. name: station.name,
  199. x: station.lgtd,
  200. y: station.lttd,
  201. }
  202. })
  203. if (data && data.length > 0) {
  204. const res: any = slopeCalculation(data)
  205. taihuUI(res.direction, res.slope, res.max, res.min)
  206. }
  207. if (timeList[value].substring(0, 10) != time) {
  208. time = timeList[value].substring(0, 10)
  209. bus.emit(
  210. 'chat',
  211. `汇报当前时间 ${time} 台风情况,太湖局应该如何响应,回复内容简单明了,条理清晰,通俗易懂,字数限制200字。如果没有信息就返回null。 台风信息如下:${JSON.stringify(typhoonData.points[value])}`,
  212. )
  213. }
  214. setTyphoonTrack(tfid, timeList[value])
  215. return timeList[value]
  216. }
  217. let descriptor = {
  218. command: 'AddTyphoonTrack',
  219. data: {
  220. tfid: tfid,
  221. },
  222. }
  223. Bus.emit('emitUIInteraction', descriptor)
  224. console.log('-- 台风路径:', JSON.stringify(descriptor))
  225. timeScrollbarStore.play()
  226. typhoonStore.setTyphoon(true)
  227. }
  228. export function setTyphoonTrack(tfid: string, time: string) {
  229. let descriptor = {
  230. command: 'TyphoonTime',
  231. data: {
  232. tfid: tfid,
  233. time: time,
  234. },
  235. }
  236. Bus.emit('emitUIInteraction', descriptor)
  237. console.log('-- 设置台风时间点:', JSON.stringify(descriptor))
  238. }
  239. /**
  240. * 删除台风路径
  241. * @param tfid
  242. */
  243. export function deleteTyphoonTrack(tfid: string) {
  244. const timeScrollbarStore = useTimeScrollbarStore()
  245. timeScrollbarStore.close()
  246. let descriptor = {
  247. command: 'DelLevel',
  248. data: {
  249. tfid: 'TyphoonTrack',
  250. // "tfid": tfid,
  251. type: '3',
  252. },
  253. }
  254. Bus.emit('emitUIInteraction', descriptor)
  255. console.log('-- 删除台风路径:', JSON.stringify(descriptor))
  256. taihuUI('', '', '', '', false)
  257. const store = useTyphoonStore()
  258. store.setTyphoon(false)
  259. }
  260. /**
  261. * 实时台风
  262. */
  263. export function realTimeTyphoon(show = true) {
  264. let descriptor = {
  265. command: 'RuntimeTyphoon',
  266. data: {
  267. Display: show ? 'true' : 'false',
  268. },
  269. }
  270. Bus.emit('emitUIInteraction', descriptor)
  271. console.log('-- 实时台风:', JSON.stringify(descriptor))
  272. }
  273. /**
  274. * 设置站点基础数据
  275. * @param data
  276. */
  277. export function setStationData(data: any) {
  278. let descriptor = {
  279. command: 'SetScene',
  280. data: {
  281. id: data.name,
  282. 堤顶高程: data.damel,
  283. 保证水位: data.grz,
  284. 青坎线: data.qingkang,
  285. 警戒水位: data.wrz,
  286. 当前水位: data.z,
  287. },
  288. }
  289. Bus.emit('emitUIInteraction', descriptor)
  290. console.log('-- 设置站点基础数据:', JSON.stringify(descriptor))
  291. }
  292. let strategyMapState = false
  293. /**
  294. * 设置太湖湖面图层
  295. * @param direction
  296. * @param slope
  297. * @param show
  298. */
  299. export function strategyMap(direction: string, slope: string, show = true) {
  300. let descriptor = {
  301. command: 'InclinedAngle',
  302. data: {
  303. Direction: direction,
  304. Slope: slope,
  305. Display: show ? 'true' : 'false',
  306. },
  307. }
  308. Bus.emit('emitUIInteraction', descriptor)
  309. console.log('-- 太湖湖面图层:', JSON.stringify(descriptor))
  310. }
  311. export function taihuUI(
  312. direction: string,
  313. slope: string,
  314. max: string,
  315. min: string,
  316. show = true,
  317. ) {
  318. let descriptor = {
  319. command: 'TaihuUI',
  320. data: {
  321. Direction: direction,
  322. Slope: slope,
  323. Max: max,
  324. Min: min,
  325. Display: show ? 'true' : 'false',
  326. },
  327. }
  328. Bus.emit('emitUIInteraction', descriptor)
  329. console.log('-- 台风太湖UI:', JSON.stringify(descriptor))
  330. }
  331. export async function addRadar(type: any) {
  332. let radarList: any = await getRainfallForecastRadarMapList(
  333. formatd(new Date(), 'yyyy-MM-dd'),
  334. formatd(new Date(), 'yyyy-MM-dd'),
  335. type,
  336. ).then(res => res)
  337. const appStore = useAppStore()
  338. const timeScrollbarStore = useTimeScrollbarStore()
  339. appStore.changeCurrentView('Globe')
  340. timeScrollbarStore.setTimeScrollbarShow(true)
  341. timeScrollbarStore.setMax(radarList.length)
  342. timeScrollbarStore.setStep(3)
  343. const timeList = radarList.map((element: any) => element.TBA_GETDATE)
  344. const timeObj = extractList(timeList, 4)
  345. for (let key in timeObj) {
  346. timeObj[key] = {
  347. style: {
  348. color: '#00c7e3',
  349. 'text-shadow': '0 0 4px #32003C',
  350. },
  351. label: timeObj[key].substring(0, 10) + '\n' + timeObj[key].substring(11),
  352. }
  353. }
  354. timeScrollbarStore.setMarks(timeObj)
  355. timeScrollbarStore.sliderlTooltip = (value: number) => {
  356. Layer.radarMap(radarList[value].TBA_FILENAME)
  357. return timeList[value]
  358. }
  359. }
  360. /**
  361. * 删除台风路径
  362. */
  363. export function deleteRadar() {
  364. const timeScrollbarStore = useTimeScrollbarStore()
  365. timeScrollbarStore.close()
  366. Layer.radarMap('', false)
  367. }