gaoshp
2024-06-13 fd7586c8d91473d2850af1e48b12f1a289e6b8d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!--
 * @Descripttion: 弹窗扩展组件
 * @version: 2.0
 * @Author: sakuya
 * @Date: 2021年8月27日08:51:52
 * @LastEditors: sakuya
 * @LastEditTime: 2022年5月14日15:13:41
-->
 
<template>
    <div class="sc-dialog" ref="scDialog">
        <el-dialog ref="dialog" v-model="dialogVisible" :fullscreen="isFullscreen" v-bind="$attrs" :show-close="false">
            <template #header>
                <slot name="header">
                    <span class="el-dialog__title">{{ title }}</span>
                </slot>
                <div class="sc-dialog__headerbtn">
                    <button v-if="showFullscreen" aria-label="fullscreen" type="button" @click="setFullscreen">
                        <el-icon v-if="isFullscreen" class="el-dialog__close"><el-icon-bottom-left /></el-icon>
                        <el-icon v-else class="el-dialog__close"><el-icon-full-screen /></el-icon>
                    </button>
                    <button v-if="showClose" aria-label="close" type="button" @click="closeDialog">
                        <el-icon class="el-dialog__close"><el-icon-close /></el-icon>
                    </button>
                </div>
            </template>
            <div v-loading="loading">
                <slot></slot>
            </div>
            <template #footer>
                <slot name="footer"></slot>
            </template>
        </el-dialog>
    </div>
</template>
 
<script>
export default {
    props: {
        modelValue: { type: Boolean, default: false },
        title: { type: String, default: "" },
        showClose: { type: Boolean, default: true },
        showFullscreen: { type: Boolean, default: true },
        loading: { type: Boolean, default: false }
    },
    data() {
        return {
            dialogVisible: false,
            isFullscreen: false
        }
    },
    watch: {
        modelValue() {
            this.dialogVisible = this.modelValue
            if (this.dialogVisible) {
                this.isFullscreen = false
            }
        }
    },
    mounted() {
        this.dialogVisible = this.modelValue
    },
    methods: {
        //关闭
        closeDialog() {
            this.dialogVisible = false
        },
        //最大化
        setFullscreen() {
            this.isFullscreen = !this.isFullscreen
        }
    }
}
</script>
 
<style scoped>
.sc-dialog__headerbtn {
    position: absolute;
    top: var(--el-dialog-padding-primary);
    right: var(--el-dialog-padding-primary);
}
 
.sc-dialog__headerbtn button {
    padding: 0;
    background: transparent;
    border: none;
    outline: none;
    cursor: pointer;
    font-size: var(--el-message-close-size, 16px);
    margin-left: 15px;
    color: var(--el-color-info);
}
 
.sc-dialog__headerbtn button:hover .el-dialog__close {
    color: var(--el-color-primary);
}
 
.sc-dialog:deep(.el-dialog).is-fullscreen {
    display: flex;
    flex-direction: column;
    top: 0px !important;
    left: 0px !important;
}
 
.sc-dialog:deep(.el-dialog).is-fullscreen .el-dialog__header {}
 
.sc-dialog:deep(.el-dialog).is-fullscreen .el-dialog__body {
    flex: 1;
    overflow: auto;
}
 
.sc-dialog:deep(.el-dialog).is-fullscreen .el-dialog__footer {
    padding-bottom: 10px;
    border-top: 1px solid var(--el-border-color-base);
}
</style>