nfc验证修改

This commit is contained in:
xuli
2026-01-28 11:40:06 +08:00
parent a1835abdc8
commit 32c78e0a82
7 changed files with 74 additions and 31 deletions

View File

@@ -170,5 +170,12 @@ export function patrolBugAddLog(data) {
data data
}) })
} }
//
/**主动上报 end */ /**主动上报 end */
// 验证NFC扫描是否正确
export function patroltaskValidateNfc(data) {
return request.post({
url: '/patrol/patroltask/validateNfc',
data
})
}

View File

@@ -4,7 +4,7 @@
<view class="nfc-title"> <view class="nfc-title">
<uni-icons type="closeempty" size="20" class="nfc-close" @click="handleClose"></uni-icons>NFC识别 <uni-icons type="closeempty" size="20" class="nfc-close" @click="handleClose"></uni-icons>NFC识别
</view> </view>
<block v-if="formData.deviceId==''"> <block v-if="!deviceId">
<view class="nfc-pic"> <view class="nfc-pic">
<img class="nfc-pic-animal" :src="'static/images/polling/nfc-logo.png'" /> <img class="nfc-pic-animal" :src="'static/images/polling/nfc-logo.png'" />
</view> </view>
@@ -40,16 +40,20 @@
</template> </template>
<script setup> <script setup>
import { ref, onBeforeUnmount,onMounted } from "vue"; import { ref, onBeforeUnmount,onMounted,getCurrentInstance } from "vue";
import { parseTime } from '@/utils/datetime.js'; import { parseTime } from '@/utils/datetime.js';
import { patroltaskValidateNfc } from '@/api/polling.js'
const { proxy } = getCurrentInstance();
const props = defineProps({
nfcId:{},
})
// 定义组件 emits // 定义组件 emits
const emit = defineEmits(['close',"changeNfc"]); const emit = defineEmits(['close',"changeNfc"]);
// 状态管理 // 状态管理
const formData = ref({ const deviceId = ref(undefined);
deviceId: "", //录入的id
});
const readStatus=ref(false);//读取状态 true 成功 const readStatus=ref(false);//读取状态 true 成功
// 变量初始化 // 变量初始化
@@ -81,7 +85,8 @@ function open() {
}); });
return; return;
} }
deviceId.value=undefined;
readStatus.value=false;
initNFC(); initNFC();
} catch (e) { } catch (e) {
console.error("打开NFC失败:", e); console.error("打开NFC失败:", e);
@@ -177,7 +182,7 @@ function handleNewIntent() {
} }
// 读取NFC数据 // 读取NFC数据
function readNFCData() { async function readNFCData() {
try { try {
const main = plus.android.runtimeMainActivity(); const main = plus.android.runtimeMainActivity();
const _intent = main.getIntent(); const _intent = main.getIntent();
@@ -193,9 +198,23 @@ function readNFCData() {
function bytesToString(result) { function bytesToString(result) {
return String.fromCharCode(...result); return String.fromCharCode(...result);
} }
formData.value.deviceId = bytesToString(result).substring(3); let nfcContent = bytesToString(result).substring(3);
emit("changeNfc", formData.value.deviceId); console.log("nfcContent=>",nfcContent)
deviceId.value=nfcContent;
// 调用后台接口验证NFC内容的正确性
let param = {
nfcId:props.nfcId,
nfcContent
}
// console.log("param=>",param)
let res = await patroltaskValidateNfc(param);
// console.log("patroltaskValidateNfc=>",res)
if(!res){
emit("changeNfc", nfcContent);
readStatus.value=true; readStatus.value=true;
}
} catch (e) { } catch (e) {
console.log("读取NDEF数据错误:", e); console.log("读取NDEF数据错误:", e);
uni.showToast({ title: "读取数据失败,请重新读取", icon: "none" }); uni.showToast({ title: "读取数据失败,请重新读取", icon: "none" });

View File

@@ -19,3 +19,8 @@ export const RequestErrMsgEnum = {
ABORT: 'request:fail abort', ABORT: 'request:fail abort',
TIMEOUT: 'request:fail timeout' TIMEOUT: 'request:fail timeout'
}; };
// 特殊接口不弹默认窗口处理
export const RequestUrlAlertEum=[
'/patrol/patroltask/validateNfc'
]

View File

@@ -13,7 +13,7 @@
export default { export default {
data() { data() {
return { return {
inputText: 'testtesttesttesttestfdsf' inputText: 'testtesttesttesttestfdsftttg'
} }
}, },
onLoad() { onLoad() {

View File

@@ -103,10 +103,13 @@
</view> </view>
<!-- #endif --> <!-- #endif -->
<!-- #ifndef APP-PLUS --> <!-- #ifndef APP-PLUS -->
<view class="r-right r-active"> <view class="r-right r-active" v-if="item.resultContent" >
<img :src="'static/images/polling/icon-NFCcode-b.png'" class="img-nfc" /> <img :src="'static/images/polling/icon-NFCcode-b.png'" class="img-nfc" />
<view>识别成功</view> <view>识别成功</view>
</view> </view>
<view class="r-right" v-else>
<img :src="'static/images/polling/icon-NFCcode.png'" class="img-nfc" /> 开始识别
</view>
<!-- #endif --> <!-- #endif -->
</view> </view>
</block> </block>
@@ -127,10 +130,13 @@
</view> </view>
<!-- #endif --> <!-- #endif -->
<!-- #ifndef APP-PLUS --> <!-- #ifndef APP-PLUS -->
<view class="r-right r-active"> <view class="r-right r-active" v-if="item.resultContent">
<img :src="'static/images/polling/icon-QRcode-b.png'" class="img-nfc" /> <img :src="'static/images/polling/icon-QRcode-b.png'" class="img-nfc" />
<view>扫码成功</view> <view>扫码成功</view>
</view> </view>
<view class="r-right" v-else>
<img :src="'static/images/polling/icon-QRcode.png'" class="img-nfc" /> 开始扫码
</view>
<!-- #endif --> <!-- #endif -->
</view> </view>
</block> </block>
@@ -244,12 +250,11 @@
<!-- NFC 数据读取 --> <!-- NFC 数据读取 -->
<NFCTemplate <NFCTemplate v-if="nfcShow" ref="nfcReaderRef"
v-if="nfcShow" :nfcId="nfcId"
ref="nfcReaderRef"
@changeNfc="handleNfcData" @changeNfc="handleNfcData"
@close="nfcClose" @close="nfcClose"
/> ></NFCTemplate>
</view> </view>
</template> </template>
<script setup> <script setup>
@@ -537,7 +542,10 @@ let nfcShow = ref(false);
const nfcReaderRef = ref(null); const nfcReaderRef = ref(null);
// optionObj.pointList // optionObj.pointList
let nfcIndex = ref(0); let nfcIndex = ref(0);
let nfcId = ref()
const initNFC = async(item,index) => { const initNFC = async(item,index) => {
// console.log("item=>",item)
nfcId.value = item.refId;
nfcShow.value = true; nfcShow.value = true;
nfcIndex.value=index; nfcIndex.value=index;
// uni.navigateTo({url:'/pages/business/polling/nfcTest/index'}) // uni.navigateTo({url:'/pages/business/polling/nfcTest/index'})
@@ -553,12 +561,9 @@ const nfcClose = async(item) => {
nfcShow.value = false; nfcShow.value = false;
} }
const handleNfcData=(data)=>{ const handleNfcData= async(data)=>{
console.log("NFC数据:", data); console.log("NFC数据:", data);
// console.log("NFC数据1111:", optionObj.value.pointList,nfcIndex.value)
optionObj.value.pointList[nfcIndex.value].resultContent = data; optionObj.value.pointList[nfcIndex.value].resultContent = data;
// console.log("NFC数据1111:", optionObj.value.pointList[nfcIndex.value])
// nfcShow.value = false;
} }
// 扫二维码 // 扫二维码

View File

@@ -129,7 +129,7 @@ export default class HttpRequest {
// console.log("success111=>",response) // console.log("success111=>",response)
if (responseInterceptorsHook && isFunction(responseInterceptorsHook)) { if (responseInterceptorsHook && isFunction(responseInterceptorsHook)) {
try { try {
response = await responseInterceptorsHook(response, mergeConfig); response = await responseInterceptorsHook(response, mergeConfig,options);
resolve(response); resolve(response);
} }
catch (error) { catch (error) {

View File

@@ -1,9 +1,8 @@
import HttpRequest from './http'; import HttpRequest from './http';
import { merge } from 'lodash-es'; import { merge } from 'lodash-es';
import { getToken } from '../auth'; import { getToken,clearToken } from '../auth';
import { CLIENT_ID } from '@/enums/cacheEnums'; import { CLIENT_ID } from '@/enums/cacheEnums';
import { RequestCodeEnum, RequestMethodsEnum } from '@/enums/requestEnums'; import { RequestCodeEnum, RequestMethodsEnum,RequestUrlAlertEum } from '@/enums/requestEnums';
import { clearToken } from '@/utils/auth'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import { useMessage } from '../message'; import { useMessage } from '../message';
const message = useMessage(); const message = useMessage();
@@ -29,7 +28,7 @@ const requestHooks = {
return options; return options;
}, },
// 响应拦截器 // 响应拦截器
responseInterceptorsHook(response, config) { responseInterceptorsHook(response, config,options) {
// console.log("response=>",response) // console.log("response=>",response)
// console.log("response=>config=>",config) // console.log("response=>config=>",config)
const { isTransformResponse, isReturnDefaultResponse, isAuth } = config; const { isTransformResponse, isReturnDefaultResponse, isAuth } = config;
@@ -60,6 +59,13 @@ const requestHooks = {
return Promise.reject(); return Promise.reject();
default: default:
// 判断弹窗处理
const isUrlFlag = RequestUrlAlertEum.includes(options.url);
// console.log("返回处理==>",isUrlFlag,options.url)
if(isUrlFlag){
return {code,msg};
}
if(msg) if(msg)
message.alert(msg) message.alert(msg)
else else
@@ -70,6 +76,7 @@ const requestHooks = {
}, },
// 响应异常拦截器 // 响应异常拦截器
responseInterceptorsCatchHook(options, err) { responseInterceptorsCatchHook(options, err) {
// console.log("responseInterceptorsCatchHook=>",options,err)
if (options.method.toUpperCase() == RequestMethodsEnum.POST) { if (options.method.toUpperCase() == RequestMethodsEnum.POST) {
console.log('请求失败:', err, options); console.log('请求失败:', err, options);
} }
@@ -82,7 +89,7 @@ const defaultOptions = {
requestOptions: {// 请求配置 requestOptions: {// 请求配置
timeout: 10 * 1000, timeout: 10 * 1000,
header: { header: {
version: '1.0.0', // version: '1.0.0',
clientId:`${CLIENT_ID || 2}`, // clientId传2 clientId:`${CLIENT_ID || 2}`, // clientId传2
} }
}, },