operate.ts 9.9 KB

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