弹窗组件
<!-- components/CustomDialog.vue -->
<template>
<view v-if="visible" class="dialog-overlay" @touchmove.stop.prevent="moveHandle">
<view class="dialog-container">
<view class="dialog-header">
<view class="title"><image src="/static/info.png"></image>{{ title }}</view>
<view @click="closeDialog" class="close-btn" v-show="isShowCloseIcon">×</view>
</view>
<view class="dialog-content">
<slot> </slot>
</view>
<view v-if="isShowFooter">
<slot name="footer">
<view class="dialog-footer">
<view @click="onCancel" class="btn cancel-btn">{{ cancelText }}</view>
<view @click="onConfirm" class="btn confirm-btn">{{ confirmText }}</view>
</view>
</slot>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
const props = defineProps({
title: {
type: String,
default: '提示'
},
cancelText: {
type: String,
default: '取消'
},
confirmText: {
type: String,
default: '确定'
},
isShowFooter: {
type: Boolean,
default: true
},
isShowCloseIcon: {
type: Boolean,
default: false
},
modelValue: {
type: Boolean,
default: false
}
})
const visible = ref(props.modelValue)
const emit = defineEmits(['update:modelValue', 'cancel', 'confirm'])
const closeDialog = () => {
emit('update:modelValue', false)
visible.value = false
}
const onCancel = () => {
emit('cancel', false)
closeDialog()
}
const onConfirm = () => {
emit('confirm')
closeDialog()
}
const moveHandle = () => {}
watch(
() => props.modelValue,
(newVal) => {
visible.value = newVal
console.log('props.modelValue', props.modelValue)
emits('update:modelValue', newVal)
}
)
</script>
<style scoped lang="scss">
page {
height: 100%;
overflow-y: hidden;
}
.dialog-overlay {
z-index: 100;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.dialog-container {
background-color: #fff;
border-radius: 16rpx;
display: flex;
flex-direction: column;
width: 608rpx;
}
.dialog-header {
padding: 32rpx;
display: flex;
justify-content: space-between;
}
.close-btn {
background: none;
border: none;
font-size: 24px;
}
.title {
font-size: 32rpx;
font-weight: 600;
color: #002344;
image {
width: 30rpx;
height: 30rpx;
margin-right: 9rpx;
}
}
.dialog-content {
margin: 0 32rpx 32rpx 32rpx;
background: #f7f6ff;
font-size: 28rpx;
min-height: 88rpx;
border-radius: 20rpx;
padding: 20rpx;
font-size: 30rpx;
/* margin: 32rpx 0; */
}
.dialog-footer {
display: flex;
justify-content: center;
padding: 32rpx 0;
}
.btn {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
color: #576b95;
font-size: 30rpx;
}
.cancel-btn {
border-right: 2rpx solid #e5e5e5;
}
.inBounce_success_wrap,
.rand_dialog_wrap {
display: flex;
flex-direction: column;
}
</style>
//
使用
<SamplingWarningDialog title="抽样" v-if="showRandomDialog" v-model="showRandomDialog">
<view class="rand_dialog_wrap">
<view class="rand_dialog_content">本次抽样:货物次序 {{ curData.randomItemSequence }}</view>
</view>
<template #footer>
<view class="rand_dialog_ok_txt" @tap="showRandomDialog = false">我知道了</view>
</template>
</SamplingWarningDialog>
</view>
注意:自定义弹窗在长列表情况下会出现弹窗遮罩滚动内容依然可以滚动的情况。这时候只需要通过meta-page来控制即可
<page-meta :page-style="`overflow:${showMeta ? 'hidden' : 'visible'};`"></page-meta>
<view class="home">
xxxxx
<SamplingWarningDialog title="抽样" v-if="showRandomDialog" v-model="showRandomDialog">
<view class="rand_dialog_wrap">
<view class="rand_dialog_content">本次抽样:货物次序 {{ curData.randomItemSequence }}</view>
</view>
<template #footer>
<view class="rand_dialog_ok_txt" @tap="showRandomDialog = false">我知道了</view>
</template>
</SamplingWarningDialog>
</view>
<script lang="ts" setup>
//弹窗相关处理
const showMeta = ref(false) //控制meta-page,防止弹窗遮罩列表滚动
const showInbounceSuccessDialog = ref(false) //确认入库弹窗
const showRandomDialog = ref(false) //本次抽样:货物次序弹窗
const curData = ref({}) //对话框的数据
//弹窗:手动入库时存在两种形态
const openDialog = (data) => {
console.log('openDialog1', data)
curData.value = data.data
showMeta.value = true
if (data.type === 'noGoodsWarn') {
showInbounceSuccessDialog.value = true
} else {
showRandomDialog.value = true
}
}
const closeDialog = () => {
//设置meta-page的display,放开滚动
showMeta.value = false
}
</script>