master
xy 3 years ago
parent c68691983a
commit 56e46d1073

@ -24,6 +24,7 @@
"name" TEXT, "name" TEXT,
"position" TEXT, "position" TEXT,
"worker_name" TEXT, "worker_name" TEXT,
"worker_id" INTEGER,
"assets_status" INTEGER, "assets_status" INTEGER,
"photo" TEXT, "photo" TEXT,
"content" TEXT, "content" TEXT,
@ -38,6 +39,12 @@
"created_at" TIMESTAMP DEFAULT (datetime('now','localtime')) "created_at" TIMESTAMP DEFAULT (datetime('now','localtime'))
); );
`) `)
await executeSql(`
create table if not exists worker(
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"name" TEXT
);
`)
} catch (err) { } catch (err) {
throw new Error(err.message) throw new Error(err.message)

@ -3,7 +3,8 @@ let apiApp = {
test:"index.php?s=/Home/Worker/check_link.html", test:"index.php?s=/Home/Worker/check_link.html",
getAll:"index.php?s=/Home/Worker/get_assets.html", getAll:"index.php?s=/Home/Worker/get_assets.html",
add:"index.php?s=/Home/Worker/update_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 test = (params = {}) => vm.$u.get(apiApp.test, params);
let getAll = (params = {}) => vm.$u.get(apiApp.getAll,params); let getAll = (params = {}) => vm.$u.get(apiApp.getAll,params);
let add = (data = {}) => vm.$u.post(apiApp.add,data);//无效 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(因为vm就是this也即this.$u.api)下
vm.$u.api = {test,getAll,add}; vm.$u.api = {test,getAll,add,worker};
} }
export default { export default {

@ -10,7 +10,7 @@ const install = (Vue, vm) => {
showLoading: true, // 是否显示请求中的loading showLoading: true, // 是否显示请求中的loading
loadingMask: true, // 展示loading的时候是否给一个透明的蒙层防止触摸穿透 loadingMask: true, // 展示loading的时候是否给一个透明的蒙层防止触摸穿透
loadingText: '加载中', // 请求loading中的文字提示 loadingText: '加载中', // 请求loading中的文字提示
loadingTime: 5000, loadingTime: 1000 * 60 * 3,
originalData: true, // 是否在拦截器中返回服务端的原始数据 originalData: true, // 是否在拦截器中返回服务端的原始数据
// 设置自定义头部content-type // 设置自定义头部content-type
header: { header: {

@ -6,6 +6,10 @@
"versionCode" : 100, "versionCode" : 100,
"transformPx" : false, "transformPx" : false,
/* 5+App */ /* 5+App */
"networkTimeout" : {
"uploadFile" : 300000,
"request" : 300000
},
"app-plus" : { "app-plus" : {
"usingComponents" : true, "usingComponents" : true,
"nvueStyleCompiler" : "uni-app", "nvueStyleCompiler" : "uni-app",

@ -124,26 +124,12 @@
}) })
return 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{ try{
// #ifdef APP-PLUS // #ifdef APP-PLUS
androidModule.showToast("开始同步资产...") androidModule.showToast("开始同步资产...")
// #endif // #endif
this.isSync = true this.isSync = true
let res = await this.$u.api.getAll() let res = await this.$u.api.getAll()
console.log('assetapi',res.data);
// //
await executeSql(` await executeSql(`
DELETE from property; DELETE from property;
@ -158,13 +144,16 @@
for(let i = 0;i < res?.data.length;i++){ for(let i = 0;i < res?.data.length;i++){
let item = res?.data[i] let item = res?.data[i]
await executeSql(` 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 ( values (
${item.id}, ${item.id},
"${item.serial}", "${item.serial}",
"${item.name}", "${item.name}",
"${item.position}", "${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 ("同步资产"); INSERT INTO log (remark) VALUES ("同步资产");
`) `)
//
await this.getInitInfo(); 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 // #ifdef APP-PLUS
androidModule.showToast(`获取到${this.baseInfo.num}条资产`) androidModule.showToast(`获取到${this.baseInfo.num}条资产`)
this.isSync = false this.isSync = false
uni.hideLoading() uni.hideLoading()
console.log(await selectFromTable(`select * from property;`));
// #endif // #endif
uni.$emit('assetsSync',{msg:'success'}) uni.$emit('assetsSync',{msg:'success'})

@ -84,9 +84,9 @@
<u-input v-model="fund.position" placeholder="请输入存放位置"> <u-input v-model="fund.position" placeholder="请输入存放位置">
</u-input> </u-input>
</u-form-item> </u-form-item>
<u-form-item label="保管人" required> <u-form-item label="保管人">
<u-input v-model="fund.worker_name" placeholder="请输入保管人"> <u-input :value="activeWorkerFormat(fund.worker_id)" type="select"
</u-input> @click="isShowWorkerSelect = true" placeholder="请选择保管人"></u-input>
</u-form-item> </u-form-item>
<u-form-item label="资产状态" required> <u-form-item label="资产状态" required>
<u-input :value="activeStatusFormat(fund.assets_status)" type="select" <u-input :value="activeStatusFormat(fund.assets_status)" type="select"
@ -112,7 +112,8 @@
</u-popup> </u-popup>
<u-select :list="statusList" v-model="isShowSelect" @confirm="e => fund.assets_status = e[0].value"></u-select> <u-select :list="statusList" v-model="isShowSelect" @confirm="e => fund.assets_status = e[0].value"></u-select>
<u-select :list="workers" label-name="name" value-name="id" v-model="isShowWorkerSelect"
@confirm="e => fund.worker_id = e[0].value"></u-select>
</view> </view>
</template> </template>
@ -155,6 +156,9 @@
} }
], ],
isShowWorkerSelect: false,
workers: [],
btnStyle: { btnStyle: {
'margin': '60rpx 30rpx 0 30rpx' 'margin': '60rpx 30rpx 0 30rpx'
}, },
@ -166,7 +170,7 @@
}, },
{ {
image: '/static/3.jpg' image: '/static/3.jpg'
},{ }, {
image: '/static/4.jpg' image: '/static/4.jpg'
}, },
], ],
@ -178,20 +182,24 @@
serial: '', serial: '',
position: '', position: '',
worker_name: '', worker_name: '',
worker_id: '',
assets_status: '', assets_status: '',
photo: '', photo: '',
content: '' content: ''
}, },
rules: { rules: {
position: [ position: [{
{ required:true,message:"请输入存放位置" } required: true,
], message: "请输入存放位置"
worker_name: [ }],
{ required:true,message:"请输入保管人" } worker_name: [{
], required: true,
assets_status: [ message: "请输入保管人"
{ required:true,message:"请选择资产状态" } }],
], assets_status: [{
required: true,
message: "请选择资产状态"
}],
}, },
qrIdList: [], qrIdList: [],
@ -208,12 +216,23 @@
serial: '', serial: '',
position: '', position: '',
worker_name: '', worker_name: '',
worker_id: '',
assets_status: '', assets_status: '',
photo: '', photo: '',
content: '' content: ''
} }
}, },
async getWorkers() {
try {
this.workers = await selectFromTable(`
select * from worker;
`)
} catch (err) {
console.error('sql-err', err)
}
},
async getLogs() { async getLogs() {
this.logs = await selectFromTable(` this.logs = await selectFromTable(`
select * from log where type = 1; select * from log where type = 1;
@ -221,7 +240,7 @@
}, },
async confirm() { async confirm() {
if(!this.fund.position || !this.fund.worker_name || !this.fund.assets_status) { if (!this.fund.position || !this.fund.assets_status) {
androidModule.showToast("请填写完整信息") androidModule.showToast("请填写完整信息")
} }
try { try {
@ -233,7 +252,7 @@
this.fund.photo = filePath[1]?.savedFilePath this.fund.photo = filePath[1]?.savedFilePath
} }
await executeSql(` 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}; 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({ uni.showToast({
icon: 'success', icon: 'success',
@ -305,15 +324,6 @@
//rfid //rfid
androidModule.asyncStartReading() androidModule.asyncStartReading()
try {
await executeSql(`
INSERT INTO log (remark) VALUES ('开始扫描');
`)
} catch (err) {
console.warn('sqlite-err', err)
androidModule.showToast(err)
}
} else { } else {
this.flag = 0 this.flag = 0
@ -334,7 +344,9 @@
let propertys = await selectFromTable(` let propertys = await selectFromTable(`
select * from property where assets_id in (${getSqlIn()}); select * from property where assets_id in (${getSqlIn()});
`) `)
androidModule.showToast(`扫描到:${propertys.length}件资产,扫描到编号:${Array.from(new Set([...dataList, ...this.qrIdList])).toString()}`) androidModule.showToast(
`扫描到:${propertys.length}件资产,扫描到编号:${Array.from(new Set([...dataList, ...this.qrIdList])).toString()}`
)
this.info = propertys this.info = propertys
this.fund = propertys[0] this.fund = propertys[0]
} catch (e) { } catch (e) {
@ -354,6 +366,11 @@
return function(status) { return function(status) {
return map.get(status) return map.get(status)
} }
},
activeWorkerFormat() {
return function(worker_id) {
return this.workers.find(i => i.id == worker_id)?.name || ""
}
} }
}, },
onLoad() { onLoad() {
@ -373,6 +390,9 @@
main.unregisterReceiver(receiver) main.unregisterReceiver(receiver)
// #endif // #endif
}, },
onShow() {
this.getWorkers();
},
mounted() { mounted() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
try { try {
@ -383,21 +403,21 @@
} }
// #endif // #endif
uni.$on('uploadSuccess',() => { uni.$on('uploadSuccess', () => {
this.clear() this.clear()
}) })
uni.$on('assetsSync',async () => { // uni.$on('assetsSync', async () => {
try{ // try {
await executeSql(` // await executeSql(`
DELETE from log; // DELETE from log;
`) // `)
await executeSql(` // await executeSql(`
UPDATE sqlite_sequence SET seq = 0 where name = 'log'; // UPDATE sqlite_sequence SET seq = 0 where name = 'log';
`) // `)
}catch(err){ // } catch (err) {
} // }
}) // })
}, },
destroyed() { destroyed() {
uni.$off() uni.$off()

@ -92,7 +92,7 @@
} }
try { try {
let res = await selectFromTable(` 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) { if (res.length === 0) {
@ -113,7 +113,7 @@
filePath: res[i].photo, filePath: res[i].photo,
name: "file" 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) let result = await Promise.all(promiseAll)
console.log(result);
androidModule.showToast(`上传成功`) androidModule.showToast(`上传成功`)
this.isUpload = false this.isUpload = false
// //
// await executeSql(` await executeSql(`
// delete from property where is_check = 1; update property set is_check = 0 where is_check = 1;
// `) `)
// //
await executeSql(` await executeSql(`

Loading…
Cancel
Save