按钮:
<u-button shape="circle" plain type="info" @click="clearStorage"><text style="color: #000;font-size: 32rpx;">当前缓存: {{fileSizeString}}, 点击清除缓存</text></u-button>
获取本机缓存:
// 获取缓存formatSize() {plus.cache.calculate((size) => {let sizeCache = parseInt(size);if (sizeCache == 0) {this.fileSizeString = "0B";} else if (sizeCache < 1024) {this.fileSizeString = sizeCache + "B";} else if (sizeCache < 1048576) {this.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB";} else if (sizeCache < 1073741824) {this.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB";} else {this.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB";}});},
清除缓存:
clearStorage() {uni.showModal({title: '清除缓存',content: '您确定要清除缓存吗?',success: (res) => {if (firm) {console.log('用户点击确定');this.clearCache();} else if (res.cancel) {console.log('用户点击取消');}}});},
清理缓存:
clearCache() {let os = plus.os.name;if (os == 'Android') {let main = plus.android.runtimeMainActivity();let sdRoot = CacheDir();let files = plus.android.invoke(sdRoot, "listFiles");let len = files.length;for (let i = 0; i < len; i++) {let filePath = '' + files[i]; solveLocalFileSystemURL(filePath, (entry) => {if (entry.isDirectory) {veRecursively((entry) => { uni.showToast({title: '缓存清理完成',duration: 2000});this.formatSize(); }, (e) => {console.ssage)});} else {ve();}}, (e) => {console.log('文件路径读取失败')});}} else { // ios plus.cache.clear(() =>{uni.showToast({title: '缓存清理完成',duration: 2000});this.formatSize();});}}
本文发布于:2024-02-02 11:33:44,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170684482343529.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |