index.vue 6.58 KB
<template>
    <section class="setting-modal" v-show="isSettingModalVisible">
        <Card :title="$t('setting')" customClass="setting-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">
                    <div class="side-bar">
                        <div
                            class="setting-list"
                            :key="index"
                            v-for="(item, index) in items"
                            @click="onClickSettings(item.key)"
                        >
                            <span class="setting-items">
                                <span
                                    :class="selecteditem === item.key ? 'setting-item selected' : 'setting-item'"
                                    v-text="$t(item.key)"
                                />
                            </span>
                        </div>
                    </div>
                    <div class="side-content">
                        <component :is="selecteditemComponent" />
                    </div>
                </div>
                <div class="footer">
                    <span class="button-hollow" @click="onCloseModal" v-text="$t('cancel')" />
                    <span class="button-big" v-text="$t('apply')" @click="onCloseModal" />
                </div>
            </template>
        </Card>
    </section>
</template>
<script setup>
import { ref, markRaw } from 'vue';
import { storeToRefs } from 'pinia';
import Card from '@/components/simple-card.vue';
import { useHeaderUserInfoStore } from '@/views/stores/useHeaderUserInfoStore';
import { useSettingModalStore } from '@/views/stores/useSettingModalStore';
import { Close } from '@element-plus/icons-vue';

import LanguagesComponent from './languages.vue';

const store = useHeaderUserInfoStore();
const { isSettingModalVisible } = storeToRefs(store);
const { setSettingModalVisible } = store;

const settingStore = useSettingModalStore();
const { selecteditem, items } = storeToRefs(settingStore);
const { setSelectedItem } = settingStore;

const selecteditemComponent = ref(markRaw(LanguagesComponent));

const onCloseModal = () => {
    setSettingModalVisible(false);
};

const onClickSettings = (key) => {
    const object = items.value.find((el) => el.key === key);
    if (object) {
        setSelectedItem(key);
        // switch Components
        const lookup = {
            LanguagesComponent
        };
        selecteditemComponent.value = markRaw(lookup[`${key.replace(/^./, key[0].toUpperCase())}Component`]);
    }
};
</script>
<style lang="less" scoped>
.setting-modal-card {
    position: absolute;
    background-color: #fff;
    box-shadow: 1px 1px 1px 0 rgba(0, 0, 0, 0.2);
    border: 1px solid #cdd1d5;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    z-index: 300;
    width: 500px !important;

    .content {
        display: flex;
        flex-direction: row;
        min-height: 566px;
        .side-bar {
            display: flex;
            flex-direction: column;
            -webkit-box-pack: justify;
            justify-content: space-between;
            max-width: 200px;
            padding: 12px 0;

            .setting-list {
                display: flex;
                width: 150px;
                flex-direction: column;
                -webkit-box-flex: 1;
                flex-grow: 1;
                border-right: 1px solid rgb(240, 241, 244);
                border-top-color: rgb(240, 241, 244);
                border-bottom-color: rgb(240, 241, 244);
                border-left-color: rgb(240, 241, 244);
                .setting-items {
                    display: flex;
                    flex-direction: column;
                    margin-left: 16px;
                    margin-right: 16px;
                    .setting-item {
                        -webkit-tap-highlight-color: transparent;
                        outline: 0px;
                        border: 0px;
                        margin: 0px;
                        cursor: pointer;
                        user-select: none;
                        vertical-align: middle;
                        appearance: none;
                        color: inherit;
                        display: flex;
                        -webkit-box-pack: start;
                        justify-content: flex-start;
                        -webkit-box-align: center;
                        align-items: center;
                        position: relative;
                        text-decoration: none;
                        box-sizing: border-box;
                        white-space: nowrap;
                        background-color: rgb(255, 255, 255);
                        border-radius: 8px;
                        min-height: 34px;
                        font-size: 14px;
                        line-height: 22px;
                        font-weight: 400;
                        padding: 6px 30px 6px 12px;
                        &:hover {
                            background-color: rgb(246, 247, 248);
                        }
                        &.selected {
                            background-color: rgb(246, 247, 248);
                            color: rgb(0, 131, 202);
                        }
                    }
                }
            }
        }
        .side-content {
            display: flex;
            flex-direction: column;
            width: 100%;
            padding: 12px 22px;
        }
    }

    .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">
.setting-modal-card.card {
    max-height: calc(100% - 64px);
    max-width: 1020px;
    min-height: 634px;
    width: calc(100% - 64px) !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>