230 lines
6.3 KiB
Vue
230 lines
6.3 KiB
Vue
<template>
|
|
<Box title="监控">
|
|
<div class="h-full flex flex-col">
|
|
<div class="py-10px relative" v-if="!isBase">
|
|
<div
|
|
class="text-center bg-clip-text text-transparent bg-gradient-to-t from-[#76E9F0] to-[#A7E6EE] text-14px font-bold"
|
|
>
|
|
{{ currentTabValue }}
|
|
</div>
|
|
<div
|
|
class="absolute right-18px top-1/2 transform -translate-y-1/2"
|
|
v-if="tabList.length > 1"
|
|
>
|
|
<Dropdown
|
|
overlayClassName="dropdownClass"
|
|
placement="bottomRight"
|
|
trigger="click"
|
|
:style="{ height: '300px' }"
|
|
>
|
|
<div class="cursor-pointer">
|
|
<span class="text-white text-12px">更多</span>
|
|
<DownOutlined :style="{ fontSize: '12px', color: '#FFF' }" />
|
|
</div>
|
|
<template #overlay>
|
|
<Menu @click="onMenuClick">
|
|
<menu-item v-for="item in tabList" :key="item.id">
|
|
<div>{{ item.name }}</div>
|
|
</menu-item>
|
|
</Menu>
|
|
</template>
|
|
</Dropdown>
|
|
</div>
|
|
</div>
|
|
<div class="flex-1 px-11px flex flex-col py-10px box-content" :class="{ 'pt-0': !isBase }">
|
|
<div class="flex-1">
|
|
<div
|
|
class="h-full"
|
|
:class="{ 'h-140px': isBase }"
|
|
v-for="(item, index) in listBig"
|
|
:key="index"
|
|
>
|
|
<VideoFlv
|
|
@onScreen="onScreenClick"
|
|
class="cursor-pointer"
|
|
:url="item.url"
|
|
:name="item.base_name"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="grid grid-cols-3 gap-x-6px pt-10px">
|
|
<div class="h-66px" v-for="item in listSmall" :key="item.id">
|
|
<VideoFlv
|
|
@onScreen="onScreenClick"
|
|
class="cursor-pointer"
|
|
:url="item.url"
|
|
:name="item.base_name"
|
|
:screen="true"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<LinkModal
|
|
v-model:visible="visibleModal"
|
|
:footer="null"
|
|
:title1="currentModelVideo && currentModelVideo.name"
|
|
:width="1100"
|
|
>
|
|
<template #content>
|
|
<div class="w-full">
|
|
<VideoFlv :url="currentModelVideo.url" :screen="false" :name="currentModelVideo.name" />
|
|
</div>
|
|
</template>
|
|
</LinkModal>
|
|
</Box>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import {
|
|
defineComponent,
|
|
reactive,
|
|
ref,
|
|
onBeforeMount,
|
|
computed,
|
|
toRefs,
|
|
onBeforeUnmount,
|
|
} from 'vue'
|
|
import { DownOutlined } from '@ant-design/icons-vue'
|
|
import { Dropdown, Menu } from 'ant-design-vue'
|
|
import { getAgriculturalDeviceBasic, getDevices, getffmpegip } from '/@/api/sys/other'
|
|
import Box from './Box.vue'
|
|
import VideoFlv from './VideoFlv.vue'
|
|
import v01 from '../../../assets/images/v01.png'
|
|
import v02 from '../../../assets/images/v02.png'
|
|
import v03 from '../../../assets/images/v03.png'
|
|
import LinkModal from '../LinkModal.vue'
|
|
export default defineComponent({
|
|
components: {
|
|
Box,
|
|
Dropdown,
|
|
DownOutlined,
|
|
Menu,
|
|
MenuItem: Menu.Item,
|
|
VideoFlv,
|
|
LinkModal,
|
|
},
|
|
props: ['baseId'],
|
|
setup(props) {
|
|
console.log('===JK')
|
|
console.log(props.baseId)
|
|
const Data = reactive({
|
|
tabList: ref<any>([]),
|
|
currentTab: ref<number | string>(''),
|
|
list: ref<any[]>([]),
|
|
})
|
|
|
|
const visibleModal = ref(false)
|
|
|
|
const chartRef = ref<HTMLDivElement | null>(null)
|
|
|
|
const currentVido = ref<any>(null)
|
|
|
|
const currentModelVideo = ref<any>(null)
|
|
|
|
const listSmall = computed(() => Data.list.slice(1, 4))
|
|
const listBig = computed(() => Data.list.slice(0, 1))
|
|
|
|
const currentTabValue = computed(
|
|
() => Data.tabList.find((e) => e.id == Data.currentTab)?.name ?? '',
|
|
)
|
|
|
|
function onMenuClick({ key }) {
|
|
if (Data.currentTab == key) return
|
|
Data.currentTab = key
|
|
getData()
|
|
}
|
|
|
|
async function getTabs() {
|
|
const resData = await getAgriculturalDeviceBasic({
|
|
device_type: 1,
|
|
})
|
|
Data.tabList = resData
|
|
if (resData.length) Data.currentTab = resData[0].id
|
|
getData()
|
|
}
|
|
|
|
async function getData() {
|
|
const { ip, port, change_time } = await getffmpegip()
|
|
|
|
const resData = await getDevices({
|
|
base_id: props.baseId ?? Data.currentTab,
|
|
type: 1,
|
|
status: 1,
|
|
is_recommend: 1,
|
|
})
|
|
|
|
currentVido.value = null
|
|
|
|
Data.list = resData.splice(0, 4).map((e, index) => {
|
|
const { rtsp_url } = e.extends
|
|
const url = rtsp_url
|
|
// const url = 'rtsp://admin:admin12345@183.222.79.115:9007/cam/realmonitor?channel=1&subtype=0'
|
|
return {
|
|
...e,
|
|
img: index == 0 ? v01 : index == 1 ? v02 : index == 2 ? v03 : v01,
|
|
url: `ws://${ip}:${port}/rtsp?url=${window.btoa(url)}`,
|
|
}
|
|
})
|
|
if (Data.list.length > 0) currentVido.value = Data.list[0]
|
|
|
|
if (!isBase.value) {
|
|
autoChage(change_time)
|
|
}
|
|
}
|
|
let timer: any = null
|
|
|
|
function autoChage(time) {
|
|
timer && clearInterval(timer)
|
|
if (time == 0) return
|
|
timer = setInterval(() => {
|
|
const index = Data.tabList.findIndex((e) => e.id == Data.currentTab)
|
|
const currentIndex = index + 1
|
|
const current = Data.tabList[currentIndex % Data.tabList.length]
|
|
onMenuClick({ key: current.id, ...current })
|
|
}, 1000 * time)
|
|
}
|
|
|
|
function onChangeVideo(e) {
|
|
if (currentVido.value.url == e.url) return
|
|
currentVido.value = e
|
|
}
|
|
|
|
function onScreenClick(e) {
|
|
currentModelVideo.value = e
|
|
visibleModal.value = true
|
|
}
|
|
|
|
const isBase = computed(() => !!props.baseId)
|
|
|
|
onBeforeMount(() => {
|
|
if (isBase.value) {
|
|
getData()
|
|
} else {
|
|
getTabs()
|
|
}
|
|
})
|
|
|
|
onBeforeUnmount(() => {
|
|
timer && clearInterval(timer)
|
|
})
|
|
|
|
return {
|
|
isBase,
|
|
listBig,
|
|
listSmall,
|
|
onChangeVideo,
|
|
currentVido,
|
|
currentModelVideo,
|
|
...toRefs(Data),
|
|
chartRef,
|
|
currentTabValue,
|
|
onMenuClick,
|
|
visibleModal,
|
|
onScreenClick,
|
|
}
|
|
},
|
|
})
|
|
</script>
|