master
xy 3 years ago
parent 35c18f266e
commit c68691983a

@ -1,19 +1,49 @@
const mode = 'devOnline'; //devLocal本地测试、devOnline线上测试、production生产环境
let ROOTPATH = ''; //域名
let DBNAME = 'gongguan';//sqlite数据库名称
let DBPATH = '_doc/gongguan.db';//sqlite路径
switch (mode) {
case 'devLocal':
ROOTPATH = "http://assets.langye.net"
break;
case 'devOnline':
ROOTPATH = "http://assets.langye.net"
break;
case 'production':
ROOTPATH = "https://xxxxx.cn"
break;
default:
throw new Error('未配置环境');
console.log(`未配置环境`);
//const mode = 'devOnline'; //devLocal本地测试、devOnline线上测试、production生产环境
import Vue from 'vue'
let ROOTPATH = 'http://assets.langye.net'; //域名
let DBNAME = 'gongguan'; //sqlite数据库名称
let DBPATH = '_doc/gongguan.db'; //sqlite路径
function setRootpath(value) {
ROOTPATH = value ?? 'http://assets.langye.net'
uni.setStorageSync('ROOTPATH', ROOTPATH)
setTimeout(() => {
Vue.prototype.$u.http.setConfig({
baseUrl: ROOTPATH,
showLoading: true, // 是否显示请求中的loading
loadingMask: true, // 展示loading的时候是否给一个透明的蒙层防止触摸穿透
loadingText: '加载中', // 请求loading中的文字提示
loadingTime: 5000,
originalData: true, // 是否在拦截器中返回服务端的原始数据
// 设置自定义头部content-type
header: {
'content-type': 'application/json;charset=UTF-8'
}
})
},50)
}
function getRootpath() {
return uni.getStorageSync('ROOTPATH')
}
setRootpath(getRootpath())
// switch (mode) {
// case 'devLocal':
// ROOTPATH = "http://assets.langye.net"
// break;
// case 'devOnline':
// ROOTPATH = "http://assets.langye.net"
// break;
// case 'production':
// ROOTPATH = "https://xxxxx.cn"
// break;
// default:
// throw new Error('未配置环境');
// console.log(`未配置环境`);
// }
export {
ROOTPATH,
DBNAME,
DBPATH,
setRootpath,
getRootpath
}
export { ROOTPATH,DBNAME,DBPATH }

@ -8,7 +8,14 @@
</view>
<u-card>
<view slot="head">
<view slot="head">
<view>
<view style="display: flex;align-items: center;">
<span>当前连接地址</span>
<u-input border v-model="path"></u-input>
</view>
<u-button type="primary" @click="setPath" style="margin-top: 20rpx;">确认</u-button>
</view>
<view class="status">
<span class="status__label">服务器连接状态</span>
<span
@ -41,10 +48,12 @@
let androidModule = uni.requireNativePlugin('uhfr')
// #endif
import { executeSql,selectFromTable } from '@/common/sqlite.js'
import { executeSql,selectFromTable } from '@/common/sqlite.js'
import { getRootpath,setRootpath } from '@/common/config.js'
export default {
data() {
return {
path:getRootpath(),
baseInfo:{
syncTime:"",
num:0
@ -58,6 +67,13 @@
}
},
methods: {
setPath(){
setRootpath(this.path)
setTimeout(()=>{
this.testConnect()
},100)
},
async getInitInfo(){
let time;
@ -86,9 +102,17 @@
this.isConnect = true
}else{
this.isConnect = false
uni.showToast({
icon:'none',
title:'连接失败'
})
}
}).catch(err => {
this.isConnect = false
uni.showToast({
icon:'none',
title:'连接失败'
})
})
},
@ -119,6 +143,7 @@
// #endif
this.isSync = true
let res = await this.$u.api.getAll()
console.log('assetapi',res.data);
//
await executeSql(`
DELETE from property;
@ -163,6 +188,8 @@
uni.$emit('assetsSync',{msg:'success'})
}catch(err){
console.warn('sqlite-err',err)
androidModule.showToast(err)
this.isSync = false
}
}
},

@ -47,7 +47,7 @@
</view>
<u-button type="primary" :ripple="true" :custom-style="btnStyle" @click="isShowPop = true">
</u-button>
</view>
@ -79,8 +79,16 @@
<u-form-item label="盘点时间">
<u-input disabled :value="$moment(new Date()).format('YYYY-MM-DD')" placeholder="盘点时间">
</u-input>
</u-form-item>
<u-form-item label="存放位置" required>
<u-input v-model="fund.position" placeholder="请输入存放位置">
</u-input>
</u-form-item>
<u-form-item label="保管人" required>
<u-input v-model="fund.worker_name" placeholder="请输入保管人">
</u-input>
</u-form-item>
<u-form-item label="资产状态">
<u-form-item label="资产状态" required>
<u-input :value="activeStatusFormat(fund.assets_status)" type="select"
@click="isShowSelect = true" placeholder="请选择资产状态"></u-input>
</u-form-item>
@ -173,6 +181,17 @@
assets_status: '',
photo: '',
content: ''
},
rules: {
position: [
{ required:true,message:"请输入存放位置" }
],
worker_name: [
{ required:true,message:"请输入保管人" }
],
assets_status: [
{ required:true,message:"请选择资产状态" }
],
},
qrIdList: [],
@ -201,40 +220,35 @@
`)
},
async confirm() {
if (!this.fund.assets_status) {
uni.showToast({
icon: "none",
title: "请选择资产状态"
})
return
async confirm() {
if(!this.fund.position || !this.fund.worker_name || !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 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_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)
}
},
@ -309,7 +323,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,"")}"`
@ -319,7 +334,7 @@
let propertys = await selectFromTable(`
select * from property where assets_id in (${getSqlIn()});
`)
androidModule.showToast(`扫描到:${propertys.length}件资产`)
androidModule.showToast(`扫描到:${propertys.length}件资产,扫描到编号:${Array.from(new Set([...dataList, ...this.qrIdList])).toString()}`)
this.info = propertys
this.fund = propertys[0]
} catch (e) {

@ -9,6 +9,11 @@
<u-card>
<view slot="head">
<view style="display: flex;align-items: center;">
<span>当前连接地址</span>
<u-input border v-model="path"></u-input>
</view>
<u-button type="primary" @click="setPath" style="margin-top: 20rpx;">确认</u-button>
<view class="status">
<span class="status__label">服务器连接状态</span>
<span
@ -29,7 +34,8 @@
</view>
<view slot="foot">
<u-button :disabled="isUpload" :ripple="true" :custom-style="btnStyle" @click="uploadClick">{{ isUpload ? "" : "" }}</u-button>
<u-button :disabled="isUpload" :ripple="true" :custom-style="btnStyle" @click="uploadClick">
{{ isUpload ? "上传中" : "点击开始上传" }}</u-button>
</view>
</u-card>
</view>
@ -37,124 +43,153 @@
</view>
</template>
<script>
// #ifdef APP-PLUS
let androidModule = uni.requireNativePlugin('uhfr')
// #endif
<script>
// #ifdef APP-PLUS
let androidModule = uni.requireNativePlugin('uhfr')
// #endif
import {
selectFromTable,
executeSql
} from '@/common/sqlite.js'
import {
ROOTPATH
ROOTPATH,
setRootpath,
getRootpath
} from '@/common/config.js'
export default {
data() {
return {
path: getRootpath(),
baseInfo: {
syncTime: "",
num: 0
},
isConnect: false,
isUpload:false,
isConnect: false,
isUpload: false,
btnStyle: {
"color": "#fff",
'background': "#107fc9"
},
}
},
methods: {
async uploadClick(){
if(!this.isConnect){
uni.showToast({
icon:'none',
title:'连接服务器失败'
})
return
}
try{
let res = await selectFromTable(`
select assets_id,serial,name,position,worker_name,assets_status,photo,content from property where is_check = 1;
`)
if(res.length === 0){
uni.showToast({
icon:'none',
title:"本地无数据上传"
})
return
}
androidModule.showToast("开始上传...")
this.isUpload = true
for(let i = 0;i < res.length;i++){
if(res[i].files){
let picRes = await uni.uploadFile({
url:`${ROOTPATH}/index.php?s=/Home/Worker/upload.html`,
filePath:res[i].files,
name:"file"
})
res[i].files = JSON.parse(picRes[1]?.data).data?.id
}
}
let promiseAll = res.map(item => {
return this.upload(item)
})
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(`
INSERT INTO log (remark) VALUES ("数据上传");
`)
await this.getInitInfo()
uni.$emit('uploadSuccess',{msg:'success'})
}catch(err){
console.warn('sqlite-err',err)
androidModule.showToast(err)
}
},
methods: {
setPath() {
setRootpath(this.path)
setTimeout(() => {
this.testConnect()
}, 100)
},
async uploadClick() {
if (!this.isConnect) {
uni.showToast({
icon: 'none',
title: '连接服务器失败'
})
return
}
try {
let res = await selectFromTable(`
select assets_id,serial,name,position,worker_name,assets_status,photo,content from property where is_check = 1;
`)
if (res.length === 0) {
uni.showToast({
icon: 'none',
title: "本地无数据上传"
})
return
}
androidModule.showToast("开始上传...")
this.isUpload = true
for (let i = 0; i < res.length; i++) {
if (res[i].photo) {
let picRes = await uni.uploadFile({
url: `${ROOTPATH}/index.php?s=/Home/Worker/upload.html`,
filePath: res[i].photo,
name: "file"
})
res[i].files = picRes[1]?.data ? JSON.parse(picRes[1]?.data).data?.id : ""
}
}
let promiseAll = res.map(item => {
console.log('upload-data', res);
return this.upload(item)
})
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(`
INSERT INTO log (remark) VALUES ("数据上传");
`)
await this.getInitInfo()
uni.$emit('uploadSuccess', {
msg: 'success'
})
} catch (err) {
console.warn('sqlite-err', err)
androidModule.showToast(err)
this.isUpload = false
}
},
async getInitInfo() {
let time;
let num;
try {
time = await selectFromTable(`
SELECT * FROM log WHERE remark = "数据上传" ORDER BY created_at DESC;
`)
let num;
try {
time = await selectFromTable(`
SELECT * FROM log WHERE remark = "数据上传" ORDER BY created_at DESC;
`)
this.baseInfo.syncTime = time[0]?.created_at || ""
num = await selectFromTable(`
SELECT count(*) as count FROM property WHERE is_check = 1;
`)
`)
this.baseInfo.num = num[0]?.count || 0
} catch (err) {
console.warn('sqlite-err', err);
console.warn('sqlite-err', err);
androidModule.showToast(err)
}
},
testConnect() {
uni.showLoading({
mask: true,
title: '连接中',
})
this.$u.api.test().then(res => {
uni.hideLoading()
if (res.data.msg === '链接成功') {
this.isConnect = true
} else {
this.isConnect = false
uni.showToast({
icon: 'none',
title: '连接失败'
})
}
}).catch(err => {
uni.hideLoading()
this.isConnect = false
uni.showToast({
icon: 'none',
title: '连接失败'
})
})
},

Loading…
Cancel
Save