Files
dvcp_v2_webapp/packages/bigscreen/viewer/AppGigscreenViewer.vue

213 lines
5.4 KiB
Vue
Raw Normal View History

2021-12-14 18:36:19 +08:00
<template>
<div class="AppGigscreenViewer">
<div v-if="!component">
<div
2022-03-25 11:09:26 +08:00
class="component-item"
:style="{
2021-12-31 16:45:42 +08:00
width: item.width + 'px',
height: item.height + 'px',
2021-12-28 09:45:37 +08:00
left: item.left * scale + 'px',
top: item.top * scale + 'px',
2021-12-14 18:36:19 +08:00
position: 'absolute',
2021-12-31 16:45:42 +08:00
zIndex: item.zIndex,
transform: `scale(${scale})`
2021-12-14 18:36:19 +08:00
}"
2022-03-25 11:09:26 +08:00
v-for="(item, index) in componentList"
:key="index">
2021-12-14 18:36:19 +08:00
<RenderElement :data="item" :index="index"></RenderElement>
</div>
</div>
<components v-else :is="component" :dict="dict" :instance="instance" :nav="meta"/>
</div>
</template>
<script>
2022-03-25 11:09:26 +08:00
import RenderElement from '../designer/components/RenderElement'
export default {
name: 'AppGigscreenViewer',
label: '大屏预览',
props: {
instance: Function,
dict: Object,
id: String,
urlPrefix: {
type: String,
default: '/app'
}
},
2021-12-14 18:36:19 +08:00
2022-03-25 11:09:26 +08:00
watch: {
id(v) {
this.getInfo(v)
}
},
components: {
RenderElement
},
data() {
return {
component: '',
dashboard: {
title: '大屏',
width: 1920,
height: 1080,
backgroundColor: '',
backgroundImage: []
},
componentList: [],
scale: 1,
meta: {}
}
},
2021-12-14 18:36:19 +08:00
2022-03-25 11:09:26 +08:00
created() {
this.getInfo(this.id)
2021-12-28 09:45:37 +08:00
2022-03-25 11:09:26 +08:00
// this.scale = document.body.clientWidth / 1920
},
2021-12-28 09:45:37 +08:00
2022-03-25 11:09:26 +08:00
mounted() {
this.$nextTick(() => {
let content = document.querySelector('#dv-full-screen-container')
if (content) {
const transform = content.style.transform
2021-12-28 09:45:37 +08:00
const scale = transform.replace('scale', '').replace('(', '').replace(')', '')
if (scale == 1) {
this.scale = document.body.clientWidth / 1920
}
2022-03-25 11:09:26 +08:00
}
})
},
methods: {
getInfo(id) {
this.component = null
this.instance.post(`${this.urlPrefix}/appdiylargescreen/queryLargeScreenDetailById?id=${id}`).then(res => {
if (res?.data) {
const config = JSON.parse(res.data.config)
if (config.custom) {
this.component = config.custom
this.meta = config?.meta || {}
} else {
this.componentList = JSON.parse(res.data.config).config
this.dashboard = JSON.parse(res.data.config).dashboard
this.componentList.forEach((item, index) => {
if (item.dataType !== 'staticData' && ((item.type.indexOf('Chart') > -1) || item.type === 'display' || item.type === 'table' || item.type === 'summary')) {
this.getSourceData(item, index)
}
if (item.type === 'monitor' && item.monitorType === 'cmcc') {
this.instance.post(`${this.urlPrefix}/appzyvideoequipment/getWebSdkUrl?deviceId=${item.moniterId}`).then(res => {
if (res.code == 0) {
this.$set(this.componentList[index], 'src', JSON.parse(res.data).url)
}
})
}
if (item.type === 'monitor' && item.monitorType === 'slw') {
this.instance.post(`${this.urlPrefix}/appzyvideoequipment/getWebSdkUrl?deviceId=${item.moniterId}`).then(res => {
if (res.code == 0) {
this.$set(this.componentList[index], 'src', res.data)
}
})
}
})
}
}
2021-12-28 09:45:37 +08:00
})
2021-12-14 18:36:19 +08:00
},
2022-03-25 11:09:26 +08:00
getSourceData(item, index) {
const api = item.dataType === 'apiData' ? item.api : `${this.urlPrefix}/appdiylargescreen/statisticsByLsid?id=${item.sourceDataId}`
this.instance.post(api).then(res => {
if (res.code == 0) {
if (res.data.length) {
const keys = Object.keys(res.data[0])
const list = res.data
let dynamicData = []
if (item.type === 'table') {
dynamicData = keys.map(v => {
let obj = {}
list.forEach((item, index) => {
obj[`v${index}`] = item[v]
})
2021-12-14 18:36:19 +08:00
2022-03-25 11:09:26 +08:00
return {
row: v,
...obj
2021-12-14 18:36:19 +08:00
}
2022-03-25 11:09:26 +08:00
})
} else if (item.type === 'summary') {
dynamicData = Object.keys(res.data[0]).map(item => {
return {
key: item,
value: res.data[0][item]
2022-03-23 14:19:06 +08:00
}
2021-12-14 18:36:19 +08:00
})
2022-03-25 11:09:26 +08:00
} else {
if (item.dataX && item.dataY.length) {
list.forEach(i => {
2021-12-14 18:36:19 +08:00
let obj = {}
2022-03-25 11:09:26 +08:00
item.dataY.forEach(v => {
obj[v] = i[v]
2021-12-14 18:36:19 +08:00
})
2022-03-25 11:09:26 +08:00
dynamicData.push({
[item.dataX]: i[item.dataX],
2021-12-14 18:36:19 +08:00
...obj
})
2022-03-25 11:09:26 +08:00
})
2021-12-14 18:36:19 +08:00
}
}
2022-03-25 11:09:26 +08:00
this.$set(this.componentList[index], item.dataType, dynamicData)
2021-12-14 18:36:19 +08:00
}
2022-03-25 11:09:26 +08:00
}
})
},
2021-12-14 18:36:19 +08:00
2022-03-25 11:09:26 +08:00
close() {
this.$emit('close')
2021-12-14 18:36:19 +08:00
}
}
2022-03-25 11:09:26 +08:00
}
2021-12-14 18:36:19 +08:00
</script>
<style lang="scss">
.AppGigscreenViewer {
position: relative;
height: 100%;
background: transparent !important;
2021-12-31 16:45:42 +08:00
.component-item {
transform-origin: 0 0;
}
2021-12-14 18:36:19 +08:00
.dv-scroll-board {
height: calc(100%) !important;
.header-item {
color: #7e8697;
font-size: 16px;
}
.index {
display: inline-block;
width: 26px;
height: 26px;
line-height: 26px;
font-size: 16px;
background-color: #4F57FF !important;
}
}
.vdr {
border: none;
}
}
</style>