生成二维码组件
This commit is contained in:
parent
41bc4cce96
commit
bbbbad5d89
213
components/QRCodeModal.vue
Normal file
213
components/QRCodeModal.vue
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
<template>
|
||||
<view v-if="visible" class="modal-overlay" @click="handleOverlayClick">
|
||||
<view class="modal-content" @click.stop>
|
||||
<!-- 关闭按钮 -->
|
||||
<view class="close-btn" @click="handleClose">
|
||||
<text class="close-icon">×</text>
|
||||
</view>
|
||||
|
||||
<!-- 二维码卡片 -->
|
||||
<view class="qrcode-card">
|
||||
<!-- 标题 -->
|
||||
<view class="card-title">
|
||||
<text class="title-text">{{ title }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 二维码 -->
|
||||
<view class="qrcode-container">
|
||||
<uv-qrcode
|
||||
ref="qrcode"
|
||||
:value="value"
|
||||
:options="qrcodeOptions"
|
||||
canvas-id="modal-qrcode"
|
||||
size="400rpx"
|
||||
></uv-qrcode>
|
||||
</view>
|
||||
|
||||
<!-- 票号信息 -->
|
||||
<view class="ticket-info">
|
||||
<text class="ticket-label">票号:</text>
|
||||
<text class="ticket-number">{{ ticketNumber }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 提示文字 -->
|
||||
<view class="tip-text">
|
||||
<text>此二维码可直接检票</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import UvQrcode from "../uni_modules/uv-qrcode/components/uv-qrcode/uv-qrcode.vue";
|
||||
|
||||
export default {
|
||||
name: "QRCodeModal",
|
||||
components: { UvQrcode },
|
||||
props: {
|
||||
// 是否显示弹窗
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 二维码内容
|
||||
value: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
// 标题
|
||||
title: {
|
||||
type: String,
|
||||
default: "预约详情"
|
||||
},
|
||||
// 票号
|
||||
ticketNumber: {
|
||||
type: String,
|
||||
default: ""
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
qrcodeOptions: {
|
||||
errorCorrectLevel: "Q",
|
||||
margin: 10,
|
||||
areaColor: "#fff"
|
||||
}
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
visible(newVal) {
|
||||
if (newVal) {
|
||||
this.$nextTick(() => {
|
||||
this.generateQRCode();
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 生成二维码
|
||||
generateQRCode() {
|
||||
if (this.$refs.qrcode) {
|
||||
this.$refs.qrcode.remake({
|
||||
success: () => {
|
||||
console.log("二维码生成成功");
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("二维码生成失败:", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 关闭弹窗
|
||||
handleClose() {
|
||||
this.$emit("close");
|
||||
},
|
||||
|
||||
// 点击遮罩层
|
||||
handleOverlayClick() {
|
||||
this.handleClose();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
bottom: 100rpx;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 10000;
|
||||
}
|
||||
|
||||
.close-icon {
|
||||
font-size: 40rpx;
|
||||
color: #666;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.qrcode-card {
|
||||
background-color: white;
|
||||
border-radius: 20rpx;
|
||||
padding: 60rpx 40rpx;
|
||||
box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.15);
|
||||
max-width: 600rpx;
|
||||
width: 90%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.title-text {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.qrcode-container {
|
||||
margin-bottom: 40rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.ticket-info {
|
||||
margin-bottom: 20rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.ticket-label {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.ticket-number {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.tip-text {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.tip-text text {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -9,14 +9,29 @@
|
|||
size="300rpx"
|
||||
></uv-qrcode>
|
||||
</view>
|
||||
|
||||
<!-- 测试按钮 -->
|
||||
<view class="button-container">
|
||||
<button @click="showQRModal" class="test-btn">显示二维码弹窗</button>
|
||||
</view>
|
||||
|
||||
<!-- 二维码弹窗组件 -->
|
||||
<QRCodeModal
|
||||
:visible="modalVisible"
|
||||
:value="modalValue"
|
||||
:title="modalTitle"
|
||||
:ticket-number="modalTicketNumber"
|
||||
@close="handleModalClose"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import UvQrcode from "../../uni_modules/uv-qrcode/components/uv-qrcode/uv-qrcode.vue";
|
||||
import QRCodeModal from "../../components/QRCodeModal.vue";
|
||||
|
||||
export default {
|
||||
components: { UvQrcode },
|
||||
components: { UvQrcode, QRCodeModal },
|
||||
data() {
|
||||
return {
|
||||
value: "测试二维码内容",
|
||||
|
|
@ -24,7 +39,12 @@ export default {
|
|||
errorCorrectLevel: "Q",
|
||||
margin: 10,
|
||||
areaColor: "#fff"
|
||||
}
|
||||
},
|
||||
// 弹窗相关数据
|
||||
modalVisible: false,
|
||||
modalValue: "VERIFY:31454786135789613287",
|
||||
modalTitle: "观音诞祈福法会",
|
||||
modalTicketNumber: "31454786135789613287"
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
|
|
@ -38,6 +58,17 @@ export default {
|
|||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
// 显示二维码弹窗
|
||||
showQRModal() {
|
||||
this.modalVisible = true;
|
||||
},
|
||||
|
||||
// 关闭弹窗
|
||||
handleModalClose() {
|
||||
this.modalVisible = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
@ -47,8 +78,10 @@ export default {
|
|||
background: #f5f0e7;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.qrcode-container {
|
||||
|
|
@ -56,5 +89,21 @@ export default {
|
|||
background: white;
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.button-container {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.test-btn {
|
||||
background: #48893B;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 10rpx;
|
||||
padding: 20rpx 40rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user