setUp.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="container">
  3. <view class="person" @click="checkUserInfo()">
  4. <u-image width=140 height="140" shape="circle" :src="userInfo.face || '/static/missing-face.png'" mode=""></u-image>
  5. <view class="user-name">
  6. {{ userInfo.id ? userInfo.nickName || '' : '暂未登录' }}
  7. </view>
  8. <u-icon color="#ccc" name="arrow-right"></u-icon>
  9. </view>
  10. <!-- #ifdef MP-WEIXIN -->
  11. <view style="height: 20rpx; width: 100%"></view>
  12. <!-- #endif -->
  13. <u-cell-group :border="false">
  14. <!-- #ifdef APP-PLUS -->
  15. <u-cell-item title="清除缓存" :value="fileSizeString" @click="clearCache"></u-cell-item>
  16. <!-- #endif -->
  17. <u-cell-item title="安全中心" @click="navigateTo('/pages/mine/set/securityCenter/securityCenter')"></u-cell-item>
  18. <u-cell-item title="意见反馈" @click="navigateTo('/pages/mine/set/feedBack')"></u-cell-item>
  19. <!-- #ifndef H5 -->
  20. <!-- #endif -->
  21. <u-cell-item :title="`关于${config.name}`" @click="navigateTo('/pages/mine/set/editionIntro')"></u-cell-item>
  22. </u-cell-group>
  23. <view class="submit" @click="showModalDialog">{{userInfo.id ?'退出登录':'返回登录'}}</view>
  24. <u-modal show-cancel-button v-model="quitShow" @confirm="confirm" :confirm-color="lightColor" :async-close="true" :content="userInfo.id ? '确定要退出登录么?' : '确定要返回登录么?'"></u-modal>
  25. </view>
  26. </template>
  27. <script>
  28. import storage from "@/utils/storage.js";
  29. import config from "@/config/config";
  30. export default {
  31. data() {
  32. return {
  33. config,
  34. lightColor: this.$lightColor,
  35. quitShow: false,
  36. isCertificate: false,
  37. userInfo: {},
  38. fileSizeString: "0B",
  39. };
  40. },
  41. methods: {
  42. navigateTo(url) {
  43. if (url == "/pages/set/securityCenter/securityCenter") {
  44. url += `?mobile=${this.userInfo.mobile}`;
  45. }
  46. uni.navigateTo({
  47. url: url,
  48. });
  49. },
  50. /**
  51. * 确认退出
  52. * 清除缓存重新登录
  53. */
  54. confirm() {
  55. storage.setAccessToken("");
  56. storage.setRefreshToken("");
  57. storage.setUserInfo({});
  58. uni.redirectTo({
  59. url: "/pages/passport/login",
  60. });
  61. },
  62. /**
  63. * 显示退出登录对话框
  64. */
  65. showModalDialog() {
  66. this.quitShow = true;
  67. },
  68. /**
  69. * 读取当前缓存
  70. */
  71. getCacheSize() {
  72. //获取缓存数据
  73. let that = this;
  74. plus.cache.calculate(function (size) {
  75. let sizeCache = parseInt(size);
  76. if (sizeCache == 0) {
  77. that.fileSizeString = "0B";
  78. } else if (sizeCache < 1024) {
  79. that.fileSizeString = sizeCache + "B";
  80. } else if (sizeCache < 1048576) {
  81. that.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB";
  82. } else if (sizeCache < 1073741824) {
  83. that.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB";
  84. } else {
  85. that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB";
  86. }
  87. });
  88. },
  89. /**
  90. * 点击用户详情
  91. * 判断当前是否进入用户中心
  92. */
  93. checkUserInfo() {
  94. if (this.$options.filters.isLogin("auth")) {
  95. this.navigateTo("/pages/mine/set/personMsg");
  96. } else {
  97. uni.showToast({
  98. title: "当前暂无用户请登录后重试",
  99. duration: 2000,
  100. icon: "none",
  101. });
  102. }
  103. },
  104. /**
  105. * 清除当前设备缓存
  106. */
  107. clearCache() {
  108. //清理缓存
  109. let that = this;
  110. let os = plus.os.name;
  111. if (os == "Android") {
  112. let main = plus.android.runtimeMainActivity();
  113. let sdRoot = main.getCacheDir();
  114. let files = plus.android.invoke(sdRoot, "listFiles");
  115. let len = files.length;
  116. for (let i = 0; i < len; i++) {
  117. let filePath = "" + files[i]; // 没有找到合适的方法获取路径,这样写可以转成文件路径
  118. plus.io.resolveLocalFileSystemURL(
  119. filePath,
  120. function (entry) {
  121. if (entry.isDirectory) {
  122. entry.removeRecursively(
  123. function (entry) {
  124. //递归删除其下的所有文件及子目录
  125. uni.showToast({
  126. title: "缓存清理完成",
  127. duration: 2000,
  128. icon: "none",
  129. });
  130. that.getCacheSize(); // 重新计算缓存
  131. },
  132. function (e) {}
  133. );
  134. } else {
  135. entry.remove();
  136. }
  137. },
  138. function (e) {
  139. uni.showToast({
  140. title: "文件路径读取失败",
  141. duration: 2000,
  142. icon: "none",
  143. });
  144. }
  145. );
  146. }
  147. } else {
  148. // ios
  149. plus.cache.clear(function () {
  150. uni.showToast({
  151. title: "缓存清理完成",
  152. duration: 2000,
  153. icon: "none",
  154. });
  155. that.getCacheSize();
  156. });
  157. }
  158. },
  159. },
  160. onShow() {
  161. this.userInfo = this.$options.filters.isLogin();
  162. // #ifdef APP-PLUS
  163. this.getCacheSize();
  164. // #endif
  165. },
  166. };
  167. </script>
  168. <style lang='scss' scoped>
  169. .submit {
  170. height: 90rpx;
  171. line-height: 90rpx;
  172. text-align: center;
  173. margin-top: 90rpx;
  174. background: #fff;
  175. width: 100%;
  176. margin: 0 auto;
  177. color: $main-color;
  178. }
  179. .person {
  180. height: 208rpx;
  181. display: flex;
  182. padding: 0 20rpx;
  183. font-size: $font-base;
  184. justify-content: space-between;
  185. align-items: center;
  186. margin-bottom: 20rpx;
  187. .user-name {
  188. width: 500rpx;
  189. overflow: hidden;
  190. text-overflow: ellipsis;
  191. white-space: nowrap;
  192. margin-left: 30rpx;
  193. line-height: 2em;
  194. font-size: 34rpx;
  195. }
  196. }
  197. .u-cell {
  198. height: 110rpx;
  199. /* line-height: 110rpx; */
  200. padding: 0 20rpx;
  201. align-items: center;
  202. color: #333333;
  203. }
  204. /deep/ .u-cell__value {
  205. color: #cccccc !important;
  206. }
  207. /deep/ .u-cell__right-icon-wrap {
  208. color: #cccccc !important;
  209. }
  210. </style>