setting.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view class="setting">
  3. <view class="header-bg"></view>
  4. <view class="block b1">
  5. <view class="row portrait">
  6. <image class="image" src="../../static/images/login/logo.png" mode="scaleToFill"></image>
  7. </view>
  8. <view class="row">
  9. <view class="label">
  10. 昵称 <text class="info">{{nickname}}</text>
  11. </view>
  12. <view class="option">
  13. 修改
  14. </view>
  15. </view>
  16. </view>
  17. <view class="block b2">
  18. <view class="row">
  19. <view class="label">支付宝绑定</view>
  20. <view class="option">未绑定</view>
  21. </view>
  22. <view class="line"></view>
  23. <view class="row">
  24. <view>微信绑定</view>
  25. <view class="option">未绑定</view>
  26. </view>
  27. </view>
  28. <view class="block b3">
  29. <view class="row">
  30. <view class="label">修改手机号 <text class="info">{{mobile}}</text></view>
  31. <view class="option">已绑定</view>
  32. </view>
  33. <view class="line"></view>
  34. <view class="row">
  35. <view class="label">修改密码</view>
  36. <view class="option"></view>
  37. </view>
  38. </view>
  39. <view class="block b4">
  40. <view class="row">
  41. <view class="label">清除缓存 <text class="info">{{fileSizeString}}</text></view>
  42. <view class="option"><button class="clear-cache-btn" type="default" @tap="clearCache()">清除缓存</button></view>
  43. </view>
  44. </view>
  45. <view class="logout-block">
  46. <button class="logout-btn" type="default" @tap="logout()">退出登录</button>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import {
  52. mapState
  53. } from 'vuex'
  54. export default {
  55. data() {
  56. return {
  57. fileSizeString: "计算中..."
  58. }
  59. },
  60. computed: mapState({
  61. nickname: state => state.user.nickname,
  62. mobile: state => state.user.mobile
  63. }),
  64. onLoad() {
  65. const info = uni.getStorageInfoSync();
  66. console.log(info)
  67. this.formatSize();
  68. },
  69. methods: {
  70. logout() {
  71. uni.navigateBack({
  72. delta: 999,
  73. animationType: 'none'
  74. })
  75. uni.navigateTo({
  76. url: '/pages/user/login'
  77. })
  78. this.$store.dispatch("user/logout")
  79. },
  80. formatSize() {
  81. let that = this;
  82. plus.cache.calculate(function(size) {
  83. let sizeCache = parseInt(size);
  84. if (sizeCache == 0) {
  85. that.fileSizeString = "0B";
  86. } else if (sizeCache < 1024) {
  87. that.fileSizeString = sizeCache + "B";
  88. } else if (sizeCache < 1048576) {
  89. that.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB";
  90. } else if (sizeCache < 1073741824) {
  91. that.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB";
  92. } else {
  93. that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB";
  94. }
  95. });
  96. },
  97. clearCache() {
  98. let that = this;
  99. let os = plus.os.name;
  100. if (os == 'Android') {
  101. let main = plus.android.runtimeMainActivity();
  102. let sdRoot = main.getCacheDir();
  103. let files = plus.android.invoke(sdRoot, "listFiles");
  104. let len = files.length;
  105. for (let i = 0; i < len; i++) {
  106. let filePath = '' + files[i]; // 没有找到合适的方法获取路径,这样写可以转成文件路径
  107. plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
  108. if (entry.isDirectory) {
  109. entry.removeRecursively(function(entry) { //递归删除其下的所有文件及子目录
  110. uni.showToast({
  111. icon:'none',
  112. title: '缓存清理完成',
  113. duration: 2000
  114. });
  115. that.formatSize(); // 重新计算缓存
  116. }, function(e) {
  117. console.log(e.message)
  118. });
  119. } else {
  120. entry.remove();
  121. }
  122. }, function(e) {
  123. console.log('文件路径读取失败')
  124. });
  125. }
  126. } else { // ios暂时未找到清理缓存的方法,以下是官方提供的方法,但是无效,会报错
  127. plus.cache.clear(function() {
  128. uni.showToast({
  129. icon:'none',
  130. title: '缓存清理完成',
  131. duration: 2000
  132. });
  133. that.formatSize();
  134. });
  135. }
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .setting {
  142. overflow: hidden;
  143. position: relative;
  144. }
  145. .header-bg {
  146. background-color: $primary-color;
  147. height: 120upx;
  148. position: absolute;
  149. top: 0;
  150. width: 100%;
  151. z-index: 1;
  152. }
  153. .portrait {
  154. justify-content: center !important;
  155. margin-top: 20upx;
  156. .image {
  157. width: 168upx;
  158. height: 168upx;
  159. border: 10upx solid $primary-color;
  160. border-radius: 100upx;
  161. }
  162. }
  163. .block {
  164. border-radius: 20upx;
  165. background-color: white;
  166. margin: 20upx;
  167. position: relative;
  168. overflow: hidden;
  169. z-index: 2;
  170. .row {
  171. display: flex;
  172. justify-content: space-between;
  173. padding: 20upx 40upx;
  174. align-items: center;
  175. font-size: 28upx;
  176. .info {
  177. color: #999999;
  178. font-size: 24upx;
  179. display: inline-block;
  180. margin-left: 20upx;
  181. }
  182. .option {
  183. color: #999999;
  184. }
  185. }
  186. }
  187. .logout-block {
  188. margin: 20upx;
  189. }
  190. .clear-cache-btn {
  191. line-height: normal;
  192. padding: 4upx 20upx;
  193. background: white;
  194. border: 2upx solid $primary-color;
  195. font-size: 24upx;
  196. border-radius: 50upx;
  197. color: $primary-color;
  198. }
  199. .logout-btn {
  200. background: $primary-color;
  201. color: white;
  202. font-size: 30upx;
  203. line-height: 80upx;
  204. }
  205. .line {
  206. border: 2upx solid #EEEEEE;
  207. transform: scale(0.9, 0.5);
  208. }
  209. </style>