nfc验证修改
This commit is contained in:
@@ -170,5 +170,12 @@ export function patrolBugAddLog(data) {
|
||||
data
|
||||
})
|
||||
}
|
||||
//
|
||||
/**主动上报 end */
|
||||
/**主动上报 end */
|
||||
|
||||
// 验证NFC扫描是否正确
|
||||
export function patroltaskValidateNfc(data) {
|
||||
return request.post({
|
||||
url: '/patrol/patroltask/validateNfc',
|
||||
data
|
||||
})
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
<view class="nfc-title">
|
||||
<uni-icons type="closeempty" size="20" class="nfc-close" @click="handleClose"></uni-icons>NFC识别
|
||||
</view>
|
||||
<block v-if="formData.deviceId==''">
|
||||
<block v-if="!deviceId">
|
||||
<view class="nfc-pic">
|
||||
<img class="nfc-pic-animal" :src="'static/images/polling/nfc-logo.png'" />
|
||||
</view>
|
||||
@@ -40,16 +40,20 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onBeforeUnmount,onMounted } from "vue";
|
||||
import { ref, onBeforeUnmount,onMounted,getCurrentInstance } from "vue";
|
||||
import { parseTime } from '@/utils/datetime.js';
|
||||
import { patroltaskValidateNfc } from '@/api/polling.js'
|
||||
|
||||
const { proxy } = getCurrentInstance();
|
||||
const props = defineProps({
|
||||
nfcId:{},
|
||||
})
|
||||
|
||||
// 定义组件 emits
|
||||
const emit = defineEmits(['close',"changeNfc"]);
|
||||
|
||||
// 状态管理
|
||||
const formData = ref({
|
||||
deviceId: "", //录入的id
|
||||
});
|
||||
const deviceId = ref(undefined);
|
||||
const readStatus=ref(false);//读取状态 true 成功
|
||||
|
||||
// 变量初始化
|
||||
@@ -81,7 +85,8 @@ function open() {
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
deviceId.value=undefined;
|
||||
readStatus.value=false;
|
||||
initNFC();
|
||||
} catch (e) {
|
||||
console.error("打开NFC失败:", e);
|
||||
@@ -177,7 +182,7 @@ function handleNewIntent() {
|
||||
}
|
||||
|
||||
// 读取NFC数据
|
||||
function readNFCData() {
|
||||
async function readNFCData() {
|
||||
try {
|
||||
const main = plus.android.runtimeMainActivity();
|
||||
const _intent = main.getIntent();
|
||||
@@ -193,9 +198,23 @@ function readNFCData() {
|
||||
function bytesToString(result) {
|
||||
return String.fromCharCode(...result);
|
||||
}
|
||||
formData.value.deviceId = bytesToString(result).substring(3);
|
||||
emit("changeNfc", formData.value.deviceId);
|
||||
readStatus.value=true;
|
||||
let nfcContent = bytesToString(result).substring(3);
|
||||
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;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.log("读取NDEF数据错误:", e);
|
||||
uni.showToast({ title: "读取数据失败,请重新读取", icon: "none" });
|
||||
|
||||
@@ -18,4 +18,9 @@ export const RequestCodeEnum = {
|
||||
export const RequestErrMsgEnum = {
|
||||
ABORT: 'request:fail abort',
|
||||
TIMEOUT: 'request:fail timeout'
|
||||
};
|
||||
};
|
||||
|
||||
// 特殊接口不弹默认窗口处理
|
||||
export const RequestUrlAlertEum=[
|
||||
'/patrol/patroltask/validateNfc'
|
||||
]
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
inputText: 'testtesttesttesttestfdsf'
|
||||
inputText: 'testtesttesttesttestfdsftttg'
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
|
||||
@@ -103,10 +103,13 @@
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
<!-- #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" />
|
||||
<view>识别成功</view>
|
||||
</view>
|
||||
<view class="r-right" v-else>
|
||||
<img :src="'static/images/polling/icon-NFCcode.png'" class="img-nfc" /> 开始识别
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
</block>
|
||||
@@ -127,10 +130,13 @@
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
<!-- #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" />
|
||||
<view>扫码成功</view>
|
||||
</view>
|
||||
<view class="r-right" v-else>
|
||||
<img :src="'static/images/polling/icon-QRcode.png'" class="img-nfc" /> 开始扫码
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
</block>
|
||||
@@ -244,12 +250,11 @@
|
||||
|
||||
|
||||
<!-- NFC 数据读取 -->
|
||||
<NFCTemplate
|
||||
v-if="nfcShow"
|
||||
ref="nfcReaderRef"
|
||||
@changeNfc="handleNfcData"
|
||||
<NFCTemplate v-if="nfcShow" ref="nfcReaderRef"
|
||||
:nfcId="nfcId"
|
||||
@changeNfc="handleNfcData"
|
||||
@close="nfcClose"
|
||||
/>
|
||||
></NFCTemplate>
|
||||
</view>
|
||||
</template>
|
||||
<script setup>
|
||||
@@ -537,7 +542,10 @@ let nfcShow = ref(false);
|
||||
const nfcReaderRef = ref(null);
|
||||
// optionObj.pointList
|
||||
let nfcIndex = ref(0);
|
||||
let nfcId = ref()
|
||||
const initNFC = async(item,index) => {
|
||||
// console.log("item=>",item)
|
||||
nfcId.value = item.refId;
|
||||
nfcShow.value = true;
|
||||
nfcIndex.value=index;
|
||||
// uni.navigateTo({url:'/pages/business/polling/nfcTest/index'})
|
||||
@@ -553,12 +561,9 @@ const nfcClose = async(item) => {
|
||||
nfcShow.value = false;
|
||||
}
|
||||
|
||||
const handleNfcData=(data)=>{
|
||||
const handleNfcData= async(data)=>{
|
||||
console.log("NFC数据:", data);
|
||||
// console.log("NFC数据1111:", optionObj.value.pointList,nfcIndex.value)
|
||||
optionObj.value.pointList[nfcIndex.value].resultContent = data;
|
||||
// console.log("NFC数据1111:", optionObj.value.pointList[nfcIndex.value])
|
||||
// nfcShow.value = false;
|
||||
}
|
||||
|
||||
// 扫二维码
|
||||
|
||||
@@ -129,7 +129,7 @@ export default class HttpRequest {
|
||||
// console.log("success111=>",response)
|
||||
if (responseInterceptorsHook && isFunction(responseInterceptorsHook)) {
|
||||
try {
|
||||
response = await responseInterceptorsHook(response, mergeConfig);
|
||||
response = await responseInterceptorsHook(response, mergeConfig,options);
|
||||
resolve(response);
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import HttpRequest from './http';
|
||||
import { merge } from 'lodash-es';
|
||||
import { getToken } from '../auth';
|
||||
import { getToken,clearToken } from '../auth';
|
||||
import { CLIENT_ID } from '@/enums/cacheEnums';
|
||||
import { RequestCodeEnum, RequestMethodsEnum } from '@/enums/requestEnums';
|
||||
import { clearToken } from '@/utils/auth'
|
||||
import { RequestCodeEnum, RequestMethodsEnum,RequestUrlAlertEum } from '@/enums/requestEnums';
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { useMessage } from '../message';
|
||||
const message = useMessage();
|
||||
@@ -29,7 +28,7 @@ const requestHooks = {
|
||||
return options;
|
||||
},
|
||||
// 响应拦截器
|
||||
responseInterceptorsHook(response, config) {
|
||||
responseInterceptorsHook(response, config,options) {
|
||||
// console.log("response=>",response)
|
||||
// console.log("response=>config=>",config)
|
||||
const { isTransformResponse, isReturnDefaultResponse, isAuth } = config;
|
||||
@@ -60,6 +59,13 @@ const requestHooks = {
|
||||
return Promise.reject();
|
||||
|
||||
default:
|
||||
// 判断弹窗处理
|
||||
const isUrlFlag = RequestUrlAlertEum.includes(options.url);
|
||||
// console.log("返回处理==>",isUrlFlag,options.url)
|
||||
if(isUrlFlag){
|
||||
return {code,msg};
|
||||
}
|
||||
|
||||
if(msg)
|
||||
message.alert(msg)
|
||||
else
|
||||
@@ -70,6 +76,7 @@ const requestHooks = {
|
||||
},
|
||||
// 响应异常拦截器
|
||||
responseInterceptorsCatchHook(options, err) {
|
||||
// console.log("responseInterceptorsCatchHook=>",options,err)
|
||||
if (options.method.toUpperCase() == RequestMethodsEnum.POST) {
|
||||
console.log('请求失败:', err, options);
|
||||
}
|
||||
@@ -82,7 +89,7 @@ const defaultOptions = {
|
||||
requestOptions: {// 请求配置
|
||||
timeout: 10 * 1000,
|
||||
header: {
|
||||
version: '1.0.0',
|
||||
// version: '1.0.0',
|
||||
clientId:`${CLIENT_ID || 2}`, // clientId传2
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user