Files
dvcp_v2_webapp/ui/dv/AiDvViewer.vue

254 lines
7.5 KiB
Vue
Raw Normal View History

2021-12-14 18:36:19 +08:00
<template>
2022-08-29 08:58:52 +08:00
<section class="AiDvViewer">
2021-12-14 18:36:19 +08:00
<div v-if="!component">
2024-01-24 16:34:57 +08:00
<div 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
}"
2024-01-24 16:34:57 +08:00
v-for="(item, index) in componentList"
:key="index" @click="handleClick(item)">
2023-03-15 11:02:13 +08:00
<ai-dv-render :instance="instance" :key="index" :data="item" :index="index" :theme="dashboard.theme"/>
2021-12-14 18:36:19 +08:00
</div>
</div>
<components v-else :is="component" :dict="dict" :instance="instance" :nav="meta"/>
2024-02-05 11:59:20 +08:00
<ai-dv-dialog ref="dvDialog" v-bind="dialog">
<div v-if="dialog.content" v-html="dialog.content"/>
</ai-dv-dialog>
2022-06-28 09:15:10 +08:00
</section>
2021-12-14 18:36:19 +08:00
</template>
<script>
2024-01-24 16:34:57 +08:00
import AiDvDialog from "./AiDvDialog.vue";
2022-05-06 16:31:24 +08:00
2022-03-25 11:09:26 +08:00
export default {
2022-08-29 08:58:52 +08:00
name: 'AiDvViewer',
2024-01-24 16:34:57 +08:00
components: {AiDvDialog},
2022-03-25 11:09:26 +08:00
label: '大屏预览',
props: {
instance: Function,
dict: Object,
id: String,
urlPrefix: {
type: String,
default: '/app'
}
},
watch: {
2022-08-29 14:12:26 +08:00
id: {
handler(v) {
v && this.getInfo(v)
},
immediate: true
2022-03-25 11:09:26 +08:00
}
},
data() {
return {
component: '',
dashboard: {
title: '大屏',
width: 1920,
height: 1080,
backgroundColor: '',
2022-05-05 18:00:11 +08:00
theme: '0',
2022-03-25 11:09:26 +08:00
backgroundImage: []
},
componentList: [],
scale: 1,
2024-01-24 16:34:57 +08:00
meta: {},
dialog: {}
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
2022-08-29 14:12:26 +08:00
id && this.instance.post(`${this.urlPrefix}/appdiylargescreen/queryLargeScreenDetailById?id=${id}`).then(res => {
2022-03-25 11:09:26 +08:00
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) => {
2023-03-15 15:18:19 +08:00
if (item.dataType !== 'staticData' && ((item.type.indexOf('Chart') > -1) || ['display', 'table', 'map', 'summary', 'AiRanking', 'AiDvTable'].includes(item.type))) {
2022-03-25 11:09:26 +08:00
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 => {
2022-08-29 09:16:50 +08:00
if (res?.data) {
2022-03-25 11:09:26 +08:00
if (res.data.length) {
const keys = Object.keys(res.data[0])
const list = res.data
let dynamicData = []
2023-03-15 16:10:33 +08:00
if (item.type === 'table' || item.type === 'AiDvTable') {
2022-03-25 11:09:26 +08:00
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') {
2022-03-31 17:04:46 +08:00
if (item.display === 'summary9') {
2022-03-31 16:03:40 +08:00
dynamicData = res.data
} else {
dynamicData = Object.keys(res.data[0]).map(item => {
return {
key: item,
value: res.data[0][item]
}
})
}
2022-03-31 17:04:46 +08:00
} else if (item.dataType === 'dynamicData' && !item.dataX && !item.dataY.length) {
dynamicData = Object.keys(res.data[0]).map(item => {
return {
label: item,
value: res.data[0][item]
}
})
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
})
2022-06-28 09:15:10 +08:00
} else {
dynamicData = res.data
}
2021-12-14 18:36:19 +08:00
}
2022-03-25 11:09:26 +08:00
this.$set(this.componentList[index], item.dataType, dynamicData)
2022-06-28 09:15:10 +08:00
} else {
this.$set(this.componentList[index], item.dataType, [])
2021-12-14 18:36:19 +08:00
}
2022-03-25 11:09:26 +08:00
}
})
},
2024-01-24 16:34:57 +08:00
handleClick(item = {}) {
const {dialogTitle, dialogContent} = item
if (dialogTitle) {
this.dialog = {title: dialogTitle, content: dialogContent, ...this.getStaticDataProps(item.staticData)}
this.$refs.dvDialog.show()
}
},
//新版静态数据处理
getStaticDataProps(meta = []) {
const columnProp = "name"
let columns = [], tableData = []
meta.map((row, i) => {
const prop = `c${i || ""}`
columns.push({label: row[columnProp], prop})
Object.entries(row).map(([k, v]) => {
if (/^v/.test(k)) {
const item = tableData[k.substring(1) || 0] || {}
item[prop] = v
tableData[k.substring(1) || 0] = item
2024-02-08 11:09:18 +08:00
}else if (k != columnProp) {
const index = columns.findIndex(e => k == e)
if (index > -1) {
const item = tableData[index] || {}
item[prop] = v
tableData[index] = item
} else {
columns.push(k)
const newIndex = columns.length - 1
const item = tableData[newIndex] || {}
item[prop] = v
tableData[newIndex] = item
}
2024-01-24 16:34:57 +08:00
}
})
})
tableData = tableData.map(e => ({...e, $cellEdit: false}))
return {columns, tableData}
},
2022-03-25 11:09:26 +08:00
close() {
this.$emit('close')
2021-12-14 18:36:19 +08:00
}
2024-01-24 16:34:57 +08:00
},
2022-03-25 11:09:26 +08:00
}
2021-12-14 18:36:19 +08:00
</script>
<style lang="scss">
2022-08-29 08:58:52 +08:00
.AiDvViewer {
2021-12-14 18:36:19 +08:00
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>