刷卡与安卓交互
This commit is contained in:
parent
56db79cc23
commit
98d1fdc287
|
@ -8,7 +8,7 @@
|
||||||
<view class="dialog-content">
|
<view class="dialog-content">
|
||||||
<!-- 头部标题和标签 -->
|
<!-- 头部标题和标签 -->
|
||||||
<view class="dialog-header">
|
<view class="dialog-header">
|
||||||
<text class="title">{{currentRow.name}}</text>
|
<text class="title">{{ currentRow.name }}</text>
|
||||||
<u-tag class="tag" text="室内" mode="light" />
|
<u-tag class="tag" text="室内" mode="light" />
|
||||||
<!-- <u-tag
|
<!-- <u-tag
|
||||||
class="tag"
|
class="tag"
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
<view v-if="step === 1">1.请将标签卡贴靠设备NFC识别处!</view>
|
<view v-if="step === 1">1.请将标签卡贴靠设备NFC识别处!</view>
|
||||||
<view v-if="step === 2">2.如果确定将该卡片写入该区域,请将标签卡贴靠设备xNFC识别处,否则请退出!</view>
|
<view v-if="step === 2">2.如果确定将该卡片写入该区域,请将标签卡贴靠设备xNFC识别处,否则请退出!</view>
|
||||||
<view v-if="step === 3">3.请再次将标签卡贴靠设备NFC识别处!</view>
|
<view v-if="step === 3">3.请再次将标签卡贴靠设备NFC识别处!</view>
|
||||||
<view v-if="step === 4">{{lookData}}</view>
|
<view v-if="step === 4">{{ lookData }}</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 底部按钮 -->
|
<!-- 底部按钮 -->
|
||||||
|
@ -86,12 +86,15 @@ export default {
|
||||||
mounted() {
|
mounted() {
|
||||||
window.nfcInitFn = this.nfcInitFn
|
window.nfcInitFn = this.nfcInitFn
|
||||||
},
|
},
|
||||||
onLoad() {},
|
onLoad() { },
|
||||||
methods: {
|
methods: {
|
||||||
nfcInitFn(data) {
|
nfcInitFn(data) {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return uni.showToast({ title: '未传入参数 initFn', icon: 'none' })
|
return uni.showToast({ title: '未传入参数 initFn', icon: 'none' })
|
||||||
}
|
}
|
||||||
|
if (this.isChange === true) {
|
||||||
|
return uni.showToast({ title: '请点击更换绑定后刷卡', icon: 'none' })
|
||||||
|
}
|
||||||
if (data.step === 1) {
|
if (data.step === 1) {
|
||||||
this.step = 1
|
this.step = 1
|
||||||
}
|
}
|
||||||
|
@ -121,6 +124,29 @@ export default {
|
||||||
nfcChange() {
|
nfcChange() {
|
||||||
this.isChange = false
|
this.isChange = false
|
||||||
this.step = 1
|
this.step = 1
|
||||||
|
try {
|
||||||
|
if (isAndroid && AndroidJs) {
|
||||||
|
console.log("%c%s", "color:red", "安卓--调用方法");
|
||||||
|
const reqRow = {
|
||||||
|
name: "area",
|
||||||
|
data: {
|
||||||
|
state: this.currentRow.state,
|
||||||
|
areaId: this.currentRow.id,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log(reqRow, 'reqRow--')
|
||||||
|
AndroidJs.func(JSON.stringify(reqRow)); // 给安卓传参
|
||||||
|
} else {
|
||||||
|
console.log("%c%s", "color:red", "苹果--调用方法");
|
||||||
|
const reqRow = {
|
||||||
|
name: "back-iphone",
|
||||||
|
data: "",
|
||||||
|
};
|
||||||
|
window.webkit.messageHandlers.func.postMessage(JSON.stringify(reqRow)); // 给ios 传参
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e, "e-----判断安卓苹果类型出错");
|
||||||
|
}
|
||||||
// this.$emit('changeBinding')
|
// this.$emit('changeBinding')
|
||||||
// this.closeDialogInternal(); // 可以选择点击后是否关闭弹窗
|
// this.closeDialogInternal(); // 可以选择点击后是否关闭弹窗
|
||||||
},
|
},
|
||||||
|
@ -136,6 +162,18 @@ export default {
|
||||||
this.$emit('close') // 兼容只使用 :visible 和 @close 的情况
|
this.$emit('close') // 兼容只使用 :visible 和 @close 的情况
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
visible(newVal) {
|
||||||
|
if (newVal) {
|
||||||
|
console.log('打开');
|
||||||
|
window.nfcInitFn = this.nfcInitFn
|
||||||
|
} else {
|
||||||
|
console.log('关闭');
|
||||||
|
// 清除 nfcInitFn 函数引用,避免内存泄漏
|
||||||
|
window.nfcInitFn = null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -148,7 +186,8 @@ export default {
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
background-color: rgba(0, 0, 0, 0.5);
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
z-index: 999; /* 确保遮罩在底层 */
|
z-index: 999;
|
||||||
|
/* 确保遮罩在底层 */
|
||||||
}
|
}
|
||||||
|
|
||||||
.dialog-container {
|
.dialog-container {
|
||||||
|
@ -156,9 +195,11 @@ export default {
|
||||||
top: 50%;
|
top: 50%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
width: 90%; /* 或者根据需要设置固定宽度 */
|
width: 90%;
|
||||||
|
/* 或者根据需要设置固定宽度 */
|
||||||
// max-width: 600rpx;
|
// max-width: 600rpx;
|
||||||
z-index: 1000; /* 确保弹窗在遮罩上 */
|
z-index: 1000;
|
||||||
|
/* 确保弹窗在遮罩上 */
|
||||||
}
|
}
|
||||||
|
|
||||||
.dialog-content {
|
.dialog-content {
|
||||||
|
@ -174,7 +215,8 @@ export default {
|
||||||
.dialog-header {
|
.dialog-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center; /* 居中显示 */
|
justify-content: center;
|
||||||
|
/* 居中显示 */
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-bottom: 16rpx;
|
margin-bottom: 16rpx;
|
||||||
|
|
||||||
|
@ -211,18 +253,23 @@ export default {
|
||||||
// border: 1px solid red;
|
// border: 1px solid red;
|
||||||
height: auto;
|
height: auto;
|
||||||
margin-bottom: 30rpx;
|
margin-bottom: 30rpx;
|
||||||
|
|
||||||
.dialog-image {
|
.dialog-image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
width: 200rpx; /* 根据图片调整 */
|
width: 200rpx;
|
||||||
height: auto; /* 让图片自适应高度 */
|
/* 根据图片调整 */
|
||||||
|
height: auto;
|
||||||
|
/* 让图片自适应高度 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.change-binding {
|
.change-binding {
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: #4a90e2; /* 蓝色链接颜色 */
|
color: #4a90e2;
|
||||||
|
/* 蓝色链接颜色 */
|
||||||
// margin-bottom: 50rpx;
|
// margin-bottom: 50rpx;
|
||||||
cursor: pointer; /* 鼠标悬停显示手型 */
|
cursor: pointer;
|
||||||
|
/* 鼠标悬停显示手型 */
|
||||||
}
|
}
|
||||||
|
|
||||||
.dialog-footer {
|
.dialog-footer {
|
||||||
|
@ -233,12 +280,14 @@ export default {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 88rpx;
|
height: 88rpx;
|
||||||
line-height: 88rpx;
|
line-height: 88rpx;
|
||||||
background-color: #4879e6; /* 蓝色按钮背景 */
|
background-color: #4879e6;
|
||||||
|
/* 蓝色按钮背景 */
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
font-size: 32rpx;
|
font-size: 32rpx;
|
||||||
border-radius: 0 0 24rpx 24rpx;
|
border-radius: 0 0 24rpx 24rpx;
|
||||||
border: none;
|
border: none;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
// 移除按钮默认边框(H5)
|
// 移除按钮默认边框(H5)
|
||||||
&::after {
|
&::after {
|
||||||
border: none;
|
border: none;
|
||||||
|
@ -248,5 +297,4 @@ export default {
|
||||||
/* 可以添加按钮按下的效果 */
|
/* 可以添加按钮按下的效果 */
|
||||||
// .confirm-button:active {
|
// .confirm-button:active {
|
||||||
// background-color: #4879e6;
|
// background-color: #4879e6;
|
||||||
// }
|
// }</style>
|
||||||
</style>
|
|
||||||
|
|
|
@ -12,10 +12,12 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- tabs -->
|
<!-- tabs -->
|
||||||
<u-tabs class="tabs-box" bg-color="#F6F8FC" :list="tabsList" :is-scroll="true" :current="tabCurrent" @change="tabChangeFn"></u-tabs>
|
<u-tabs class="tabs-box" bg-color="#F6F8FC" :list="tabsList" :is-scroll="true" :current="tabCurrent"
|
||||||
|
@change="tabChangeFn"></u-tabs>
|
||||||
<!-- 搜索 -->
|
<!-- 搜索 -->
|
||||||
<view class="search-box">
|
<view class="search-box">
|
||||||
<u-input class="search-input" v-model="keyword" :clearable="false" border placeholder="搜索名称" @keyup.enter="searchFn"></u-input>
|
<u-input class="search-input" v-model="keyword" :clearable="false" border placeholder="搜索名称"
|
||||||
|
@keyup.enter="searchFn"></u-input>
|
||||||
<u-icon name="search" class="search-icon" size="40" @click="searchFn"></u-icon>
|
<u-icon name="search" class="search-icon" size="40" @click="searchFn"></u-icon>
|
||||||
<view class="select-box" @click="selectFn">
|
<view class="select-box" @click="selectFn">
|
||||||
<view>
|
<view>
|
||||||
|
@ -26,7 +28,8 @@
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- tip -->
|
<!-- tip -->
|
||||||
<view v-if="sonList.length" class="tip-box">共{{sonForm.countData}}个子区域,其中{{sonForm.countData - sonForm.bindData}}个未绑定</view>
|
<view v-if="sonList.length" class="tip-box">共{{ sonForm.countData }}个子区域,其中{{ sonForm.countData -
|
||||||
|
sonForm.bindData }}个未绑定</view>
|
||||||
<!-- 列表 -->
|
<!-- 列表 -->
|
||||||
<view class="list-box">
|
<view class="list-box">
|
||||||
<scroll-view :scroll-y="true" class="scroll-Y">
|
<scroll-view :scroll-y="true" class="scroll-Y">
|
||||||
|
@ -42,7 +45,8 @@
|
||||||
<!-- 筛选的下拉 -->
|
<!-- 筛选的下拉 -->
|
||||||
<u-action-sheet :list="options" title="请选择" @click="changeFn" v-model:value="selectShow"></u-action-sheet>
|
<u-action-sheet :list="options" title="请选择" @click="changeFn" v-model:value="selectShow"></u-action-sheet>
|
||||||
<!-- 弹窗 -->
|
<!-- 弹窗 -->
|
||||||
<bind-dialog ref="dialogRef" :visible="showDialog" @close="showDialog = false" :currentRow="currentRow" @changeBinding="onChangeBinding" @confirm="onConfirm"></bind-dialog>
|
<bind-dialog ref="dialogRef" :visible="showDialog" @close="showDialog = false" :currentRow="currentRow"
|
||||||
|
@changeBinding="onChangeBinding" @confirm="onConfirm"></bind-dialog>
|
||||||
|
|
||||||
<u-tabbar :list="vuex_tabbar"></u-tabbar>
|
<u-tabbar :list="vuex_tabbar"></u-tabbar>
|
||||||
</view>
|
</view>
|
||||||
|
@ -110,10 +114,43 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
dialogShowFn(row) {
|
dialogShowFn(row) {
|
||||||
|
// 给安卓传参
|
||||||
|
let u = navigator.userAgent;
|
||||||
|
let isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android
|
||||||
|
// 添加的时候给安卓传参
|
||||||
|
if (row.state === false) {
|
||||||
|
try {
|
||||||
|
if (isAndroid && AndroidJs) {
|
||||||
|
console.log("%c%s", "color:red", "安卓--调用方法");
|
||||||
|
const reqRow = {
|
||||||
|
name: "area",
|
||||||
|
data: {
|
||||||
|
state: row.state,
|
||||||
|
areaId: row.id,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log(reqRow, 'reqRow--')
|
||||||
|
AndroidJs.func(JSON.stringify(reqRow)); // 给安卓传参
|
||||||
|
} else {
|
||||||
|
console.log("%c%s", "color:red", "苹果--调用方法");
|
||||||
|
const reqRow = {
|
||||||
|
name: "back-iphone",
|
||||||
|
data: "",
|
||||||
|
};
|
||||||
|
window.webkit.messageHandlers.func.postMessage(JSON.stringify(reqRow)); // 给ios 传参
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e, "e-----判断安卓苹果类型出错");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log(JSON.parse(JSON.stringify(row)), 'row--')
|
console.log(JSON.parse(JSON.stringify(row)), 'row--')
|
||||||
this.currentRow = row
|
this.currentRow = row
|
||||||
this.$refs.dialogRef.isChange = row.state // 重置弹窗状态
|
this.$refs.dialogRef.isChange = row.state // 重置弹窗状态
|
||||||
this.$refs.dialogRef.step = 0 // 重置弹窗状态
|
this.$refs.dialogRef.step = 0 // 重置弹窗状态
|
||||||
|
if (row.state === false) {
|
||||||
|
this.$refs.dialogRef.step = 1 // 重置弹窗状态
|
||||||
|
}
|
||||||
this.showDialog = true
|
this.showDialog = true
|
||||||
},
|
},
|
||||||
async getDataFn() {
|
async getDataFn() {
|
||||||
|
@ -233,12 +270,14 @@ export default {
|
||||||
// border: 1px solid red;
|
// border: 1px solid red;
|
||||||
// margin-top: 20rpx;
|
// margin-top: 20rpx;
|
||||||
padding: 20rpx;
|
padding: 20rpx;
|
||||||
|
|
||||||
.search-icon {
|
.search-icon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 210rpx;
|
right: 210rpx;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-input {
|
.search-input {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border-radius: 50rpx;
|
border-radius: 50rpx;
|
||||||
|
|
Loading…
Reference in New Issue