useFlightInfo.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import { CommonData, CommonValue } from '~/common'
  2. import { Query } from '@/api/webApi'
  3. import { ElMessage } from 'element-plus'
  4. const flightInfoItemsMap = {
  5. departure: [
  6. [
  7. {
  8. label: '起飞机场简称',
  9. key: 'departureAirportZh',
  10. },
  11. {
  12. label: '日期',
  13. getter: info => info.planDepartureTime?.split('T')[0],
  14. },
  15. {
  16. label: '时间',
  17. getter: info => info.planDepartureTime?.split('T')[1],
  18. },
  19. {
  20. label: '停机位',
  21. key: 'takeOffStand',
  22. },
  23. ],
  24. [
  25. {
  26. label: '特货信息/货物数',
  27. key: 'speCargoInfo',
  28. },
  29. {
  30. label: '托运运单数/货物数',
  31. key: "concat(preLoadList,'/',preLoad)",
  32. },
  33. {
  34. label: '中转进运单/货物数',
  35. key: "concat(transInList,'/',transInList)",
  36. },
  37. {
  38. label: '已配载集装器',
  39. key: 'stowage_Yes',
  40. },
  41. {
  42. label: '货站已交接集装器',
  43. key: 'depotJoin',
  44. },
  45. {
  46. label: '已装载集装器/运单/货物数',
  47. key: 'loadPlane',
  48. },
  49. {
  50. label: '拉下集装器/运单/货物数',
  51. key: 'pull',
  52. },
  53. {
  54. label: '集装器数量',
  55. key: 'stowage',
  56. },
  57. ],
  58. [
  59. {
  60. label: '降落机场简称',
  61. key: 'landingAirportZh',
  62. },
  63. {
  64. label: '日期',
  65. getter: info => info.planLandingTime?.split('T')[0],
  66. },
  67. {
  68. label: '时间',
  69. getter: info => info.planLandingTime?.split('T')[1],
  70. },
  71. ],
  72. ],
  73. arrival: [
  74. [
  75. {
  76. label: '起飞机场简称',
  77. key: 'departureAirportZh',
  78. },
  79. {
  80. label: '日期',
  81. getter: info => info.planDepartureTime?.split('T')[0],
  82. },
  83. {
  84. label: '时间',
  85. getter: info => info.planDepartureTime?.split('T')[1],
  86. },
  87. ],
  88. [
  89. {
  90. label: '特货信息/货物数',
  91. key: 'speCargoInfo',
  92. },
  93. {
  94. label: '卸载运单数/货物数',
  95. key: "concat(unLoadPlaneList,'/',unLoadPlane)",
  96. },
  97. {
  98. label: '中转进运单/货物数',
  99. key: "concat(transInList,'/',transIn)",
  100. },
  101. {
  102. label: '已卸载集装器',
  103. key: 'stowage_Yes',
  104. },
  105. {
  106. label: '卸载数量(板/箱/卡)',
  107. key: 'unloadPlane',
  108. },
  109. {
  110. label: '货站交接数量(板/箱/卡)',
  111. key: 'pull',
  112. },
  113. ],
  114. [
  115. {
  116. label: '降落机场简称',
  117. key: 'landingAirportZh',
  118. },
  119. {
  120. label: '日期',
  121. getter: info => info.planLandingTime?.split('T')[0],
  122. },
  123. {
  124. label: '时间',
  125. getter: info => info.planLandingTime?.split('T')[1],
  126. },
  127. {
  128. label: '停机位',
  129. key: 'landingStand',
  130. },
  131. ],
  132. ],
  133. }
  134. const simulateFlightInfoMap = {
  135. departure: {
  136. C0: '深圳机场',
  137. C1: '2021-12-24',
  138. C2: '19 : 30 : 25',
  139. C3: '012',
  140. C4: '0',
  141. C5: '0',
  142. C6: '0',
  143. C7: '0',
  144. C8: '0',
  145. C9: '0',
  146. C10: '南京机场',
  147. C11: '2021-12-24',
  148. C12: '22 : 25 : 25',
  149. },
  150. arrival: {
  151. C0: '南京机场',
  152. C1: '2021-12-24',
  153. C2: '19 : 30 : 25',
  154. C3: '0',
  155. C4: '0',
  156. C5: '0',
  157. C6: '0',
  158. C7: '0',
  159. C8: '0',
  160. C9: '深圳机场',
  161. C10: '2021-12-24',
  162. C11: '19 : 30 : 25',
  163. C12: '012',
  164. },
  165. }
  166. export function useFlightInfo(name: string, dataContent: CommonValue[]) {
  167. const flightInfoItems = ref<
  168. { label: string; key?: string; getter?: (info: any) => string }[][]
  169. >([])
  170. const getFlightInfoItems = () => {
  171. flightInfoItems.value =
  172. flightInfoItemsMap[name.includes('Departure') ? 'departure' : 'arrival']
  173. }
  174. getFlightInfoItems()
  175. const flightInfo = reactive<CommonData>({})
  176. const getFlightInfo = async () => {
  177. try {
  178. const {
  179. code,
  180. returnData: { listValues },
  181. message,
  182. } = await Query({
  183. id:
  184. DATACONTENT_ID[
  185. name.slice(0, 1).toLowerCase() + name.slice(1) + 'Info'
  186. ],
  187. dataContent,
  188. })
  189. if (Number(code) !== 0) {
  190. throw new Error(message ?? '失败')
  191. }
  192. if (!listValues.length) {
  193. ElMessage.info('未查询到航班信息')
  194. return
  195. }
  196. Object.assign(flightInfo, listValues[0])
  197. } catch (error) {
  198. console.error(error)
  199. }
  200. }
  201. const computedFlightInfo = computed(() => item => {
  202. if (item.getter) {
  203. return item.getter(flightInfo)
  204. } else if (item.key) {
  205. return flightInfo[item.key]
  206. } else {
  207. return ''
  208. }
  209. })
  210. const getSimulateFlightInfo = () => {
  211. const simulateFlightInfo =
  212. simulateFlightInfoMap[
  213. name.includes('Departure') ? 'departure' : 'arrival'
  214. ]
  215. Object.assign(flightInfo, simulateFlightInfo)
  216. }
  217. const getAirportNameZh = async (airportCode: string) => {
  218. try {
  219. const {
  220. code,
  221. returnData: { listValues },
  222. message,
  223. } = await Query({
  224. id: DATACONTENT_ID.airportNameZh,
  225. dataContent: [airportCode],
  226. })
  227. if (Number(code) !== 0) {
  228. throw new Error(message ?? '失败')
  229. }
  230. if (!listValues.length) {
  231. ElMessage.info('未查询到航班中文名')
  232. return ''
  233. }
  234. return listValues[0].airportname
  235. } catch (error) {
  236. console.error(error)
  237. return ''
  238. }
  239. }
  240. onMounted(async () => {
  241. await getFlightInfo()
  242. const { departureAirport, landingAirport } = flightInfo
  243. if (departureAirport) {
  244. flightInfo.departureAirportZh = await getAirportNameZh(
  245. String(departureAirport)
  246. )
  247. }
  248. if (landingAirport) {
  249. flightInfo.landingAirportZh = await getAirportNameZh(
  250. String(landingAirport)
  251. )
  252. }
  253. // getSimulateFlightInfo()
  254. })
  255. return {
  256. flightInfoItems,
  257. flightInfo,
  258. computedFlightInfo,
  259. }
  260. }