// An highlighted block
<template>
<view class="flex align-center justify-center">
<view class="flex align-center btn-view-top">
<view class="flex align-center flex-column" style='margin-right: 200rpx;' @tap='scanTap'>
<view class="text">资产扫码</view>
</view>
<view class="flex align-center flex-column" @tap='goPageTap'>
<view class="text">盘点</view>
</view>
</view>
</view>
</template>
<script>
//引入读取方法
import {getJsonData} from '@/common/convertFormat.js';
export default {
data() {
return {
dataObj:null
};
},
onLoad(options) {
this.readFiles()
},
methods: {
async readFiles(){
const pathUrl = 'eqp/data.txt';
let res = await getJsonData(pathUrl);
// console.log('读取-----',JSON.parse(res))
this.dataObj = JSON.parse(res);
// console.log('读取文件===----',this.dataList)
},
scanTap(){
let that = this;
uni.scanCode({
success(res){
let eqpCode = res.result;
let obj = that.dataObj[eqpCode];
console.log('====',obj)
}
})
},
}
};
</script>
<style>
page{
background-color: white;
}
</style>
<style lang="scss" scoped>
page {
background-color: white;
.btn-view-top{
margin-top: 400rpx;
}
.img{
width: 90rpx;
height: 90rpx;
}
.text{
font-size: 27rpx;
margin-top: 10rpx;
}
}
</style>
// An highlighted block
<!-- 盘点 -->
<template>
<view>
<u-navbar back-icon-color="#699AEB" :is-back="false" title="" :is-fixed="true" :border-bottom="false" :background="background">
<view class="slot-wrap">
<view class="flex align-center justify-between px-3">
<image class="leftIcon" src="/static/customer/left-icon.png" mode="aspectFill" @tap="clickLeft"></image>
<view class="titles">盘点</view>
<image src="/static/equipment/scan.png" class="befite-01 mr-4" mode="widthFix" @tap.stop='scanTap'></image>
</view>
</view>
</u-navbar>
<!-- <view>{{dataList}}</view> -->
<view class="contents" >
<!-- <scroll-view
scroll-y="true"
:style="{ height: scrollHeight+ 'px' }"> -->
<view style='padding-top: 30rpx;' v-if="dataList.length>0">
<view class="card" v-for="(v,idx) in dataList" :key="idx">
<view class="flex align-center"><view class="index">{{idx+1}}</view></view>
<view class="">【盘点编码】{{v.eqpCode}}</view>
<view class='mt-2'>【盘点时间】{{v.checkTime || '无'}}</view>
</view>
</view>
<!-- <no-data title="暂无数据" v-else></no-data> -->
<!-- </scroll-view> -->
</view>
<!-- <view class="footer">
<view class="btn" @tap='submitTap'>上 传</view>
</view> -->
</view>
</template>
<script>
import {getNowDate} from '@/common/checkUtil.js';
import {changeData,getJsonData} from '@/common/convertFormat.js';
export default{
data(){
return{
background: {
backgroundColor: '#FFFFFF'
},
scrollHeight:0,
uuid:null,
dataList:[],
}
},
onReady() {
// this.calcScrollHeight();
},
onLoad() {
const _self = this;
plus.device.getInfo({
success(e){
_self.uuid = JSON.stringify(e.uuid);
console.log(_self.uuid)
}
});
console.log(this.uuid)
// const res = uni.getStorageSync('resObj');
// if (res.data) this.dataList = res.data
// console.log('---',this.dataList)
this.readFiles();
},
methods:{
async readFiles(){
const pathUrl = 'records/data.txt';
let res = await getJsonData(pathUrl);
let obj = JSON.parse(res);
// console.log('读取文件===',obj)
if(obj.data.length>0) this.dataList = obj.data;
},
calcScrollHeight() {
let that = this;
uni.getSystemInfo({
success(res) {
let windowH = res.windowHeight;
let info = uni.createSelectorQuery().select('.footer');
info.boundingClientRect(function(data) {
let topH = data.height;
that.scrollHeight = windowH - topH - 108;
}).exec();
}
});
},
scanTap(){
let that = this;
uni.scanCode({
success(res){
// console.log('盘点扫码===',res)
if(res.result){
that.dataList.push({eqpCode:res.result,checkTime:getNowDate()});
//未改之前:每次扫码本地保存,不在扫码方法调用扫码,点上传按钮,写入文件并清空本地保存。在进入页面onLoad时,先获取本地保存,再扫码
// that.$forceUpdate();
// let obj = {
// "data":that.dataList
// }
// uni.setStorageSync('resObj',obj);
// uni.showToast({
// title: '盘点成功',
// icon: 'success'
// });
//写入文件
let data = {
scanEqpCode:that.uuid,
data:that.dataList
}
// console.log('data---',data)
const pathUrl = 'records/data.txt';
changeData(pathUrl, 0,data);
// that.readFiles();
that.scanTap();
}
}
})
},
clickLeft() {
uni.navigateBack({
delta: 1
});
},
// submitTap(){
// if(this.dataList.length==0){
// uni.showToast({
// title: '请扫码',
// icon: 'none'
// });
// }else{
// let data = {
// scanEqpCode:this.uuid,
// data:this.dataList
// }
// const pathUrl = 'records/data.txt';
// changeData(pathUrl, 0,data);
// uni.showToast({
// title: '上传成功',
// icon: 'success'
// });
// this.dataList = [];
// uni.removeStorageSync('resObj');
// }
// }
},
}
</script>
<style>
page {
background-color: #f6f7fb;
}
</style>
<style lang="scss" scoped>
page {
width: 100%;
height: 100%;
background-color: #f6f7fb;
.leftIcon {
width: 17rpx;
height: 30rpx;
}
.titles {
width: 640rpx;
padding: 0 20rpx;
font-weight: 600;
font-size: 28rpx;
text-align: center;
}
.befite-01 {
width: 50rpx;
height: 50rpx;
}
.right-icon{
width: 14rpx;
height: 14rpx;
margin-left: 16rpx;
}
.black{
color: black;
}
.grey{
color: #c3c3c3;
}
.footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 30rpx 34rpx;
background: #ffffff;
box-shadow: 0rpx 4rpx 11rpx 2rpx rgba(62, 62, 62, 0.17);
.btn {
margin: 0 auto;
width: 690rpx;
height: 80rpx;
line-height: 80rpx;
text-align: center;
background: #588fe9;
border-radius: 45rpx;
font-size: 28rpx;
font-weight: 500;
color: #ffffff;
}
}
.contents{
margin-left:28rpx;
margin-right: 26rpx;
margin-top: 30rpx;
background: #ffffff;
border-radius: 16rpx;
.card{
padding: 0rpx 30rpx 30rpx;
margin-bottom: 30rpx;
font-size: 26rpx;
color: #787B8B;
border-bottom: 1rpx solid #f6f7fb;
.index{
padding: 4rpx 10rpx;
background: #F2F6FE;
border-radius: 20%;
font-size: 26rpx;
font-weight: 600;
color: #4B8EF0;
margin-bottom: 20rpx;
}
.select-img {
width: 33rpx;
height: 33rpx;
margin-right: 10rpx;
}
.bottom-view{
border-top: 1rpx solid #eee;
margin-top: 30rpx;
padding-top: 30rpx;
.btn-view{
padding: 10rpx 40rpx;
border-radius: 10rpx;
background-color: #4B8EF0;
color: white;
}
}
}
}
}
</style>
//数据线连接电脑传送文件:此电脑\HUAWEI P30\内部存储\Android\data\com.dianwang.mes\downloads\eqp
//包名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":"蒽醌一车间"}}
// 路径 /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
}
// 路径:/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,
};