Apicloud——关于获取缓存与清除缓存功能、字节转换

2019-01-02  13:58:15

清除缓存功能很常见,Apicloud中有现成的方法,整理记录一下;

其中字节转换部分,很合用。

以后会整理一份不仅限Apicloud中使用的。

  1 <!doctype html>
  2 <html>
  3 
  4     <head>
  5         <meta charset="utf-8">
  6         <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  7         <title>APICloud APP</title>
  8         <link rel="stylesheet" type="text/css" href="../css/api.css" />
  9         <link rel="stylesheet" type="text/css" href="../css/style.css" />
 10 
 11     </head>
 12 
 13     <body>
 14         <header style="display:flex;flex-direction:column-reverse;" class="buy_car_wrap" id="header">
 15             <div style="width:100%;height:60px;display:flex;justify-content:space-around;align-items:center;">
 16                 <div class="buy_car_arrowl" onclick="closeWin()"></div>
 17                 <div style="height:100%;width:65%;display:flex;align-items:center;justify-content:center;">设置</div>
 18                 <div></div>
 19             </div>
 20         </header>
 21 
 22         <div class="h10"></div>
 23         <section>
 24             <!-- 车辆款式 -->
 25             <div class="vehicle_type ">
 26                 <div class="vehicle_type_set">密码管理</div>
 27                 <input type="text" placeholder="" readonly class="vehicle_set" onclick="confirm_mobile()">
 28                 <div class="vehicle_type_left"></div>
 29             </div>
 30             <div class="vehicle_type " onclick="aboutus()">
 31                 <div class="vehicle_type_set">关于我们</div>
 32                 <input type="text" placeholder="" readonly class="vehicle_set">
 33                 <div class="vehicle_type_left"></div>
 34             </div>
 35             <div class="vehicle_type ">
 36                 <div class="vehicle_type_set">意见反馈</div>
 37                 <input type="text" onclick="view()" readonly placeholder="" class="vehicle_set">
 38                 <div class="vehicle_type_left"></div>
 39             </div>
 40             <div class="vehicle_type " onclick="qinc();">
 41                 <div class="vehicle_type_set">清除缓存</div>
 42                 <div class="vehicle_set" id="huancun"></div>
 43                 <div class="vehicle_type_left"></div>
 44             </div>
 45             <div class="vehicle_type ">
 46                 <div class="vehicle_type_set">版本</div>
 47                 <div class="vehicle_set">当前版本:1.0.5</div>
 48                 <div class="vehicle_type_left"></div>
 49             </div>
 50 
 51             <div class="frame1_findmore" onclick="close_quit()" id="quit">退出登录</div>
 52 
 53         </section>
 54         
 55 
 56     </body>
 57     <script type="text/javascript" src="../script/api.js"></script>
 58     <script type="text/javascript" src="../script/jquery.min.js"></script>
 59     <script type="text/javascript">
 60         var size;
 61         apiready = function() {
 62             hc();
 63 
 64         };
 65 
 66         //获取缓存大小
 67         function hc() {
 68             api.getCacheSize(function(ret) {
 69                 size = ret.size;
 70                 console.log(size);
 71                 bytesToSize();
 72                 // console.log(bytesToSize(parseInt(size)));
 73                 $api.byId('huancun').innerHTML = bytesToSize(parseInt(size));
 74                 
 75             });
 76 
 77         }
 78         //转换
 79         function bytesToSize(bytes) {
 80             if(bytes === 0) return '0 B';
 81             var k = 1024, 
 82                 sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
 83                 i = Math.floor(Math.log(bytes) / Math.log(k));
 84 
 85             return(bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
 86         }
 87         //清除缓存
 88         function qinc() {
 89             var dialogBox = api.require('dialogBox');
 90             dialogBox.alert({
 91                 texts: {
 92                     title: '提示',
 93                     content: '您确定要清除缓存吗?',
 94                     leftBtnTitle: '取消',
 95                     rightBtnTitle: '确认'
 96                 },
 97                 styles: {
 98                     bg: '#fff',
 99                     w: 300,
100                     corner: 2,
101                     title: {
102                         marginT: 20,
103                         icon: 'widget://res/gou.png',
104                         iconSize: 40,
105                         titleSize: 22,
106                         titleColor: '#000'
107                     },
108                     content: {
109                         color: '#000',
110                         size: 16
111                     },
112                     left: {
113                         marginB: 7,
114                         marginL: 20,
115                         w: 130,
116                         h: 35,
117                         corner: 2,
118                         bg: '#fff',
119                         color: '#F3544E',
120                         size: 14
121                     },
122                     right: {
123                         marginB: 7,
124                         marginL: 10,
125                         w: 130,
126                         h: 35,
127                         corner: 2,
128                         bg: '#fff',
129                         color: '#F3544E',
130                         size: 14
131                     }
132                 }
133             }, function(ret) {
134 
135                 if(ret.eventType == 'left') {
136                     //取消
137                     var dialogBox = api.require('dialogBox');
138                     dialogBox.close({
139                         dialogName: 'alert'
140                     });
141                 } else if(ret.eventType == 'right') {
142                     //确定
143                     var dialogBox = api.require('dialogBox');
144                     dialogBox.close({
145                         dialogName: 'alert'
146                     });
147 
148                     api.clearCache(function() {
149                         api.toast({
150                             msg: '清除完成'
151                         });
152                     });
153 
154                     hc();
155 
156                 }
157 
158             });
159 
160         }
161     </script>
162 
163 </html>

 

posted @ 2019-01-02 14:00  吉吉国王丶  阅读(1375)  评论(0编辑  收藏  举报