setting.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  7. <link href="../css/mui.min.css" rel="stylesheet" />
  8. <link rel="stylesheet" type="text/css" href="../css/common.css" />
  9. </head>
  10. <body>
  11. <header class="mui-bar mui-bar-nav">
  12. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  13. <h1 class="mui-title">设置</h1>
  14. </header>
  15. <div class="mui-content">
  16. <ul class="mui-table-view" id="user" style="margin-top: 15px;">
  17. <li class="mui-table-view-cell">
  18. <div>接受新消息通知</div>
  19. <div class="mui-switch mui-switch-mini mui-switch-blue" id="ReceiveNews">
  20. <div class="mui-switch-handle"></div>
  21. </div>
  22. </li>
  23. <li class="mui-table-view-cell" id='cache'>
  24. <a class="mui-navigate-right">清除缓存</a>
  25. </li>
  26. </ul>
  27. <ul class="mui-table-view" id="" style="margin-top: 15px;">
  28. <li class="mui-table-view-cell" id='quitBtn'>
  29. <a class="mui-navigate-right">退出</a>
  30. </li>
  31. </ul>
  32. </div>
  33. <script src="../js/mui.min.js"></script>
  34. <script type="text/javascript">
  35. mui.init();
  36. var isActive = document.getElementById("ReceiveNews").classList.contains("mui-active");
  37. if(isActive) {
  38. console.log("打开状态");
  39. } else {
  40. console.log("关闭状态");
  41. }
  42. document.getElementById("ReceiveNews").addEventListener("toggle", function(event) {
  43. if(event.detail.isActive) {
  44. console.log("你启动了开关");
  45. } else {
  46. console.log("你关闭了开关");
  47. }
  48. })
  49. document.getElementById("cache").addEventListener('tap', function() {
  50. plus.cache.calculate(function(size) {
  51. console.log(size)
  52. sizeCache = size;
  53. // 您目前的系统缓存为" + parseFloat(sizeCache / (1024 * 1024)).toFixed(2) + "M?
  54. mui.confirm("清除后App中的数据将会被清理,用户需重新登录", "清除缓存", ["确认", "取消"], function(e) {
  55. if(e.index == 1) {} else {
  56. plus.cache.clear(function() {
  57. clearAllItem()
  58. });
  59. }
  60. });
  61. });
  62. })
  63. //清除所有内容
  64. function getLengthFun() {
  65. return plus.storage.getLength();
  66. }
  67. function clearAllItem() {
  68. plus.storage.clear();
  69. var num = getLengthFun();
  70. if(num == 0) {
  71. plus.nativeUI.toast("重置成功,2秒后重启app。", {
  72. verticalAlign: "center"
  73. });
  74. /**
  75. * 2秒后重启应用
  76. * http://www.html5plus.org/doc/zh_cn/runtime.html#plus.runtime.restart
  77. */
  78. setTimeout(function() {
  79. plus.runtime.restart();
  80. }, 2000);
  81. } else {
  82. toast('重置失败')
  83. }
  84. }
  85. //退出选择
  86. document.getElementById('quitBtn').addEventListener('tap', function() {
  87. plus.nativeUI.actionSheet({
  88. // title: '退出',
  89. cancel: '取消',
  90. buttons: [{
  91. title: '退出登录'
  92. }, {
  93. title: '关闭程序'
  94. }]
  95. }, function(b) {
  96. switch(b.index) {
  97. case 0:
  98. break;
  99. case 1:
  100. //退出登录
  101. var username = plus.storage.getItem('username');
  102. console.log(username)
  103. mui.ajax('http://120.27.222.26/app_logout',{
  104. data:{
  105. username:username
  106. },
  107. dataType:'json',//服务器返回json格式数据
  108. type:'post',//HTTP请求类型
  109. timeout:10000,//超时时间设置为10秒;
  110. success:function(data){
  111. if(data == 0){
  112. plus.storage.clear();
  113. mui.openWindow({
  114. url:'../home/login.html',
  115. id:'login'
  116. })
  117. }
  118. },
  119. error:function(xhr,type,errorThrown){
  120. console.log(type)
  121. }
  122. });
  123. break;
  124. case 2:
  125. //关闭程序
  126. plus.runtime.quit();
  127. break;
  128. default:
  129. break;
  130. }
  131. }, false);
  132. })
  133. </script>
  134. </body>
  135. </html>