setting.vue 5.5 KB

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