<template>
    <a-config-provider :locale="locale">
        <div class="main flex-column">
            <top-header></top-header>
            <div class="content-box flex-wrap flex-con-1">
                <left-menu></left-menu>
                <div class="right-box flex-column">
                    <div class="tab-box">
                        <a-tabs
                            v-model="activeKey"
                            type="editable-card"
                            @change="changeTab"
                            @edit="onEdit"
                        >
                            <a-tab-pane
                                v-for="pane in panes"
                                :key="pane.key"
                                :tab="pane.name"
                                :closable="pane.closable"
                            >
                                <keep-alive>
                                    <router-view v-if="activeKey === pane.key"></router-view>
                                </keep-alive>
                            </a-tab-pane>
                        </a-tabs>
                    </div>
                </div>
            </div>
        </div>
    </a-config-provider>
</template>

<script>
import leftMenu from "./left-menu";
import topHeader from "./top-header";
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN';
import auth from "../../../utils/auth"
export default {
    name: "index",
    components: {
        leftMenu,
        topHeader,
    },
    data() {
        return {
            locale: zhCN
        };
    },
    updated() {

    },
    computed: {
        panes() {
            return this.$store.state.tabData;
        },
        activeKey: {
            get() {
                return this.$store.state.activeKey;
            },
            set(v) {
                this.$store.state.activeKey = v;
            },
        },
    },
    methods: {
        //新增和删除页签的回调，在 type="editable-card" 时有效  factoryInformation
        onEdit(targetKey, action) {
            this[action](targetKey);
        },
        remove(targetKey) {
            let that = this;
            that.$store.dispatch("removeTab", targetKey).then((remove_idx) => {
                //删除
                if (targetKey === that.activeKey) {
                    //重新激活一个 并且跳转
                    let tabData = this.$store.state.tabData
                    that.$store.commit("changeActiveKey", tabData[remove_idx].key);
                    that.$router.push({
                        path: tabData[remove_idx].path,
                        //有些路由是带参数的，因此这个路由跳转得把参数传递过去
                        params: tabData[remove_idx].params,
                        query: tabData[remove_idx].query
                    });
                }
            })

        },
        changeTab(key) {
            //切换面板的回调 找到对应的路由
            let that = this;
            let tabData = that.$store.state.tabData;
            this.$store.commit("changeActiveKey", key);
            for (let k in tabData) {
                if (tabData[k].key === key)
                    that.$router.push({
                        path: tabData[k].path,
                        //有些路由是带参数的，因此这个路由跳转得把参数传递过去
                        params: tabData[k].params,
                        query: tabData[k].query
                    });
            }
        },
    },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.main {
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    overflow: hidden;

    .right-box {
        width: calc(100% - 200px);
        height: 100%;
        background-color: #ecedef;

        .tab-box {
            width: 100%;
            height: 100%;
            padding: 8px 16px 16px 15px;
        }

        .container {
            flex: 1;
            // padding: 24px;
            height: 100%;
            overflow: hidden;
        }
    }

    .content-box {
        height: 100%;
        width: 100%;
        overflow: hidden;
    }
}
</style>
<style scoped>
.right-box /deep/ .ant-tabs-bar {
    margin: 0;
}

.right-box /deep/ .ant-tabs.ant-tabs-card .ant-tabs-card-bar .ant-tabs-tab {
    transition: all 0.1s cubic-bezier(0.645, 0.045, 0.355, 1);
    margin-right: 0px;
    line-height: 32px;
    height: 32px;
}

.right-box
/deep/
.ant-tabs.ant-tabs-card
.ant-tabs-card-bar
.ant-tabs-nav-container {
    height: 32px;
}

.right-box /deep/ .ant-tabs-nav .ant-tabs-tab-active {
    font-weight: 400;
}

.right-box /deep/ .ant-tabs-extra-content {
    display: none;
}

.right-box /deep/ .ant-tabs {
    height: 100%;
}

.right-box /deep/ .ant-tabs-content {
    height: calc(100% - 32px);
}

.right-box /deep/ .ant-tabs-tabpane {
    height: 100%;
    background-color: #ffff;
}
</style>
