index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. id="`移栽情况分析`"
  42. title="移栽情况分析"
  43. :area="HorizontalArea"
  44. :dataArray="HorizontalArray"
  45. ></HorizontalHistogram>
  46. <wavyLineChart
  47. id="`移栽趋势分析`"
  48. style="position: absolute; right: 50px; top: 760px"
  49. v-if="isWavyLine"
  50. title="移栽趋势分析"
  51. :area="trendarea"
  52. :dataArray="trendDataArray"
  53. >
  54. </wavyLineChart>
  55. <threeMap
  56. style="
  57. position: absolute;
  58. top: 50%;
  59. left: 50%;
  60. transform: translate(-55%, 20%);
  61. "
  62. v-if="hasGetJson"
  63. :getJson="getJson"
  64. ></threeMap>
  65. </bgBox>
  66. </template>
  67. <script>
  68. import bgBox from '@/components/bgBox/index.vue'
  69. import { screenSize } from '@/assets/js/utils'
  70. import cake from '@/components/Customize/cake'
  71. import cylindricalHistogram from '@/components/Customize/cylindricalHistogram'
  72. import weatherForecast from '@/components/Customize/weatherForecast'
  73. import wavyLineChart from '@/components/Customize/wavyLineChart'
  74. import HorizontalHistogram from '@/components/Customize/HorizontalHistogram'
  75. import threeMap from '@/components/Customize/map/index'
  76. const apiLists = [
  77. {
  78. key: `weatherForecast`,
  79. fn(data, arg) {
  80. const area = []
  81. const dataArray = []
  82. data.forEach((element) => {
  83. area.push(element.时间)
  84. dataArray.push(element.温度)
  85. })
  86. this.Weatherarea = area
  87. this.WeatherdataArray = dataArray
  88. this.isWeather = true
  89. },
  90. },
  91. {
  92. key: `eachRegion`,
  93. fn(data, arg) {
  94. const area = []
  95. const dataArray = {
  96. LastYear: [],
  97. thisYear: [],
  98. }
  99. data.forEach((element) => {
  100. area.push(element.名称.slice(0, 2))
  101. dataArray.LastYear.push(element.去年)
  102. dataArray.thisYear.push(element.今年)
  103. })
  104. this.wavyLineArea = area
  105. this.wavyLinedataArray = dataArray
  106. this.isWavyLine = true
  107. },
  108. },
  109. {
  110. key: `variousRegions`,
  111. fn(data, arg) {
  112. const area = []
  113. const dataArray = []
  114. data.forEach((element) => {
  115. area.push(element.名称.slice(0, 2))
  116. dataArray.push(element.值)
  117. })
  118. this.Transplantarea = area
  119. this.TransplantdataArray = dataArray
  120. this.isGetData = true
  121. },
  122. },
  123. {
  124. key: `situation`,
  125. fn(data, arg) {
  126. const area = []
  127. const dataArray = {
  128. Done: [],
  129. Percentage: [],
  130. }
  131. const date = data.sort((a, b) => b.已移载 - a.已移载)
  132. date.forEach((element) => {
  133. area.push(element.名称.slice(0, 2))
  134. dataArray.Done.push(element.已移载)
  135. dataArray.Percentage.push(element.比率.toFixed(0))
  136. })
  137. this.HorizontalArea = area
  138. this.HorizontalArray = dataArray
  139. this.isHorizontal = true
  140. },
  141. },
  142. {
  143. key: `statistics`,
  144. fn(data, arg) {
  145. const obj = this.statisticsData
  146. // eslint-disable-next-line no-prototype-builtins
  147. if (data.hasOwnProperty(obj.title)) {
  148. obj.value = data[obj.title]
  149. }
  150. const list1 = this.statisticsData.acrossList
  151. this.statisticsData.acrossList = list1.map((item) => {
  152. // eslint-disable-next-line no-prototype-builtins
  153. if (data.hasOwnProperty(item.name)) {
  154. return { ...item, value: data[item.name] }
  155. }
  156. return item
  157. })
  158. const list2 = this.statisticsData.verticalList
  159. this.statisticsData.verticalList = list2.map((item) => {
  160. // eslint-disable-next-line no-prototype-builtins
  161. if (data.hasOwnProperty(item.name)) {
  162. return { ...item, value: data[item.name] }
  163. }
  164. return item
  165. })
  166. this.isCake = true
  167. },
  168. },
  169. {
  170. key: `trendAnalysis`,
  171. fn(data, arg) {
  172. const area = []
  173. const dataArray = {
  174. LastYear: [],
  175. thisYear: [],
  176. }
  177. data.forEach((element) => {
  178. area.push(element.时间)
  179. dataArray.LastYear.push(element.去年)
  180. dataArray.thisYear.push(element.今年)
  181. })
  182. this.trendarea = area
  183. this.trendDataArray = dataArray
  184. this.isTrend = true
  185. },
  186. },
  187. ]
  188. export default {
  189. name: `Home`,
  190. components: {
  191. cylindricalHistogram,
  192. weatherForecast,
  193. wavyLineChart,
  194. HorizontalHistogram,
  195. bgBox,
  196. threeMap,
  197. cake,
  198. },
  199. data() {
  200. return {
  201. statisticsData: {
  202. title: `目标完成率`,
  203. value: 0,
  204. acrossList: [
  205. { name: `年移栽数量`, value: undefined },
  206. { name: `年移栽面积`, value: undefined },
  207. ],
  208. verticalList: [
  209. { name: `移栽区域数`, value: undefined },
  210. { name: `烟农数量`, value: undefined },
  211. ],
  212. },
  213. TransplantdataArray: [],
  214. Transplantarea: [],
  215. Weatherarea: [],
  216. WeatherdataArray: [],
  217. wavyLineArea: [],
  218. wavyLinedataArray: {
  219. LastYear: [],
  220. thisYear: [],
  221. },
  222. trendarea: [],
  223. trendDataArray: {
  224. LastYear: [],
  225. thisYear: [],
  226. },
  227. HorizontalArea: [],
  228. HorizontalArray: {
  229. Done: [],
  230. Percentage: [],
  231. },
  232. getJson: {},
  233. isGetData: false,
  234. isWeather: false,
  235. isWavyLine: false,
  236. isHorizontal: false,
  237. isTrend: false,
  238. hasGetJson: false,
  239. isCake: false,
  240. }
  241. },
  242. computed: {},
  243. created() {
  244. console.log(`开始`)
  245. apiLists.forEach((item) => {
  246. this.$bus.$on(item.key, (data) => {
  247. item.fn.call(this, data)
  248. })
  249. })
  250. this.getJSON()
  251. // this.$http.get(`https://httpbin.org/get`)
  252. },
  253. mounted() {
  254. // this.getAnalysisOfTransplantYieldInVariousRegions()
  255. // this.getWeatherForecast()
  256. // this.getTransplantAreaInEachRegion()
  257. // this.getAnalysisOfTransplantingSituation()
  258. screenSize(this.$refs.editor)
  259. },
  260. beforeDestroy() {
  261. apiLists.forEach((item) => {
  262. console.log(`销毁了`, item.key)
  263. this.$bus.$off(item.key)
  264. })
  265. },
  266. methods: {
  267. tabChange(val) {
  268. if (val === 0) {
  269. this.$router.push(`/page1`)
  270. } else if (val === 1) {
  271. this.$router.push(`/page2`)
  272. }
  273. console.log(`val`, val)
  274. },
  275. getAnalysisOfTransplantYieldInVariousRegions() {
  276. this.$http
  277. .get(`/api/analysisOfTransplantYieldInVariousRegions`)
  278. .then((res) => {
  279. res.forEach((element) => {
  280. this.Transplantarea.push(element.名称.slice(0, 2))
  281. this.TransplantdataArray.push(element.值)
  282. })
  283. this.isGetData = true
  284. })
  285. },
  286. getWeatherForecast() {
  287. this.$http.get(`/api/weatherForecast`).then((res) => {
  288. res.forEach((element) => {
  289. this.Weatherarea.push(element.时间)
  290. this.WeatherdataArray.push(element.温度)
  291. })
  292. this.isWeather = true
  293. })
  294. },
  295. getTransplantAreaInEachRegion() {
  296. this.$http.get(`/api/transplantAreaInEachRegion`).then((res) => {
  297. res.forEach((element) => {
  298. this.wavyLineArea.push(element.名称.slice(0, 2))
  299. this.wavyLinedataArray.LastYear.push(element.去年)
  300. this.wavyLinedataArray.thisYear.push(element.今年)
  301. })
  302. this.isWavyLine = true
  303. })
  304. },
  305. getAnalysisOfTransplantingSituation() {
  306. this.$http.get(`/api/analysisOfTransplantingSituation`).then((res) => {
  307. const date = res.sort((a, b) => b.已移载 - a.已移载)
  308. date.forEach((element) => {
  309. this.HorizontalArea.push(element.名称.slice(0, 2))
  310. this.HorizontalArray.Done.push(element.已移载)
  311. this.HorizontalArray.Percentage.push(element.比率.toFixed(0))
  312. })
  313. this.isHorizontal = true
  314. })
  315. },
  316. async getJSON() {
  317. console.log(`获取JSOn`)
  318. this.getJson = await this.$http.get(
  319. `/datav/areas_v3/bound/geojson?code=520600_full`
  320. )
  321. console.log(this.getJson)
  322. this.hasGetJson = true
  323. },
  324. },
  325. }
  326. </script>