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
ca0e8c74
Commit
ca0e8c74
authored
May 17, 2021
by
Damon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
缓存图片队列清理
parent
b4fb3328
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
7 deletions
+36
-7
App.vue
src/App.vue
+17
-1
XhFiles.vue
src/components/createCom/XhFiles.vue
+1
-1
task.js
src/components/upload/task.js
+18
-5
No files found.
src/App.vue
View file @
ca0e8c74
...
@@ -86,17 +86,33 @@ export default {
...
@@ -86,17 +86,33 @@ export default {
},
},
onShow
:
async
function
()
{
onShow
:
async
function
()
{
// 应用启动,或从后台进入前台显示
// 应用启动,或从后台进入前台显示
this
.
handleImageTask
()
},
},
onHide
:
function
()
{
onHide
:
function
()
{
// 应用从前台进入后台
// 应用从前台进入后台
},
},
watch
:
{
watch
:
{
uploadTask
:
function
(
newValue
,
oldValue
)
{
uploadTask
:
function
(
newValue
,
oldValue
)
{
console
.
log
(
"oldValue, newValue"
,
oldValue
,
newValue
)
if
(
newValue
.
length
>
0
)
upload
.
uploadImageTask
(
this
)
if
(
newValue
.
length
>
0
)
upload
.
uploadImageTask
(
this
)
}
}
},
},
methods
:
{
methods
:
{
// 处理上传图片队列数据
handleImageTask
()
{
if
(
this
.
uploadTask
.
length
>
0
)
{
upload
.
uploadImageTask
(
this
)
}
else
{
// 定时清理缓存在本地的文件
const
result
=
uni
.
getStorageSync
(
'delImg'
)
if
(
result
.
length
>
0
)
{
for
(
let
i
of
result
)
{
uni
.
removeSavedFile
({
filePath
:
i
})
}
uni
.
setStorageSync
(
'delImg'
,
[])
}
}
},
getSystemInfo
()
{
getSystemInfo
()
{
try
{
try
{
let
a
=
wx
.
getSystemInfoSync
();
let
a
=
wx
.
getSystemInfoSync
();
...
...
src/components/createCom/XhFiles.vue
View file @
ca0e8c74
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
import
arrMixin
from
'./arrMixin'
import
arrMixin
from
'./arrMixin'
import
baseFile
from
'@/components/upload/index'
;
import
baseFile
from
'@/components/upload/index'
;
import
takePhoto
from
'@/components/take/index.vue'
import
takePhoto
from
'@/components/take/index.vue'
import
uploader
from
'@/plugins/uploader/index.js'
//
import uploader from '@/plugins/uploader/index.js'
export
default
{
export
default
{
name
:
'XhFiles'
,
name
:
'XhFiles'
,
...
...
src/components/upload/task.js
View file @
ca0e8c74
...
@@ -7,7 +7,6 @@ export default {
...
@@ -7,7 +7,6 @@ export default {
*/
*/
async
uploadImageTask
(
that
)
{
async
uploadImageTask
(
that
)
{
const
uploadTask
=
that
.
uploadTask
const
uploadTask
=
that
.
uploadTask
console
.
log
(
"uploadTask"
,
uploadTask
)
const
options
=
{
const
options
=
{
files
:
uploadTask
,
// 必填 临时文件路径 格式: [{path: "图片地址"}]
files
:
uploadTask
,
// 必填 临时文件路径 格式: [{path: "图片地址"}]
...
@@ -15,13 +14,27 @@ export default {
...
@@ -15,13 +14,27 @@ export default {
maxSize
:
300000
,
//(默认 无 说明:上传的文件最大字节数限制,默认不限制)
maxSize
:
300000
,
//(默认 无 说明:上传的文件最大字节数限制,默认不限制)
onEachUpdate
:
res
=>
{
onEachUpdate
:
res
=>
{
console
.
log
(
"上传成功返回:"
,
res
);
console
.
log
(
"上传成功返回:"
,
res
);
const
newTask
=
uploadTask
.
filter
(
v
=>
v
.
key
!==
res
.
key
)
// that.$u.vuex('uploadTask', newTask)
},
},
Update
:
res
=>
{
Update
:
res
=>
{
console
.
log
(
"上传进度返回:"
,
res
);
console
.
log
(
"上传进度返回:"
,
res
);
}
}
}
}
uploader
.
qnFileUpload
(
options
)
const
result
=
await
uploader
.
qnFileUpload
(
options
)
},
if
(
result
)
{
// 匹配已上传完成的图片,更新缓存数据
let
newTask
=
[]
let
delImg
=
[]
uploadTask
.
forEach
(
v
=>
{
if
(
result
.
includes
(
`/
${
v
.
key
}
`
))
{
// 删除已上传的图片
delImg
.
push
(
v
.
path
)
}
else
{
// 未上传的重新存储
newTask
.
push
(
v
)
}
})
uni
.
setStorageSync
(
'delImg'
,
delImg
)
// 已上传完的图片,会在启动系统的时候做一次清理
that
.
$u
.
vuex
(
'uploadTask'
,
newTask
)
}
}
}
}
\ No newline at end of file
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