Commit da7916eb authored by Damon's avatar Damon

feat: 图片上传进度

parent 27fb0f22
<template>
<view class="upload-progress">
<view :class="['u-flex', 'suspension', {'error': uploadStatus === 3}]" @click="openpRrogress">
<view class="progress" v-if="taskCount > 0">{{ uploadPercentage }}%</view>
<view class="upload-img" v-if="taskCount === 0">
<image class="icon" :src="icon"></image>
</view>
</view>
<u-popup
v-model="open"
border-radius="12"
mode="center"
:animation="false"
@close="closePopup"
width="690rpx">
<view class="slot-content">
<view class="upload-title">
<text class='status-txt'>图片上传进度</text>
</view>
<view v-if="taskCount > 0">
<view class="progress-circle">
<u-loading class="loading" v-if="!progressStatus" mode="circle"></u-loading>
<u-circle-progress v-if="progressStatus" :width="320" :border-width="20" inactive-color="#F4F5F7" :active-color="progressColor" :percent="uploadPercentage">
<view :class="['u-progress-content', {'error': uploadStatus === 3}]"> {{ uploadPercentage }}%</view>
</u-circle-progress>
</view>
<view class="u-flex upload-data">
<view class="u-flex">
<view class="title">需上传</view>
<view class="pending">{{ taskCount }}</view>
</view>
<view class="u-flex">
<view class="title">已上传</view>
<view class="resolve">{{ uploadSuccess }}</view>
</view>
<view class="u-flex">
<view class="title">状态</view>
<view :class="['status', {'error': uploadStatus === 3}]">{{ uploadStatusName }}</view>
</view>
</view>
<view class="upload-bottom" v-if="uploadStatus === 3">
<view class="button confirm" @click="$u.throttle(retry, 500)">重试</view>
</view>
</view>
<view class="u-flex default" v-if="taskCount === 0">
<view><image class="default-img" :src="defaultImg"></image></view>
<view class="text">当前暂无上传图片</view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
/**
* upload-progress 图片上传进度
*/
import upload from '@/components/upload/task.js'
export default {
name:"upload-progress",
data() {
return {
open: false,
progressStatus: false
}
},
computed: {
icon() {
return process.uniEnv.qn_base_url + 'upload-photo.png'
},
defaultImg() {
return process.uniEnv.qn_base_url + 'upload-default.png'
},
taskCount() {
return this.uploadTask.length
},
uploadStatusName() {
let status
switch (this.uploadStatus) {
case 1:
status = '等待上传'
break;
case 2:
status = '上传中'
break;
case 3:
status = '上传中断'
break;
}
return status
},
progressColor() {
return this.uploadStatus === 3 ? '#FA5A49' : '#2272FF'
},
uploadPercentage() {
return Number(this.uploadSuccess) / Number(this.uploadTask.length)
}
},
methods: {
closePopup() {
this.progressStatus = false
},
openpRrogress() {
this.open = true
setTimeout(() => {
this.progressStatus = true
}, 300)
},
retry() {
if(this.uploadStatus !== 2) upload.uploadImageTask(this)
}
}
}
</script>
<style lang="scss" scoped>
.upload-progress {
width: 100%;
height: 100%;
.suspension {
position: fixed;
right: 5%;
bottom: 20%;
width: 80rpx;
height: 80rpx;
border-radius: 50%;
background: #2272FF;
&.error {
background: #FA5A49;
}
.progress {
font-size: 24rpx;
color: #fff;
width: 100%;
text-align: center;
}
.upload-img {
width: 100%;
text-align: center;
padding-top: 8rpx;
.icon {
width: 36rpx;
height: 32rpx;
}
}
}
.slot-content {
padding: 40rpx 30rpx 0rpx 30rpx;
.upload-title {
margin: 20rpx 0 50rpx 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.status-txt {
height: 46rpx;
font-size: 40rpx;
font-weight: bold;
color: #333;
line-height: 46rpx;
}
}
.progress-circle {
width: 100%;
height: 320rpx;
text-align: center;
.loading {
line-height: 320rpx;
}
.u-progress-content {
color: #2272FF;
font-size: 60rpx;
&.error {
color: #FA5A49;
}
}
}
.upload-data {
margin: 50rpx 0 30rpx 0;
.u-flex {
flex-flow: column;
font-size: 48rpx;
width: 210rpx;
height: 120rpx;
.title {
color: #666;
font-size: 28rpx;
padding-bottom: 20rpx;
}
.pending {
color: #333;
}
.resolve {
color: #2272FF;
}
.status {
color: #2272FF;
font-size: 36rpx;
&.error {
color: #FA5A49;
}
}
}
}
.upload-bottom {
display: flex;
justify-content: center;
align-items: center;
.button {
text-align: center;
height: 104rpx;
width: 300rpx;
border-radius: 52rpx;
font-size: 32rpx;
font-weight: 600;
line-height: 104rpx;
}
.confirm {
margin: 36rpx 30rpx 52rpx 15rpx;
background: #2272FF;
color: #FFFFFF;
}
}
.default {
flex-flow: column;
margin: 150rpx 0;
.default-img {
width: 360rpx;
height: 240rpx;
}
.text {
color: #666;
font-size: 28rpx;
margin-top: 50rpx;
}
}
}
}
</style>
...@@ -19,6 +19,7 @@ export default { ...@@ -19,6 +19,7 @@ export default {
* 执行任务队列 * 执行任务队列
*/ */
async uploadImageTask(that) { async uploadImageTask(that) {
that.$u.vuex('uploadStatus', 2)
const uploadTask = JSON.parse(JSON.stringify(that.uploadTask)).reverse() const uploadTask = JSON.parse(JSON.stringify(that.uploadTask)).reverse()
const networkType = await getNetworkType() const networkType = await getNetworkType()
const options = { const options = {
...@@ -34,6 +35,8 @@ export default { ...@@ -34,6 +35,8 @@ export default {
} }
delete log.files delete log.files
RUN('upload_photo_success', log) RUN('upload_photo_success', log)
that.$u.vuex('uploadSuccess', that.uploadSuccess++)
}, },
onProgressUpdate: res => { onProgressUpdate: res => {
//console.log("上传进度返回:",res); //console.log("上传进度返回:",res);
...@@ -44,7 +47,7 @@ export default { ...@@ -44,7 +47,7 @@ export default {
this.refreshTask(that, res) this.refreshTask(that, res)
}).catch(err => { }).catch(err => {
console.log("err", err) console.log("err", err)
that.$u.vuex('uploadStatus', 3)
err.mobile = that.vuex_user.mobile err.mobile = that.vuex_user.mobile
if(!err.key) err.files = uploadTask if(!err.key) err.files = uploadTask
if(!err.orderNumber) err.orderNumber = uploadTask[0].orderNumber if(!err.orderNumber) err.orderNumber = uploadTask[0].orderNumber
...@@ -54,6 +57,7 @@ export default { ...@@ -54,6 +57,7 @@ export default {
if (err.errMsg && (err.errMsg.indexOf('fail file not found') !== -1 || err.errMsg.indexOf('file doesn') !== -1)) { // 在任务中删除不存在的图片 if (err.errMsg && (err.errMsg.indexOf('fail file not found') !== -1 || err.errMsg.indexOf('file doesn') !== -1)) { // 在任务中删除不存在的图片
const newTask = uploadTask.filter(v => v.key !== err.key) const newTask = uploadTask.filter(v => v.key !== err.key)
that.$u.vuex('uploadTask', newTask) that.$u.vuex('uploadTask', newTask)
this.resetProgress(that)
} }
}) })
}, },
...@@ -68,5 +72,13 @@ export default { ...@@ -68,5 +72,13 @@ export default {
// uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理 // uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理
that.$u.vuex('uploadTask', newTask) that.$u.vuex('uploadTask', newTask)
this.resetProgress(that)
},
// 重置任务状态
resetProgress(that) {
if (that.uploadTask.length === 0) { // 上传完本地所有照片
that.$u.vuex('uploadSuccess', 0)
that.$u.vuex('uploadStatus', 1)
}
} }
} }
<template> <template>
<TabBarPage title="扳手会" :fixed="true" @click="goTop"> <TabBarPage title="扳手会" :fixed="true" @click="goTop">
<view class="content-view"> <view class="content-view">
<scroll-view style="height: 100%;" scroll-y @scrolltolower="reachBottom" :scroll-top="scrollTop" @scroll="scroll" <scroll-view style="height: 100%;" scroll-y @scrolltolower="reachBottom" :scroll-top="scrollTop" @scroll="scroll"
scroll-anchoring scroll-y="true" refresher-enabled="true" :refresher-triggered="triggered" :refresher-threshold="100" scroll-anchoring scroll-y="true" refresher-enabled="true" :refresher-triggered="triggered" :refresher-threshold="100"
refresher-background="#F4F5F7" @refresherrefresh="onRefresh" refresher-background="#F4F5F7" @refresherrefresh="onRefresh"
@refresherrestore="onRestore" enable-back-to-top> @refresherrestore="onRestore" enable-back-to-top>
<image class="banner-image" :src="bannerImage" @click="handleClickBanner"></image> <image class="banner-image" :src="bannerImage" @click="handleClickBanner"></image>
<view class="msg-view"> <view class="msg-view">
...@@ -58,8 +58,9 @@ ...@@ -58,8 +58,9 @@
<view class="bottom-text">我也是有底线哒</view> <view class="bottom-text">我也是有底线哒</view>
<view class="bottom-line-view"></view> <view class="bottom-line-view"></view>
</view> </view>
</scroll-view> </scroll-view>
</view> </view>
<upload-progress></upload-progress>
</TabBarPage> </TabBarPage>
</template> </template>
...@@ -74,10 +75,10 @@ ...@@ -74,10 +75,10 @@
components: { components: {
OrderCell, OrderCell,
TabBarPage, TabBarPage,
NoOrder, NoOrder,
}, },
data() { data() {
return { return {
status: 0, // 入驻状态:0=>'待提交',1=>'待审核',2=>'已通过',3=>'备选',4=>'已驳回',6=>'已签约',7=>'已支付保证金',8=>'已通过考试',9=>'待提交' status: 0, // 入驻状态:0=>'待提交',1=>'待审核',2=>'已通过',3=>'备选',4=>'已驳回',6=>'已签约',7=>'已支付保证金',8=>'已通过考试',9=>'待提交'
location: [], // 经纬度 location: [], // 经纬度
title: false, title: false,
...@@ -94,11 +95,11 @@ ...@@ -94,11 +95,11 @@
pageNumber: 0, pageNumber: 0,
pageSize: 100, pageSize: 100,
}, },
waitInit: false, // 当token为空时,等待自动登录结束 waitInit: false, // 当token为空时,等待自动登录结束
triggered: true, triggered: true,
scrollTop: 0, scrollTop: 0,
old: { old: {
scrollTop: 0 scrollTop: 0
} }
}; };
}, },
...@@ -135,16 +136,16 @@ ...@@ -135,16 +136,16 @@
}, },
}, },
onLoad(e) { onLoad(e) {
app.trackPage('自营平台首页') app.trackPage('自营平台首页')
this._freshing = false; this._freshing = false;
if(this.vuex_token) { if(this.vuex_token) {
this.getOrderCount() this.getOrderCount()
} else { } else {
this.waitInit = true this.waitInit = true
} }
}, },
onShow() { onShow() {
// 每次进入页面都刷新入驻状态 // 每次进入页面都刷新入驻状态
this.pageNumber = 0 this.pageNumber = 0
this.initSettleInfo(); this.initSettleInfo();
...@@ -154,39 +155,39 @@ ...@@ -154,39 +155,39 @@
this.getOrderCount() this.getOrderCount()
this.initSettleInfo(); this.initSettleInfo();
}, },
handleClick(item, type, showCountTime) { // 跳转工单详情页面 showCountTime:是否显示倒计时 handleClick(item, type, showCountTime) { // 跳转工单详情页面 showCountTime:是否显示倒计时
// type类型 // type类型
// 'waitAccept': 待接单、待抢单;'waitAppointment': 待预约;'waitCheckIn': 待签到;'waitFinish': 待完工;'audit': 审核中;'exception': 异常单;'finish': 已完工;'other': 工单结算信息 // 'waitAccept': 待接单、待抢单;'waitAppointment': 待预约;'waitCheckIn': 待签到;'waitFinish': 待完工;'audit': 审核中;'exception': 异常单;'finish': 已完工;'other': 工单结算信息
uni.navigateTo({ uni.navigateTo({
url: 'pages/order/detail?id=' + item.orderId + '&type=' + type + '&showCountTime=' + showCountTime url: 'pages/order/detail?id=' + item.orderId + '&type=' + type + '&showCountTime=' + showCountTime
}) })
}, },
async initSettleInfo() { async initSettleInfo() {
let self = this; let self = this;
// 加载消息列表 // 加载消息列表
this.loadMessageList(); this.loadMessageList();
if (this.vuex_token) { if (this.vuex_token) {
const callBack = (vm, result) => { const callBack = (vm, result) => {
// 后台自动判断入驻流程是否完成,前台通过status确定状态 // 后台自动判断入驻流程是否完成,前台通过status确定状态
if (result && result.record) { if (result && result.record) {
vm.needSettled = result.needSettled; vm.needSettled = result.needSettled;
vm.status = Number(result.record.status || '0'); vm.status = Number(result.record.status || '0');
// vm.status = 8 // vm.status = 8
} }
}; };
self.search.pageNumber = 0 self.search.pageNumber = 0
self.loadedOrder = false self.loadedOrder = false
self.loadOrderList(); self.loadOrderList();
await app.getBaseInfo(self, callBack); await app.getBaseInfo(self, callBack);
if (this.status == 7) { if (this.status == 7) {
this.getLocation() this.getLocation()
} }
this.loaded = true; this.loaded = true;
} else { } else {
this.loaded = true this.loaded = true
} }
}, },
loadMessageList() { loadMessageList() {
...@@ -209,61 +210,61 @@ ...@@ -209,61 +210,61 @@
let self = this; let self = this;
// 加载订单列表 // 加载订单列表
self.search.token = self.vuex_token; self.search.token = self.vuex_token;
self.$u.api.listByRecommendOrder(self.search).then((res) => { self.$u.api.listByRecommendOrder(self.search).then((res) => {
self.loadedOrder = true self.loadedOrder = true
if (res.code == 200 && res.data) { if (res.code == 200 && res.data) {
if (self.search.pageNumber == 1) { if (self.search.pageNumber == 1) {
self.orderList = [] self.orderList = []
} }
if (res.data.list) { if (res.data.list) {
// self.orderList.push(...res.data.list) // self.orderList.push(...res.data.list)
// 更新每一条时间戳,防止后台返回的数据和原先一样,不触发ordercell的时间计算 // 更新每一条时间戳,防止后台返回的数据和原先一样,不触发ordercell的时间计算
var time = new Date().getTime() var time = new Date().getTime()
for (var item of res.data.list) { for (var item of res.data.list) {
item.currentCellTime = time item.currentCellTime = time
self.orderList.push(item); self.orderList.push(item);
} }
} }
self.currentLoadStatus = res.data.total > self.orderList.length && (res.data.list || []).length == self.search.pageSize ? 'loadmore' : 'nomore' self.currentLoadStatus = res.data.total > self.orderList.length && (res.data.list || []).length == self.search.pageSize ? 'loadmore' : 'nomore'
} else { } else {
console.log(res.message, "初始化订单列表异常"); console.log(res.message, "初始化订单列表异常");
} }
self.$nextTick(()=>{ self.$nextTick(()=>{
if (self._freshing) { if (self._freshing) {
self.triggered = false; self.triggered = false;
self._freshing = false; self._freshing = false;
} }
}) })
}); });
}, },
reachBottom() { reachBottom() {
if (this.vuex_token) { if (this.vuex_token) {
if (this.currentLoadStatus != 'loadmore') return if (this.currentLoadStatus != 'loadmore') return
this.currentLoadStatus == 'loading' this.currentLoadStatus == 'loading'
this.loadOrderList() this.loadOrderList()
} }
}, },
onRefresh() { onRefresh() {
if (this._freshing) return if (this._freshing) return
this._freshing = true this._freshing = true
this.initSettleInfo() this.initSettleInfo()
}, },
onRestore() { onRestore() {
this.triggered = 'restore'; // 需要重置 this.triggered = 'restore'; // 需要重置
}, },
scroll(e) { scroll(e) {
this.old.scrollTop = e.detail.scrollTop this.old.scrollTop = e.detail.scrollTop
}, },
goTop(e) { goTop(e) {
this.scrollTop = this.old.scrollTop this.scrollTop = this.old.scrollTop
this.$nextTick(function() { this.$nextTick(function() {
this.scrollTop = 0 this.scrollTop = 0
}); });
}, },
/* 立即入驻 */ /* 立即入驻 */
immediatelyIn() { immediatelyIn() {
if (this.vuex_token) { if (this.vuex_token) {
...@@ -313,17 +314,17 @@ ...@@ -313,17 +314,17 @@
for (var i in res.data) { for (var i in res.data) {
count += res.data[i] count += res.data[i]
} }
// 修改tab总数 // 修改tab总数
if (count > 0) { if (count > 0) {
uni.setTabBarBadge({ uni.setTabBarBadge({
index: 1, index: 1,
text: String(count) text: String(count)
}) })
} else { } else {
uni.removeTabBarBadge({ uni.removeTabBarBadge({
index: 1 index: 1
}) })
} }
} }
...@@ -332,38 +333,38 @@ ...@@ -332,38 +333,38 @@
} }
}); });
}, },
/** /**
* 获取当前位置的经纬度 * 获取当前位置的经纬度
*/ */
getLocation() { getLocation() {
let self = this let self = this
uni.getLocation({ uni.getLocation({
type: 'gcj02', type: 'gcj02',
success: function(res) { success: function(res) {
self.location = [res.latitude, res.longitude] self.location = [res.latitude, res.longitude]
}, },
complete: function(res) { complete: function(res) {
if (res.errMsg.indexOf('auth') != -1) { if (res.errMsg.indexOf('auth') != -1) {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '获取权限失败,请到设置页面开启权限', content: '获取权限失败,请到设置页面开启权限',
confirmText: '好的', confirmText: '好的',
success(res) { success(res) {
if (res.confirm) { if (res.confirm) {
uni.openSetting({ uni.openSetting({
success(res) { success(res) {
console.log(res.authSetting) console.log(res.authSetting)
} }
}); });
} }
} }
}) })
} }
}, },
fail: function(err) { fail: function(err) {
} }
}); });
}, },
toNewsDetail(item) { toNewsDetail(item) {
wx.navigateTo({ wx.navigateTo({
...@@ -372,12 +373,12 @@ ...@@ -372,12 +373,12 @@
res.eventChannel.emit('acceptDataFromLearn', item) res.eventChannel.emit('acceptDataFromLearn', item)
} }
}); });
}, },
handleClickBanner() { handleClickBanner() {
uni.navigateTo({ uni.navigateTo({
url: "/pages/mine/customer/index" + '?type=exclusive', url: "/pages/mine/customer/index" + '?type=exclusive',
}); });
}, },
}, },
}; };
</script> </script>
...@@ -387,10 +388,10 @@ ...@@ -387,10 +388,10 @@
width: 730rpx; width: 730rpx;
height: 280rpx; height: 280rpx;
margin-left: -16rpx; margin-left: -16rpx;
} }
.content-view { .content-view {
height: 100%; height: 100%;
overflow: auto; overflow: auto;
} }
.msg-view { .msg-view {
...@@ -515,8 +516,8 @@ ...@@ -515,8 +516,8 @@
.order-item-view { .order-item-view {
background-color: #F4F5F7; background-color: #F4F5F7;
border-radius: 12rpx; border-radius: 12rpx;
margin-bottom: 20rpx; margin-bottom: 20rpx;
} }
} }
} }
...@@ -538,4 +539,4 @@ ...@@ -538,4 +539,4 @@
font-size: 24rpx; font-size: 24rpx;
} }
} }
</style> </style>
...@@ -12,7 +12,7 @@ try { ...@@ -12,7 +12,7 @@ try {
} }
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名 // 需要永久存储,且下次APP启动需要取出的,在state中的变量名
let saveStateKeys = ['vuex_user', 'vuex_wx_uid', 'vuex_token', 'vuex_cache', 'uploadTask', 'vuex_superuser']; let saveStateKeys = ['vuex_user', 'vuex_wx_uid', 'vuex_token', 'vuex_cache', 'uploadTask', 'uploadSuccess', 'vuex_superuser'];
// 保存变量到本地存储中 // 保存变量到本地存储中
const saveLifeData = function(key, value) { const saveLifeData = function(key, value) {
...@@ -42,7 +42,11 @@ const store = new Vuex.Store({ ...@@ -42,7 +42,11 @@ const store = new Vuex.Store({
// 授权用户信息 // 授权用户信息
vuex_auth_user: {}, vuex_auth_user: {},
// 上传队列 // 上传队列
uploadTask: lifeData.uploadTask ? lifeData.uploadTask : [] uploadTask: lifeData.uploadTask ? lifeData.uploadTask : [],
// 上传状态 1 未开始 2 上传中 3 上传中断
uploadStatus: 1,
// 已上传数量
uploadSuccess: lifeData.uploadSuccess ? lifeData.uploadSuccess : 0,
}, },
mutations: { mutations: {
$uStore(state, payload) { $uStore(state, payload) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment