Browse Source

Merge branch 'master' of bls-dan/busRoute into master

Caner 2 years ago
parent
commit
7c79a33416

+ 95 - 33
src/pages/views/home/components/HomePage.vue

@@ -290,11 +290,14 @@
 
 <script setup lang='ts'>
 import Layout from '@/components/layout.vue'
-import { ref, watch } from 'vue'
+import { onMounted, ref } from 'vue'
 import Box from '@/components/box.vue'
 import { Vue3Marquee } from 'vue3-marquee'
 import { graphic } from 'echarts'
 import Echart from '@/components/chart.vue'
+import HomeService from '../services/homepage.service'
+
+const homeService = new HomeService()
 
 const datas = [
   {
@@ -522,6 +525,7 @@ const leftContent = ref({
             fontSize: 20
           }
         },
+        yAxis: [ ],
         series: [
           {
             type: 'pie', // 图表类型为饼图
@@ -577,7 +581,7 @@ const leftContent = ref({
             fontSize: 18
           }
         },
-        yAxis: {
+        yAxis: [ {
           type: 'category',
           inverse: true,
           axisTick: {
@@ -654,7 +658,7 @@ const leftContent = ref({
               return `{b|${id}}  ${params}`
             }
           }
-        },
+        } ],
         series: [
           {
             z: 2,
@@ -663,19 +667,7 @@ const leftContent = ref({
             barWidth: 25,
             zlevel: 1,
             data: datas.map((item, i) => ({
-              value: item.value,
-              itemStyle: {
-                color: new graphic.LinearGradient(0, 0, 1, 0, [
-                  {
-                    offset: 0,
-                    color: 'rgba(20,167,250,0.3)'
-                  },
-                  {
-                    offset: 1,
-                    color: 'rgba(0,255,209,1)'
-                  }
-                ])
-              }
+              value: item.value
             })),
             label: {
               position: 'inside',
@@ -683,7 +675,17 @@ const leftContent = ref({
               fontSize: 16
             },
             itemStyle: {
-              borderRadius: [ 0, 15, 15, 0 ]
+              borderRadius: [ 0, 15, 15, 0 ],
+              color: new graphic.LinearGradient(0, 0, 1, 0, [
+                {
+                  offset: 0,
+                  color: 'rgba(20,167,250,0.3)'
+                },
+                {
+                  offset: 1,
+                  color: 'rgba(0,255,209,1)'
+                }
+              ])
             }
           }
         ]
@@ -717,7 +719,7 @@ const leftContent = ref({
             fontSize: 18
           }
         },
-        yAxis: {
+        yAxis: [ {
           type: 'category',
           inverse: true,
           axisTick: {
@@ -794,7 +796,7 @@ const leftContent = ref({
               return `{b|${id}}  ${params}`
             }
           }
-        },
+        } ],
         series: [
           {
             z: 2,
@@ -803,19 +805,7 @@ const leftContent = ref({
             barWidth: 25,
             zlevel: 1,
             data: datas.map((item, i) => ({
-              value: item.value,
-              itemStyle: {
-                color: new graphic.LinearGradient(0, 0, 1, 0, [
-                  {
-                    offset: 0,
-                    color: 'rgba(20,167,250,0.3)'
-                  },
-                  {
-                    offset: 1,
-                    color: 'rgba(246,189,22,1)'
-                  }
-                ])
-              }
+              value: item.value
             })),
             label: {
               position: 'inside',
@@ -823,7 +813,17 @@ const leftContent = ref({
               fontSize: 16
             },
             itemStyle: {
-              borderRadius: [ 0, 15, 15, 0 ]
+              borderRadius: [ 0, 15, 15, 0 ],
+              color: new graphic.LinearGradient(0, 0, 1, 0, [
+                {
+                  offset: 0,
+                  color: 'rgba(20,167,250,0.3)'
+                },
+                {
+                  offset: 1,
+                  color: 'rgba(246,189,22,1)'
+                }
+              ])
             }
           }
         ]
@@ -951,6 +951,68 @@ const rightContent = ref([
 function changeFn(id: number, item: any) {
   item.checkId = id
 }
+const type = 1
+
+async function getBusSummaryInfo() {
+  const res = await homeService.getBusSummaryInfo()
+  leftContent.value.topCount[0][0].num = res.swipeCount
+  leftContent.value.topCount[0][1].num = res.passengerFlow
+  leftContent.value.topCount[0][2].num = res.mileageDriven
+
+  leftContent.value.topCount[1][0].num = res.carbonEmission
+  leftContent.value.topCount[1][1].num = res.accidentRate
+  leftContent.value.topCount[1][2].num = res.satisfaction
+}
+getBusSummaryInfo()
+
+async function getBusTrafficVolume() {
+  const res = await homeService.getBusTrafficVolume(type)
+  const xData = res.map((item: any) => item.time)
+  const trafficVolumeData = res.map((item: any) => item.trafficVolume)
+  const growthRateData = res.map((item: any) => item.growthRate)
+
+  leftContent.value.charts[0].option.xAxis!.data = xData
+  leftContent.value.charts[0].option.series[0].data = trafficVolumeData
+  leftContent.value.charts[0].option.series[1].data = growthRateData
+}
+async function getBusStatistics() {
+  const { consumptionProportion = [], flowRanking = [], lineFlowRanking = [] } = await homeService.getBusStatistics()
+
+  leftContent.value.charts[1].option.series[0].data = consumptionProportion
+
+  leftContent.value.charts[2].option.yAxis[0].data = flowRanking.map((item: any) => item.name)
+  leftContent.value.charts[2].option.series[0].data = flowRanking
+
+  leftContent.value.charts[3].option.yAxis[0].data = lineFlowRanking.map((item: any) => item.name)
+  leftContent.value.charts[3].option.series[0].data = lineFlowRanking
+}
+
+async function getBusWarning() {
+  const {
+    warningNum, companyNum, feedbackNum, secureNum, warningSummary
+  } = await homeService.getBusWarning()
+
+  rightContent.value[0].content[0][0].num = warningNum
+  rightContent.value[0].content[0][1].num = companyNum
+  rightContent.value[0].content[0][2].num = feedbackNum
+  rightContent.value[0].content[0][3].num = secureNum
+
+  rightContent.value[0].content[1][0].num = warningSummary.accident
+  rightContent.value[0].content[1][1].num = warningSummary.sentiment
+  rightContent.value[0].content[1][2].num = warningSummary.risk
+  rightContent.value[0].content[1][3].num = warningSummary.flood
+  rightContent.value[0].content[1][4].num = warningSummary.network
+  rightContent.value[0].content[1][5].num = warningSummary.fire
+  rightContent.value[0].content[1][6].num = warningSummary.warning
+  rightContent.value[0].content[1][7].num = warningSummary.charge
+  rightContent.value[0].content[1][8].num = warningSummary.battery
+}
+getBusWarning()
+
+onMounted(() => {
+  getBusTrafficVolume()
+  getBusStatistics()
+})
 </script>
 
 <style lang="scss" scoped>

+ 15 - 0
src/pages/views/home/index.vue

@@ -9,6 +9,9 @@ import stationManagement from './components/StationManagement.vue'
 import passengerFlow from './components/PassengerFlow.vue'
 import Map from '@/components/map.vue'
 import useStore from '@/pages/store'
+import HomeService from './services/homepage.service'
+
+const homeService = new HomeService()
 
 const store = useStore()
 const menus = [
@@ -137,6 +140,18 @@ function changMenu(_id: number) {
   active.value = _id
   currentComponent.value = menus[_id].component
 }
+
+async function getBusTotal() {
+  const res = await homeService.getBusTotal()
+  menus[0].count[0].value = res.busNum
+  menus[0].count[1].value = res.lineNum
+  menus[0].count[2].value = res.stationNum
+  menus[0].count[3].value = res.midwayStationNum
+  menus[0].count[4].value = res.classesNum
+  menus[0].count[5].value = res.totalMileage
+  menus[0].count[6].value = res.admissionRate
+}
+getBusTotal()
 </script>
 <template>
   <div class="home">

+ 64 - 0
src/pages/views/home/services/homepage.service.ts

@@ -0,0 +1,64 @@
+import useStore from '@/pages/store'
+import NetService from '@/services/net.service'
+import { injectable, Service } from '@/services/service'
+
+@injectable
+export default class HomeService extends Service {
+  private netService = new NetService()
+
+  /** 汇总统计数据  /homePage/getBusSummaryInfo   */
+  async getBusSummaryInfo() {
+    const { success, data } = await this.netService.get('/homePage/getBusSummaryInfo')
+    if (success) {
+      return data
+    }
+    return {}
+  }
+
+  /** 客运量数据 type 1月 2年  /homePage/getBusTrafficVolume */
+  async getBusTrafficVolume(type: 1|2) {
+    const { success, data } = await this.netService.get(`/homePage/getBusTrafficVolume?type=${type}`)
+    if (success) {
+      return data
+    }
+    return []
+  }
+
+  /** 消费占比/客流排名数据/线路客流排名  /homePage/getBusStatistics */
+  async getBusStatistics() {
+    const { success, data } = await this.netService.get('/homePage/getBusStatistics')
+    if (success) {
+      return {
+        consumptionProportion: JSON.parse(data.consumptionProportion),
+        flowRanking: JSON.parse(data.flowRanking),
+        lineFlowRanking: JSON.parse(data.lineFlowRanking)
+      }
+    }
+    return {}
+  }
+
+  /** 舆情统计数据   /homePage/getBusWarning */
+  async getBusWarning() {
+    const { success, data } = await this.netService.get('/homePage/getBusWarning')
+    if (success) {
+      const obj:any = {}
+      const temp = JSON.parse(data.warningSummary || '[]')
+      temp.forEach((item: { [x: string]: any }) => {
+        for (const key in item) {
+          obj[key] = item[key]
+        }
+      })
+      data.warningSummary = obj
+      return data
+    }
+  }
+
+  /** 场站设备统计数据  /homePage/getBusTotal */
+  async getBusTotal() {
+    const { success, data } = await this.netService.get('/homePage/getBusTotal')
+    if (success) {
+      return data
+    }
+    return {}
+  }
+}

+ 6 - 2
src/services/net.service.ts

@@ -1,3 +1,4 @@
+import useStore from '@/pages/store'
 import { injectable, Service } from './service'
 
 /** api接口返回值类型 */
@@ -11,7 +12,9 @@ declare type NetResult = {
  */
 @injectable
 export default class NetService extends Service {
-  protected url = import.meta.env.VITE_PROXY_URL
+  protected url = import.meta.env.VITE_SERVER_URL
+
+  private _store = useStore()
 
   /**
    * post方法请求接口
@@ -92,6 +95,7 @@ export default class NetService extends Service {
    * @returns
    */
   private fetch(url: string, opt: RequestInit, timeout = 0): Promise<NetResult> {
+    const satoken = this._store.token
     return new Promise((resolve) => {
       const controller = new AbortController()
       const { signal } = controller
@@ -103,7 +107,7 @@ export default class NetService extends Service {
       fetch(this.url + url, {
         signal,
         ...opt,
-        headers: opt.headers || { 'Content-Type': 'application/json' }
+        headers: opt.headers || { satoken, 'Content-Type': 'application/json' }
       }).then((res) => {
         if (res.status === 500) return { success: false, data: '请求错误' }
         return res.json()