setting.vue 5.7 KB

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