From c5072da2b1aa9702a8733c5f9bde68655cf242f4 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Tue, 13 May 2025 15:38:42 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20feat:=20smart-park=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=A8=A1=E6=8B=9F=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/info.ts | 2 +- mock/smart-park.ts | 88 +++++++++++++ package.json | 2 +- src/api/smartPark.ts | 16 +++ src/store/modules/smartPark.ts | 38 ++++++ src/views/smart-park/charts/right-sidebar.ts | 11 +- .../components/smart-park-content.vue | 118 +++++++++--------- src/views/smart-park/index.vue | 31 ++++- tsconfig.json | 23 +--- 9 files changed, 240 insertions(+), 89 deletions(-) create mode 100644 mock/smart-park.ts create mode 100644 src/api/smartPark.ts create mode 100644 src/store/modules/smartPark.ts diff --git a/build/info.ts b/build/info.ts index da94b93..916479f 100644 --- a/build/info.ts +++ b/build/info.ts @@ -47,7 +47,7 @@ export const viteConsoleLog = (mode: string) => { console.log( boxen( gradientString('cyan', 'magenta').multiline( - `🎉 恭喜打包完成(总用时${format})打包大小(${logOutputSize()})` + `🎉 恭喜打包完成(总用时${format})打包大小(${logOutputSize()})` ), boxenOptions ) diff --git a/mock/smart-park.ts b/mock/smart-park.ts new file mode 100644 index 0000000..70a628b --- /dev/null +++ b/mock/smart-park.ts @@ -0,0 +1,88 @@ +import { defineFakeRoute } from 'vite-plugin-fake-server'; + +const randomNumber = (range: number = 100) => { + return parseInt((Math.random() * range).toFixed(0)); +}; + +const mockRoadStatus = () => { + const list = ['拥堵', '畅通']; + const index = randomNumber(1); + + return list[index]; +}; + +export default defineFakeRoute([ + // 道路状况 + { + url: '/api/smart-park/road-status', + method: 'GET', + response: () => ({ + code: 200, + data: { + entrances: [ + { + id: 1, + name: '入卡口(西北门)', + status: mockRoadStatus(), + }, + { + id: 2, + name: '入卡口(东北门)', + status: mockRoadStatus(), + }, + { + id: 3, + name: '入卡口(东南门)', + status: mockRoadStatus(), + }, + { + id: 4, + name: '入卡口(东南门)', + status: mockRoadStatus(), + }, + ], + suggest: ` 高峰时段大量车流量容易造成拥堵,主要由XXX企业、XXX企业的车辆构成, + 可建议XXX企业向后延迟15min错峰入园。 + 高峰时段大量车流量容易造成拥堵, 主要由XXX企业、XXX企业的车辆构成`, + }, + message: '操作成功', + }), + }, + // 车辆监控 + { + url: '/api/smart-park/monitor', + method: 'GET', + response: () => ({ + code: 200, + data: [ + { count: randomNumber(999), door: '入卡口(西北门)', percent: randomNumber() }, + { count: randomNumber(999), door: '入卡口(东北门)', percent: randomNumber() }, + { count: randomNumber(999), door: '入卡口(东南门)', percent: randomNumber() }, + { count: randomNumber(999), door: '入卡口(东南门)', percent: randomNumber() }, + ], + message: '操作成功', + }), + }, + // 车流量 + { + url: '/api/smart-park/flow-rate', + method: 'GET', + response: () => ({ + code: 200, + data: { + overview: [ + { title: '最高进园车流量', statistics: randomNumber(9999) }, + { title: '最高出园车流量', statistics: randomNumber(9999) }, + ], + timeline: ['02.01', '02.02', '02.03', '02.04', '02.05', '02.06', '02.22'], + enter: Array(11) + .fill(0) + .map(() => randomNumber(999).toFixed(2)), + outer: Array(11) + .fill(0) + .map(() => randomNumber(999).toFixed(2)), + }, + message: '操作成功', + }), + }, +]); diff --git a/package.json b/package.json index f31903d..79a520a 100644 --- a/package.json +++ b/package.json @@ -93,4 +93,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/api/smartPark.ts b/src/api/smartPark.ts new file mode 100644 index 0000000..16d630c --- /dev/null +++ b/src/api/smartPark.ts @@ -0,0 +1,16 @@ +import request from '@/api/server/request'; + +/* 实时道路 */ +export const fetchRoadStatus = () => { + return request.get('/smart-park/road-status'); +}; + +/* 车辆监控 */ +export const fetchTollgateMonitoringData = () => { + return request.get('smart-park/monitor'); +}; + +/* 车流量概览 */ +export const fetchTrafficStatistics = () => { + return request.get('/smart-park/flow-rate'); +}; diff --git a/src/store/modules/smartPark.ts b/src/store/modules/smartPark.ts new file mode 100644 index 0000000..5fc3f7b --- /dev/null +++ b/src/store/modules/smartPark.ts @@ -0,0 +1,38 @@ +import { defineStore } from 'pinia'; + +import { + fetchRoadStatus, + fetchTollgateMonitoringData, + fetchTrafficStatistics, +} from '@/api/smartPark'; + +export const useSmartPark = defineStore('smartparkStore', { + state: () => ({ + // 道路状态 + roadStatus: [], + // 道路建议 + roadStatusSuggest: '', + // 卡口车辆监控 + tollgateMonitoringData: [], + // 车浏览概览 + trafficStatistics: { overview: [], outer: [], enter: [], timeline: [] }, + }), + actions: { + /* 道路情况 */ + async loadRoadStatus() { + const result: any = await fetchRoadStatus(); + this.roadStatus = result.entrances; + this.roadStatusSuggest = result.suggest; + }, + /* 卡口车辆监控 */ + async loadTollgateMonitoringData() { + const result = await fetchTollgateMonitoringData(); + this.tollgateMonitoringData = result; + }, + /* 车流量概览 */ + async loadFlowRate() { + const result = await fetchTrafficStatistics(); + this.trafficStatistics = result; + }, + }, +}); diff --git a/src/views/smart-park/charts/right-sidebar.ts b/src/views/smart-park/charts/right-sidebar.ts index 0ca2711..ccf3dd4 100644 --- a/src/views/smart-park/charts/right-sidebar.ts +++ b/src/views/smart-park/charts/right-sidebar.ts @@ -31,7 +31,7 @@ const option = { xAxis: { type: 'category', show: true, - data: ['02.01', '02.02', '02.03', '02.04', '02.05', '02.06', '02.07'], + data: [], itemStyle: { color: '#ccc' }, splitLine: { show: true, @@ -108,7 +108,10 @@ export const renderEcharts = (element: Ref) => { /** 更新图表数据 */ export const updateChart = (option: any) => { const series = myChart.getOption().series; - series[0].data = option.data1; - series[1].data = option.data2; - myChart.setOption({ series }); + const xAxis = myChart.getOption().xAxis; + series[0].data = option.outer; + series[1].data = option.enter; + xAxis[0].data = option.timeline; + + myChart.setOption({ series, xAxis }); }; diff --git a/src/views/smart-park/components/smart-park-content.vue b/src/views/smart-park/components/smart-park-content.vue index db47313..599af2b 100644 --- a/src/views/smart-park/components/smart-park-content.vue +++ b/src/views/smart-park/components/smart-park-content.vue @@ -1,33 +1,38 @@ @@ -42,36 +47,33 @@ onMounted(() => {
车流量建议
-

- 高峰时段大量车流量容易造成拥堵,主要由XXX企业、XXX企业的车辆构成, - 可建议XXX企业向后延迟15min错峰入园。 - 高峰时段大量车流量容易造成拥堵, 主要由XXX企业、XXX企业的车辆构成 -

+

@@ -84,21 +86,13 @@ onMounted(() => {
-
- - -
-
- - -
-
- - -
-
- - +
+ +
@@ -119,13 +113,13 @@ onMounted(() => {
    -
  • - 最高进园车流量 - 897 -
  • -
  • - 最高进园车流量 - 494 +
  • + {{ item.title }} + {{ item.statistics }}
@@ -172,7 +166,7 @@ onMounted(() => { background: url('@/views/smart-park/images/bg/bg-suggest.png') no-repeat center; background-size: cover; - span { + :deep(span) { color: var(--color-warning-secondary); } } diff --git a/src/views/smart-park/index.vue b/src/views/smart-park/index.vue index e35d833..8cbd3b5 100644 --- a/src/views/smart-park/index.vue +++ b/src/views/smart-park/index.vue @@ -1,11 +1,36 @@