|
|
|
|
@ -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: '连接失败'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|