<template>
	<u-popup :show="show" closeable @close="show = false">
    <view class="w-clear">
        <view>缓存信息</view>
        <view>占用的空间大小: {{obj.currentSize?.toFixed(1)}}kb</view>
        <view>限制的空间大小: {{obj.limitSize?.toFixed(1)}}kb</view>
        <view class="w-btn" @click="clear" hover-class="w-hover-before">清空缓存</view>
    </view>
	</u-popup>
</template>

<script setup>
import { onLoad,onShow } from '@dcloudio/uni-app'
import { ref } from 'vue'
import { useAuthStore } from '@/store'

const show = ref(false);

const obj = ref({});

const authStore = useAuthStore();

const open = ()=>{
  show.value = true;
  uni.getStorageInfo({
	success: function (res) {
    obj.value=res;
    // #ifdef H5
    obj.value.limitSize=10240;
    // #endif
	}
});
}

defineExpose({open});

const clear = ()=>{
  try{
    uni.clearStorageSync();
  }catch(e){
    uni.navigateTo({url:'/pages/index/login'});
  }
  authStore.login().then(r=>{
    uni.navigateTo({url:'/pages/index/index'});
  }).catch(e=>{
    uni.navigateTo({url:'/pages/index/login'});
  })
  
}

</script>

<style lang="scss" scoped>
.w-clear {
  width: 100%;
	padding: 1rem;
  font-size: .9rem;
  line-height: 2;
	color: var(--w-text);
  &>view:first-child {
    font-size: 1.1rem;
    font-weight: bold;
  }
  &>view:last-child {
    margin-top: .5rem;
  }
}
</style>
