123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <template>
- <div class="general-dialog" v-if="value">
- <!-- 内容区域 -->
- <div class="dialog__container">
- <div class="dialog__close iconfont icon-close" @click="$emit('change', false)"></div>
- <div class="dialog__title">
- <slot name="title"></slot>
- <span v-text="title" v-if="!$slots.title"></span>
- </div>
- <div class="dialog__content">
- <slot></slot>
- <div class="dialog__content_text" v-text="content" v-if="!$slots.default"></div>
- </div>
- <div class="dialog__footer">
- <slot name="footer"></slot>
- <template v-if="!$slots.footer">
- <div class="btn confirm" @click="$emit('confirm')" v-if="confirm">
- {{ confirmText ? confirmText : '确定' }}
- </div>
- <div class="btn cancel" @click="$emit('cancel')" v-if="cancel">
- {{ cancelText ? cancelText : '取消' }}
- </div>
- </template>
- </div>
- </div>
- <!-- 遮罩层 -->
- <div class="dialog__mask"></div>
- </div>
- </template>
- <script>
- export default {
- model: {
- prop: 'value',
- event: 'change',
- },
- props: {
- title: {
- type: String,
- default: '提示',
- },
- content: String,
- value: {
- type: Boolean,
- default: false,
- },
- confirm: {
- type: Boolean,
- default: true,
- },
- cancel: {
- type: Boolean,
- default: false,
- },
- confirmText: String,
- cancelText: String,
- },
- watch: {
- value(val) {
- this.$nextTick(() => {
- val ? document.body.classList.add('scroll-none') : document.body.classList.remove('scroll-none')
- if (!val) {
- this.$emit('closed')
- }
- })
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- @media screen and (min-width: 768px) {
- .general-dialog {
- position: relative;
- z-index: 999;
- .dialog__container {
- position: fixed;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- min-width: 400px;
- background: #fff;
- box-sizing: border-box;
- padding: 40px 32px 32px;
- z-index: 1;
- border-radius: 4px;
- .dialog__close {
- position: absolute;
- width: 36px;
- height: 36px;
- right: 8px;
- top: 8px;
- text-align: center;
- line-height: 36px;
- font-size: 24px;
- color: #b2b2b2;
- transition: all 0.2s;
- cursor: pointer;
- &:hover {
- color: #666;
- }
- }
- .dialog__title {
- font-size: 24px;
- color: #282828;
- text-align: center;
- }
- .dialog__content {
- padding: 32px 0;
- .dialog__content_text {
- font-size: 16px;
- color: #282828;
- text-align: center;
- }
- }
- .dialog__footer {
- .btn {
- height: 46px;
- border-radius: 4px;
- text-align: center;
- box-sizing: border-box;
- font-size: 14px;
- margin: 0 auto;
- cursor: pointer;
- &.confirm {
- line-height: 46px;
- background: #f3920d;
- color: #fff;
- }
- &.cancel {
- line-height: 44px;
- border: 1px solid #f3920d;
- color: #f3920d;
- margin-top: 16px;
- }
- }
- }
- }
- .dialog__mask {
- position: fixed;
- width: 100vw;
- height: 100vh;
- left: 0;
- top: 0;
- background: #000;
- opacity: 0.4;
- }
- }
- }
- @media screen and (max-width: 768px) {
- .general-dialog {
- position: relative;
- z-index: 999;
- .dialog__container {
- position: fixed;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- min-width: 76vw;
- background: #fff;
- box-sizing: border-box;
- padding: 7vw 7vw 6.4vw;
- z-index: 1;
- border-radius: 0.4vw;
- .dialog__close {
- position: absolute;
- width: 5.6vw;
- height: 5.6vw;
- right: 3.2vw;
- top: 3.2vw;
- text-align: center;
- line-height: 5.6vw;
- font-size: 4.8vw;
- color: #b2b2b2;
- transition: all 0.2s;
- cursor: pointer;
- &:hover {
- color: #666;
- }
- }
- .dialog__title {
- font-size: 4.8vw;
- color: #282828;
- text-align: center;
- }
- .dialog__content {
- padding: 3.2vw 0;
- .dialog__content_text {
- font-size: 3.6vw;
- color: #282828;
- line-height: 5.6vw;
- text-align: center;
- }
- }
- .dialog__footer {
- .btn {
- height: 8.8vw;
- border-radius: 0.4vw;
- text-align: center;
- box-sizing: border-box;
- font-size: 3.6vw;
- margin: 0 auto;
- cursor: pointer;
- &.confirm {
- line-height: 8.8vw;
- background: #f3920d;
- color: #fff;
- }
- &.cancel {
- line-height: 8.8vw;
- border: 0.1vw solid #f3920d;
- color: #f3920d;
- margin-top: 2.4vw;
- }
- }
- }
- }
- .dialog__mask {
- position: fixed;
- width: 100vw;
- height: 100vh;
- left: 0;
- top: 0;
- background: #000;
- opacity: 0.4;
- }
- }
- }
- </style>
|