Swanky 2 years ago
parent 8019beddea
commit 5a7a95768b
  1. 2
      App.vue
  2. 108
      pages/lssjgl/lssjgl.vue
  3. 87
      pages/sjsb/sjsb.vue
  4. 2
      pages/workbench/workbench.vue

@ -35,7 +35,7 @@
} }
}) })
} }
}, },
fail(err) { fail(err) {
console.log('error', err); console.log('error', err);
if (token) { if (token) {

@ -1,5 +1,8 @@
<template> <template>
<view class="sjgl"> <view class="sjgl">
<uni-notice-bar color="#2979FF" background-color="#EAF2FF"
text="在无网络环境时上报的数据将存储在此处,进入到有网络的环境时进行统一上报." />
<view v-for="(item,i) in datas"> <view v-for="(item,i) in datas">
<uni-card style="padding: 0;"> <uni-card style="padding: 0;">
<view style="padding: 10px;"> <view style="padding: 10px;">
@ -18,8 +21,11 @@
</view> </view>
</uni-card> </uni-card>
</view> </view>
<view v-if="datas.length===0" style="text-align: center;color: #666;margin: 24px;">
<button class="submit-btn" type="primary" @click="submit" :loading="submiting">上报所有数据</button> <text>无临时数据</text>
</view>
<button v-if="datas.length!==0" class="submit-btn" type="primary" @click="submit"
:loading="submiting">上报所有数据</button>
</view> </view>
</template> </template>
@ -29,10 +35,21 @@
data() { data() {
return { return {
datas: [], datas: [],
submiting: false submiting: false,
token: '',
successDatas: []
} }
}, },
onLoad() {}, onLoad() {
uni.getStorage({
key: 'token',
success: (resp) => {
this.token = resp.data;
},
fail(err) {},
complete: () => {}
})
},
onShow(e) { onShow(e) {
console.log('onshow', e) console.log('onshow', e)
uni.getStorage({ uni.getStorage({
@ -45,8 +62,90 @@
}) })
}, },
methods: { methods: {
_uploadFiles(index, paths, callback, resultUrls) {
if (!resultUrls) {
resultUrls = []
}
if (paths[index]) {
uni.uploadFile({
url: `${helper.serverUrl}/system/oss/upload`,
method: 'POST',
header: {
Authorization: `Bearer ${this.token}`
},
files: [{
uri: paths[index]
}],
// name: 'file',
success: (resp) => {
let data = resp.data;
if (typeof(resp.data) === 'string') {
data = JSON.parse(resp.data);
}
resultUrls.push(data.data.url)
this._uploadFiles(++index, paths, callback, resultUrls);
},
fail(resp) {
this._uploadFiles(++index, paths, callback, resultUrls);
},
complete: () => {}
})
} else {
callback(resultUrls);
}
},
_submit(index, callback, successDatas) {
if (!successDatas) {
successDatas = [];
}
if (this.datas[index]) {
console.log(this.datas[index].imgPaths)
this._uploadFiles(0, this.datas[index].imgPaths, (urls) => {
console.log(urls);
uni.request({
url: `${helper.serverUrl}/ffzy/ffzy`,
method: 'POST',
data: {
geom: this.datas[index].geom,
img: urls.join(','),
reason: this.datas[index].reason
},
header: {
Authorization: `Bearer ${this.token}`
},
success: (resp) => {
if (resp.data.code === 200) {
successDatas.push(this.datas[index]);
}
this._submit(++index, callback, successDatas)
},
fail: () => {
this._submit(++index, callback, successDatas)
},
complete: () => {}
})
})
} else {
callback(successDatas);
}
},
submit() { submit() {
if (this.datas.length === 0) {
return;
}
this.submiting = true;
this._submit(0, (successDatas) => {
this.datas = this.datas.filter(item => {
return successDatas.indexOf(item) === -1;
})
this.submiting = false;
uni.setStorage({
data: this.datas,
key: 'sbsjTemp'
})
});
}, },
delItem(index) { delItem(index) {
uni.showModal({ uni.showModal({
@ -94,5 +193,4 @@
.sjgl>>>.uni-card { .sjgl>>>.uni-card {
padding: 0 !important; padding: 0 !important;
} }
</style> </style>

@ -157,7 +157,7 @@
this.wd = parseFloat(strs[1]); this.wd = parseFloat(strs[1]);
this.reason = item.reason; this.reason = item.reason;
this.imgStrs = item.img?.split(','); this.imgStrs = item.img?.split(',');
// this.imgs = item.img?.split(','); this.imgs = item.img?.split(',');
} }
}, },
}) })
@ -260,38 +260,61 @@
} }
} }
}, },
_saveFile(index, imgPaths, callback, resultPaths) {
if (!resultPaths) {
resultPaths = [];
}
if (imgPaths[index]) {
uni.saveFile({
tempFilePath: imgPaths[index],
success: (res) => {
resultPaths.push(res.savedFilePath);
this._saveFile(++index, imgPaths, callback, resultPaths);
},
fail: () => {
this._saveFile(++index, imgPaths, callback, resultPaths);
}
})
} else {
callback(resultPaths);
}
},
saveTemp(data) { saveTemp(data) {
uni.getStorage({ this._saveFile(0, data.imgPaths, (paths) => {
key: 'sbsjTemp', data.imgPaths = paths;
success: (resp) => { uni.getStorage({
console.log(resp); key: 'sbsjTemp',
uni.setStorage({ success: (resp) => {
key: 'sbsjTemp', console.log(resp);
data: [...resp.data || [], data], uni.setStorage({
success: () => { key: 'sbsjTemp',
uni.showToast({ data: [...resp.data || [], data],
title: '已保存到临时数据管理' success: () => {
}) uni.showToast({
setTimeout(() => { title: '已保存到临时数据管理'
uni.navigateBack(); })
}, 1500) setTimeout(() => {
} uni.navigateBack();
}) }, 1500)
}, }
fail: () => { })
uni.setStorage({ },
key: 'sbsjTemp', fail: () => {
data: [data], uni.setStorage({
success: () => { key: 'sbsjTemp',
uni.showToast({ data: [data],
title: '已保存到临时数据管理' success: () => {
}) uni.showToast({
setTimeout(() => { title: '已保存到临时数据管理'
uni.navigateBack(); })
}, 1500) setTimeout(() => {
} uni.navigateBack();
}) }, 1500)
} }
})
}
})
}) })
}, },
chooseImg() { chooseImg() {

@ -25,7 +25,7 @@
</view> </view>
</view> </view>
<view class="flex"> <view class="flex">
<view class="action-btn fill flex" style="align-items: center;justify-content: flex-start;" @click="toLssjgl"> <view class="action-btn fill flex" style="align-items: center;justify-content: flex-start;margin-left: 4px;" @click="toLssjgl">
<image src="/static/sjgl.png" class="action-img"></image> <image src="/static/sjgl.png" class="action-img"></image>
<text class="action-text">临时数据管理</text> <text class="action-text">临时数据管理</text>
<image src="/static/jr.png" class="action-arrow"></image> <image src="/static/jr.png" class="action-arrow"></image>

Loading…
Cancel
Save