slice-modal.vue 3.61 KB
<template>
    <section class="slice-button">
        <span class="button-big" @click="onSlice" v-text="$t('slice')" />
    </section>
    <section class="slice-modal" v-show="isSliceModalVisible">
        <Card :title="$t('slice')" customClass="slice-modal-card">
            <template v-slot:extend>
                <el-icon class="icon" :size="24" @click="onCloseModal">
                    <Close />
                </el-icon>
            </template>
            <template v-slot:component>
                <div class="content">
                    <SliceCanvas />
                </div>
                <div class="footer">
                    <span class="button-hollow" @click="onCloseModal" v-text="$t('cancel')" />
                    <span class="button-big" v-text="$t('apply')" @click="onApply" />
                </div>
            </template>
        </Card>
    </section>
</template>

<script setup>
import { nextTick } from 'vue';
import { storeToRefs } from 'pinia';
import Card from '@/components/simple-card.vue';
import { useSliceModalStore } from '@/views/stores/useSliceModalStore';
import { Close } from '@element-plus/icons-vue';
import SliceCanvas from './slice-canvas.vue';

const store = useSliceModalStore();
const { isSliceModalVisible } = storeToRefs(store);
const { setIsVisible, apply } = store;

const onSlice = () => {
    setIsVisible(true);
};

const onCloseModal = () => {
    setIsVisible(false);
    nextTick(() => {
        const b = document.getElementsByClassName('el-slider__button-wrapper');
        const popperDom = document.getElementsByClassName('el-popper');
        if (popperDom) {
            const canvas = document.getElementById('viewer-editor');
            const rect = canvas.getBoundingClientRect();
            for (let i = 0; i < popperDom.length; i++) {
                const element = b[i].getBoundingClientRect();
                popperDom[i].style['transform'] = `translate(${
                    element.right - rect.width - element.width * 0.75 - 15
                }px,${element.top - element.height * 0.25}px)`;
            }
        }
    });
};

const onApply = () => {
    apply();
};
</script>

<style lang="less">
.slice-button {
    position: absolute;
    right: 62px;
    bottom: 40px;
    .button-big {
        width: 200px;
        height: 70px;
        font-size: 18px;
    }
}
.slice-modal-card {
    position: absolute;
    background-color: #fff;
    box-shadow: 1px 1px 1px 0 rgba(0, 0, 0, 0.2);
    border: 1px solid #cdd1d5;
    top: 44px;
    z-index: 200;

    .content {
        display: flex;
        flex-direction: row;
        min-height: 566px;
        height: calc(100vh - 44px - 63px - 79px);
        justify-content: center;
    }

    .footer {
        display: flex;
        -webkit-box-align: center;
        align-items: center;
        -webkit-box-pack: end;
        justify-content: flex-end;
        flex: 0 0 auto;
        border-top: 1px solid rgb(222, 225, 229);
        padding: 16px;
        gap: 10px;
    }
}
</style>

<style lang="less">
.slice-modal-card.card {
    max-width: 100vw;
    min-height: 634px;
    width: 100vw !important;
    height: calc(100% - 44px) !important;
    padding: 0px !important;
    .icon {
        cursor: pointer;
        &:hover {
            background-color: rgb(246, 247, 248);
        }
        &:active {
            background-color: #eef0f2;
        }
    }
    .header {
        padding: 22px !important;
        margin-bottom: 0px !important;
        border-bottom: 1px solid #f0f1f4;
        .title {
            margin: 0px;
            font-size: 20px;
            line-height: 34px;
            font-weight: 700;
        }
    }
}
</style>