Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
basic-uniapp-v3
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-uniapp-v3
Commits
2f212ff3
提交
2f212ff3
authored
12月 30, 2024
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 添加清理缓存示例
上级
8b4e19c3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
71 行增加
和
1 行删除
+71
-1
index.vue
src/pages/example/index.vue
+55
-1
index.ts
src/utils/index.ts
+15
-0
unocss.config.ts
unocss.config.ts
+1
-0
没有找到文件。
src/pages/example/index.vue
浏览文件 @
2f212ff3
<
script
setup
lang=
"ts"
>
import
*
as
Pages
from
'@/utils/pages'
import
{
convertKB
}
from
'@/utils'
import
{
calculateCacheSize
,
cleanCache
}
from
'@/components/CacheImage/index'
interface
Item
{
name
:
string
icon
:
string
page
:
string
page
?
:
string
type
?:
'link'
|
'bottom'
animationType
?:
Pages
.
AnimationType
explain
?:
string
before
?:
()
=>
void
event
?:
()
=>
void
}
...
...
@@ -68,6 +71,38 @@
}
},
},
{
name
:
'清理缓存'
,
icon
:
'fxemoji-clockwiserightwardsleftwardscirclearrows'
,
type
:
'bottom'
,
explain
:
''
,
event
()
{
if
(
!
this
.
explain
)
{
Message
.
toast
(
'无需清理 ~'
)
return
}
Message
.
confirm
(
'确认清除缓存?'
,
'温馨提示'
).
then
(
async
(
confirm
)
=>
{
if
(
confirm
)
{
Message
.
loading
(
'清理中...'
)
try
{
// 清理缓存
await
cleanCache
()
// 重新计算
calculateCache
()
}
finally
{
// 延迟提示
setTimeout
(()
=>
{
Message
.
toast
(
'缓存清除成功'
)
Message
.
hideLoading
()
},
500
)
}
}
})
},
},
],
})
...
...
@@ -83,6 +118,24 @@
Pages
.
to
(
item
.
page
,
item
.
animationType
)
}
/**
* 计算缓存
*/
function
calculateCache
()
{
// 重新计算
const
cacheIamgeSizeTotal
=
calculateCacheSize
()
const
{
size
:
currentStorageSize
,
unit
:
currentStorageSizeUnit
}
=
convertKB
(
cacheIamgeSizeTotal
/
1024
)
// 更新视图
data
.
items
.
find
((
item
)
=>
item
.
name
===
'清理缓存'
).
explain
=
Number
(
currentStorageSize
)
===
0
?
''
:
`
${
currentStorageSize
}${
currentStorageSizeUnit
}
`
}
onShow
(()
=>
{
// 计算缓存
calculateCache
()
})
</
script
>
<
template
>
...
...
@@ -103,6 +156,7 @@
<Icon
:class=
"[`icon-$
{item.icon}`]" size="48" />
<text>
{{
item
.
name
}}
</text>
</view>
<text
class=
"fui-text__explain text-#999"
v-if=
"item.explain"
>
{{
item
.
explain
}}
</text>
</fui-list-cell>
</view>
</scroll-view>
...
...
src/utils/index.ts
浏览文件 @
2f212ff3
...
...
@@ -60,3 +60,18 @@ export function withInstall<T>(component: T, alias?: string) {
}
return
component
as
T
&
Plugin
}
// 将 KB 转换为其他单位
export
function
convertKB
(
kb
:
number
)
{
const
bytes
=
kb
*
1024
const
units
=
[
'B'
,
'KB'
,
'MB'
,
'GB'
,
'TB'
]
let
size
=
bytes
let
unitIndex
=
0
while
(
size
>=
1024
&&
unitIndex
<
units
.
length
-
1
)
{
size
/=
1024
unitIndex
++
}
return
{
size
:
size
.
toFixed
(
2
),
unit
:
units
[
unitIndex
]
}
}
unocss.config.ts
浏览文件 @
2f212ff3
...
...
@@ -18,6 +18,7 @@ const ICONS = [
'emojione:cowboy-hat-face'
,
'twemoji:laptop'
,
'vscode-icons:file-type-pdf2'
,
'fxemoji:clockwiserightwardsleftwardscirclearrows'
,
]
export
default
defineConfig
({
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论