Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
basic-uniapp-v3
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-uniapp-v3
Commits
814a183e
提交
814a183e
authored
3月 31, 2023
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: ThumbnailPreview 组件默认使用 CacheImage 组件来实现图片缓存
上级
0081f13c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
8 行删除
+27
-8
index.vue
src/components/CacheImage/index.vue
+11
-4
index.vue
src/components/ThumbnailPreview/index.vue
+16
-4
没有找到文件。
src/components/CacheImage/index.vue
浏览文件 @
814a183e
...
...
@@ -18,6 +18,10 @@
type
:
String
,
default
:
'scaleToFill'
,
},
background
:
{
type
:
String
,
default
:
'#F7F7F7'
,
},
src
:
{
type
:
String
,
required
:
true
,
...
...
@@ -38,10 +42,10 @@
const
hash
=
md5
(
url
).
toString
()
hashCacheKey
.
value
=
`G_CACHE_IMAGE_
${
hash
}
`
if
(
uni
.
getStorageSync
(
hashCacheKey
.
value
))
{
console
.
lo
g
(
'CacheImage cache hit'
)
console
.
debu
g
(
'CacheImage cache hit'
)
url
=
uni
.
getStorageSync
(
hashCacheKey
.
value
)
}
else
{
console
.
lo
g
(
'CacheImage cache miss'
)
console
.
debu
g
(
'CacheImage cache miss'
)
try
{
const
res
=
await
uni
.
downloadFile
({
url
})
if
(
res
.
statusCode
===
200
)
{
...
...
@@ -61,7 +65,7 @@
console
.
error
(
e
)
}
}
console
.
lo
g
(
props
.
src
,
'=>'
,
url
,
hash
,
hashCacheKey
.
value
)
console
.
debu
g
(
props
.
src
,
'=>'
,
url
,
hash
,
hashCacheKey
.
value
)
// #endif
src
.
value
=
url
...
...
@@ -87,7 +91,10 @@
:width=
"props.width"
:height=
"props.height"
:radius=
"props.radius"
:background=
"props.background"
:src=
"src"
@
error=
"onError"
/>
>
<slot></slot>
</fui-lazyload>
</
template
>
src/components/ThumbnailPreview/index.vue
浏览文件 @
814a183e
<
script
lang=
"ts"
setup
>
import
type
{
PropType
}
from
'vue'
import
md5
from
'crypto-js/md5'
import
{
nanoid
}
from
'nanoid'
import
{
getPoster
,
isImage
,
isVideo
}
from
'./utils'
import
CacheImage
from
'@/components/CacheImage/index.vue'
type
Asset
=
Recordable
&
{
url
:
string
}
const
props
=
defineProps
({
...
...
@@ -35,7 +37,17 @@
// 预览图片
const
preview
=
(
index
:
number
)
=>
{
uni
.
previewImage
({
urls
:
images
.
value
.
map
((
item
)
=>
item
.
url
),
urls
:
images
.
value
.
map
((
item
)
=>
{
// #ifdef APP-PLUS
const
hash
=
md5
(
item
.
url
).
toString
()
const
key
=
`G_CACHE_IMAGE_
${
hash
}
`
if
(
uni
.
getStorageSync
(
key
))
{
return
uni
.
getStorageSync
(
key
)
}
// #endif
return
item
.
url
}),
current
:
index
,
})
}
...
...
@@ -67,7 +79,7 @@
<
template
>
<view
class=
"preview-wrap"
>
<!-- 视频预览 -->
<
fui-lazyload
<
CacheImage
class=
"preview-video"
:background=
"props.background"
:mode=
"props.mode"
...
...
@@ -82,10 +94,10 @@
<view
class=
"icon-wrap"
:style=
"
{ width: props.width, height: props.height }">
<fui-icon
class=
"video-play-icon"
name=
"suspend"
size=
"40"
color=
"#fff"
/>
</view>
</
fui-lazyload
>
</
CacheImage
>
<!-- 图片预览 -->
<
fui-lazyload
<
CacheImage
class=
"preview-image"
:background=
"props.background"
:mode=
"props.mode"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论