Ver código fonte

清除缓存

sys 2 anos atrás
pai
commit
7a118e4ff7
1 arquivos alterados com 49 adições e 5 exclusões
  1. 49 5
      pages/my/set.vue

+ 49 - 5
pages/my/set.vue

@@ -4,8 +4,8 @@
     <view class="set-list">
       <view class="set-item">
         <view class="item-text sys-height-44 sys-color-black">清理缓存</view>
-        <view class="item-icon">
-          <text class=" sys-height-44 sys-color-gray-9"> 20.47MB</text>
+        <view class="item-icon" @click="clearStorage()">
+          <text class=" sys-height-44 sys-color-gray-9"> {{storageSize}}</text>
           <text class="iconfont sys-height-44 sys-color-gray-9"> &#xe62b;</text>
         </view>
       </view>
@@ -51,6 +51,7 @@ export default {
   components: {EnNav},
   data() {
     return {
+      storageSize:'',
       setList:[
         {'text':'实名认证(未认证)','url':''},
         {'text':'修改密码','url':''},
@@ -70,6 +71,9 @@ export default {
       ],
     }
   },
+  mounted() {
+    this.getStorageSize()
+  },
   methods: {
       goToUrl(url){
         if(url===''){
@@ -78,7 +82,47 @@ export default {
         uni.navigateTo({
           'url':'./set/'+url
         })
-      }
+      },
+    getStorageSize:function(){
+      let that = this;
+      uni.getStorageInfo({
+        success(res) {
+          console.log(res)
+          console.log(res.keys);
+          console.log(res.limitSize);
+          let size = res.currentSize;
+          if (size < 1024) {
+            that.storageSize = (size).toFixed(2) + ' B';
+          } else if (size/1024>=1 && size/1024/1024<1) {
+            that.storageSize = (Math.floor(size/1024*100)/100).toFixed(2) + ' KB';
+          } else if (size/1024/1024>=1) {
+            that.storageSize = (Math.floor(size/1024/1024*100)/100).toFixed(2) + ' M';
+          }
+        }
+      })
+    },
+    clearStorage:function (){
+      let that = this;
+      uni.showModal({
+        title:'提示',
+        content:'确定清除缓存吗?',
+        confirmText:'立即清除',
+        success(res) {
+          if(res.confirm){
+            let token=uni.getStorageSync('token')
+            uni.clearStorageSync();
+            if(token){
+              uni.setStorageSync('token',token)
+            }
+            //重新获取并显示清除后的缓存大小
+            that.getStorageSize();
+            uni.showToast({
+              title:'清除成功'
+            })
+          }
+        }
+      })
+    }
   }
 }
 </script>
@@ -89,8 +133,8 @@ export default {
   min-height: 100vh;
   padding-bottom: 50rpx;
   .set-list{
+    margin: 20rpx 32rpx 0 32rpx;
     background-color: #fff;
-
     border-radius: 20rpx;
     .set-item{
       padding: 32rpx;
@@ -112,7 +156,7 @@ export default {
     font-size: 24rpx;
   }
   .set-quit{
-    margin: 20rpx;
+    margin: 40rpx 32rpx;
     font-size: 32rpx;
     height: 88rpx;
     line-height: 88rpx;