index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <bgBox :tabChange="tabChange" class="bgBox" :tabIndex="0">
  3. <cake
  4. style="position: absolute; top: 115px; left: 50px"
  5. title="实时统计"
  6. :data="statisticsData"
  7. v-if="isCake"
  8. ></cake>
  9. <cylindricalHistogram
  10. style="position: absolute; left: 50px; top: 430px"
  11. v-if="isGetData"
  12. :unit="`公斤/产量`"
  13. title="各区域移栽产量分析"
  14. :area="Transplantarea"
  15. :dataArray="TransplantdataArray"
  16. ></cylindricalHistogram>
  17. <weatherForecast
  18. :unit="`摄氏度`"
  19. style="position: absolute; left: 50px; top: 760px"
  20. v-if="isWeather"
  21. title="天气预报"
  22. :area="Weatherarea"
  23. :dataArray="WeatherdataArray"
  24. :alertValue="30"
  25. >
  26. </weatherForecast>
  27. <wavyLineChart
  28. :unit="`平方米/面积`"
  29. id="`wavyLineChart`"
  30. style="position: absolute; right: 50px; top: 115px"
  31. v-if="isWavyLine"
  32. title="各区域移栽面积"
  33. :area.sync="wavyLineArea"
  34. :dataArray.sync="wavyLinedataArray"
  35. smooth="true"
  36. >
  37. </wavyLineChart>
  38. <HorizontalHistogram
  39. style="position: absolute; right: 50px; top: 430px"
  40. v-if="isHorizontal"
  41. title="移栽情况分析"
  42. :area="HorizontalArea"
  43. :dataArray="HorizontalArray"
  44. ></HorizontalHistogram>
  45. <wavyLineChart
  46. id="`移栽趋势分析`"
  47. style="position: absolute; right: 50px; top: 760px"
  48. v-if="isWavyLine"
  49. title="移栽趋势分析"
  50. :area="trendarea"
  51. :dataArray="trendDataArray"
  52. >
  53. </wavyLineChart>
  54. <threeMap
  55. style="
  56. position: absolute;
  57. top: 50%;
  58. left: 50%;
  59. transform: translate(-55%, 20%);
  60. "
  61. v-if="hasGetJson"
  62. :getJson="getJson"
  63. ></threeMap>
  64. </bgBox>
  65. </template>
  66. <script>
  67. import bgBox from '@/components/bgBox/index.vue'
  68. import { screenSize } from '@/assets/js/utils'
  69. import cake from '@/components/Customize/cake'
  70. import cylindricalHistogram from '@/components/Customize/cylindricalHistogram'
  71. import weatherForecast from '@/components/Customize/weatherForecast'
  72. import wavyLineChart from '@/components/Customize/wavyLineChart'
  73. import HorizontalHistogram from '@/components/Customize/HorizontalHistogram'
  74. import threeMap from '@/components/Customize/map/index'
  75. const apiLists = [
  76. {
  77. key: `weatherForecast`,
  78. fn(data, arg) {
  79. const area = []
  80. const dataArray = []
  81. data.forEach((element) => {
  82. area.push(element.时间)
  83. dataArray.push(element.温度)
  84. })
  85. this.Weatherarea = area
  86. this.WeatherdataArray = dataArray
  87. this.isWeather = true
  88. },
  89. },
  90. {
  91. key: `eachRegion`,
  92. fn(data, arg) {
  93. const area = []
  94. const dataArray = {
  95. LastYear: [],
  96. thisYear: [],
  97. }
  98. data.forEach((element) => {
  99. area.push(element.名称.slice(0, 2))
  100. dataArray.LastYear.push(element.去年)
  101. dataArray.thisYear.push(element.今年)
  102. })
  103. this.wavyLineArea = area
  104. this.wavyLinedataArray = dataArray
  105. this.isWavyLine = true
  106. },
  107. },
  108. {
  109. key: `variousRegions`,
  110. fn(data, arg) {
  111. const area = []
  112. const dataArray = []
  113. data.forEach((element) => {
  114. area.push(element.名称.slice(0, 2))
  115. dataArray.push(element.值)
  116. })
  117. this.Transplantarea = area
  118. this.TransplantdataArray = dataArray
  119. this.isGetData = true
  120. },
  121. },
  122. {
  123. key: `situation`,
  124. fn(data, arg) {
  125. const area = []
  126. const dataArray = {
  127. Done: [],
  128. Percentage: [],
  129. }
  130. const date = data.sort((a, b) => b.已移载 - a.已移载)
  131. date.forEach((element) => {
  132. area.push(element.名称.slice(0, 2))
  133. dataArray.Done.push(element.已移载)
  134. dataArray.Percentage.push(element.比率.toFixed(0))
  135. })
  136. this.HorizontalArea = area
  137. this.HorizontalArray = dataArray
  138. this.isHorizontal = true
  139. },
  140. },
  141. {
  142. key: `statistics`,
  143. fn(data, arg) {
  144. this.statisticsData = data
  145. this.isCake = true
  146. },
  147. },
  148. {
  149. key: `trendAnalysis`,
  150. fn(data, arg) {
  151. const area = []
  152. const dataArray = {
  153. LastYear: [],
  154. thisYear: [],
  155. }
  156. data.forEach((element) => {
  157. area.push(element.时间)
  158. dataArray.LastYear.push(element.去年)
  159. dataArray.thisYear.push(element.今年)
  160. })
  161. this.trendarea = area
  162. this.trendDataArray = dataArray
  163. this.isTrend = true
  164. },
  165. },
  166. ]
  167. export default {
  168. name: `Home`,
  169. components: {
  170. cylindricalHistogram,
  171. weatherForecast,
  172. wavyLineChart,
  173. HorizontalHistogram,
  174. bgBox,
  175. threeMap,
  176. cake,
  177. },
  178. data() {
  179. return {
  180. statisticsData: {},
  181. TransplantdataArray: [],
  182. Transplantarea: [],
  183. Weatherarea: [],
  184. WeatherdataArray: [],
  185. wavyLineArea: [],
  186. wavyLinedataArray: {
  187. LastYear: [],
  188. thisYear: [],
  189. },
  190. trendarea: [],
  191. trendDataArray: {
  192. LastYear: [],
  193. thisYear: [],
  194. },
  195. HorizontalArea: [],
  196. HorizontalArray: {
  197. Done: [],
  198. Percentage: [],
  199. },
  200. getJson: {},
  201. isGetData: false,
  202. isWeather: false,
  203. isWavyLine: false,
  204. isHorizontal: false,
  205. isTrend: false,
  206. hasGetJson: false,
  207. isCake: false,
  208. }
  209. },
  210. computed: {},
  211. created() {
  212. console.log(`开始`)
  213. apiLists.forEach((item) => {
  214. this.$bus.$on(item.key, (data) => {
  215. item.fn.call(this, data)
  216. })
  217. })
  218. this.getJSON()
  219. // this.$http.get(`https://httpbin.org/get`)
  220. },
  221. mounted() {
  222. // this.getAnalysisOfTransplantYieldInVariousRegions()
  223. // this.getWeatherForecast()
  224. // this.getTransplantAreaInEachRegion()
  225. // this.getAnalysisOfTransplantingSituation()
  226. screenSize(this.$refs.editor)
  227. },
  228. methods: {
  229. tabChange(val) {
  230. if (val === 0) {
  231. this.$router.push(`/page1`)
  232. } else if (val === 1) {
  233. this.$router.push(`/page2`)
  234. }
  235. console.log(`val`, val)
  236. },
  237. getAnalysisOfTransplantYieldInVariousRegions() {
  238. this.$http
  239. .get(`/api/analysisOfTransplantYieldInVariousRegions`)
  240. .then((res) => {
  241. res.forEach((element) => {
  242. this.Transplantarea.push(element.名称.slice(0, 2))
  243. this.TransplantdataArray.push(element.值)
  244. })
  245. this.isGetData = true
  246. })
  247. },
  248. getWeatherForecast() {
  249. this.$http.get(`/api/weatherForecast`).then((res) => {
  250. res.forEach((element) => {
  251. this.Weatherarea.push(element.时间)
  252. this.WeatherdataArray.push(element.温度)
  253. })
  254. this.isWeather = true
  255. })
  256. },
  257. getTransplantAreaInEachRegion() {
  258. this.$http.get(`/api/transplantAreaInEachRegion`).then((res) => {
  259. res.forEach((element) => {
  260. this.wavyLineArea.push(element.名称.slice(0, 2))
  261. this.wavyLinedataArray.LastYear.push(element.去年)
  262. this.wavyLinedataArray.thisYear.push(element.今年)
  263. })
  264. this.isWavyLine = true
  265. })
  266. },
  267. getAnalysisOfTransplantingSituation() {
  268. this.$http.get(`/api/analysisOfTransplantingSituation`).then((res) => {
  269. const date = res.sort((a, b) => b.已移载 - a.已移载)
  270. date.forEach((element) => {
  271. this.HorizontalArea.push(element.名称.slice(0, 2))
  272. this.HorizontalArray.Done.push(element.已移载)
  273. this.HorizontalArray.Percentage.push(element.比率.toFixed(0))
  274. })
  275. this.isHorizontal = true
  276. })
  277. },
  278. async getJSON() {
  279. console.log(`获取JSOn`)
  280. this.getJson = await this.$http.get(`/api/mapOfTongren`)
  281. console.log(this.getJson)
  282. this.hasGetJson = true
  283. },
  284. },
  285. }
  286. </script>