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 }

@ -9,6 +9,13 @@
<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
@ -42,9 +49,11 @@
// #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>
@ -80,7 +80,15 @@
<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>
<u-form-item label="资产状态"> <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="资产状态" 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>
@ -174,6 +182,17 @@
photo: '', photo: '',
content: '' content: ''
}, },
rules: {
position: [
{ required:true,message:"请输入存放位置" }
],
worker_name: [
{ required:true,message:"请输入保管人" }
],
assets_status: [
{ required:true,message:"请选择资产状态" }
],
},
qrIdList: [], qrIdList: [],
info: [], info: [],
@ -202,13 +221,8 @@
}, },
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) {
@ -219,7 +233,7 @@
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',
@ -310,6 +324,7 @@
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>
@ -47,17 +53,20 @@
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"
@ -65,23 +74,31 @@
} }
}, },
methods: { methods: {
async uploadClick(){ setPath() {
if(!this.isConnect){ setRootpath(this.path)
setTimeout(() => {
this.testConnect()
}, 100)
},
async uploadClick() {
if (!this.isConnect) {
uni.showToast({ uni.showToast({
icon:'none', icon: 'none',
title:'连接服务器失败' title: '连接服务器失败'
}) })
return return
} }
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,serial,name,position,worker_name,assets_status,photo,content from property where is_check = 1;
`) `)
if(res.length === 0){ if (res.length === 0) {
uni.showToast({ uni.showToast({
icon:'none', icon: 'none',
title:"本地无数据上传" title: "本地无数据上传"
}) })
return return
} }
@ -89,18 +106,19 @@
androidModule.showToast("开始上传...") androidModule.showToast("开始上传...")
this.isUpload = true this.isUpload = true
for(let i = 0;i < res.length;i++){ for (let i = 0; i < res.length; i++) {
if(res[i].files){ if (res[i].photo) {
let picRes = await uni.uploadFile({ let picRes = await uni.uploadFile({
url:`${ROOTPATH}/index.php?s=/Home/Worker/upload.html`, url: `${ROOTPATH}/index.php?s=/Home/Worker/upload.html`,
filePath:res[i].files, filePath: res[i].photo,
name:"file" name: "file"
}) })
res[i].files = JSON.parse(picRes[1]?.data).data?.id res[i].files = picRes[1]?.data ? JSON.parse(picRes[1]?.data).data?.id : ""
} }
} }
let promiseAll = res.map(item => { let promiseAll = res.map(item => {
console.log('upload-data', res);
return this.upload(item) return this.upload(item)
}) })
@ -110,9 +128,9 @@
androidModule.showToast(`上传成功`) androidModule.showToast(`上传成功`)
this.isUpload = false this.isUpload = false
// //
await executeSql(` // await executeSql(`
delete from property where is_check = 1; // delete from property where is_check = 1;
`) // `)
// //
await executeSql(` await executeSql(`
@ -121,11 +139,14 @@
await this.getInitInfo() await this.getInitInfo()
uni.$emit('uploadSuccess',{msg:'success'}) uni.$emit('uploadSuccess', {
}catch(err){ msg: 'success'
console.warn('sqlite-err',err) })
} catch (err) {
console.warn('sqlite-err', err)
androidModule.showToast(err) androidModule.showToast(err)
} this.isUpload = false
}
}, },
async getInitInfo() { async getInitInfo() {
@ -147,14 +168,28 @@
}, },
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