setUp.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. <view>{{ userInfo.id ? userInfo.username || '' : '暂未登录' }}</view>
  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. <u-cell-item title="版本说明" @click="navigateTo('/pages/mine/set/editionIntro')"></u-cell-item>
  21. <!-- #endif -->
  22. <!-- <u-cell-item title="好评鼓励"></u-cell-item> -->
  23. <u-cell-item title="关于我们" @click="navigateTo('/pages/mine/aboutUs')"></u-cell-item>
  24. </u-cell-group>
  25. <view class="submit" @click="showModalDialog">{{userInfo.id ?'退出登录':'返回登录'}}</view>
  26. <u-modal show-cancel-button v-model="quitShow" @confirm="confirm" :confirm-color="lightColor" :async-close="true" :content="userInfo.id ? '确定要退出登录么?' : '确定要返回登录么?'"></u-modal>
  27. </view>
  28. </template>
  29. <script>
  30. import storage from "@/utils/storage.js";
  31. export default {
  32. data() {
  33. return {
  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. );
  135. } else {
  136. entry.remove();
  137. }
  138. },
  139. function (e) {
  140. uni.showToast({
  141. title: "文件路径读取失败",
  142. duration: 2000,
  143. icon: "none",
  144. });
  145. }
  146. );
  147. }
  148. } else {
  149. // ios
  150. plus.cache.clear(function () {
  151. uni.showToast({
  152. title: "缓存清理完成",
  153. duration: 2000,
  154. icon: "none",
  155. });
  156. that.getCacheSize();
  157. });
  158. }
  159. },
  160. },
  161. onShow() {
  162. this.userInfo = this.$options.filters.isLogin();
  163. // #ifdef APP-PLUS
  164. this.getCacheSize();
  165. // #endif
  166. },
  167. };
  168. </script>
  169. <style lang='scss' scoped>
  170. .submit {
  171. height: 90rpx;
  172. line-height: 90rpx;
  173. text-align: center;
  174. margin-top: 90rpx;
  175. background: #fff;
  176. width: 100%;
  177. margin: 0 auto;
  178. color: $main-color;
  179. }
  180. .person {
  181. height: 208rpx;
  182. display: flex;
  183. padding: 0 20rpx;
  184. font-size: $font-base;
  185. justify-content: space-between;
  186. align-items: center;
  187. margin-bottom: 20rpx;
  188. .user-name {
  189. flex: 1;
  190. margin-left: 30rpx;
  191. line-height: 2em;
  192. font-size: 34rpx;
  193. }
  194. }
  195. .u-cell {
  196. height: 110rpx;
  197. /* line-height: 110rpx; */
  198. padding: 0 20rpx;
  199. align-items: center;
  200. color: #333333;
  201. }
  202. /deep/ .u-cell__value {
  203. color: #cccccc !important;
  204. }
  205. /deep/ .u-cell__right-icon-wrap {
  206. color: #cccccc !important;
  207. }
  208. </style>