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
79c9852b
Commit
79c9852b
authored
Aug 24, 2021
by
Damon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 日志封装、图片异步优化
parent
599f15ec
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
132 additions
and
30 deletions
+132
-30
log.js
src/common/log.js
+72
-0
index.js
src/components/upload/index.js
+5
-4
task.js
src/components/upload/task.js
+26
-19
order.vue
src/pages/index/order.vue
+3
-1
complete.vue
src/pages/order/complete.vue
+14
-3
detail.vue
src/pages/order/detail.vue
+6
-2
upload.js
src/plugins/uploader/request/upload/upload.js
+1
-0
utils.js
src/plugins/uploader/request/upload/utils.js
+5
-1
No files found.
src/common/log.js
0 → 100644
View file @
79c9852b
const
VERSION
=
process
.
uniEnv
.
version
const
canIUseLogManage
=
wx
.
canIUse
(
"getLogManager"
);
const
logger
=
canIUseLogManage
?
wx
.
getLogManager
({
level
:
0
})
:
null
;
var
realtimeLogger
=
wx
.
getRealtimeLogManager
?
wx
.
getRealtimeLogManager
()
:
null
;
/**
* @param {string} file 所在文件名
* @param {...any} arg 参数
*/
export
function
DEBUG
(
file
,
...
args
)
{
console
.
debug
(
file
,
" | "
,
...
args
);
if
(
canIUseLogManage
)
{
logger
.
debug
(
`[
${
VERSION
}
]`
,
file
,
" | "
,
...
args
);
}
realtimeLogger
&&
realtimeLogger
.
info
(
`[
${
VERSION
}
]`
,
file
,
" | "
,
...
args
);
}
/**
*
* @param {string} file 所在文件名
* @param {...any} arg 参数
*/
export
function
RUN
(
file
,
...
args
)
{
console
.
log
(
file
,
" | "
,
...
args
);
if
(
canIUseLogManage
)
{
logger
.
log
(
`[
${
VERSION
}
]`
,
file
,
" | "
,
...
args
);
}
realtimeLogger
&&
realtimeLogger
.
info
(
`[
${
VERSION
}
]`
,
file
,
" | "
,
...
args
);
}
/**
*
* @param {string} file 所在文件名
* @param {...any} arg 参数
*/
export
function
ERROR
(
file
,
...
args
)
{
console
.
error
(
file
,
" | "
,
...
args
);
if
(
canIUseLogManage
)
{
logger
.
warn
(
`[
${
VERSION
}
]`
,
file
,
" | "
,
...
args
);
}
if
(
realtimeLogger
)
{
realtimeLogger
.
error
(
`[
${
VERSION
}
]`
,
file
,
" | "
,
...
args
);
// 判断是否支持设置模糊搜索
// 错误的信息可记录到 FilterMsg,方便搜索定位
if
(
realtimeLogger
.
addFilterMsg
)
{
try
{
realtimeLogger
.
addFilterMsg
(
`[
${
VERSION
}
]
${
file
}
${
JSON
.
stringify
(
args
)}
`
);
}
catch
(
e
)
{
realtimeLogger
.
addFilterMsg
(
`[
${
VERSION
}
]
${
file
}
`
);
}
}
}
}
// 方便将页面名字自动打印
export
function
getLogger
(
fileName
)
{
return
{
DEBUG
:
function
(...
args
)
{
DEBUG
(
fileName
,
...
args
);
},
RUN
:
function
(...
args
)
{
RUN
(
fileName
,
...
args
);
},
ERROR
:
function
(...
args
)
{
ERROR
(
fileName
,
...
args
);
}
};
}
\ No newline at end of file
src/components/upload/index.js
View file @
79c9852b
...
@@ -45,14 +45,15 @@ export default {
...
@@ -45,14 +45,15 @@ export default {
* 存储图片到任务队列
* 存储图片到任务队列
* @param {Array} files 图片路径
* @param {Array} files 图片路径
*/
*/
async
saveToTask
(
files
)
{
async
saveToTask
(
files
,
order
)
{
// 生成key返回,然后把key放到异步上传的任务队列
// 生成key返回,然后把key放到异步上传的任务队列
let
lists
=
files
.
map
(
v
=>
{
let
lists
=
files
.
map
(
v
=>
{
const
key
=
randomChar
(
10
)
const
key
=
randomChar
(
10
)
return
{
return
{
key
:
key
,
key
:
key
,
path
:
v
,
path
:
v
,
src
:
key
src
:
key
,
...
order
}
}
})
})
// for (let i = 0; i < files.length; i++) {
// for (let i = 0; i < files.length; i++) {
...
@@ -69,7 +70,7 @@ export default {
...
@@ -69,7 +70,7 @@ export default {
* 选择图片
* 选择图片
* @param {Object} data option
* @param {Object} data option
*/
*/
async
chooseImg
(
data
){
async
chooseImg
(
data
,
order
){
const
self
=
this
const
self
=
this
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
uni
.
chooseImage
({
uni
.
chooseImage
({
...
@@ -77,7 +78,7 @@ export default {
...
@@ -77,7 +78,7 @@ export default {
sizeType
:
data
.
sizeType
||
[
'original'
,
'compressed'
],
//可以指定是原图还是压缩图,默认二者都有
sizeType
:
data
.
sizeType
||
[
'original'
,
'compressed'
],
//可以指定是原图还是压缩图,默认二者都有
sourceType
:
data
.
sourceType
||
[
'album'
,
'camera'
],
//从相册选择
sourceType
:
data
.
sourceType
||
[
'album'
,
'camera'
],
//从相册选择
success
:
function
(
res
)
{
success
:
function
(
res
)
{
const
lists
=
self
.
saveToTask
(
res
.
tempFilePaths
)
const
lists
=
self
.
saveToTask
(
res
.
tempFilePaths
,
order
)
resolve
(
lists
)
resolve
(
lists
)
},
},
fail
:
err
=>
{
fail
:
err
=>
{
...
...
src/components/upload/task.js
View file @
79c9852b
import
uploader
from
'@/plugins/uploader/index.js'
import
uploader
from
'@/plugins/uploader/index.js'
import
{
RUN
,
ERROR
}
from
"@/common/log.js"
export
default
{
export
default
{
/**
/**
* 执行任务队列
* 执行任务队列
...
@@ -11,7 +10,6 @@ export default {
...
@@ -11,7 +10,6 @@ export default {
const
options
=
{
const
options
=
{
files
:
uploadTask
,
// 必填 临时文件路径 格式: [{path: "图片地址"}]
files
:
uploadTask
,
// 必填 临时文件路径 格式: [{path: "图片地址"}]
load
:
false
,
//(默认 true 说明:本接口是否提示加载动画)
load
:
false
,
//(默认 true 说明:本接口是否提示加载动画)
maxSize
:
300000
,
//(默认 无 说明:上传的文件最大字节数限制,默认不限制)
onEachUpdate
:
res
=>
{
onEachUpdate
:
res
=>
{
console
.
log
(
"上传成功返回:"
,
res
);
console
.
log
(
"上传成功返回:"
,
res
);
},
},
...
@@ -19,22 +17,31 @@ export default {
...
@@ -19,22 +17,31 @@ export default {
console
.
log
(
"上传进度返回:"
,
res
);
console
.
log
(
"上传进度返回:"
,
res
);
}
}
}
}
const
result
=
await
uploader
.
qnFileUpload
(
options
)
if
(
result
&&
!
result
.
statusCode
)
{
// 匹配已上传完成的图片,更新缓存数据
uploader
.
qnFileUpload
(
options
).
then
(
res
=>
{
let
newTask
=
[]
this
.
refreshTask
(
that
,
res
)
let
delImg
=
[]
}).
catch
(
err
=>
{
uploadTask
.
forEach
(
v
=>
{
console
.
log
(
"err"
,
err
)
if
(
result
.
includes
(
`/
${
v
.
key
}
`
))
{
// 删除已上传的图片
ERROR
(
'upload_photo'
,
err
)
delImg
.
push
(
v
.
path
)
if
(
err
.
errMsg
&&
err
.
errMsg
.
indexOf
(
'fail file not found'
)
!==
-
1
)
{
// 在任务中删除不存在的图片
}
else
{
// 未上传的重新存储
this
.
refreshTask
(
that
,
[
'failErr'
])
newTask
.
push
(
v
)
}
}
})
})
},
refreshTask
(
that
,
result
)
{
console
.
log
(
"result"
,
result
)
const
uploadTask
=
JSON
.
parse
(
JSON
.
stringify
(
that
.
uploadTask
))
let
newTask
=
[]
let
delImg
=
[]
uploadTask
.
forEach
(
v
=>
{
if
(
result
.
includes
(
`/
${
v
.
key
}
`
)
||
result
.
includes
(
'failErr'
))
{
// 删除已上传的图片
delImg
.
push
(
v
.
path
)
}
else
{
// 未上传的重新存储
newTask
.
push
(
v
)
}
})
// uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理
// uni.setStorageSync('delImg', delImg) // 已上传完的图片,会在启动系统的时候做一次清理
that
.
$u
.
vuex
(
'uploadTask'
,
newTask
)
that
.
$u
.
vuex
(
'uploadTask'
,
newTask
)
}
}
}
}
}
\ No newline at end of file
src/pages/index/order.vue
View file @
79c9852b
...
@@ -325,7 +325,9 @@ export default {
...
@@ -325,7 +325,9 @@ export default {
'&brandId='
+
'&brandId='
+
item
.
lianbaoBrandId
+
item
.
lianbaoBrandId
+
'&auditResults='
+
'&auditResults='
+
(
item
.
auditResults
?
Object
.
keys
(
item
.
auditResults
).
join
()
:
''
),
(
item
.
auditResults
?
Object
.
keys
(
item
.
auditResults
).
join
()
:
''
)
+
'&orderNumber='
+
item
.
orderNumber
})
})
},
},
handleClick
(
item
,
type
,
showCountTime
)
{
handleClick
(
item
,
type
,
showCountTime
)
{
...
...
src/pages/order/complete.vue
View file @
79c9852b
...
@@ -521,6 +521,7 @@ export default {
...
@@ -521,6 +521,7 @@ export default {
onLoad
(
option
)
{
onLoad
(
option
)
{
getApp
().
trackPage
(
'订单完工信息页'
)
getApp
().
trackPage
(
'订单完工信息页'
)
if
(
option
)
{
if
(
option
)
{
this
.
orderNumber
=
option
.
orderNumber
this
.
maintainStep
=
option
.
maintainStep
this
.
maintainStep
=
option
.
maintainStep
this
.
orderId
=
option
.
orderId
this
.
orderId
=
option
.
orderId
this
.
categoryId
=
option
.
categoryId
this
.
categoryId
=
option
.
categoryId
...
@@ -1147,7 +1148,12 @@ export default {
...
@@ -1147,7 +1148,12 @@ export default {
async
closeTake
(
val
)
{
async
closeTake
(
val
)
{
if
(
val
&&
val
.
length
>
0
)
{
if
(
val
&&
val
.
length
>
0
)
{
const
files
=
val
.
map
((
v
)
=>
v
.
path
)
const
files
=
val
.
map
((
v
)
=>
v
.
path
)
const
value
=
await
this
.
saveToTask
(
files
)
const
order
=
{
orderNumber
:
this
.
orderNumber
,
fieldsName
:
this
.
photoItem
.
fieldsName
,
fieldsTitle
:
this
.
photoItem
.
fieldsTitle
}
const
value
=
await
this
.
saveToTask
(
files
,
order
)
this
.
$refs
[
this
.
$refs
[
`fileChild
${
this
.
photoItem
.
groupIndex
}${
this
.
photoItem
.
itemIndex
}
`
`fileChild
${
this
.
photoItem
.
groupIndex
}${
this
.
photoItem
.
itemIndex
}
`
][
0
].
setTmpValue
(
value
)
][
0
].
setTmpValue
(
value
)
...
@@ -1162,9 +1168,14 @@ export default {
...
@@ -1162,9 +1168,14 @@ export default {
let
options
=
{
let
options
=
{
sourceType
:
[
'album'
],
//['album', 'camera']
sourceType
:
[
'album'
],
//['album', 'camera']
count
:
3
,
count
:
3
,
sizeType
:
[
'original'
],
sizeType
:
[
'original'
]
}
const
order
=
{
orderNumber
:
this
.
orderNumber
,
fieldsName
:
this
.
photoItem
.
fieldsName
,
fieldsTitle
:
this
.
photoItem
.
fieldsTitle
}
}
const
value
=
await
this
.
chooseImg
(
options
)
const
value
=
await
this
.
chooseImg
(
options
,
order
)
self
.
$refs
[
self
.
$refs
[
`fileChild
${
self
.
photoItem
.
groupIndex
}${
self
.
photoItem
.
itemIndex
}
`
`fileChild
${
self
.
photoItem
.
groupIndex
}${
self
.
photoItem
.
itemIndex
}
`
][
0
].
setTmpValue
(
value
)
][
0
].
setTmpValue
(
value
)
...
...
src/pages/order/detail.vue
View file @
79c9852b
...
@@ -515,7 +515,9 @@ export default {
...
@@ -515,7 +515,9 @@ export default {
'&systemId='
+
'&systemId='
+
this
.
order
.
partnerCompanyId
+
this
.
order
.
partnerCompanyId
+
'&classifyId='
+
'&classifyId='
+
this
.
order
.
categoryId
,
this
.
order
.
categoryId
+
'&orderNumber='
+
this
.
order
.
orderNumber
,
})
})
},
},
take
()
{
take
()
{
...
@@ -938,7 +940,9 @@ export default {
...
@@ -938,7 +940,9 @@ export default {
'&orderStatus='
+
'&orderStatus='
+
this
.
order
.
orderStatus
+
this
.
order
.
orderStatus
+
'&brandId='
+
'&brandId='
+
this
.
order
.
lianbaoBrandId
,
this
.
order
.
lianbaoBrandId
+
'&orderNumber='
+
this
.
order
.
orderNumber
})
})
},
},
rejectOrder
()
{
rejectOrder
()
{
...
...
src/plugins/uploader/request/upload/upload.js
View file @
79c9852b
...
@@ -92,6 +92,7 @@ export default class fileUpload extends request {
...
@@ -92,6 +92,7 @@ export default class fileUpload extends request {
}
}
const
parmas
=
JSON
.
parse
(
JSON
.
stringify
(
qnRes
))
const
parmas
=
JSON
.
parse
(
JSON
.
stringify
(
qnRes
))
parmas
.
visitPrefix
=
''
parmas
.
visitPrefix
=
''
let
requestResult
=
await
qiniuUpload
(
requestInfo
,
parmas
);
let
requestResult
=
await
qiniuUpload
(
requestInfo
,
parmas
);
return
Promise
.
resolve
(
requestResult
);
return
Promise
.
resolve
(
requestResult
);
}
catch
(
err
)
{
}
catch
(
err
)
{
...
...
src/plugins/uploader/request/upload/utils.js
View file @
79c9852b
...
@@ -115,7 +115,11 @@ export const qiniuUpload = function(requestInfo, qnRes) {
...
@@ -115,7 +115,11 @@ export const qiniuUpload = function(requestInfo, qnRes) {
resolve
(
fileList
);
resolve
(
fileList
);
}
}
},
(
error
)
=>
{
},
(
error
)
=>
{
reject
(
error
);
const
rejectMsg
=
{
...
error
,
...
item
}
reject
(
rejectMsg
);
},
{
},
{
region
:
qnRes
.
region
||
'SCN'
,
//地区
region
:
qnRes
.
region
||
'SCN'
,
//地区
domain
:
qnRes
.
visitPrefix
,
// bucket 域名,下载资源时用到。
domain
:
qnRes
.
visitPrefix
,
// bucket 域名,下载资源时用到。
...
...
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