<!--管理界面-->
<template>
    <div class="containers">
        <!--主页-->
        <div :style="{
                    position: 'relative',
                    left:homeJson ? homeJson.Left*bigScale+'px' : '',
                    top:homeJson ? homeJson.Top*bigScale+'px' : '',
                    width:homeJson ? homeJson.Width*bigScale + 'px' : '',
                    height:homeJson ? homeJson.Height*bigScale + 'px' : '',
                    zIndex:homeJson ? homeJson.ZIndex : '',
                    display:homeJson ? (homeJson.IsVisibility ? 'block' : 'none') : '',
                    backgroundRepeat:'no-repeat',
                    backgroundSize:'100% 100%',
                    backgroundColor:`#${homeJson ? (homeJson.BrackgroupStr ? homeJson.BrackgroupStr.slice(3) : null) : ''}`,
                    margin:'0 auto'}"
             ref="mainpage"
        >
            <Window />
            <SignalList />
        </div>

        <!--最小化和关闭按钮-->
        <div class="mini" @click="miniWindow">－</div>
        <div class="close" @click="closeWindow">×</div>
    </div>
</template>

<script>
    import {mapState} from 'vuex'

    import '../assets/less/mainpage.less'
    import storageUtils from "../../utils/storageUtils"
    import Window from "./Window"
    import SignalList from "./SignalList"
    import {getStaticFile} from "../../utils/tools"

    export default {
        components: {
            Window,
            SignalList,
        },

        data() {
            return {
                user: storageUtils.getUser(), // 本地存储的用户
                homeJson:{},
                staticUrl:this.$store.state.staticUrl, // 静态资源路径
            }
        },

        async beforeCreate() {
            const windowJson = await getStaticFile('EnityWindow.Data')
            const arr = windowJson.filter(item => item.IsVisibility)
            this.homeJson = arr[0]
            // 主页添加背景图片
            this.$refs.mainpage.style.backgroundImage = this.homeJson.BackIcon ? 'url('+`${this.staticUrl}/Data/${this.homeJson.BackIcon}`+')' : null
        },

        methods: {
            // 最小化窗口
            miniWindow() {
                require('electron').ipcRenderer.send('window-min')
            },

            // 关闭窗口
            closeWindow() {
                require('electron').ipcRenderer.send('window-close')
            },
        },

        computed: {
            ...mapState(['bigScale'])
        }
    }
</script>
