- 1,扫码页:读取手机内存中放入的文件,把符合条件的筛选出来,渲染页面
- 2,盘点页:先读取手机文件,扫码写入该文件
- 3,放在手机eqp文件夹下面的data.txt文件内容
- 4,封装获取当前时间的方法
- 5,封装读取写入方法
- 6,扫的二维码
注意事项:扫码页读取文件时,先把data.txt文件放入手机内(eqp/data.txt),再用调试基座扫码筛选出数据打印出来;盘点页:可以先扫码,每次扫码都会写入文件(records/data.txt),返回上一页时,再次进入此页面,先读取已经有的文件内容,扫码写入此文件。查找时,可断开数据线,再次连接数据线,在手机内存中找,看是否写入文件,核实一下。后端会把这个文件内容导入数据,同时删掉此文件。(先读再写的好处:盘点时中途休息或手机没电) 1,扫码页:读取手机内存中放入的文件,把符合条件的筛选出来,渲染页面
// An highlighted block2,盘点页:先读取手机文件,扫码写入该文件资产扫码 盘点
// An highlighted block3,放在手机eqp文件夹下面的data.txt文件内容--> {dataList}} 盘点 {{idx+1}} 【盘点编码】{{v.eqpCode}} 【盘点时间】{{v.checkTime || '无'}}
//数据线连接电脑传送文件:此电脑HUAWEI P30内部存储Androiddatacom.dianwang.mesdownloadseqp
//包名com.dianwang.mes
//调试基座 io.dcloud.HBuilder
// An highlighted block
{"EQP1539546740871532544":{"brand":"622测试设备3","eqpCode":"EQP1539546740871532544","eqpModel":"622测试设备3","eqpName":"622测试设备3","id":"1539546740869046274","locationName":"蒽醌一车间"},"EQP1541672639645487104":{"eqpCode":"EQP1541672639645487104","eqpName":"628测试设备","id":"1541672639814270977","locationName":"一楼北"},"EQP1550030826174025728":{"brand":"721资产","eqpCode":"EQP1550030826174025728","eqpModel":"721资产","eqpName":"721资产","id":"1550030826213539841","locationName":"蒽醌一车间"},"EQP1542760718493945856":{"brand":"111","deptName":"设备部","eqpCode":"EQP1542760718493945856","eqpModel":"L","eqpName":"设备刘","id":"1542760718504099841","locationName":"二楼西北"},"0101V01ceshi1":{"eqpCode":"0101V01ceshi1","eqpName":"纯水槽测试1","id":"1540166541860249602","locationName":"一线车间"},"0113R99999":{"eqpCode":"0113R99999","eqpModel":"10","eqpName":"可以导入","id":"1542802363341668354","locationName":"四楼西北"},"0101V088":{"eqpCode":"0101V088","eqpName":"缓冲罐","id":"1541353353916719105","locationName":" 测试四车间"},"0101V066":{"eqpCode":"0101V066","eqpName":"缓冲罐","id":"1541353353849610245","locationName":"三楼"},"0101V044":{"eqpCode":"0101V044","eqpName":"缓冲罐","id":"1541353353849610243","locationName":"二楼北"},"0101V022":{"eqpCode":"0101V022","eqpName":"缓冲罐","id":"1541353353849610241","locationName":"二楼西"},"0101V023":{"eqpCode":"0101V023","eqpName":"缓冲罐","id":"1541353353849610242","locationName":"一楼西"},"0101V01":{"eqpCode":"0101V01","eqpName":"纯水槽","id":"1539549663652294658","locationName":"一线车间"},"0113R107":{"eqpCode":"0113R107","eqpModel":"3","eqpName":"活性炭打浆釜","id":"1542088258313347075","locationName":"一楼西北"},"0113R305":{"eqpCode":"0113R305","eqpModel":"8","eqpName":"水解釜","id":"1542088258250432513","locationName":"三楼西南","remark":"单端面机封204JT-110"},"0101V02ceshi2":{"eqpCode":"0101V02ceshi2","eqpName":"纯水槽测试2","id":"1540166541860249603","locationName":"一线车间"},"0101V02":{"eqpCode":"0101V02","eqpName":"缓冲罐","id":"1539549663664877569","locationName":"四楼西北"},"0113R106":{"eqpCode":"0113R106","eqpModel":"3","eqpName":"氯化钙溶解釜","id":"1542088258313347074","locationName":"一楼西北"},"EQP1539546497513820160":{"brand":"622测试设备2","eqpCode":"EQP1539546497513820160","eqpModel":"622测试设备2","eqpName":"622测试设备2","id":"1539546497511333890","locationName":"蒽醌一车间"},"0113R7627":{"eqpCode":"0113R7627","eqpName":"7月4日导入设备","id":"1543779187847864322","locationName":"四楼西北","remark":"暂无"},"0113R101":{"eqpCode":"0113R101","eqpModel":"15","eqpName":"稀释釜","id":"1542088258250432514","locationName":"一楼西南","remark":"单端面机封204JT-125"},"EQP1542793745408331776":{"deptName":"日兴生物科技","eqpCode":"EQP1542793745408331776","eqpModel":"M","eqpName":"刘钦的设备","id":"1542793745414291457","locationName":"三楼西北"},"0113R105":{"eqpCode":"0113R105","eqpModel":"30","eqpName":"盐析釜","id":"1542088258313347073","locationName":"一楼西北"},"0113R303":{"eqpCode":"0113R303","eqpModel":"5","eqpName":"溴化釜","id":"1542088258179129347","locationName":"三楼西北","remark":"双端面机封221-95"},"0113R104":{"eqpCode":"0113R104","eqpModel":"45","eqpName":"中和釜","id":"1542088258250432517","locationName":"一楼西北"},"0113R302":{"eqpCode":"0113R302","eqpModel":"10","eqpName":"磺化釜","id":"1542088258179129346","locationName":"三楼西北","remark":"双端面机封221-110"},"0113R401":{"eqpCode":"0113R401","eqpModel":"10","eqpName":"分层釜","id":"1542088258103631874","locationName":"四楼西北"},"EQP1539546040905109504":{"brand":"622测试设备","deptName":"日兴生物科技","eqpCode":"EQP1539546040905109504","eqpModel":"622测试设备","eqpName":"622测试设备","id":"1539546040906817537","locationName":"蒽醌一车间"},"0113R103":{"eqpCode":"0113R103","eqpModel":"30","eqpName":"一精釜","id":"1542088258250432516","locationName":"一楼西南"},"0113R301":{"eqpCode":"0113R301","eqpModel":"10","eqpName":"磺化釜","id":"1542088258179129345","locationName":"三楼西北","remark":"双端面机封221-110"},"0113R201":{"eqpCode":"0113R201","eqpModel":"5","eqpName":"配酸釜","id":"1542088258313347076","locationName":"二楼西北"},"0113R102":{"eqpCode":"0113R102","eqpModel":"30","eqpName":"二精釜","id":"1542088258250432515","locationName":"一楼西南"},"EQP1540163441451470848":{"eqpCode":"EQP1540163441451470848","eqpName":"624测试设备2","id":"1540163441405566977","locationName":"蒽醌一车间"},"EQP1540159981989531648":{"brand":"624测试设备","deptName":"日兴生物科技","eqpCode":"EQP1540159981989531648","eqpModel":"624测试设备","eqpName":"624测试设备","id":"1540159982191091713","locationName":"一线汽化间"},"0101V077":{"eqpCode":"0101V077","eqpName":"缓冲罐","id":"1541353353849610246","locationName":"测试三车间"},"0101V055":{"eqpCode":"0101V055","eqpName":"缓冲罐","id":"1541353353849610244","locationName":"测试三车间"},"0101V011":{"eqpCode":"0101V011","eqpName":"纯水槽","id":"1541353353824444418","locationName":"一楼北"},"EQP1539489933109104640":{"eqpCode":"EQP1539489933109104640","eqpName":"110","id":"1539489933110812673","locationName":"蒽醌一车间"},"0113":{"deptName":"生产部","eqpCode":"0113","eqpName":"分层釜","id":"1537075241819504642","locationName":"四楼西北"},"0113R999":{"deptName":"日兴生物科技","eqpCode":"0113R999","eqpModel":"10","eqpName":"感冒灵测试","id":"1542723508735426561","locationName":"四楼西北"},"EQP1550753570918371328":{"brand":"723设备","eqpCode":"EQP1550753570918371328","eqpModel":"723设备","eqpName":"723设备","id":"1550753570957873154","locationName":"蒽醌一车间"}}
4,封装获取当前时间的方法
// 路径 /common/checkUtil.js
// 获取系统当前时间
export function getNowDate() {
var nowdate = new Date();
var Y = nowdate.getFullYear();
var M = (nowdate.getMonth() + 1)<10?'0'+(nowdate.getMonth() + 1):(nowdate.getMonth() + 1);
var D = nowdate.getDate()<10?'0'+nowdate.getDate():nowdate.getDate();
var h = nowdate.getHours()<10?'0'+nowdate.getHours():nowdate.getHours();
var m = nowdate.getMinutes()<10?'0'+nowdate.getMinutes():nowdate.getMinutes();
var s = nowdate.getSeconds()<10?'0'+nowdate.getSeconds():nowdate.getSeconds();
var formatnowdate = Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s
return formatnowdate
}
5,封装读取写入方法
// 路径:/common/convertFormat.js
// 读取json文件
function getJsonData(path) { //path:路径
return new Promise(resolve => {
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, fs => { //请求文件系统
fs.root.getFile(
path, {
create: true //当文件不存在时创建
}, fileEntry => {
fileEntry.file(function(file) {
let fileReader = new plus.io
.FileReader(); //new一个可以用来读取文件的对象fileReader
fileReader.readAsText(file, "utf-8"); //读文件的格式
fileReader.onerror = e => { //读文件失败
// console.log("获取文件失败", fileReader.error);
plus.nativeUI.toast("获取文件失败,请重启应用", {
background: "#ffa38c",
});
return;
};
fileReader.onload = e => { //读文件成功
// console.log("读取文件成功");
let txtData = e.target.result;
resolve(txtData);
// 回调函数内的值想返回到函数外部 就用promise+resolve来返回出去
};
});
}, error => {
console.log("2新建获取文件失败", error);
plus.nativeUI.toast("获取文件失败,请重启应用", {
background: "#ffa38c",
});
return;
});
},
e => {
console.log("1请求文件系统失败", e.message);
plus.nativeUI.toast("请求系统失败,请重启应用", {
background: "#ffa38c",
});
return;
}
);
});
};
// 写入josn文件
function changeData(path, seek, writeData) { //参数1:上传路径,参数2:seek方法可设置文件操作指定位置,参数3:写入的json数据
return new Promise(resolve => {
plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, fs => {
fs.root.getFile(path, {
create: true
}, fileEntry => {
fileEntry.file(file => {
fileEntry.createWriter(writer => {
plus.nativeUI.showWaiting("正在保存信息");
writer.seek(seek); //覆盖文件
const writeDataTemp = JSON.stringify(writeData, null,
"r").replace(/[r]/g, "");
writer.write(writeDataTemp); // 整个文件重写
writer.onerror = function() {
console.log("4写入文件失败", writer.error.message);
plus.nativeUI.closeWaiting();
plus.nativeUI.toast("修改信息失败,请重新操作", {
background: "#ffa38c",
});
return;
};
writer.onsuccess = function() { //填写文件成功
plus.nativeUI.closeWaiting();
plus.nativeUI.toast("盘点成功", {
background: "rgba(255, 255, 255, 0.6)",
});
resolve("1");
};
},
error => {
console.log("3创建creactWriter失败", error);
plus.nativeUI.toast("保存文件失败,请重新操作", {
background: "#ffa38c",
});
return;
});
});
},
error => {
console.log("2获取文件失败", error);
plus.nativeUI.toast("保存文件失败,请重新操作", {
background: "#ffa38c",
});
return;
}
);
}, e => {
console.log("1请求文件系统失败", e.message);
plus.nativeUI.toast("请求系统失败,请重新操作", {
background: "#ffa38c",
});
return;
});
});
}
async function saveFile(url, file, newfilename) {
let c = await creatDirs(url)
let isokm = moveDirectyOrFile(file, url + "/", newfilename);
return isokm
}
//循环创建目录 url:"_doc/...." _doc开头
async function creatDirs(url) {
let urllist = url.split("/");
console.log(urllist)
//创建文件夹
let u = "";
for (let i = 0; i < urllist.length - 1; i++) {
let j = i;
if (i == 0) {
u = urllist[i];
} else {
u = u + "/" + urllist[i];
}
console.log(i + "-------------------")
console.log(u)
console.log(urllist[j + 1])
await CreateNewDir(u, urllist[j + 1]);
}
}
//重命名目录或文件名
function moveDirectyOrFile(srcUrl, dstUrl, newName) { //srcUrl需要移动的目录或文件,dstUrl要移动到的目标目录(父级)
plus.io.resolveLocalFileSystemURL(srcUrl, function(srcEntry) {
//console.log(111)
plus.io.resolveLocalFileSystemURL(dstUrl, function(dstEntry) {
//console.log(222)
if (srcEntry.isDirectory) {
//console.log(33)
srcEntry.moveTo(dstEntry, newName, function(entry) {
//console.log("New Path: " + entry.fullPath);
return true;
}, function(e) {
return e;
//console.log(e.message);
});
} else {
srcEntry.moveTo(dstEntry, newName, function(entry) {
//console.log("New Path: " + entry.fullPath);
return true;
}, function(e) {
return e;
//console.log(e.message);
});
}
}, function(e) {
uni.showToast({
title: '获取目标目录失败:' + e.message,
duration: 2000,
icon: 'none'
});
});
}, function(e) {
uni.showToast({
title: '获取目录失败:' + e.message,
duration: 2000,
icon: 'none'
});
});
}
//创建一个新目录
function CreateNewDir(url, dirName) {
//url值可支持相对路径URL、本地路径URL
return new Promise((resolver, reject) => {
plus.io.resolveLocalFileSystemURL(url, function(entry) {
entry.getDirectory(dirName, {
create: true,
exclusive: false
}, function(dir) {
resolver(true)
}, function(error) {
reject(error.message)
uni.showToast({
title: dirName + '目录创建失败:' + error.message,
duration: 2000,
icon: 'none'
});
});
}, function(e) {
reject(error.message)
uni.showToast({
title: '获取目录失败:' + e.message,
duration: 2000,
icon: 'none'
});
});
})
}
function copyFileTo(url, newUrl, dirName, newName) {
if (url.length >= 7 && "file://" == url.substring(0, 7)) {
url = url.substring(7)
}
let tempUrl = url.substring(0, url.lastIndexOf('/'));
let addUrl = newUrl + '/' + dirName;
console.log(addUrl, tempUrl)
if (addUrl == tempUrl) {
return url;
}
console.log(newUrl, dirName, newName)
return new Promise((resolve, reject) => {
plus.io.resolveLocalFileSystemURL(url, async (entry) => {
if (entry.isFile) {
let c = await CreateNewDir(newUrl, dirName)
let u = await getDirsys(addUrl)
entry.copyTo(u, newName, en => {
resolve(en.fullPath);
}, e => {
console.log(e);
reject('错误:复制时出现错误')
uni.showModal({
title: "错误",
content: "复制时出现错误"
})
})
} else {
reject('错误:路径必须是文件')
uni.showModal({
title: "错误",
content: "路径必须是文件"
})
}
}, (e) => {
console.log(e);
reject(e)
uni.showModal({
title: "错误",
content: "打开文件系统时出错"
})
});
})
}
//获取目录对象
function getDirsys(url) {
return new Promise((resolve, reject) => {
plus.io.resolveLocalFileSystemURL(url, (entry) => {
resolve(entry)
}, (e) => {
reject(e)
console.log(e);
});
})
}
//将这些方法暴露出去
export {
getJsonData,
changeData,
saveFile,
creatDirs,
moveDirectyOrFile,
copyFileTo,
getDirsys,
};
6,扫的二维码



