Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
self-support
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李俊赕
self-support
Commits
da7916eb
Commit
da7916eb
authored
Sep 01, 2021
by
Damon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 图片上传进度
parent
27fb0f22
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
398 additions
and
137 deletions
+398
-137
upload-progress.vue
src/components/upload-progress/upload-progress.vue
+244
-0
task.js
src/components/upload/task.js
+13
-1
index.vue
src/pages/index/index.vue
+135
-134
index.js
src/store/index.js
+6
-2
No files found.
src/components/upload-progress/upload-progress.vue
0 → 100644
View file @
da7916eb
<
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
>
src/components/upload/task.js
View file @
da7916eb
...
...
@@ -19,6 +19,7 @@ export default {
* 执行任务队列
*/
async
uploadImageTask
(
that
)
{
that
.
$u
.
vuex
(
'uploadStatus'
,
2
)
const
uploadTask
=
JSON
.
parse
(
JSON
.
stringify
(
that
.
uploadTask
)).
reverse
()
const
networkType
=
await
getNetworkType
()
const
options
=
{
...
...
@@ -34,6 +35,8 @@ export default {
}
delete
log
.
files
RUN
(
'upload_photo_success'
,
log
)
that
.
$u
.
vuex
(
'uploadSuccess'
,
that
.
uploadSuccess
++
)
},
onProgressUpdate
:
res
=>
{
//console.log("上传进度返回:",res);
...
...
@@ -44,7 +47,7 @@ export default {
this
.
refreshTask
(
that
,
res
)
}).
catch
(
err
=>
{
console
.
log
(
"err"
,
err
)
that
.
$u
.
vuex
(
'uploadStatus'
,
3
)
err
.
mobile
=
that
.
vuex_user
.
mobile
if
(
!
err
.
key
)
err
.
files
=
uploadTask
if
(
!
err
.
orderNumber
)
err
.
orderNumber
=
uploadTask
[
0
].
orderNumber
...
...
@@ -54,6 +57,7 @@ export default {
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
)
that
.
$u
.
vuex
(
'uploadTask'
,
newTask
)
this
.
resetProgress
(
that
)
}
})
},
...
...
@@ -68,5 +72,13 @@ export default {
// uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理
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
)
}
}
}
src/pages/index/index.vue
View file @
da7916eb
<
template
>
<TabBarPage
title=
"扳手会"
:fixed=
"true"
@
click=
"goTop"
>
<
template
>
<TabBarPage
title=
"扳手会"
:fixed=
"true"
@
click=
"goTop"
>
<view
class=
"content-view"
>
<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"
refresher-background=
"#F4F5F7"
@
refresherrefresh=
"onRefresh"
@
refresherrestore=
"onRestore"
enable-back-to-top
>
<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"
refresher-background=
"#F4F5F7"
@
refresherrefresh=
"onRefresh"
@
refresherrestore=
"onRestore"
enable-back-to-top
>
<image
class=
"banner-image"
:src=
"bannerImage"
@
click=
"handleClickBanner"
></image>
<view
class=
"msg-view"
>
...
...
@@ -58,8 +58,9 @@
<view
class=
"bottom-text"
>
我也是有底线哒
</view>
<view
class=
"bottom-line-view"
></view>
</view>
</scroll-view>
</view>
</scroll-view>
</view>
<upload-progress></upload-progress>
</TabBarPage>
</template>
...
...
@@ -74,10 +75,10 @@
components
:
{
OrderCell
,
TabBarPage
,
NoOrder
,
NoOrder
,
},
data
()
{
return
{
return
{
status
:
0
,
// 入驻状态:0=>'待提交',1=>'待审核',2=>'已通过',3=>'备选',4=>'已驳回',6=>'已签约',7=>'已支付保证金',8=>'已通过考试',9=>'待提交'
location
:
[],
// 经纬度
title
:
false
,
...
...
@@ -94,11 +95,11 @@
pageNumber
:
0
,
pageSize
:
100
,
},
waitInit
:
false
,
// 当token为空时,等待自动登录结束
triggered
:
true
,
scrollTop
:
0
,
old
:
{
scrollTop
:
0
waitInit
:
false
,
// 当token为空时,等待自动登录结束
triggered
:
true
,
scrollTop
:
0
,
old
:
{
scrollTop
:
0
}
};
},
...
...
@@ -135,16 +136,16 @@
},
},
onLoad
(
e
)
{
app
.
trackPage
(
'自营平台首页'
)
app
.
trackPage
(
'自营平台首页'
)
this
.
_freshing
=
false
;
if
(
this
.
vuex_token
)
{
this
.
getOrderCount
()
}
else
{
this
.
waitInit
=
true
}
}
},
onShow
()
{
// 每次进入页面都刷新入驻状态
// 每次进入页面都刷新入驻状态
this
.
pageNumber
=
0
this
.
initSettleInfo
();
...
...
@@ -154,39 +155,39 @@
this
.
getOrderCount
()
this
.
initSettleInfo
();
},
handleClick
(
item
,
type
,
showCountTime
)
{
// 跳转工单详情页面 showCountTime:是否显示倒计时
// type类型
// 'waitAccept': 待接单、待抢单;'waitAppointment': 待预约;'waitCheckIn': 待签到;'waitFinish': 待完工;'audit': 审核中;'exception': 异常单;'finish': 已完工;'other': 工单结算信息
handleClick
(
item
,
type
,
showCountTime
)
{
// 跳转工单详情页面 showCountTime:是否显示倒计时
// type类型
// 'waitAccept': 待接单、待抢单;'waitAppointment': 待预约;'waitCheckIn': 待签到;'waitFinish': 待完工;'audit': 审核中;'exception': 异常单;'finish': 已完工;'other': 工单结算信息
uni
.
navigateTo
({
url
:
'pages/order/detail?id='
+
item
.
orderId
+
'&type='
+
type
+
'&showCountTime='
+
showCountTime
})
},
async
initSettleInfo
()
{
let
self
=
this
;
// 加载消息列表
this
.
loadMessageList
();
async
initSettleInfo
()
{
let
self
=
this
;
// 加载消息列表
this
.
loadMessageList
();
if
(
this
.
vuex_token
)
{
const
callBack
=
(
vm
,
result
)
=>
{
// 后台自动判断入驻流程是否完成,前台通过status确定状态
// 后台自动判断入驻流程是否完成,前台通过status确定状态
if
(
result
&&
result
.
record
)
{
vm
.
needSettled
=
result
.
needSettled
;
vm
.
status
=
Number
(
result
.
record
.
status
||
'0'
);
// vm.status = 8
}
};
self
.
search
.
pageNumber
=
0
self
.
loadedOrder
=
false
};
self
.
search
.
pageNumber
=
0
self
.
loadedOrder
=
false
self
.
loadOrderList
();
await
app
.
getBaseInfo
(
self
,
callBack
);
if
(
this
.
status
==
7
)
{
this
.
getLocation
()
await
app
.
getBaseInfo
(
self
,
callBack
);
if
(
this
.
status
==
7
)
{
this
.
getLocation
()
}
this
.
loaded
=
true
;
}
else
{
this
.
loaded
=
true
}
this
.
loaded
=
true
;
}
else
{
this
.
loaded
=
true
}
},
loadMessageList
()
{
...
...
@@ -209,61 +210,61 @@
let
self
=
this
;
// 加载订单列表
self
.
search
.
token
=
self
.
vuex_token
;
self
.
$u
.
api
.
listByRecommendOrder
(
self
.
search
).
then
((
res
)
=>
{
self
.
loadedOrder
=
true
self
.
$u
.
api
.
listByRecommendOrder
(
self
.
search
).
then
((
res
)
=>
{
self
.
loadedOrder
=
true
if
(
res
.
code
==
200
&&
res
.
data
)
{
if
(
self
.
search
.
pageNumber
==
1
)
{
self
.
orderList
=
[]
}
if
(
res
.
data
.
list
)
{
// self.orderList.push(...res.data.list)
// 更新每一条时间戳,防止后台返回的数据和原先一样,不触发ordercell的时间计算
var
time
=
new
Date
().
getTime
()
for
(
var
item
of
res
.
data
.
list
)
{
item
.
currentCellTime
=
time
self
.
orderList
.
push
(
item
);
}
}
if
(
res
.
code
==
200
&&
res
.
data
)
{
if
(
self
.
search
.
pageNumber
==
1
)
{
self
.
orderList
=
[]
}
if
(
res
.
data
.
list
)
{
// self.orderList.push(...res.data.list)
// 更新每一条时间戳,防止后台返回的数据和原先一样,不触发ordercell的时间计算
var
time
=
new
Date
().
getTime
()
for
(
var
item
of
res
.
data
.
list
)
{
item
.
currentCellTime
=
time
self
.
orderList
.
push
(
item
);
}
}
self
.
currentLoadStatus
=
res
.
data
.
total
>
self
.
orderList
.
length
&&
(
res
.
data
.
list
||
[]).
length
==
self
.
search
.
pageSize
?
'loadmore'
:
'nomore'
}
else
{
console
.
log
(
res
.
message
,
"初始化订单列表异常"
);
}
self
.
$nextTick
(()
=>
{
if
(
self
.
_freshing
)
{
self
.
triggered
=
false
;
self
.
_freshing
=
false
;
}
}
self
.
$nextTick
(()
=>
{
if
(
self
.
_freshing
)
{
self
.
triggered
=
false
;
self
.
_freshing
=
false
;
}
})
});
},
reachBottom
()
{
reachBottom
()
{
if
(
this
.
vuex_token
)
{
if
(
this
.
currentLoadStatus
!=
'loadmore'
)
return
this
.
currentLoadStatus
==
'loading'
this
.
loadOrderList
()
}
},
onRefresh
()
{
if
(
this
.
_freshing
)
return
this
.
_freshing
=
true
this
.
initSettleInfo
()
},
onRestore
()
{
this
.
triggered
=
'restore'
;
// 需要重置
},
scroll
(
e
)
{
this
.
old
.
scrollTop
=
e
.
detail
.
scrollTop
},
goTop
(
e
)
{
this
.
scrollTop
=
this
.
old
.
scrollTop
this
.
$nextTick
(
function
()
{
this
.
scrollTop
=
0
});
},
},
onRefresh
()
{
if
(
this
.
_freshing
)
return
this
.
_freshing
=
true
this
.
initSettleInfo
()
},
onRestore
()
{
this
.
triggered
=
'restore'
;
// 需要重置
},
scroll
(
e
)
{
this
.
old
.
scrollTop
=
e
.
detail
.
scrollTop
},
goTop
(
e
)
{
this
.
scrollTop
=
this
.
old
.
scrollTop
this
.
$nextTick
(
function
()
{
this
.
scrollTop
=
0
});
},
/* 立即入驻 */
immediatelyIn
()
{
if
(
this
.
vuex_token
)
{
...
...
@@ -313,17 +314,17 @@
for
(
var
i
in
res
.
data
)
{
count
+=
res
.
data
[
i
]
}
// 修改tab总数
if
(
count
>
0
)
{
uni
.
setTabBarBadge
({
index
:
1
,
text
:
String
(
count
)
})
}
else
{
uni
.
removeTabBarBadge
({
index
:
1
})
}
// 修改tab总数
if
(
count
>
0
)
{
uni
.
setTabBarBadge
({
index
:
1
,
text
:
String
(
count
)
})
}
else
{
uni
.
removeTabBarBadge
({
index
:
1
})
}
}
...
...
@@ -332,38 +333,38 @@
}
});
},
/**
* 获取当前位置的经纬度
*/
getLocation
()
{
let
self
=
this
uni
.
getLocation
({
type
:
'gcj02'
,
success
:
function
(
res
)
{
self
.
location
=
[
res
.
latitude
,
res
.
longitude
]
},
complete
:
function
(
res
)
{
if
(
res
.
errMsg
.
indexOf
(
'auth'
)
!=
-
1
)
{
uni
.
showModal
({
title
:
'提示'
,
content
:
'获取权限失败,请到设置页面开启权限'
,
confirmText
:
'好的'
,
success
(
res
)
{
if
(
res
.
confirm
)
{
uni
.
openSetting
({
success
(
res
)
{
console
.
log
(
res
.
authSetting
)
}
});
}
}
})
}
},
fail
:
function
(
err
)
{
}
});
/**
* 获取当前位置的经纬度
*/
getLocation
()
{
let
self
=
this
uni
.
getLocation
({
type
:
'gcj02'
,
success
:
function
(
res
)
{
self
.
location
=
[
res
.
latitude
,
res
.
longitude
]
},
complete
:
function
(
res
)
{
if
(
res
.
errMsg
.
indexOf
(
'auth'
)
!=
-
1
)
{
uni
.
showModal
({
title
:
'提示'
,
content
:
'获取权限失败,请到设置页面开启权限'
,
confirmText
:
'好的'
,
success
(
res
)
{
if
(
res
.
confirm
)
{
uni
.
openSetting
({
success
(
res
)
{
console
.
log
(
res
.
authSetting
)
}
});
}
}
})
}
},
fail
:
function
(
err
)
{
}
});
},
toNewsDetail
(
item
)
{
wx
.
navigateTo
({
...
...
@@ -372,12 +373,12 @@
res
.
eventChannel
.
emit
(
'acceptDataFromLearn'
,
item
)
}
});
},
handleClickBanner
()
{
uni
.
navigateTo
({
url
:
"/pages/mine/customer/index"
+
'?type=exclusive'
,
});
},
},
handleClickBanner
()
{
uni
.
navigateTo
({
url
:
"/pages/mine/customer/index"
+
'?type=exclusive'
,
});
},
},
};
</
script
>
...
...
@@ -387,10 +388,10 @@
width
:
730rpx
;
height
:
280rpx
;
margin-left
:
-16rpx
;
}
.content-view
{
height
:
100%
;
overflow
:
auto
;
}
.content-view
{
height
:
100%
;
overflow
:
auto
;
}
.msg-view
{
...
...
@@ -515,8 +516,8 @@
.order-item-view
{
background-color
:
#F4F5F7
;
border-radius
:
12rpx
;
margin-bottom
:
20rpx
;
border-radius
:
12rpx
;
margin-bottom
:
20rpx
;
}
}
}
...
...
@@ -538,4 +539,4 @@
font-size
:
24rpx
;
}
}
</
style
>
</
style
>
src/store/index.js
View file @
da7916eb
...
...
@@ -12,7 +12,7 @@ try {
}
// 需要永久存储,且下次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
)
{
...
...
@@ -42,7 +42,11 @@ const store = new Vuex.Store({
// 授权用户信息
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
:
{
$uStore
(
state
,
payload
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment