From 56e46d107390b3cbcbde4eb7e9eae6010939be7c Mon Sep 17 00:00:00 2001
From: xy <271556543@qq.com>
Date: Sun, 23 Apr 2023 16:17:36 +0800
Subject: [PATCH] 2023-4-23
---
App.vue | 7 ++
common/http.api.js | 7 +-
common/http.interceptor.js | 2 +-
manifest.json | 4 +
pages/assets/index.vue | 54 +++++++---
pages/scan/index.vue | 216 ++++++++++++++++++++-----------------
pages/upload/index.vue | 13 ++-
7 files changed, 177 insertions(+), 126 deletions(-)
diff --git a/App.vue b/App.vue
index 7372c46..2afe5f9 100644
--- a/App.vue
+++ b/App.vue
@@ -24,6 +24,7 @@
"name" TEXT,
"position" TEXT,
"worker_name" TEXT,
+ "worker_id" INTEGER,
"assets_status" INTEGER,
"photo" TEXT,
"content" TEXT,
@@ -38,6 +39,12 @@
"created_at" TIMESTAMP DEFAULT (datetime('now','localtime'))
);
`)
+ await executeSql(`
+ create table if not exists worker(
+ "id" INTEGER PRIMARY KEY AUTOINCREMENT,
+ "name" TEXT
+ );
+ `)
} catch (err) {
throw new Error(err.message)
diff --git a/common/http.api.js b/common/http.api.js
index a974524..020e228 100644
--- a/common/http.api.js
+++ b/common/http.api.js
@@ -3,7 +3,8 @@ let apiApp = {
test:"index.php?s=/Home/Worker/check_link.html",
getAll:"index.php?s=/Home/Worker/get_assets.html",
add:"index.php?s=/Home/Worker/update_assets.html",
- upload:"index.php?s=/Home/Worker/upload.html"
+ upload:"index.php?s=/Home/Worker/upload.html",
+ worker:"index.php?s=/Home/Worker/work_list.html"
}
@@ -14,9 +15,9 @@ const install = (Vue, vm) => {
let test = (params = {}) => vm.$u.get(apiApp.test, params);
let getAll = (params = {}) => vm.$u.get(apiApp.getAll,params);
let add = (data = {}) => vm.$u.post(apiApp.add,data);//无效
-
+ let worker = (data = {}) => vm.$u.get(apiApp.worker)
// 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下
- vm.$u.api = {test,getAll,add};
+ vm.$u.api = {test,getAll,add,worker};
}
export default {
diff --git a/common/http.interceptor.js b/common/http.interceptor.js
index 88e7eb1..298ce04 100644
--- a/common/http.interceptor.js
+++ b/common/http.interceptor.js
@@ -10,7 +10,7 @@ const install = (Vue, vm) => {
showLoading: true, // 是否显示请求中的loading
loadingMask: true, // 展示loading的时候,是否给一个透明的蒙层,防止触摸穿透
loadingText: '加载中', // 请求loading中的文字提示
- loadingTime: 5000,
+ loadingTime: 1000 * 60 * 3,
originalData: true, // 是否在拦截器中返回服务端的原始数据
// 设置自定义头部content-type
header: {
diff --git a/manifest.json b/manifest.json
index b2d1a4e..e213b5a 100644
--- a/manifest.json
+++ b/manifest.json
@@ -6,6 +6,10 @@
"versionCode" : 100,
"transformPx" : false,
/* 5+App特有相关 */
+ "networkTimeout" : {
+ "uploadFile" : 300000,
+ "request" : 300000
+ },
"app-plus" : {
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
diff --git a/pages/assets/index.vue b/pages/assets/index.vue
index 33fc0cd..964c160 100644
--- a/pages/assets/index.vue
+++ b/pages/assets/index.vue
@@ -124,26 +124,12 @@
})
return
}
- const getSql = () => {
- let sql = ""
- res.data?.forEach(item => {
- sql += `INSERT INTO property (assets_id,serial,name,position,worker_name)
- VALUES (
- ${item.id},
- ${item.serial},
- ${item.name},
- ${item.position},
- ${item.worker_name}) `
- })
- return sql;
- }
try{
// #ifdef APP-PLUS
androidModule.showToast("开始同步资产...")
// #endif
this.isSync = true
let res = await this.$u.api.getAll()
- console.log('assetapi',res.data);
//先清空表
await executeSql(`
DELETE from property;
@@ -158,13 +144,16 @@
for(let i = 0;i < res?.data.length;i++){
let item = res?.data[i]
await executeSql(`
- insert into property (assets_id,serial,name,position,worker_name)
+ insert into property (assets_id,serial,name,position,worker_name,worker_id,content,assets_status)
values (
${item.id},
"${item.serial}",
"${item.name}",
"${item.position}",
- "${item.worker_name}"
+ "${item.worker_name}",
+ "${item.worker_id}",
+ "${item.checks?.content || ''}",
+ "${item.checks?.assets_status || ''}"
);
`)
}
@@ -176,13 +165,44 @@
INSERT INTO log (remark) VALUES ("同步资产");
`)
+ //
await this.getInitInfo();
+ //获取工作人员
+ let workers = await this.$u.api.worker()
+ //先清空表
+ await executeSql(`
+ DELETE from worker;
+ `)
+ await executeSql(`
+ UPDATE sqlite_sequence SET seq = 0 where name = 'worker';
+ `)
+ //插入表
+ await executeSql(`
+ BEGIN;
+ `)
+ for(let i = 0;i < workers?.data?.data?.length;i++){
+ let item = workers?.data?.data[i]
+ await executeSql(`
+ insert into worker (id,name)
+ values (
+ ${item.id},
+ "${item.name}"
+ );
+ `)
+ }
+ await executeSql(`
+ COMMIT;
+ `)
+ //日志
+ await executeSql(`
+ INSERT INTO log (remark) VALUES ("同步人员");
+ `)
+
// #ifdef APP-PLUS
androidModule.showToast(`获取到${this.baseInfo.num}条资产`)
this.isSync = false
uni.hideLoading()
- console.log(await selectFromTable(`select * from property;`));
// #endif
uni.$emit('assetsSync',{msg:'success'})
diff --git a/pages/scan/index.vue b/pages/scan/index.vue
index f32b40c..580eb4d 100644
--- a/pages/scan/index.vue
+++ b/pages/scan/index.vue
@@ -79,14 +79,14 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
fund.assets_status = e[0].value">
-
+ fund.worker_id = e[0].value">
@@ -155,43 +156,50 @@
}
],
+ isShowWorkerSelect: false,
+ workers: [],
+
btnStyle: {
'margin': '60rpx 30rpx 0 30rpx'
},
- list: [{
- image: '/static/1.jpg'
- },
- {
- image: '/static/2.jpg'
- },
- {
- image: '/static/3.jpg'
- },{
- image: '/static/4.jpg'
- },
+ list: [{
+ image: '/static/1.jpg'
+ },
+ {
+ image: '/static/2.jpg'
+ },
+ {
+ image: '/static/3.jpg'
+ }, {
+ image: '/static/4.jpg'
+ },
],
flag: 0, //当前扫码状态0未开始,1进行中
fund: {
- assets_id: 0,
- name: '',
- serial: '',
- position: '',
- worker_name: '',
- assets_status: '',
- photo: '',
+ assets_id: 0,
+ name: '',
+ serial: '',
+ position: '',
+ worker_name: '',
+ worker_id: '',
+ assets_status: '',
+ photo: '',
content: ''
- },
- rules: {
- position: [
- { required:true,message:"请输入存放位置" }
- ],
- worker_name: [
- { required:true,message:"请输入保管人" }
- ],
- assets_status: [
- { required:true,message:"请选择资产状态" }
- ],
+ },
+ rules: {
+ position: [{
+ required: true,
+ message: "请输入存放位置"
+ }],
+ worker_name: [{
+ required: true,
+ message: "请输入保管人"
+ }],
+ assets_status: [{
+ required: true,
+ message: "请选择资产状态"
+ }],
},
qrIdList: [],
@@ -208,47 +216,58 @@
serial: '',
position: '',
worker_name: '',
+ worker_id: '',
assets_status: '',
photo: '',
content: ''
}
},
+ async getWorkers() {
+ try {
+ this.workers = await selectFromTable(`
+ select * from worker;
+ `)
+ } catch (err) {
+ console.error('sql-err', err)
+ }
+ },
+
async getLogs() {
this.logs = await selectFromTable(`
select * from log where type = 1;
`)
},
- async confirm() {
- if(!this.fund.position || !this.fund.worker_name || !this.fund.assets_status) {
- androidModule.showToast("请填写完整信息")
+ async confirm() {
+ if (!this.fund.position || !this.fund.assets_status) {
+ androidModule.showToast("请填写完整信息")
}
- try {
- if (this.$refs.uUpload.lists[0]?.url) {
- const filePath = await uni.saveFile({
- tempFilePath: this.$refs.uUpload.lists[0]?.url
- })
- console.log(filePath);
- this.fund.photo = filePath[1]?.savedFilePath
- }
- await executeSql(`
- update property set position = "${this.fund.position}",worker_name = "${this.fund.worker_name}",assets_status = "${this.fund.assets_status}",content = "${this.fund.content}",is_check = 1${this.fund.photo ? ',photo = "' + this.fund.photo + '"' : '' } where assets_id = ${this.fund.assets_id};
- `)
- uni.showToast({
- icon: 'success',
- title: '本地保存成功'
- })
- this.isShowPop = false
-
- await executeSql(`
- INSERT INTO log (remark,type) VALUES ('本地盘点:${this.fund.name}',1);
- `)
-
- await this.getLogs()
- } catch (err) {
- console.warn('sqlite-err', err)
- androidModule.showToast(err)
+ try {
+ if (this.$refs.uUpload.lists[0]?.url) {
+ const filePath = await uni.saveFile({
+ tempFilePath: this.$refs.uUpload.lists[0]?.url
+ })
+ console.log(filePath);
+ this.fund.photo = filePath[1]?.savedFilePath
+ }
+ await executeSql(`
+ update property set position = "${this.fund.position}",worker_id = ${this.fund.worker_id},assets_status = "${this.fund.assets_status}",content = "${this.fund.content}",is_check = 1${this.fund.photo ? ',photo = "' + this.fund.photo + '"' : '' } where assets_id = ${this.fund.assets_id};
+ `)
+ uni.showToast({
+ icon: 'success',
+ title: '本地保存成功'
+ })
+ this.isShowPop = false
+
+ await executeSql(`
+ INSERT INTO log (remark,type) VALUES ('本地盘点:${this.fund.name}',1);
+ `)
+
+ await this.getLogs()
+ } catch (err) {
+ console.warn('sqlite-err', err)
+ androidModule.showToast(err)
}
},
@@ -305,15 +324,6 @@
//rfid扫描
androidModule.asyncStartReading()
- try {
- await executeSql(`
- INSERT INTO log (remark) VALUES ('开始扫描');
- `)
- } catch (err) {
- console.warn('sqlite-err', err)
- androidModule.showToast(err)
- }
-
} else {
this.flag = 0
@@ -323,8 +333,8 @@
androidModule.asyncStopReading()
androidModule.tagInventoryRealTime(async res => {
- let dataList = JSON.parse(res)
-
+ let dataList = JSON.parse(res)
+
const getSqlIn = () => {
return Array.from(new Set([...dataList, ...this.qrIdList])).map(item => {
return `"${item.replace(/^1(0+)/g,"")}"`
@@ -334,8 +344,10 @@
let propertys = await selectFromTable(`
select * from property where assets_id in (${getSqlIn()});
`)
- androidModule.showToast(`扫描到:${propertys.length}件资产,扫描到编号:${Array.from(new Set([...dataList, ...this.qrIdList])).toString()}`)
- this.info = propertys
+ androidModule.showToast(
+ `扫描到:${propertys.length}件资产,扫描到编号:${Array.from(new Set([...dataList, ...this.qrIdList])).toString()}`
+ )
+ this.info = propertys
this.fund = propertys[0]
} catch (e) {
console.warn('sqlite-err', e);
@@ -354,6 +366,11 @@
return function(status) {
return map.get(status)
}
+ },
+ activeWorkerFormat() {
+ return function(worker_id) {
+ return this.workers.find(i => i.id == worker_id)?.name || ""
+ }
}
},
onLoad() {
@@ -372,6 +389,9 @@
androidModule.close()
main.unregisterReceiver(receiver)
// #endif
+ },
+ onShow() {
+ this.getWorkers();
},
mounted() {
// #ifdef APP-PLUS
@@ -381,26 +401,26 @@
console.warn('sqlite-err', e);
androidModule.showToast(err)
}
- // #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){
-
- }
+ // #endif
+
+ uni.$on('uploadSuccess', () => {
+ this.clear()
})
- },
- destroyed() {
- uni.$off()
+ // 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()
}
}
diff --git a/pages/upload/index.vue b/pages/upload/index.vue
index 5c7f43d..f304596 100644
--- a/pages/upload/index.vue
+++ b/pages/upload/index.vue
@@ -92,7 +92,7 @@
}
try {
let res = await selectFromTable(`
- select assets_id,serial,name,position,worker_name,assets_status,photo,content from property where is_check = 1;
+ select assets_id,position,assets_status,photo,content,worker_id from property where is_check = 1;
`)
if (res.length === 0) {
@@ -113,7 +113,7 @@
filePath: res[i].photo,
name: "file"
})
- res[i].files = picRes[1]?.data ? JSON.parse(picRes[1]?.data).data?.id : ""
+ res[i].photo = picRes[1]?.data ? JSON.parse(picRes[1]?.data).data?.id : ""
}
}
@@ -123,14 +123,13 @@
})
let result = await Promise.all(promiseAll)
- console.log(result);
androidModule.showToast(`上传成功`)
this.isUpload = false
- //先清空表
- // await executeSql(`
- // delete from property where is_check = 1;
- // `)
+ //将是否被盘点状态重置
+ await executeSql(`
+ update property set is_check = 0 where is_check = 1;
+ `)
//插入日志
await executeSql(`