master
xy 3 years ago
parent 35c18f266e
commit c68691983a

@ -1,19 +1,49 @@
const mode = 'devOnline'; //devLocal本地测试、devOnline线上测试、production生产环境 //const mode = 'devOnline'; //devLocal本地测试、devOnline线上测试、production生产环境
let ROOTPATH = ''; //域名 import Vue from 'vue'
let DBNAME = 'gongguan';//sqlite数据库名称 let ROOTPATH = 'http://assets.langye.net'; //域名
let DBPATH = '_doc/gongguan.db';//sqlite路径 let DBNAME = 'gongguan'; //sqlite数据库名称
switch (mode) { let DBPATH = '_doc/gongguan.db'; //sqlite路径
case 'devLocal': function setRootpath(value) {
ROOTPATH = "http://assets.langye.net" ROOTPATH = value ?? 'http://assets.langye.net'
break; uni.setStorageSync('ROOTPATH', ROOTPATH)
case 'devOnline': setTimeout(() => {
ROOTPATH = "http://assets.langye.net" Vue.prototype.$u.http.setConfig({
break; baseUrl: ROOTPATH,
case 'production': showLoading: true, // 是否显示请求中的loading
ROOTPATH = "https://xxxxx.cn" loadingMask: true, // 展示loading的时候是否给一个透明的蒙层防止触摸穿透
break; loadingText: '加载中', // 请求loading中的文字提示
default: loadingTime: 5000,
throw new Error('未配置环境'); originalData: true, // 是否在拦截器中返回服务端的原始数据
console.log(`未配置环境`); // 设置自定义头部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> </view>
<u-card> <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"> <view class="status">
<span class="status__label">服务器连接状态</span> <span class="status__label">服务器连接状态</span>
<span <span
@ -41,10 +48,12 @@
let androidModule = uni.requireNativePlugin('uhfr') let androidModule = uni.requireNativePlugin('uhfr')
// #endif // #endif
import { executeSql,selectFromTable } from '@/common/sqlite.js' import { executeSql,selectFromTable } from '@/common/sqlite.js'
import { getRootpath,setRootpath } from '@/common/config.js'
export default { export default {
data() { data() {
return { return {
path:getRootpath(),
baseInfo:{ baseInfo:{
syncTime:"", syncTime:"",
num:0 num:0
@ -58,6 +67,13 @@
} }
}, },
methods: { methods: {
setPath(){
setRootpath(this.path)
setTimeout(()=>{
this.testConnect()
},100)
},
async getInitInfo(){ async getInitInfo(){
let time; let time;
@ -86,9 +102,17 @@
this.isConnect = true this.isConnect = true
}else{ }else{
this.isConnect = false this.isConnect = false
uni.showToast({
icon:'none',
title:'连接失败'
})
} }
}).catch(err => { }).catch(err => {
this.isConnect = false this.isConnect = false
uni.showToast({
icon:'none',
title:'连接失败'
})
}) })
}, },
@ -119,6 +143,7 @@
// #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;
@ -163,6 +188,8 @@
uni.$emit('assetsSync',{msg:'success'}) uni.$emit('assetsSync',{msg:'success'})
}catch(err){ }catch(err){
console.warn('sqlite-err',err) console.warn('sqlite-err',err)
androidModule.showToast(err)
this.isSync = false
} }
} }
}, },

@ -47,7 +47,7 @@
</view> </view>
<u-button type="primary" :ripple="true" :custom-style="btnStyle" @click="isShowPop = true"> <u-button type="primary" :ripple="true" :custom-style="btnStyle" @click="isShowPop = true">
</u-button> </u-button>
</view> </view>
@ -79,8 +79,16 @@
<u-form-item label="盘点时间"> <u-form-item label="盘点时间">
<u-input disabled :value="$moment(new Date()).format('YYYY-MM-DD')" placeholder="盘点时间"> <u-input disabled :value="$moment(new Date()).format('YYYY-MM-DD')" placeholder="盘点时间">
</u-input> </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>
<u-form-item label="资产状态"> <u-form-item label="资产状态" required>
<u-input :value="activeStatusFormat(fund.assets_status)" type="select" <u-input :value="activeStatusFormat(fund.assets_status)" type="select"
@click="isShowSelect = true" placeholder="请选择资产状态"></u-input> @click="isShowSelect = true" placeholder="请选择资产状态"></u-input>
</u-form-item> </u-form-item>
@ -173,6 +181,17 @@
assets_status: '', assets_status: '',
photo: '', photo: '',
content: '' content: ''
},
rules: {
position: [
{ required:true,message:"请输入存放位置" }
],
worker_name: [
{ required:true,message:"请输入保管人" }
],
assets_status: [
{ required:true,message:"请选择资产状态" }
],
}, },
qrIdList: [], qrIdList: [],
@ -201,40 +220,35 @@
`) `)
}, },
async confirm() { async confirm() {
if(!this.fund.position || !this.fund.worker_name || !this.fund.assets_status) {
if (!this.fund.assets_status) { androidModule.showToast("请填写完整信息")
uni.showToast({
icon: "none",
title: "请选择资产状态"
})
return
} }
try { try {
if (this.$refs.uUpload.lists[0]?.url) { if (this.$refs.uUpload.lists[0]?.url) {
const filePath = await uni.saveFile({ const filePath = await uni.saveFile({
tempFilePath: this.$refs.uUpload.lists[0]?.url tempFilePath: this.$refs.uUpload.lists[0]?.url
}) })
console.log(filePath); console.log(filePath);
this.fund.photo = filePath[1]?.savedFilePath this.fund.photo = filePath[1]?.savedFilePath
} }
await executeSql(` 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}; 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({ uni.showToast({
icon: 'success', icon: 'success',
title: '本地保存成功' title: '本地保存成功'
}) })
this.isShowPop = false this.isShowPop = false
await executeSql(` await executeSql(`
INSERT INTO log (remark,type) VALUES ('本地盘点:${this.fund.name}',1); INSERT INTO log (remark,type) VALUES ('本地盘点:${this.fund.name}',1);
`) `)
await this.getLogs() await this.getLogs()
} catch (err) { } catch (err) {
console.warn('sqlite-err', err) console.warn('sqlite-err', err)
androidModule.showToast(err) androidModule.showToast(err)
} }
}, },
@ -309,7 +323,8 @@
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,"")}"`
@ -319,7 +334,7 @@
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}件资产`) 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) {

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

Loading…
Cancel
Save