z8018
8 天以前 d5317aef1dbb595923af02ede8bfa33ba37d6eb6
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<template>
    <base-modal v-model="visible" :title="title" :width="width" :animation-type="animationType" :show-close="showClose"
        :show-footer="showFooter" :mask-closable="maskClosable" :custom-class="customClass" @confirm="handleConfirm"
        @cancel="handleCancel" @close="handleClose">
        <!-- 内容插槽 -->
        <slot name="content">
            <view class="custom-content">
                <image v-if="imageUrl" class="custom-image" :src="imageUrl" mode="aspectFit" />
                <text class="custom-text">{{ content }}</text>
            </view>
        </slot>
 
        <!-- 底部插槽 -->
        <template v-if="!hideFooter" #footer>
            <slot name="footer">
                <button v-if="showCancelBtn" class="custom-btn cancel-btn"
                    @click="handleCancel">{{ cancelText }}</button>
                <button class="custom-btn confirm-btn" :style="confirmBtnStyle" @click="handleConfirm">
                    {{ confirmText }}
                    <image v-if="confirmIcon" class="btn-icon" :src="confirmIcon" />
                </button>
            </slot>
        </template>
    </base-modal>
</template>
 
<script>
    // 确保路径正确
    import BaseModal from '@/components/BaseModal.vue'
    export default {
        components: {
            BaseModal
        },
        name: 'CustomModal',
        props: {
            value: Boolean,
            title: String,
            content: String,
            imageUrl: String,
            confirmText: {
                type: String,
                default: '确认'
            },
            cancelText: {
                type: String,
                default: '取消'
            },
            confirmIcon: String,
            width: {
                type: String,
                default: '650rpx'
            },
            animationType: {
                type: String,
                default: 'fade'
            },
            showClose: {
                type: Boolean,
                default: true
            },
            showFooter: {
                type: Boolean,
                default: true
            },
            showCancelBtn: {
                type: Boolean,
                default: true
            },
            maskClosable: {
                type: Boolean,
                default: true
            },
            hideFooter: Boolean,
            customClass: String,
            confirmBtnStyle: {
                type: Object,
                default: () => ({
                    background: 'linear-gradient(to right, #4facfe, #00f2fe)'
                })
            }
        },
        data() {
            return {
                visible: this.value
            }
        },
        watch: {
            value(newVal) {
                this.visible = newVal
            },
            visible(newVal) {
                this.$emit('input', newVal)
            }
        },
        methods: {
            handleConfirm() {
                this.$emit('confirm')
            },
            handleCancel() {
                this.$emit('cancel')
                this.visible = false
            },
            handleClose() {
                this.$emit('close')
            }
        }
    }
</script>
 
<style scoped>
    .custom-content {
        padding: 20rpx;
    }
 
    .custom-image {
        width: 100%;
        height: 300rpx;
        border-radius: 8rpx;
        margin-bottom: 20rpx;
    }
 
    .custom-text {
        font-size: 28rpx;
        color: #666;
        line-height: 1.6;
    }
 
    .custom-btn {
        height: 70rpx;
        min-width: 160rpx;
        margin: 0;
        margin-left: 20rpx;
        padding: 0 30rpx;
        border-radius: 35rpx;
        font-size: 28rpx;
        line-height: 70rpx;
    }
 
    .cancel-btn {
        background-color: #f5f5f5;
        color: #666;
    }
 
    .confirm-btn {
        color: #fff;
    }
 
    .btn-icon {
        width: 30rpx;
        height: 30rpx;
        margin-left: 10rpx;
    }
</style>