master
xy 3 years ago
parent e3f77112f0
commit 3a3c8d9a92

@ -6,11 +6,15 @@
"type" : "uni-app:app-android" "type" : "uni-app:app-android"
}, },
{ {
"app-plus" : "app-plus" :
{ {
"launchtype" : "local" "launchtype" : "local"
}, },
"type" : "uniCloud" "mp-weixin" :
} {
"launchtype" : "local"
},
"type" : "uniCloud"
}
] ]
} }

@ -29,7 +29,7 @@
</view> </view>
<view slot="foot"> <view slot="foot">
<u-button :ripple="true" :custom-style="btnStyle" @click="getAllAssets"></u-button> <u-button :disabled="isSync" :ripple="true" :custom-style="btnStyle" @click="getAllAssets">{{ isSync ? "..." : "" }}</u-button>
</view> </view>
</u-card> </u-card>
</view> </view>
@ -53,7 +53,8 @@
btnStyle: { btnStyle: {
"color": "#fff", "color": "#fff",
'background': "#107fc9" 'background': "#107fc9"
}, },
isSync:false,
} }
}, },
methods: { methods: {
@ -102,13 +103,14 @@
const getSql = () => { const getSql = () => {
let sql = "" let sql = ""
res.data?.forEach(item => { res.data?.forEach(item => {
sql += `INSERT INTO property (id,serial,name,position,worker_name) sql += `INSERT INTO property (id,serial,name,position,worker_name,remark)
VALUES ( VALUES (
${item.id}, ${item.id},
${item.serial}, ${item.serial},
${item.name}, ${item.name},
${item.position}, ${item.position},
${item.worker_name}); ` ${item.worker_name}),
${item.remark}; `
}) })
return sql; return sql;
} }
@ -116,7 +118,7 @@
// #ifdef APP-PLUS // #ifdef APP-PLUS
androidModule.showToast("开始同步资产...") androidModule.showToast("开始同步资产...")
// #endif // #endif
this.isSync = true
let res = await this.$u.api.getAll() let res = await this.$u.api.getAll()
// //
await executeSql(` await executeSql(`
@ -155,9 +157,12 @@
// #ifdef APP-PLUS // #ifdef APP-PLUS
androidModule.showToast(`获取到${this.baseInfo.num}条资产`) androidModule.showToast(`获取到${this.baseInfo.num}条资产`)
this.isSync = false
uni.hideLoading()
console.log(await selectFromTable(`select * from property;`)); console.log(await selectFromTable(`select * from property;`));
// #endif // #endif
uni.$emit('assetsSync',{msg:'success'})
}catch(err){ }catch(err){
console.warn('sqlite-err',err) console.warn('sqlite-err',err)
} }

@ -9,6 +9,10 @@
@click="scanClick">{{ flag ? "停止扫描" : "开始扫描" }}</u-button> @click="scanClick">{{ flag ? "停止扫描" : "开始扫描" }}</u-button>
<u-card title="资产列表" v-show="info.length > 0"> <u-card title="资产列表" v-show="info.length > 0">
<view slot="head" style="display: flex;justify-content: space-between;align-items: center;">
<view style="flex: 1;">资产列表</view>
<u-button size="medium" type="primary" @click="clear"></u-button>
</view>
<view class="card-body" slot="body"> <view class="card-body" slot="body">
<view v-for="(item,index) in info" :key="item.id" <view v-for="(item,index) in info" :key="item.id"
style="display: flex;justify-content: space-between;padding: 10rpx 0;align-items: center;"> style="display: flex;justify-content: space-between;padding: 10rpx 0;align-items: center;">
@ -108,7 +112,7 @@
// #ifdef APP-PLUS // #ifdef APP-PLUS
let androidModule = uni.requireNativePlugin('uhfr') let androidModule = uni.requireNativePlugin('uhfr')
let receiver; let receiver;
let receiverQR; let receiverQR;
let timerQR; let timerQR;
let main = plus.android.runtimeMainActivity(); let main = plus.android.runtimeMainActivity();
let intent = plus.android.importClass('android.content.Intent'); let intent = plus.android.importClass('android.content.Intent');
@ -172,14 +176,28 @@
active_status: '', active_status: '',
files: '', files: '',
remark: '' remark: ''
}, },
qrIdList:[], qrIdList: [],
info: [], info: [],
logs: [] logs: []
} }
}, },
methods: { methods: {
clear() {
this.info = []
this.fund = {
id: 0,
name: '',
serial: '',
position: '',
worker_name: '',
active_status: '',
files: '',
remark: ''
}
},
async getLogs() { async getLogs() {
this.logs = await selectFromTable(` this.logs = await selectFromTable(`
select * from log where type = 1; select * from log where type = 1;
@ -204,7 +222,7 @@
this.fund.files = filePath[1]?.savedFilePath this.fund.files = filePath[1]?.savedFilePath
} }
await executeSql(` await executeSql(`
update property set active_status = "${this.fund.active_status}",remark = "${this.fund.remark}",is_check = 1,${this.fund.files ? 'files = "' + this.fund.files + '"' : '' } where id = ${this.fund.id}; update property set active_status = "${this.fund.active_status}",remark = "${this.fund.remark}",is_check = 1${this.fund.files ? ',files = "' + this.fund.files + '"' : '' } where id = ${this.fund.id};
`) `)
uni.showToast({ uni.showToast({
icon: 'success', icon: 'success',
@ -227,38 +245,38 @@
receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', { receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: (context, intent) => { onReceive: (context, intent) => {
plus.android.importClass(intent) plus.android.importClass(intent)
let action = intent.getAction() let action = intent.getAction()
switch (action){ switch (action) {
case "com.rfid.SCAN": case "com.rfid.SCAN":
let id = byteToString(intent.getExtra("data")) let id = byteToString(intent.getExtra("data"))
this.qrIdList.push(id) this.qrIdList.push(id)
break; break;
case "android.rfid.FUN_KEY": case "android.rfid.FUN_KEY":
let keydown = intent.getBooleanExtra("keydown", false); let keydown = intent.getBooleanExtra("keydown", false);
if (!keydown) { if (!keydown) {
this.scanClick() this.scanClick()
} }
break; break;
} }
} }
}) })
let intentFilter = plus.android.importClass('android.content.IntentFilter') let intentFilter = plus.android.importClass('android.content.IntentFilter')
let filter = new intentFilter() let filter = new intentFilter()
filter.addAction("android.rfid.FUN_KEY") filter.addAction("android.rfid.FUN_KEY")
filter.addAction("com.rfid.SCAN") filter.addAction("com.rfid.SCAN")
main.registerReceiver(receiver, filter) main.registerReceiver(receiver, filter)
}, },
init() { init() {
androidModule.initUhfrManage() androidModule.initUhfrManage()
// //
let intentStart = new intent("com.rfid.SCAN_INIT") let intentStart = new intent("com.rfid.SCAN_INIT")
main.sendBroadcast(intentStart) main.sendBroadcast(intentStart)
let intentTime = new intent("com.rfid.SCAN_TIME") let intentTime = new intent("com.rfid.SCAN_TIME")
intentTime.putExtra("time",1000) intentTime.putExtra("time", 1000)
let intentBroad = new intent("com.rfid.SET_SCAN_MODE") let intentBroad = new intent("com.rfid.SET_SCAN_MODE")
intentBroad.putExtra("mode",0) intentBroad.putExtra("mode", 0)
main.sendBroadcast(intentBroad) main.sendBroadcast(intentBroad)
}, },
@ -266,13 +284,13 @@
if (!this.flag) { if (!this.flag) {
this.flag = 1 this.flag = 1
// //
this.qrIdList = [] this.qrIdList = []
let intentScan = new intent("com.rfid.SCAN_CMD") let intentScan = new intent("com.rfid.SCAN_CMD")
timerQR = setInterval(() => { timerQR = setInterval(() => {
main.sendBroadcast(intentScan) main.sendBroadcast(intentScan)
},500) }, 500)
//rfid //rfid
androidModule.asyncStartReading() androidModule.asyncStartReading()
@ -286,17 +304,17 @@
} }
} else { } else {
this.flag = 0 this.flag = 0
clearInterval(timerQR) clearInterval(timerQR)
//rfid //rfid
androidModule.asyncStopReading() androidModule.asyncStopReading()
androidModule.tagInventoryRealTime(async res => { androidModule.tagInventoryRealTime(async res => {
let dataList = JSON.parse(res) let dataList = JSON.parse(res)
const getSqlIn = () => { const getSqlIn = () => {
return Array.from(new Set([...dataList,...this.qrIdList])).map(item => { return Array.from(new Set([...dataList, ...this.qrIdList])).map(item => {
return `"${item.replace(/^1(0+)/g,"")}"` return `"${item.replace(/^1(0+)/g,"")}"`
}).toString() }).toString()
} }
@ -306,7 +324,7 @@
`) `)
androidModule.showToast(`扫描到:${propertys.length}件资产`) androidModule.showToast(`扫描到:${propertys.length}件资产`)
this.info = propertys this.info = propertys
if(this.info.length > 0)this.fund = this.info[0] this.fund = propertys[0]
} catch (e) { } catch (e) {
console.warn('sqlite-err', e); console.warn('sqlite-err', e);
androidModule.showToast(err) androidModule.showToast(err)
@ -335,11 +353,11 @@
// #endif // #endif
}, },
onUnload() { onUnload() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
// //
let intentClose = new intent("com.rfid.CLOSE_SCAN") let intentClose = new intent("com.rfid.CLOSE_SCAN")
main.sendBroadcast(intentClose) main.sendBroadcast(intentClose)
androidModule.stopTagInventory() androidModule.stopTagInventory()
androidModule.close() androidModule.close()
main.unregisterReceiver(receiver) main.unregisterReceiver(receiver)
@ -353,7 +371,26 @@
console.warn('sqlite-err', e); console.warn('sqlite-err', e);
androidModule.showToast(err) androidModule.showToast(err)
} }
// #endif // #endif
uni.$on('uploadSuccess',() => {
this.clear()
})
uni.$on('assetsSync',async () => {
try{
await executeSql(`
DELETE from log;
`)
await executeSql(`
UPDATE sqlite_sequence SET seq = 0 where name = 'log';
`)
}catch(err){
}
})
},
destroyed() {
uni.$off()
} }
} }
</script> </script>

@ -29,7 +29,7 @@
</view> </view>
<view slot="foot"> <view slot="foot">
<u-button :ripple="true" :custom-style="btnStyle" @click="uploadClick"></u-button> <u-button :disabled="isUpload" :ripple="true" :custom-style="btnStyle" @click="uploadClick">{{ isUpload ? "" : "" }}</u-button>
</view> </view>
</u-card> </u-card>
</view> </view>
@ -56,7 +56,8 @@
syncTime: "", syncTime: "",
num: 0 num: 0
}, },
isConnect: false, isConnect: false,
isUpload:false,
btnStyle: { btnStyle: {
"color": "#fff", "color": "#fff",
'background': "#107fc9" 'background': "#107fc9"
@ -86,14 +87,17 @@
} }
androidModule.showToast("开始上传...") androidModule.showToast("开始上传...")
this.isUpload = true
for(let i = 0;i < res.length;i++){ for(let i = 0;i < res.length;i++){
let picRes = await uni.uploadFile({ if(res[i].files){
url:`${ROOTPATH}/index.php?s=/Home/Worker/upload.html`, let picRes = await uni.uploadFile({
filePath:res[i].files, url:`${ROOTPATH}/index.php?s=/Home/Worker/upload.html`,
name:"file" filePath:res[i].files,
}) name:"file"
res[i].files = JSON.parse(picRes[1]?.data).data?.id })
res[i].files = JSON.parse(picRes[1]?.data).data?.id
}
} }
let promiseAll = res.map(item => { let promiseAll = res.map(item => {
@ -104,18 +108,20 @@
console.log(result); console.log(result);
androidModule.showToast(`上传成功`) androidModule.showToast(`上传成功`)
this.isUpload = false
// //
await executeSql(` await executeSql(`
DELETE from property; delete from property where is_check = 1;
`)
await executeSql(`
UPDATE sqlite_sequence SET seq = 0 where name = 'property';
`) `)
//
await executeSql(` await executeSql(`
INSERT INTO log (remark) VALUES ("数据上传"); INSERT INTO log (remark) VALUES ("数据上传");
`) `)
await this.getInitInfo() await this.getInitInfo()
uni.$emit('uploadSuccess',{msg:'success'})
}catch(err){ }catch(err){
console.warn('sqlite-err',err) console.warn('sqlite-err',err)
androidModule.showToast(err) androidModule.showToast(err)

Loading…
Cancel
Save