usePublic.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. import { Query } from '@/api/webApi'
  2. import { CommonData } from '~/common'
  3. import * as _ from 'lodash'
  4. export enum showTimeMsg {
  5. HourlyPeak, //小时峰值
  6. WaybillTrend, //运单趋势
  7. NodePeak, //始发站/目的站统计分析
  8. AirlineTraffic, //航司统计
  9. AirlineAbnormal, //航班统计
  10. PickingStatistics, //拉货统计
  11. }
  12. export function usePublic() {
  13. const optionLeft = {
  14. tooltip: {
  15. trigger: 'axis',
  16. },
  17. legend: {
  18. show: true,
  19. top: 0,
  20. right: '20%',
  21. icon: 'roundRect',
  22. data: ['重量/吨', '运单/单'],
  23. textStyle: {
  24. color: '#698dc3',
  25. },
  26. },
  27. grid: {
  28. left: '5%',
  29. right: '5%',
  30. bottom: '0%',
  31. top: '17%',
  32. containLabel: true,
  33. },
  34. color: ['#4C88E1', '#51DEE9'],
  35. xAxis: {
  36. type: 'category',
  37. boundaryGap: true,
  38. data: [
  39. '0:00',
  40. '2:00',
  41. '4:00',
  42. '6:00',
  43. '8:00',
  44. '10:00',
  45. '12:00',
  46. '14:00',
  47. '16:00',
  48. '18:00',
  49. '20:00',
  50. '22:00',
  51. ],
  52. axisLine: {
  53. show: true,
  54. lineStyle: {
  55. color: '#8897BC',
  56. },
  57. },
  58. axisTick: {
  59. show: false,
  60. },
  61. axisLabel: {
  62. color: '#8897BC',
  63. interval: 0,
  64. },
  65. },
  66. yAxis: [
  67. {
  68. type: 'value',
  69. axisLabel: {
  70. color: '#8897BC',
  71. },
  72. splitLine: {
  73. lineStyle: {
  74. type: 'dashed',
  75. color: 'rgba(196,194,225, 0.54)',
  76. },
  77. },
  78. name: '吨',
  79. },
  80. {
  81. type: 'value',
  82. axisLabel: {
  83. color: '#8897BC',
  84. },
  85. splitLine: {
  86. lineStyle: {
  87. type: 'dashed',
  88. color: 'rgba(196,194,225, 0.54)',
  89. },
  90. },
  91. name: '单',
  92. },
  93. ],
  94. series: [
  95. {
  96. name: '重量/吨',
  97. type: 'line',
  98. symbol: 'none',
  99. key: 'bagsnum',
  100. yAxisIndex: 0,
  101. data: [120, 132, 101, 134, 90, 230, 210, 132, 101, 134, 90, 230],
  102. areaStyle: {
  103. color: {
  104. type: 'linear',
  105. x: 0,
  106. y: 0,
  107. x2: 0,
  108. y2: 1,
  109. colorStops: [
  110. {
  111. offset: 0,
  112. color: 'rgba(125,72,255,0.5)',
  113. },
  114. {
  115. offset: 1,
  116. color: 'rgba(0,180,255,0.01)',
  117. },
  118. ],
  119. global: false,
  120. },
  121. },
  122. },
  123. {
  124. name: '运单/单',
  125. type: 'line',
  126. symbol: 'none',
  127. yAxisIndex: 1,
  128. key: 'passengers',
  129. data: [220, 182, 191, 234, 290, 330, 310, 132, 101, 134, 90, 230],
  130. areaStyle: {
  131. color: {
  132. type: 'linear',
  133. x: 0,
  134. y: 0,
  135. x2: 0,
  136. y2: 1,
  137. colorStops: [
  138. {
  139. offset: 0,
  140. color: 'rgba(125,72,255,0.5)',
  141. },
  142. {
  143. offset: 1,
  144. color: 'rgba(0,180,255,0.01)',
  145. },
  146. ],
  147. global: false,
  148. },
  149. },
  150. },
  151. ],
  152. }
  153. const airlineAbnormalBaggage = {
  154. component: 'commonChartsBar',
  155. option: {
  156. baseOption: {
  157. tooltip: {
  158. trigger: 'axis',
  159. valueFormatter: function (value) {
  160. return value + '单'
  161. },
  162. },
  163. legend: {
  164. data: ['运单数', '航班数'],
  165. right: '20%',
  166. textStyle: {
  167. color: '#8897BC',
  168. },
  169. // top:"-10"
  170. },
  171. color: ['#4C88E1', '#51DEE9'],
  172. grid: {
  173. bottom: '10%',
  174. left: '13%',
  175. right: '8%',
  176. top: '17%',
  177. },
  178. xAxis: {
  179. data: ['卸机', '机下交接', '货站交接', '提取'],
  180. axisLine: {
  181. show: true,
  182. lineStyle: {
  183. color: '#8897BC',
  184. },
  185. },
  186. axisTick: {
  187. show: false,
  188. },
  189. axisLabel: {
  190. color: '#8897BC',
  191. },
  192. },
  193. yAxis: {
  194. type: 'value',
  195. axisLabel: {
  196. color: '#8897BC',
  197. },
  198. splitLine: {
  199. lineStyle: {
  200. type: 'dashed',
  201. color: 'rgba(196,194,225, 0.54)',
  202. },
  203. },
  204. name: '单',
  205. },
  206. series: [
  207. {
  208. name: '运单数',
  209. type: 'bar',
  210. data: [0, 0, 0, 0],
  211. barWidth: 10,
  212. },
  213. {
  214. name: '航班数',
  215. type: 'bar',
  216. data: [0, 0, 0, 0],
  217. barWidth: 10,
  218. },
  219. ],
  220. },
  221. },
  222. }
  223. const airCompaneBaggage = {
  224. component: 'commonChartsBar',
  225. option: {
  226. baseOption: {
  227. tooltip: {
  228. trigger: 'axis',
  229. },
  230. legend: {
  231. data: ['重量/吨', '运单/单'],
  232. right: '20%',
  233. textStyle: {
  234. color: '#8897BC',
  235. },
  236. },
  237. color: ['#4C88E1', '#51DEE9'],
  238. grid: {
  239. bottom: '10%',
  240. left: '13%',
  241. right: '8%',
  242. top: '17%',
  243. },
  244. xAxis: {
  245. data: ['国航', '南航', '深航', '东航', '海航', '国泰', '川航'],
  246. axisLine: {
  247. show: true,
  248. lineStyle: {
  249. color: '#8897BC',
  250. },
  251. },
  252. axisTick: {
  253. show: false,
  254. },
  255. axisLabel: {
  256. color: '#8897BC',
  257. interval: 0,
  258. },
  259. },
  260. yAxis: [
  261. {
  262. type: 'value',
  263. axisLabel: {
  264. color: '#8897BC',
  265. },
  266. splitLine: {
  267. lineStyle: {
  268. type: 'dashed',
  269. color: 'rgba(196,194,225, 0.54)',
  270. },
  271. },
  272. name: '吨',
  273. },
  274. {
  275. type: 'value',
  276. axisLabel: {
  277. color: '#8897BC',
  278. },
  279. splitLine: {
  280. lineStyle: {
  281. type: 'dashed',
  282. color: 'rgba(196,194,225, 0.54)',
  283. },
  284. },
  285. name: '单',
  286. },
  287. ],
  288. series: [
  289. {
  290. name: '重量/吨',
  291. type: 'bar',
  292. data: [11, 15, 17, 8, 1, 4, 6],
  293. yAxisIndex: 0,
  294. barWidth: 10,
  295. },
  296. {
  297. name: '运单/单',
  298. type: 'bar',
  299. data: [12, 10, 15, 11, 16, 4, 6],
  300. yAxisIndex: 1,
  301. barWidth: 10,
  302. },
  303. ],
  304. },
  305. },
  306. }
  307. const airStutas = {
  308. component: 'commonChartsBar',
  309. option: {
  310. baseOption: {
  311. // legend: {
  312. // data: ['2020年', '2021年'],
  313. // right:"20",
  314. // textStyle:{
  315. // color: "#8897BC"
  316. // }
  317. // // top:"-10"
  318. // },
  319. tooltip: {
  320. trigger: 'axis',
  321. valueFormatter: function (value) {
  322. return value + '单'
  323. },
  324. },
  325. color: ['#51DEE9', '#4C88E1'],
  326. grid: {
  327. bottom: '10%',
  328. left: '5%',
  329. right: '1%',
  330. top: '17%',
  331. },
  332. xAxis: {
  333. data: ['机下交接', '货站交接', '理货'],
  334. axisLine: {
  335. show: true,
  336. lineStyle: {
  337. color: '#8897BC',
  338. },
  339. },
  340. axisTick: {
  341. show: false,
  342. },
  343. axisLabel: {
  344. color: '#8897BC',
  345. },
  346. },
  347. yAxis: {
  348. type: 'value',
  349. axisLabel: {
  350. color: '#8897BC',
  351. },
  352. splitLine: {
  353. lineStyle: {
  354. type: 'dashed',
  355. color: 'rgba(196,194,225, 0.54)',
  356. },
  357. },
  358. name: '单',
  359. },
  360. series: [
  361. {
  362. type: 'bar',
  363. data: [12, 10, 15],
  364. },
  365. ],
  366. },
  367. },
  368. }
  369. const node = ['卸机', '机下交接', '货站交接', '提取']
  370. const hours = Array.from({ length: 24 }, (v, i) => i + 1)
  371. const hourPeak = {
  372. component: 'commonChartsScatter',
  373. option: {
  374. tooltip: {
  375. trigger: 'axis',
  376. valueFormatter: function (value) {
  377. return value + '单'
  378. },
  379. },
  380. title: node.map((month, index) => ({
  381. top: ((index + 0.5) * 100) / 4 - 3 + '%',
  382. text: month,
  383. textStyle: {
  384. fontSize: 12,
  385. fontWeight: 'normal',
  386. color: '#698dc3',
  387. },
  388. })),
  389. singleAxis: node.map((month, index) => ({
  390. type: 'category',
  391. data: hours,
  392. top: ((index + 0.5) * 100) / 4 - 3 + '%',
  393. height: 100 / 4 - 5 + '%',
  394. left: '12%',
  395. right: '1%',
  396. axisTick: {
  397. show: false,
  398. },
  399. splitLine: {
  400. show: false,
  401. },
  402. })),
  403. series: node.map((month, index) => ({
  404. singleAxisIndex: index,
  405. coordinateSystem: 'singleAxis',
  406. type: 'scatter',
  407. data: [
  408. 3,
  409. 6,
  410. 1,
  411. 4,
  412. 0,
  413. 4,
  414. 2,
  415. 5,
  416. 4,
  417. 4,
  418. 6,
  419. 2,
  420. 0,
  421. 3,
  422. 1,
  423. 6,
  424. 6,
  425. 1,
  426. 0,
  427. 3,
  428. 6,
  429. 3,
  430. 0,
  431. 5,
  432. ],
  433. symbolSize: function (dataItem) {
  434. return dataItem * 3
  435. },
  436. })),
  437. },
  438. }
  439. const getPublicData = async (id: number, times?: any[]) => {
  440. try {
  441. const {
  442. code,
  443. returnData: { listValues },
  444. } = await Query<CommonData>({
  445. id,
  446. dataContent: times,
  447. })
  448. if (Number(code) !== 0) {
  449. return []
  450. } else {
  451. return listValues
  452. }
  453. } catch (err) {
  454. return []
  455. }
  456. }
  457. const findData = (arr1, arr2, key, dot) => {
  458. const msg = _.unionWith(arr1, arr2, _.isEqual)
  459. const res = _.unionBy(msg, key)
  460. const result: any = []
  461. res.forEach((item) => {
  462. arr2.forEach((p) => {
  463. if (item[key] == p[key]) {
  464. item = _.merge(item, p)
  465. }
  466. })
  467. })
  468. res.forEach((item) => {
  469. if (item[dot] && item[dot] != undefined) {
  470. result.push(item)
  471. }
  472. })
  473. return result
  474. }
  475. return {
  476. optionLeft,
  477. airlineAbnormalBaggage,
  478. airCompaneBaggage,
  479. airStutas,
  480. hourPeak,
  481. getPublicData,
  482. findData,
  483. }
  484. }