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
40ae2164
Commit
40ae2164
authored
Jun 10, 2021
by
Facius
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
资料文件页面加访问缓存
parent
a190be72
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
45 deletions
+100
-45
App.vue
src/App.vue
+1
-0
http.interceptor.js
src/common/http.interceptor.js
+1
-2
document.vue
src/pages/order/document.vue
+98
-43
No files found.
src/App.vue
View file @
40ae2164
...
...
@@ -64,6 +64,7 @@ export default {
mixWater
:
""
,
// 缓存水印拍照图片
},
},
fileList
:
{}
// 文件地址缓存 {url最后一段: tmpPath}
},
onLaunch
:
async
function
()
{
// 应用初始化(全局只触发一次)
...
...
src/common/http.interceptor.js
View file @
40ae2164
...
...
@@ -88,7 +88,6 @@ const install = (Vue, vm) => {
*/
// 响应拦截,判断状态码是否通过
Vue
.
prototype
.
$u
.
http
.
interceptor
.
response
=
(
res
)
=>
{
console
.
log
(
res
)
let
result
=
res
.
data
||
res
;
let
msg
=
getMsg
(
res
)
//返回__token__,设置
...
...
@@ -102,7 +101,7 @@ const install = (Vue, vm) => {
// return result;
case
200
:
return
{
data
:
result
.
data
==
null
?
result
:
result
.
data
,
// result.data的值为0, false, ''的时候也要算有值
data
:
result
.
data
==
null
?
result
:
result
.
data
,
// result.data的值为0, false, ''的时候也要算有值
;;null的情况下后台返回的是单层及{header: ', data: 数据, message:'', code: ''}
code
:
code
,
message
:
msg
};
...
...
src/pages/order/document.vue
View file @
40ae2164
...
...
@@ -68,7 +68,8 @@
'2'
:
{}
// 选中的品牌
},
loading
:
false
,
// 文件列表加载中
orderFile
:
false
// 是否是订单详情进来
orderFile
:
false
,
// 是否是订单详情进来
fileList
:
{},
// 文件地址缓存 {url最后一段: tmpPath}
};
},
computed
:
{
...
...
@@ -120,7 +121,7 @@
}
else
{
// 获取所有文件资料
this
.
loadFileLabel
(
'1'
)
}
this
.
fileList
=
getApp
().
globalData
.
fileList
||
{}
// 文件地址缓存 {url最后一段: tmpPath}
},
onShow
()
{
// 从标签列表页面返回,获取选中的标签
...
...
@@ -156,61 +157,116 @@
}
this
.
$u
.
route
({
url
:
'pages/order/document-tag'
+
'?partnerCompanyId='
+
partnerCompanyId
+
'&selectedId='
+
this
.
selected
[
key
].
id
})
},
// 分享
//
点击了
分享
handleShare
(
item
)
{
// 分享资料事件
getApp
().
track
(
'share_document'
,
{
id
:
this
.
vuex_user
.
id
,
url
:
item
.
url
});
uni
.
showLoading
({
title
:
'加载中'
})
// callback 写法
wx
.
downloadFile
({
url
:
item
.
url
,
// 下载url
success
(
res
)
{
uni
.
hideLoading
()
// 下载完成后转发
wx
.
shareFileMessage
({
filePath
:
res
.
tempFilePath
,
success
()
{},
fail
:
console
.
error
,
})
},
fail
:
console
.
error
,
})
let
block
=
(
filePath
)
=>
{
wx
.
shareFileMessage
({
filePath
:
filePath
,
success
()
{},
fail
:
console
.
error
,
})
}
let
filePath
=
this
.
fileList
[(
item
.
url
||
''
).
split
(
'/'
).
pop
()]
if
(
filePath
)
{
// 有下载记录
wx
.
shareFileMessage
({
// 如果用checkFile检查文件是否存在后再分享,shareFileMess报错:shareFileMessage:fail can only be invoked by user TAP gesture.
filePath
:
filePath
,
success
()
{},
fail
:
(
error
)
=>
{
console
.
log
(
error
)
if
(
error
.
errMsg
.
indexOf
(
'internal'
)
!=
-
1
)
{
// 文件不存在重新下载
this
.
downloadFile
(
item
.
url
,
(
result
)
=>
{
wx
.
shareFileMessage
({
filePath
:
result
.
tempFilePath
,
success
()
{},
fail
:
console
.
error
,
})
})
}
},
})
}
else
{
// 无下载记录
this
.
downloadFile
(
item
.
url
,
(
res
)
=>
{
// 下载
wx
.
shareFileMessage
({
filePath
:
res
.
tempFilePath
,
success
()
{},
fail
:
console
.
error
,
})
})
}
},
// 查看
//
点击了
查看
handlePreview
(
item
)
{
// 查看资料事件
getApp
().
track
(
'preview_document'
,
{
id
:
this
.
vuex_user
.
id
,
url
:
item
.
url
});
});
let
filePath
=
this
.
fileList
[(
item
.
url
||
''
).
split
(
'/'
).
pop
()]
if
(
filePath
)
{
// 有下载记录
this
.
checkFile
(
filePath
,
(
res
)
=>
{
// 文件是否还存在
if
(
res
.
size
&&
res
.
size
>
0
)
{
// 存在,预览文件
this
.
previewFile
(
filePath
)
}
else
{
// 文件已经不存在, 下载
this
.
downloadFile
(
item
.
url
,
(
result
)
=>
{
this
.
previewFile
(
result
.
tempFilePath
)
})
}
})
}
else
{
// 无下载记录
this
.
downloadFile
(
item
.
url
,
(
res
)
=>
{
// 下载
this
.
previewFile
(
res
.
tempFilePath
)
})
}
},
// 缓存文件是否存在
checkFile
(
filePath
,
complete
)
{
uni
.
getFileInfo
({
filePath
:
filePath
,
complete
:
complete
})
},
// 下载文件
downloadFile
(
url
,
block
)
{
uni
.
showLoading
({
title
:
'加载中'
})
uni
.
downloadFile
({
url
:
item
.
url
,
success
:
function
(
res
)
{
uni
.
hideLoading
()
var
filePath
=
res
.
tempFilePath
;
if
(
/
\.(
gif|jpg|jpeg|png|GIF|JPG|PNG
)
$/
.
test
(
filePath
))
{
// 查看图片
wx
.
previewImage
({
current
:
filePath
,
// 当前显示图片的http链接
urls
:
[
filePath
]
// 需要预览的图片http链接列表
})
}
else
{
// 查看文件
uni
.
openDocument
({
filePath
:
filePath
,
success
:
function
(
res
)
{
console
.
log
(
'打开文档成功'
);
}
});
})
uni
.
downloadFile
({
url
:
url
,
success
:
(
res
)
=>
{
uni
.
hideLoading
()
this
.
fileList
[
url
.
split
(
'/'
).
pop
()]
=
res
.
tempFilePath
block
(
res
)
}
});
},
// 预览文件
previewFile
(
filePath
)
{
if
(
/
\.(
gif|jpg|jpeg|png|GIF|JPG|PNG
)
$/
.
test
(
filePath
))
{
// 查看图片
wx
.
previewImage
({
current
:
filePath
,
// 当前显示图片的http链接
urls
:
[
filePath
]
// 需要预览的图片http链接列表
})
}
else
{
// 查看文件
uni
.
openDocument
({
filePath
:
filePath
,
success
:
function
(
res
)
{
console
.
log
(
'打开文档成功'
);
}
}
});
});
}
},
// 分享文件
shareFile
(
filePath
)
{
wx
.
shareFileMessage
({
filePath
:
filePath
,
success
()
{},
fail
:
console
.
error
,
})
},
// 获取合作商或品牌列表
async
loadFileLabel
(
type
,
partnerCompanyId
)
{
...
...
@@ -245,7 +301,6 @@
})
this
.
loading
=
false
if
(
res
&&
res
.
code
==
200
)
{
console
.
log
(
res
.
data
)
this
.
list
=
res
.
data
||
[]
// this.list = [...res.data,...res.data,...res.data,...res.data,...res.data,...res.data,...res.data] // 测试模拟多条数据
...
...
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