InspectionCleaning/pages/adminNfc/components/bindDialog.vue

367 lines
9.8 KiB
Vue
Raw Normal View History

2025-04-15 13:29:51 +08:00
<template>
<view>
<!-- 遮罩层 -->
<view class="dialog-mask" v-if="visible" @click="closeDialog"></view>
<!-- 弹窗内容 -->
<view class="dialog-container" v-if="visible">
<view class="dialog-content">
<!-- 头部标题和标签 -->
<view class="dialog-header">
2025-04-27 10:17:07 +08:00
<text class="title">{{ currentRow.name }}</text>
2025-04-28 15:49:30 +08:00
<u-tag v-if="currentRow.areaType === '室内'" class="tag" text="室内" mode="light" />
<u-tag v-if="currentRow.areaType === '室外'" class="tag" text="室外" mode="light" type="success" />
<u-tag v-if="currentRow.areaType === '特殊'" class="tag" text="特殊" mode="light" type="warning" />
2025-04-15 13:29:51 +08:00
</view>
<!-- 副标题 - 负责人 -->
2025-04-28 15:31:01 +08:00
<!-- <view class="dialog-subtitle"> 区域主负责人张三 </view> -->
<view>传入参数{{ showMsg }}</view>
<view>接口返回结果{{ resData }}</view>
2025-04-28 15:49:30 +08:00
2025-04-25 14:55:58 +08:00
<!-- 已存在卡片时显示图片 -->
<view class="dialog-image-container" v-if="isChange === true">
2025-04-15 13:29:51 +08:00
<!-- 替换为实际的图片路径 -->
2025-04-25 14:55:58 +08:00
<image src="/static/adminImg/nfc-result.png" mode="widthFix" class="dialog-image"></image>
</view>
<!-- 未存在nfc时显示图片 -->
<view class="dialog-image-container" v-if="isChange === false">
<!-- 替换为实际的图片路径 -->
<image src="/static/adminImg/step.png" mode="widthFix" style="width: 500rpx;"></image>
2025-04-15 13:29:51 +08:00
</view>
<!-- 更换绑定链接 -->
2025-04-25 14:55:58 +08:00
<view v-if="isChange === true" class="change-binding" @click="nfcChange">
2025-04-15 13:29:51 +08:00
更换绑定
</view>
2025-04-25 14:55:58 +08:00
<!-- -->
<view v-if="step === 1">1.请将标签卡贴靠设备NFC识别处</view>
<view v-if="step === 2">2.如果确定将该卡片写入该区域,请将标签卡贴靠设备xNFC识别处否则请退出</view>
<view v-if="step === 3">3.请再次将标签卡贴靠设备NFC识别处</view>
2025-04-15 13:29:51 +08:00
</view>
<!-- 底部按钮 -->
<view class="dialog-footer">
2025-04-29 13:10:12 +08:00
<button class="confirm-button" @click="handleConfirm">关闭</button>
2025-04-15 13:29:51 +08:00
</view>
</view>
</view>
</template>
<script>
2025-04-28 15:31:01 +08:00
import { ResetNFCApi } from '@/api/apiAdmin'
2025-04-15 13:29:51 +08:00
export default {
props: {
// 控制弹窗显示/隐藏
visible: {
type: Boolean,
2025-04-25 14:55:58 +08:00
default: false
2025-04-15 13:29:51 +08:00
},
// 可以添加更多 props 来传递动态数据,例如标题、负责人等
// title: String,
// responsiblePerson: String,
2025-04-25 14:55:58 +08:00
currentRow: {
type: Object,
default: () => ({})
}
2025-04-15 13:29:51 +08:00
},
data() {
2025-04-25 14:55:58 +08:00
return {
isChange: false,
step: 0,
2025-04-28 15:49:30 +08:00
isAdd: false,
2025-04-28 15:31:01 +08:00
lookData: {},
resData: {},
showMsg: ''
2025-04-25 14:55:58 +08:00
}
},
mounted() {
2025-04-28 15:31:01 +08:00
// window.nfcInitFn = this.nfcInitFn
2025-04-15 13:29:51 +08:00
},
2025-04-29 11:45:17 +08:00
onLoad() {},
2025-04-15 13:29:51 +08:00
methods: {
2025-04-28 15:31:01 +08:00
async nfcInitFn(data) {
2025-04-25 14:55:58 +08:00
if (!data) {
2025-04-28 15:31:01 +08:00
uni.showToast({ title: '未传入参数nfcInitFn', icon: 'none' })
return
}
this.showMsg = data
// uni.showModal({
// title: "提示",
// content: JSON.stringify(data) || '未传入参数',
// success: function (res) {
// },
// });
if (data.step === 8) {
uni.showToast({ title: '刷卡失败', icon: 'none' })
return
2025-04-25 14:55:58 +08:00
}
2025-04-27 10:17:07 +08:00
if (this.isChange === true) {
2025-04-28 15:31:01 +08:00
uni.showToast({ title: '请点击更换绑定后刷卡', icon: 'none' })
return
2025-04-27 10:17:07 +08:00
}
2025-04-25 14:55:58 +08:00
if (data.step === 1) {
this.step = 1
}
if (data.step === 2) {
this.step = 2
}
if (data.step === 3) {
this.step = 3
2025-04-28 15:31:01 +08:00
this.lookData = data
const req = {
2025-04-29 11:45:17 +08:00
AreaId: data.areaId,
pwd: data.pwd,
isAdd: this.isAdd
2025-04-28 15:31:01 +08:00
// "isAdd": true,
}
2025-04-29 11:45:17 +08:00
// console.log(req, '重置nfc--req')
// console.log(666)
2025-04-28 15:31:01 +08:00
// uni.showLoading({ title: '加载中...' })
const res = await ResetNFCApi(req).catch(e => e)
if (!res.succeed) {
uni.showToast({ title: res.error || '绑定失败', icon: 'none' })
}
2025-04-29 11:45:17 +08:00
this.resData = res
// 给安卓传参
let u = navigator.userAgent
let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 //android
2025-04-28 15:31:01 +08:00
try {
if (isAndroid && AndroidJs) {
2025-04-29 11:45:17 +08:00
console.log('%c%s', 'color:red', '安卓--调用方法')
2025-04-28 15:31:01 +08:00
const reqRow = {
2025-04-29 11:45:17 +08:00
name: 'resetNFCRes',
data: res
}
2025-04-28 15:31:01 +08:00
console.log(reqRow, 'reqRow--')
2025-04-29 11:45:17 +08:00
AndroidJs.func(JSON.stringify(reqRow)) // 给安卓传参
2025-04-28 15:31:01 +08:00
} else {
2025-04-29 11:45:17 +08:00
console.log('%c%s', 'color:red', '苹果--调用方法')
2025-04-28 15:31:01 +08:00
const reqRow = {
2025-04-29 11:45:17 +08:00
name: 'back-iphone',
data: ''
}
window.webkit.messageHandlers.func.postMessage(JSON.stringify(reqRow)) // 给ios 传参
2025-04-28 15:31:01 +08:00
}
} catch (e) {
2025-04-29 11:45:17 +08:00
console.log(e, 'e-----判断安卓苹果类型出错')
2025-04-28 15:31:01 +08:00
}
return
// uni.hideLoading()
console.log(res, '重置nfc')
2025-04-29 11:45:17 +08:00
this.resData = res
2025-04-28 15:31:01 +08:00
if (res.succeed) {
uni.showToast({ title: '绑定成功', icon: 'none' })
} else {
uni.showToast({ title: res.error || '绑定失败', icon: 'none' })
}
return
2025-04-25 14:55:58 +08:00
}
2025-04-28 15:49:30 +08:00
// 写入完成
2025-04-25 14:55:58 +08:00
if (data.step === 4) {
2025-04-28 15:49:30 +08:00
uni.showToast({ title: '绑定成功', icon: 'none' })
2025-04-25 14:55:58 +08:00
this.lookData = data
this.step = 4
2025-04-28 15:49:30 +08:00
this.$emit('closeRes') // 兼容只使用 :visible 和 @close 的情况
return
this.isAdd = true
this.isChange = true
2025-04-25 14:55:58 +08:00
// uni.showModal({
// title: '查看',
// content: JSON.stringify(data) || '未传入参数 initFn',
// showCancel: true,
// success: function (res) {}
// })
}
},
2025-04-15 13:29:51 +08:00
// 关闭弹窗(点击遮罩)
closeDialog() {
// 推荐通过事件通知父组件关闭
2025-04-25 14:55:58 +08:00
this.$emit('close')
2025-04-15 13:29:51 +08:00
},
// 点击更换绑定
2025-04-25 14:55:58 +08:00
nfcChange() {
this.isChange = false
this.step = 1
2025-04-28 15:31:01 +08:00
console.log(this.currentRow, 'this.currentRow--')
// 给安卓传参
2025-04-29 11:45:17 +08:00
let u = navigator.userAgent
let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 //android
2025-04-27 10:17:07 +08:00
try {
if (isAndroid && AndroidJs) {
2025-04-29 11:45:17 +08:00
console.log('%c%s', 'color:red', '安卓--调用方法')
2025-04-27 10:17:07 +08:00
const reqRow = {
2025-04-29 11:45:17 +08:00
name: 'area',
2025-04-27 10:17:07 +08:00
data: {
2025-04-28 15:31:01 +08:00
// state: this.currentRow.state,
state: true,
2025-04-29 11:45:17 +08:00
areaId: this.currentRow.id
}
}
AndroidJs.func(JSON.stringify(reqRow)) // 给安卓传参
2025-04-27 10:17:07 +08:00
} else {
2025-04-29 11:45:17 +08:00
console.log('%c%s', 'color:red', '苹果--调用方法')
2025-04-27 10:17:07 +08:00
const reqRow = {
2025-04-29 11:45:17 +08:00
name: 'back-iphone',
data: ''
}
window.webkit.messageHandlers.func.postMessage(JSON.stringify(reqRow)) // 给ios 传参
2025-04-27 10:17:07 +08:00
}
} catch (e) {
2025-04-29 11:45:17 +08:00
console.log(e, 'e-----判断安卓苹果类型出错')
2025-04-27 10:17:07 +08:00
}
2025-04-25 14:55:58 +08:00
// this.$emit('changeBinding')
2025-04-15 13:29:51 +08:00
// this.closeDialogInternal(); // 可以选择点击后是否关闭弹窗
},
// 点击知道了
handleConfirm() {
2025-04-25 14:55:58 +08:00
this.$emit('confirm')
this.closeDialogInternal()
2025-04-15 13:29:51 +08:00
},
// 内部关闭避免重复emit
closeDialogInternal() {
if (this.visible) {
2025-04-25 14:55:58 +08:00
this.$emit('update:visible', false) // 如果使用 v-model
this.$emit('close') // 兼容只使用 :visible 和 @close 的情况
2025-04-15 13:29:51 +08:00
}
2025-04-25 14:55:58 +08:00
}
2025-04-27 10:17:07 +08:00
},
watch: {
visible(newVal) {
if (newVal) {
2025-04-29 11:45:17 +08:00
console.log('打开')
2025-04-27 10:17:07 +08:00
window.nfcInitFn = this.nfcInitFn
} else {
2025-04-29 11:45:17 +08:00
console.log('关闭')
2025-04-27 10:17:07 +08:00
// 清除 nfcInitFn 函数引用,避免内存泄漏
window.nfcInitFn = null
}
}
2025-04-25 14:55:58 +08:00
}
}
2025-04-15 13:29:51 +08:00
</script>
<style lang="scss" scoped>
.dialog-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
2025-04-27 10:17:07 +08:00
z-index: 999;
/* 确保遮罩在底层 */
2025-04-15 13:29:51 +08:00
}
.dialog-container {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
2025-04-27 10:17:07 +08:00
width: 90%;
/* 或者根据需要设置固定宽度 */
2025-04-15 13:29:51 +08:00
// max-width: 600rpx;
2025-04-27 10:17:07 +08:00
z-index: 1000;
/* 确保弹窗在遮罩上 */
2025-04-15 13:29:51 +08:00
}
.dialog-content {
background-color: #ffffff;
border-radius: 24rpx 24rpx 0 0;
padding: 40rpx;
display: flex;
flex-direction: column;
align-items: center;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.dialog-header {
display: flex;
align-items: center;
2025-04-27 10:17:07 +08:00
justify-content: center;
/* 居中显示 */
2025-04-15 13:29:51 +08:00
width: 100%;
margin-bottom: 16rpx;
.title {
font-size: 34rpx;
font-weight: bold;
color: #333333;
margin-right: 16rpx;
}
.tag {
font-size: 28rpx;
padding: 6rpx 10rpx;
border-radius: 10rpx;
margin-top: 2rpx;
}
// .tag {
// background-color: #e6f0ff; /* 淡蓝色背景 */
// color: #4a90e2; /* 蓝色文字 */
// font-size: 24rpx;
// padding: 4rpx 12rpx;
// border-radius: 8rpx;
// }
}
.dialog-subtitle {
font-size: 28rpx;
color: #666666;
margin-bottom: 40rpx;
}
.dialog-image-container {
2025-04-25 14:55:58 +08:00
// border: 1px solid red;
2025-04-15 13:29:51 +08:00
height: auto;
margin-bottom: 30rpx;
2025-04-27 10:17:07 +08:00
2025-04-25 14:55:58 +08:00
.dialog-image {
width: 100%;
2025-04-27 10:17:07 +08:00
width: 200rpx;
/* 根据图片调整 */
height: auto;
/* 让图片自适应高度 */
2025-04-25 14:55:58 +08:00
}
2025-04-15 13:29:51 +08:00
}
.change-binding {
font-size: 28rpx;
2025-04-27 10:17:07 +08:00
color: #4a90e2;
/* 蓝色链接颜色 */
2025-04-15 13:29:51 +08:00
// margin-bottom: 50rpx;
2025-04-27 10:17:07 +08:00
cursor: pointer;
/* 鼠标悬停显示手型 */
2025-04-15 13:29:51 +08:00
}
.dialog-footer {
width: 100%;
}
.confirm-button {
width: 100%;
height: 88rpx;
line-height: 88rpx;
2025-04-27 10:17:07 +08:00
background-color: #4879e6;
/* 蓝色按钮背景 */
2025-04-15 13:29:51 +08:00
color: #ffffff;
font-size: 32rpx;
border-radius: 0 0 24rpx 24rpx;
border: none;
text-align: center;
2025-04-27 10:17:07 +08:00
2025-04-15 13:29:51 +08:00
// 移除按钮默认边框H5
&::after {
border: none;
}
}
/* 可以添加按钮按下的效果 */
// .confirm-button:active {
// background-color: #4879e6;
2025-04-29 11:45:17 +08:00
// }
</style>