组件之间数据渲染逻辑

This commit is contained in:
ym1026
2025-09-03 15:41:12 +08:00
parent 1568677c8e
commit 369f7165cb
15 changed files with 1018 additions and 892 deletions

View File

@@ -8,7 +8,8 @@
<span class="linear-text">{{ item.title }}</span>
</div>
</div>
<component :is="item.componentId" :device-info="deviceInfo[item.infoKey]"></component>
<component :is="item.componentId" :props-total="deviceInfo.allTotal" :props-info="deviceInfo[item.infoKey]" ></component>
<!-- -->
</div>
</div>
@@ -20,7 +21,7 @@
<span class="linear-text">{{ item.title }}</span>
</div>
</div>
<component :is="item.componentId" :device-info="deviceInfo[item.infoKey]"></component>
<component :is="item.componentId" :props-total="deviceInfo.allTotal" :props-info="deviceInfo[item.infoKey]" ></component>
</div>
</div>
</div>
@@ -34,6 +35,7 @@ import Revenue from '@/components/Home/Modal/Revenue.vue'
import Utilization from '@/components/Home/Modal/Utilization.vue'
import DisCharge from '@/components/Home/Modal/DisCharge.vue'
import Operational from '@/components/Home/Operational.vue'
import { getReq, postReq } from '@/request/api'
import Charge from '@/components/Home/Charge.vue'
import Alarm from '@/components/Home/Alarm.vue'
@@ -105,222 +107,254 @@ export default {
}
},
async mounted() {
this.deviceInfo = {
alarm: [
{
date: '2025-08-30',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-29',
key1: 8,
key2: 5,
key3: 5,
key4: 7
},
{
date: '2025-08-28',
key1: 0,
key2: 10,
key3: 20,
key4: 4
},
{
date: '2025-08-27',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-26',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-25',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-24',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-23',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-22',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-21',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-20',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-19',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-18',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-17',
key1: 10,
key2: 0,
key3: 15,
key4: 5
}
],
energy: [
{
date: '2025-08-30',
key1: '2',
key2: '2'
},
{
date: '2025-08-29',
key1: '2',
key2: '2'
},
{
date: '2025-08-28',
key1: '2',
key2: '2'
},
{
date: '2025-08-27',
key1: '2',
key2: '2'
},
{
date: '2025-08-26',
key1: '2',
key2: '2'
},
{
date: '2025-08-25',
key1: '2',
key2: '2'
},
{
date: '2025-08-24',
key1: '2',
key2: '2'
}
],
charge: [
{
date: '2025-08-30',
key1: '2',
key2: '2'
},
{
date: '2025-08-29',
key1: '2',
key2: '2'
},
{
date: '2025-08-28',
key1: '2',
key2: '2'
},
{
date: '2025-08-27',
key1: '2',
key2: '2'
},
{
date: '2025-08-26',
key1: '2',
key2: '2'
},
{
date: '2025-08-25',
key1: '2',
key2: '2'
},
{
date: '2025-08-24',
key1: '2',
key2: '2'
}
],
pv: [
{
date: '2025-08-30',
key1: '2',
key2: '2'
},
{
date: '2025-08-29',
key1: '2',
key2: '2'
},
{
date: '2025-08-28',
key1: '2',
key2: '2'
},
{
date: '2025-08-27',
key1: '2',
key2: '2'
},
{
date: '2025-08-26',
key1: '2',
key2: '2'
},
{
date: '2025-08-25',
key1: '2',
key2: '2'
},
{
date: '2025-08-24',
key1: '2',
key2: '2'
}
]
}
},
await Promise.all([
this.getTotalList(),
methods: {}
( this.deviceInfo = {
alarm: [
{
date: '2025-08-30',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-29',
key1: 8,
key2: 5,
key3: 5,
key4: 7
},
{
date: '2025-08-28',
key1: 0,
key2: 10,
key3: 20,
key4: 4
},
{
date: '2025-08-27',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-26',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-25',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-24',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-23',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-22',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-21',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-20',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-19',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-18',
key1: 10,
key2: 0,
key3: 15,
key4: 5
},
{
date: '2025-08-17',
key1: 10,
key2: 0,
key3: 15,
key4: 5
}
],
energy: [
{
date: '2025-08-30',
key1: '2',
key2: '2'
},
{
date: '2025-08-29',
key1: '2',
key2: '2'
},
{
date: '2025-08-28',
key1: '2',
key2: '2'
},
{
date: '2025-08-27',
key1: '2',
key2: '2'
},
{
date: '2025-08-26',
key1: '2',
key2: '2'
},
{
date: '2025-08-25',
key1: '2',
key2: '2'
},
{
date: '2025-08-24',
key1: '2',
key2: '2'
}
],
charge: [
{
date: '2025-08-30',
key1: '2',
key2: '2'
},
{
date: '2025-08-29',
key1: '2',
key2: '2'
},
{
date: '2025-08-28',
key1: '2',
key2: '2'
},
{
date: '2025-08-27',
key1: '2',
key2: '2'
},
{
date: '2025-08-26',
key1: '2',
key2: '2'
},
{
date: '2025-08-25',
key1: '2',
key2: '2'
},
{
date: '2025-08-24',
key1: '2',
key2: '2'
}
],
pv: [
{
date: '2025-08-30',
key1: '2',
key2: '2'
},
{
date: '2025-08-29',
key1: '2',
key2: '2'
},
{
date: '2025-08-28',
key1: '2',
key2: '2'
},
{
date: '2025-08-27',
key1: '2',
key2: '2'
},
{
date: '2025-08-26',
key1: '2',
key2: '2'
},
{
date: '2025-08-25',
key1: '2',
key2: '2'
},
{
date: '2025-08-24',
key1: '2',
key2: '2'
}
]
}),
])
},
methods: {
async getTotalList(){
try {
// token: 用户TOKEN
const res = await getReq({}, '')
if (res.code === 200) {
this.deviceInfo.allTotal = res.data
} else {
throw res
}
} catch (error) {
this.deviceInfo.allTotal = {
tianshu:11,
shouyi:12,
shuliang:10,
fadianliang:15,
key2:11,
key1:12,
key3:10,
key4:15,
rongliang:15,
}
}
}
}
}
</script>

View File

@@ -8,7 +8,7 @@
export default {
name: '',
props: {
deviceInfo: {
propsInfo: {
type: Array,
default: () => []
}
@@ -41,7 +41,7 @@ export default {
}
},
watch: {
deviceInfo: {
propsInfo: {
handler(n) {
this.$nextTick(() => {
this.drawLineChart()
@@ -79,7 +79,7 @@ export default {
getDisChargeData() {
const arr=this.curList
const keyList=this.curList.map((item)=>item.key)
const result = this.processData(this.deviceInfo, keyList)
const result = this.processData(this.propsInfo, keyList)
this.lineChartData.xdata = result.dates
arr.forEach((item, index) => {

View File

@@ -2,72 +2,71 @@
<div class="onLine">
<div class="content">
<div v-for="item in list" :key="item.key" :class="`item ${item.class}`">
<a-image :preview="false" :src="item.iconPath" :width="25" class="left"> </a-image>
<i
:class="`iconfont icon-${item.icon}`"
:style="`font-size:25px; cursor: pointer; color: ${item.color};`"
/>
<div class="right">
<span>{{ item.label }}</span>
<span>{{ item.value }} {{ item.d }}</span
>
</div>
<span>{{ item.label }}</span>
<span>{{ item.value }} {{ item.d }}</span>
</div>
</div>
</div>
</div>
</template>
<script>
import { legacyLogicalPropertiesTransformer } from 'ant-design-vue'
export default {
name: '',
props: {
propsInfo: {
propsTotal: {
type: Object,
default: ()=>({
name: '场站111',
statusName:'充电'
})
default: () => {}
},
propsInfo: {
type: Array,
default: () => []
}
},
data() {
return {
list: [
{
key: 'tianshu',
value: 26,
d: 'Lux',
label: '光照',
key: 'key1',
value: '制冷',
d: '',
label: '冷机',
class: 'item-1',
iconPath: require('@/assets/home/guangzhao.png')
icon: 'lengji',
color: '#F69B52'
},
{
key: 'shouyi',
value: 25,
d: 'm/s',
label: '风速',
key: 'key2',
value: '开机',
d: '',
label: '空调',
class: 'item-2',
iconPath: require('@/assets/home/fengsu.png')
icon: 'kongdiaogongcheng',
color: '#9BD801'
},
{
key: 'shuliang',
key: 'key3',
value: 24,
d: '℃',
label: '环境温度',
class: 'item-3',
iconPath: require('@/assets/home/hj-wendu.png')
icon: 'wenduji',
color: '#3DFEFA'
},
{
key: 'shuliang',
key: 'key4',
value: 26,
d: '%',
label: '环境湿度',
class: 'item-4',
iconPath: require('@/assets/home/hj-shidu.png')
},
icon: 'shidu',
color: '#D83D6C'
}
]
}
},
@@ -79,7 +78,19 @@ export default {
return this.list.filter((_, index) => index % 2 !== 0).slice(0, 3) // 右列取前3个奇数索引
}
},
watch: {},
watch: {
propsTotal: {
handler(n) {
if (n) {
this.list.forEach((item) => {
item.value = this.propsTotal[item.key]
})
}
},
deep: true,
immediate: true
}
},
mounted() {},
methods: {}
}
@@ -91,13 +102,11 @@ export default {
display: flex;
justify-content: center;
align-items: center;
width:95%;
width: 95%;
margin: auto;
}
.content{
.content {
flex-wrap: wrap;
width: 100%;
display: flex;
@@ -105,35 +114,30 @@ export default {
justify-content: space-around;
height: 100%;
.item{
height:50%;
width: 25%;
// height: 47px;
box-sizing: border-box;
display: flex;
align-items: center;
// justify-content: center;
// text-align: center;
.item {
height: 50%;
width: 25%;
// height: 47px;
box-sizing: border-box;
display: flex;
align-items: center;
// justify-content: center;
// text-align: center;
& > span:nth-child(1) {
font-size: 12px;
margin-bottom: 10px;
& > span:nth-child(1) {
font-size: 12px;
margin-bottom: 10px;
}
.d {
margin-left: 1px;
font-size: 12px;
}
}
.d {
margin-left: 1px;
font-size: 12px;
}
}
.right {
display: flex;
flex-direction: column;
margin-left: 20px;
display: flex;
flex-direction: column;
margin-left: 20px;
}
}
}
</style>

View File

@@ -4,33 +4,27 @@
<div v-for="item in list" :key="item.key" :class="`item ${item.class}`">
<a-image :preview="false" :src="item.iconPath" :width="50" class="left"> </a-image>
<div class="right">
<span>{{ item.label }}</span>
<span>{{ item.value }} {{ item.d }}</span
>
</div>
<span>{{ item.label }}</span>
<span>{{ item.value }} {{ item.d }}</span>
</div>
</div>
</div>
</div>
</template>
<script>
import { legacyLogicalPropertiesTransformer } from 'ant-design-vue'
export default {
name: '',
props: {
propsInfo: {
propsTotal: {
type: Object,
default: ()=>({
name: '场站111',
statusName:'充电'
})
}
default: () => {}
},
propsInfo: {
type: Array,
default: () => []
},
},
data() {
return {
@@ -94,7 +88,19 @@ export default {
return this.list.filter((_, index) => index % 2 !== 0).slice(0, 3) // 右列取前3个奇数索引
}
},
watch: {},
watch: {
propsTotal: {
handler(n) {
if (n) {
this.list.forEach((item) => {
item.value = this.propsTotal[item.key]
})
}
},
deep: true,
immediate: true
}
},
mounted() {},
methods: {}
}
@@ -106,14 +112,11 @@ export default {
display: flex;
justify-content: center;
align-items: center;
width:95%;
width: 95%;
margin: auto;
}
.content{
.content {
flex-wrap: wrap;
width: 100%;
display: flex;
@@ -121,35 +124,30 @@ export default {
justify-content: space-around;
height: 100%;
.item{
height:50%;
width: 30%;
// height: 47px;
box-sizing: border-box;
display: flex;
align-items: center;
// justify-content: center;
// text-align: center;
.item {
height: 50%;
width: 30%;
// height: 47px;
box-sizing: border-box;
display: flex;
align-items: center;
// justify-content: center;
// text-align: center;
& > span:nth-child(1) {
font-size: 12px;
margin-bottom: 10px;
& > span:nth-child(1) {
font-size: 12px;
margin-bottom: 10px;
}
.d {
margin-left: 1px;
font-size: 12px;
}
}
.d {
margin-left: 1px;
font-size: 12px;
}
}
.right {
display: flex;
flex-direction: column;
margin-left: 20px;
display: flex;
flex-direction: column;
margin-left: 20px;
}
}
}
</style>

View File

@@ -3,7 +3,7 @@
<div class="content-left">
<div v-for="item in leftList" :key="item.key" :class="`item ${item.class}`">
<div>
<span>{{ item.value }}</span
<span>{{ item.value ? item.value :0}}</span
><span class="d">{{ item.d }}</span>
</div>
<span>{{ item.label }}</span>
@@ -11,13 +11,13 @@
</div>
<div style="text-align: center;font-weight: 500;">
<div class="online-icon"></div>
<span>{{ propsInfo.statusName }}</span>
<span>{{ curStatus }}</span>
</div>
<div class="content-right">
<div v-for="item in rightList" :key="item.key" :class="`item ${item.class}`">
<div>
<span>{{ item.value }}</span
<span>{{ item.value ? item.value :0 }}</span
><span class="d">{{ item.d }}</span>
</div>
<span>{{ item.label }}</span>
@@ -27,21 +27,22 @@
</template>
<script>
import { legacyLogicalPropertiesTransformer } from 'ant-design-vue'
export default {
name: '',
props: {
propsInfo: {
propsTotal: {
type: Object,
default: () => ({
name: '场站111',
statusName: '充电'
})
default: () => {}
},
propsInfo: {
type: Array,
default: () => []
}
},
data() {
return {
curStatus:'充电',
list: [
{
key: 'tianshu',
@@ -96,7 +97,19 @@ export default {
return this.list.filter((_, index) => index % 2 !== 0).slice(0, 3) // 右列取前3个奇数索引
}
},
watch: {},
watch: {
propsTotal: {
handler(n) {
if (n) {
this.list.forEach((item) => {
item.value = this.propsTotal[item.key]
})
}
},
deep: true,
immediate: true
}
},
mounted() {},
methods: {}
}

View File

@@ -8,7 +8,7 @@
export default {
name: '',
props: {
deviceInfo: {
propsInfo: {
type: Array,
default: () => []
}
@@ -37,7 +37,7 @@ export default {
}
},
watch: {
deviceInfo: {
propsInfo: {
handler(n) {
this.$nextTick(() => {
this.drawLineChart()
@@ -75,7 +75,7 @@ export default {
getRevenueData() {
const arr=this.curList
const keyList=this.curList.map((item)=>item.key)
const result = this.processData(this.deviceInfo, keyList)
const result = this.processData(this.propsInfo, keyList)
this.lineChartData.xdata = result.dates
arr.forEach((item, index) => {

View File

@@ -2,7 +2,7 @@
<div class="onLine">
<div class="content">
<div v-for="item in list" :key="item.key" :class="`item ${item.class}`">
<span>{{ item.value }} {{ item.d }}</span>
<span>{{ item.value ? item.value : 0 }} {{ item.d }}</span>
<span>{{ item.label }}</span>
</div>
</div>
@@ -10,11 +10,13 @@
</template>
<script>
import { legacyLogicalPropertiesTransformer } from 'ant-design-vue'
export default {
name: '',
props: {
propsTotal: {
type: Object,
default: () => {}
},
propsInfo: {
type: Object,
default: () => ({
@@ -77,7 +79,19 @@ export default {
return this.list.filter((_, index) => index % 2 !== 0).slice(0, 3) // 右列取前3个奇数索引
}
},
watch: {},
watch: {
propsTotal: {
handler(n) {
if (n) {
this.list.forEach((item) => {
item.value = this.propsTotal[item.key]
})
}
},
deep: true,
immediate: true
}
},
mounted() {},
methods: {}
}
@@ -89,7 +103,7 @@ export default {
display: flex;
justify-content: center;
align-items: center;
width:95%;
width: 95%;
margin: auto;
}

View File

@@ -8,7 +8,7 @@
export default {
name: '',
props: {
deviceInfo: {
propsInfo: {
type: Array,
default: () => []
}
@@ -35,7 +35,7 @@ export default {
}
},
watch: {
deviceInfo: {
propsInfo: {
handler(n) {
this.$nextTick(() => {
this.drawLineChart()
@@ -73,7 +73,7 @@ export default {
getUtilizationData() {
const arr=this.curList
const keyList=this.curList.map((item)=>item.key)
const result = this.processData(this.deviceInfo, keyList)
const result = this.processData(this.propsInfo, keyList)
this.lineChartData.xdata = result.dates
arr.forEach((item, index) => {

View File

@@ -39,7 +39,7 @@ export default {
},
{
name: '利用率',
key: 'connector_off',
key: 'key2',
percentKey: 'connector_off_percent',
lineColor:
'linear-gradient(90deg, rgba(53, 120, 124, 1) 0%, rgba(102, 225, 223, 1) 100%);',

View File

@@ -3,14 +3,20 @@
<div class="content-left">
<div v-for="item in leftList" :key="item.key" :class="`item ${item.class}`">
<span>{{ item.label }}</span>
<div> <span>{{ item.value }}</span><span class="d">{{ item.d }}</span></div>
<div>
<span>{{ item.value ? item.value : 0 }}</span
><span class="d">{{ item.d }}</span>
</div>
</div>
</div>
<div class="online-icon"></div>
<div class="content-right">
<div v-for="item in rightList" :key="item.key" :class="`item ${item.class}`">
<span>{{ item.label }}</span>
<div> <span>{{ item.value }}</span><span class="d">{{ item.d }}</span></div>
<div>
<span>{{ item.value ? item.value : 0 }}</span
><span class="d">{{ item.d }}</span>
</div>
</div>
</div>
</div>
@@ -20,6 +26,10 @@
export default {
name: '',
props: {
total: {
type: Object,
default: () => {}
},
deviceInfo: {
type: Array,
default: () => []
@@ -27,7 +37,7 @@ export default {
},
data() {
return {
list: [
curList: [
{
key: 'launchDate',
value: 20,
@@ -75,13 +85,26 @@ export default {
},
computed: {
leftList() {
return this.list.filter((_, index) => index % 2 === 0).slice(0, 3) // 左列取前3个偶数索引
return this.curList.filter((_, index) => index % 2 === 0).slice(0, 3) // 左列取前3个偶数索引
},
rightList() {
return this.list.filter((_, index) => index % 2 !== 0).slice(0, 3) // 右列取前3个奇数索引
return this.curList.filter((_, index) => index % 2 !== 0).slice(0, 3) // 右列取前3个奇数索引
}
},
watch: {
total: {
handler(n) {
if (n) {
let that = this
that.curList.forEach((item) => {
item.value = that.total[item.key]
})
}
},
deep: true, // 深度监听
immediate: true
}
},
watch: {},
mounted() {},
methods: {}
}
@@ -111,12 +134,10 @@ export default {
font-size: 12px;
margin-bottom: 10px;
}
.d{
.d {
margin-left: 1px;
font-size: 12px;
}
}
.content-left,

View File

@@ -49,23 +49,23 @@ export default {
type: Object,
default: () => ({}), // 默认空对象
required: false // 非必须
},
tableData: {
type: Array,
default: () => ([]), // 默认空对象
}
},
data() {
return {
paramsDate: {},
tableData: [],
tableOption: {
scroll: {
x: 1500
}
},
select: false,
},
tableH: 0,
pageOption: {
current: 1,
pageSize: 15,
total: 1
},
// chartOptions: [
// {
// title: '充放电分析',
@@ -233,45 +233,24 @@ export default {
chartInstances: [] // 存储 ECharts 实例
}
},
watch:{
chartData: {
handler(n) {
this.$nextTick(() => {
this.initCharts()
window.addEventListener('resize', this.handleResize)
})
}
}
},
mounted() {
this.$nextTick(() => {
// 确保 DOM 完全渲染
this.initCharts()
window.addEventListener('resize', this.handleResize)
})
},
beforeUnmount() {
window.removeEventListener('resize', this.handleResize)
this.chartInstances.forEach((chart) => chart && chart.dispose())
},
methods: {
async getList() {
let that = this
this.$refs.comTable.loading = true
const query = {
...this.paramsDate,
pageSize: this.pageOption.pageSize,
pageNumber: this.pageOption.current
}
try {
const res = await postReq(query, this.tableInfo.getUrl)
if (res.code === 200) {
this.$refs.comTable.loading = false
this.tableData = res.data.records
this.pageOption = {
current: res.data.pageNumber,
pageSize: res.data.pageSize,
total: res.data.totalRow
}
this.getScrollDateFail = false
} else {
throw res
}
} catch (error) {
that.tableData = []
that.$refs.comTable.loading = false
}
},
initCharts() {
this.chartOptions.forEach((option, index) => {
const dom = this.$refs[`chartContainer${index}`][0]
@@ -380,9 +359,10 @@ export default {
},
handlePagesizeChange(pageOption) {
this.pageOption.pageSize = pageOption.pageSize
this.pageOption.current = pageOption.current
this.getList()
this.$emit('pagesizeChange_energy',pageOption)
// this.pageOption.pageSize = pageOption.pageSize
// this.pageOption.current = pageOption.current
// this.getList()
}
}
}
@@ -390,7 +370,7 @@ export default {
<style lang="scss" scoped>
.content {
height: calc(100% - 38px);
height: calc(100% - 10px);
overflow: scroll;
}
.content-echarts {

View File

@@ -47,6 +47,7 @@ export default {
menuList: [
{
name: '系统总览',
path: '/main/',
icon: 'icon-xitongguanli'
},
{

File diff suppressed because it is too large Load Diff

View File

@@ -344,7 +344,12 @@ export default {
throw res
}
} catch (error) {
this.deviceInfo.onLine = {}
this.deviceInfo.onLine = {
launchDate:11,
incomeTotal:12,
solarDeviceNum:10,
stationNum:15
}
}
},
// 查询系统累计统计信息
@@ -423,29 +428,7 @@ export default {
throw res
}
} catch (error) {
// this.deviceInfo.allStatDayList = []
// this.deviceInfo.allStatDayList = [
// {
// date: '2025-08-30',
// storageElectIn: 2,
// storageElectOut: 5,
// chargeElect: 4,
// chargeNum: 5,
// incomeCharge: 7,
// solarElectGen: 7,
// solarElectGrid: 7
// },
// {
// date: '2025-08-31',
// storageElectIn: 3,
// storageElectOut: 7,
// chargeElect: 5,
// chargeNum: 5,
// incomeCharge: 4,
// solarElectGen: 6,
// solarElectGrid: 8
// }
// ]
console.log(error)
}
}
}