安卓开发uniapp打包apk安装在pda机器相机扫描枪识别二维码条形码
需求:
在PDA安卓机器上的一个APP小应用,扫码后得到订单信息和员工信息,将这些数据信息提交后服务端接口。
分析:
1 点击PDA机器的扫码按键,扫码后识别到二维码的信息数据
2 二维码信息数据传递给服务端接口,得到响应的详细信息(订单,员工)
3 将“订单,员工”信息提交给服务端接口,完成。
要点:
打开APP时,需要将焦点定位在‘文本框1’中(只有这样,PDA扫码后的数据才会自动填充至文本框。) ,然后通过轮询(因为我们拿不到PDA的扫码事件,所以用轮询)判断文本框中的数据值,做进一步的业务处理。
<template>
<view class="materialOrder">
<view class="materialBtn" @click="openUrl">切换url</view>
<view class="materialBox">
<view class="formHeader">
<view class="title">工单号:</view>
<input type="text" v-model="tempMaterialValue" :focus="materialFocus"></input>
<uni-icons class="scanCode" type="scan" size="32" color="#7297fe" @click="materialScanCode"></uni-icons>
</view>
<!-- <view class="formHeader2">
<view class="btn" @click="materialScanCodeBtn">工单请求</view>
<view>调试:{{ materialTemp }}</view>
<view v-if="materialParams">扫码完成:</view>
<view v-if="materialValue">全局变量工单值:{{ materialValue }}</view>
<view v-if="tempMaterialValue">输入框临时变量工单值:{{ tempMaterialValue }}</view>
<view v-if="materialParams">请求参数工单号:{{ materialParams.InputVars[0].Value }}</view>
<view v-if="materialResponse">返回参数:{{ materialResponse }}</view>
</view> -->
<view class="formBox">
<view class="form-label">生产订单号:</view>
<view class="form-input">
<input type="text" v-model="materialForm.Code" disabled></input>
</view>
</view>
<view class="formBox">
<view class="form-label">生产计划号:</view>
<view class="form-input">
<input type="text" v-model="materialForm.PlanCode" disabled></input>
</view>
</view>
<view class="formBox">
<view class="form-label">数量:</view>
<view class="form-input">
<input type="text" v-model="materialForm.PrdQty" disabled></input>
</view>
</view>
<view class="formBox">
<view class="form-label">物料名称:</view>
<view class="form-input">
<input type="text" v-model="materialForm.Name" disabled></input>
</view>
</view>
</view>
<view class="userBox">
<view class="formHeader">
<view class="title">员工号:</view>
<input type="text" v-model="tempUserValue" :focus="userFocus"></input>
<uni-icons class="scanCode" type="scan" size="32" color="#7297fe" @click="userScanCode"></uni-icons>
</view>
<!-- <view class="formHeader2">
<view class="btn" @click="userScanCodeBtn">员工请求</view>
<view>调试:{{ userTemp }}</view>
<view v-if="userParams">扫码完成:</view>
<view v-if="userValue">全局变量员工值:{{ userValue }}</view>
<view v-if="tempUserValue">输入框临时变量员工值:{{ tempUserValue }}</view>
<view v-if="userParams">请求参数员工号:{{ userParams.InputVars[1].Value }}</view>
<view v-if="userResponse">返回参数:{{ userResponse }}</view>
</view> -->
<view class="formBox">
<view class="form-label">工序号:</view>
<view class="form-input">
<input type="text" v-model="userForm.ProcedureCode" disabled></input>
</view>
</view>
<view class="formBox">
<view class="form-label">工序名称:</view>
<view class="form-input">
<input type="text" v-model="userForm.ProcedureName" disabled></input>
</view>
</view>
<view class="formBox">
<view class="form-label">员工编号:</view>
<view class="form-input">
<input type="text" v-model="userForm.EmpCode" disabled></input>
</view>
</view>
<view class="formBox">
<view class="form-label">员工名称:</view>
<view class="form-input">
<input type="text" v-model="userForm.EmpName" disabled></input>
</view>
</view>
<view class="formBox">
<view class="form-label">工时:</view>
<view class="form-input">
<input type="text" v-model="userForm.WorkTime" disabled></input>
</view>
</view>
</view>
<!-- <view class="userBox">
<view class="formHeader2">
<view v-if="submitParams">提交完成:</view>
<view v-if="submitParams">请求参数:{{ submitParams }}</view>
<view v-if="submitResponse">返回参数:{{ submitResponse }}</view>
</view>
</view> -->
<view class="send_bottom">
<view class="send_btn" @click="submit">提交</view>
</view>
<view class="win_bg" v-if="showSuccess">
<view class="win" @click.stop>
<view class="winTop">
<view class="winTip">提示</view>
<text class="iconfont icon-shanchu1" @click="closeSuccess"></text>
</view>
<text class="winTitle">提交成功</text>
<view class="winButton" @click="closeSuccess">确定</view>
</view>
</view>
<view class="urlBox" v-if="showUrl">
<view class="urlContent">
<uni-icons class="close" type="closeempty" size="20" @click="closeUrl"></uni-icons>
<view class="urlHeader">切换url</view>
<input type="text" v-model="url" placeholder="请输入要切换的url" />
<view class="urlBtn" @click="closeUrl">
<text>确定</text>
</view>
</view>
</view>
</view>
</template>
<script>
import {
getTotalRequestStatus
} from "@/api/app.js";
import {
materialOrder
} from "@/api/materialOrder.js";
import mixin from "@/mixins/mixin.js";
export default {
mixins: [mixin],
data() {
return {
// 物料展示数据
materialForm: {
Code: "", // 生产订单号
PlanCode: "", // 生产计划号
PrdQty: "", // 数量
Name: "", // 物料名称
},
// 物料提交数据
materialValue: "",
// 临时物料展示数据
tempMaterialValue: "",
// 物料获取焦点
materialFocus: true,
// 员工展示数据
userForm: {
ProcedureCode: "", // 工序号
ProcedureName: "", // 工序名称
EmpCode: "", // 员工编号
EmpName: "", // 员工名称
WorkTime: "" // 工时
},
// 员工提交数据
userValue: "",
// 临时员工展示数据
tempUserValue: "",
// 物料获取焦点
userFocus: false,
// 成功弹框显示隐藏
showSuccess: false,
// 总请求状态
totalRequestStatus: 200,
materialParams: "",
materialResponse: "",
userParams: "",
userResponse: "",
submitParams: "",
submitResponse: "",
materialTemp: "",
userTemp: "",
materialInterval: null,
userInterval: null,
// url弹框显示隐藏
showUrl: false,
// url输入框
url: "http://a.com/ExecutePyScriptIdEx",
}
},
onLoad(options) {
// this.getTotalRequestStatus();
if (uni.getStorageSync("url")) this.url = uni.getStorageSync("url");
},
mounted() {
// 设置定时器,每隔1秒执行一次
this.materialInterval = setInterval(() => {
if (this.tempMaterialValue) {
this.materialValue = this.tempMaterialValue;
this.tempMaterialValue = "";
this.materialScanCodeBtn();
}
}, 1000);
// 设置定时器,每隔1秒执行一次
this.userInterval = setInterval(() => {
if (this.tempUserValue) {
this.userValue = this.tempUserValue;
this.tempUserValue = "";
this.userScanCodeBtn();
}
}, 1000);
},
methods: {
/**
* 获取总请求状态
*/
async getTotalRequestStatus() {
let res = await getTotalRequestStatus({});
if (res.code == 200) this.totalRequestStatus = res.status;
},
/**
* 物料扫码
*/
materialScanCode() {
if (this.totalRequestStatus == 404) {
uni.showToast({
title: "网络异常",
icon: "none"
});
return false;
};
uni.scanCode({
success: async scanCodeRes => {
this.materialTemp += "a1";
console.log("物料条码类型:" + scanCodeRes.scanType);
console.log("物料条码内容:" + scanCodeRes.result);
this.materialTemp += "a2";
this.materialValue = scanCodeRes.result;
this.materialTemp += "a3";
this.tempMaterialValue = scanCodeRes.result;
this.materialTemp += "a4";
this.materialScanCodeBtn();
this.materialTemp += "a5";
this.materialFocus = false;
this.userFocus = true;
this.materialTemp += "a6";
let params = {
"Token": "9E169826F05A4FB690FF4B3F8841ECE5",
"ScriptId": "0751c1b1-2e25-4521-adc5-fafc4f611f80",
"InputVars": [{
"ValueType": 0,
"VarName": "scddh",
"Value": scanCodeRes.result
}]
};
this.materialTemp += "a7";
this.materialParams = params;
this.materialTemp += "a8";
let res = await materialOrder(this.url, params);
this.materialTemp += "a9";
this.materialResponse = res;
if (res.status == 200 && res.var_values.result.resultDatas && res.var_values.result
.resultDatas.length > 0) {
this.materialTemp += "a10";
let materialData = res.var_values.result.resultDatas[0];
Object.keys(this.materialForm).forEach(key => {
this.materialForm[key] = materialData[key];
});
// setTimeout(() => {
// this.tempMaterialValue = "";
// }, 1000);
} else {
uni.showToast({
title: res.var_values.result.message,
icon: "none"
});
};
},
fail: err => {
this.materialTemp += "a11";
this.materialScanCodeBtn();
},
complete: () => {
this.materialTemp += "a12";
this.materialScanCodeBtn();
}
});
},
/**
* 物料扫码
*/
async materialScanCodeBtn() {
this.materialFocus = false;
this.userFocus = true;
let params = {
"Token": "9E169826F05A4FB690FF4B3F8841ECE5",
"ScriptId": "0751c1b1-2e25-4521-adc5-fafc4f611f80",
"InputVars": [{
"ValueType": 0,
"VarName": "scddh",
"Value": this.tempMaterialValue ? this.tempMaterialValue : this
.materialValue
}]
};
this.materialParams = params;
let res = await materialOrder(this.url, params);
this.materialResponse = res;
if (res.status == 200 && res.var_values.result.resultDatas && res.var_values.result
.resultDatas.length > 0) {
let materialData = res.var_values.result.resultDatas[0];
Object.keys(this.materialForm).forEach(key => {
this.materialForm[key] = materialData[key];
});
// setTimeout(() => {
// this.tempMaterialValue = "";
// }, 1000);
} else {
uni.showToast({
title: res.var_values.result.message,
icon: "none"
});
};
},
/**
* 员工扫码
*/
userScanCode() {
if (this.totalRequestStatus == 404) {
uni.showToast({
title: "网络异常",
icon: "none"
});
return false;
};
if (!this.materialValue) {
uni.showToast({
title: "请先扫工单码",
icon: "none"
});
return false;
};
uni.scanCode({
success: async scanCodeRes => {
this.userTemp += "a1";
console.log("条码类型:" + scanCodeRes.scanType);
console.log("条码内容:" + scanCodeRes.result);
this.userTemp += "a2";
this.userValue = scanCodeRes.result;
this.userTemp += "a3";
this.tempUserValue = scanCodeRes.result;
this.userTemp += "a4";
this.userScanCodeBtn();
this.userTemp += "a5";
this.userTemp += "a6";
let params = {
"Token": "9E169826F05A4FB690FF4B3F8841ECE5",
"ScriptId": "f44b24b8-156d-41d1-93a2-13065088f6df",
"InputVars": [{
"ValueType": 0,
"VarName": "scddh",
"Value": this.materialValue
}, {
"ValueType": 0,
"VarName": "yggh",
"Value": scanCodeRes.result
}]
};
this.userTemp += "a7";
this.userParams = params;
this.userTemp += "a8";
let res = await materialOrder(this.url, params);
this.userTemp += "a9";
this.userResponse = res;
if (res.status == 200 && res.var_values.result.resultDatas && res
.var_values.result
.resultDatas.length > 0) {
this.userTemp += "a10";
let userData = res.var_values.result.resultDatas[0];
Object.keys(this.userForm).forEach(key => {
this.userForm[key] = userData[key];
});
// setTimeout(() => {
// this.tempUserValue = "";
// }, 1000);
} else {
uni.showToast({
title: res.var_values.result.message,
icon: "none"
});
};
},
fail: err => {
this.userTemp += "a11";
this.userScanCodeBtn();
},
complete: () => {
this.userTemp += "a12";
this.userScanCodeBtn();
}
});
},
/**
* 员工扫码
*/
async userScanCodeBtn() {
let params = {
"Token": "9E169826F05A4FB690FF4B3F8841ECE5",
"ScriptId": "f44b24b8-156d-41d1-93a2-13065088f6df",
"InputVars": [{
"ValueType": 0,
"VarName": "scddh",
"Value": this.tempMaterialValue ? this.tempMaterialValue : this
.materialValue
}, {
"ValueType": 0,
"VarName": "yggh",
"Value": this.tempUserValue ? this.tempUserValue : this.userValue
}]
};
this.userParams = params;
let res = await materialOrder(this.url, params);
this.userResponse = res;
if (res.status == 200 && res.var_values.result.resultDatas && res.var_values.result
.resultDatas.length > 0) {
let userData = res.var_values.result.resultDatas[0];
Object.keys(this.userForm).forEach(key => {
this.userForm[key] = userData[key];
});
// setTimeout(() => {
// this.tempUserValue = "";
// }, 1000);
} else {
uni.showToast({
title: res.var_values.result.message,
icon: "none"
});
};
},
/**
* 新增物料工单
*/
async submit() {
if (this.totalRequestStatus == 404) {
uni.showToast({
title: "网络异常",
icon: "none"
});
return false;
};
// if (!this.materialValue) {
// uni.showToast({
// title: "请先扫工单码",
// icon: "none"
// });
// return false;
// };
// if (!this.userValue) {
// uni.showToast({
// title: "请先扫员工码",
// icon: "none"
// });
// return false;
// };
let params = {
"Token": "9E169826F05A4FB690FF4B3F8841ECE5",
"ScriptId": "ce724c1a-2991-4586-b276-e0af6845267c",
"InputVars": [{
"ValueType": 0,
"VarName": "scddh",
"Value": this.tempMaterialValue ? this.tempMaterialValue : this
.materialValue
}, {
"ValueType": 0,
"VarName": "yggh",
"Value": this.tempUserValue ? this.tempUserValue : this.userValue
}]
};
this.submitParams = params;
let res = await materialOrder(this.url, params);
this.submitResponse = res;
if (res.status == 200 && res.var_values.result.isSuccess) {
this.showSuccess = true;
} else {
uni.showToast({
title: res.var_values.result.message,
icon: "none"
});
};
},
/**
* 关闭提交成功弹框
*/
async closeSuccess() {
Object.keys(this.materialForm).forEach(key => {
this.materialForm[key] = "";
});
this.materialValue = "";
this.tempMaterialValue = "";
this.materialFocus = true;
Object.keys(this.userForm).forEach(key => {
this.userForm[key] = "";
});
this.userValue = "";
this.tempUserValue = "";
this.userFocus = false;
this.showSuccess = false;
this.materialParams = "";
this.materialResponse = "";
this.userParams = "";
this.userResponse = "";
this.submitParams = "";
this.submitResponse = "";
},
/**
* 打开url
*/
openUrl() {
this.showUrl = true;
},
/**
* 关闭分享
*/
closeUrl() {
uni.setStorageSync("url", this.url);
this.showUrl = false;
}
}
}
</script>
<style scoped lang="scss">
@import "materialOrder.scss";
</style>
结束