main.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="main">
  3. <view class="top">
  4. <view class="icon" @click='toset'>
  5. <u-icon name="setting" color="#fff" size="28"></u-icon>
  6. </view>
  7. <view class="user">
  8. <image v-if="userInfo.headUrl" :src="userInfo.headUrl" mode=""></image>
  9. <view v-else class="name">
  10. <span>
  11. {{userInfo.realName.slice(-2)}}
  12. </span>
  13. </view>
  14. <view class="txt">
  15. {{userInfo.realName}} <span v-if="userInfo.deptName">({{userInfo.deptName}})</span>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="list">
  20. <!-- <view class="li">
  21. <view style="display: flex;">
  22. <u-icon name="bell-fill" color="#3DD4A7" size="20"></u-icon>
  23. <view class="txt">
  24. 我的消息
  25. </view>
  26. </view>
  27. <u-icon name="arrow-right" size="20"></u-icon>
  28. </view>
  29. <view class="li">
  30. <view style="display: flex;">
  31. <u-icon name="star-fill" color="#FDDB79" size="20"></u-icon>
  32. <view class="txt">
  33. 我的收藏
  34. </view>
  35. </view>
  36. <u-icon name="arrow-right" size="20"></u-icon>
  37. </view> -->
  38. <view class="li" @click='toset'>
  39. <view style="display: flex;">
  40. <u-icon name="heart-fill" color="#7C83F6" size="20"></u-icon>
  41. <view class="txt">
  42. 设置
  43. </view>
  44. </view>
  45. <u-icon name="arrow-right" size="20"></u-icon>
  46. </view>
  47. <view class="li" @click="todetail('AboutUs')">
  48. <view style="display: flex;">
  49. <u-icon name="account-fill" color="#2360EE" size="20"></u-icon>
  50. <view class="txt">
  51. 关于我们
  52. </view>
  53. </view>
  54. <u-icon name="arrow-right" size="20"></u-icon>
  55. </view>
  56. <!-- <view class="li">
  57. <view style="display: flex;">
  58. <u-icon name="coupon-fill" color="#FA746B" size="20"></u-icon>
  59. <view class="txt">
  60. 用户数据
  61. </view>
  62. </view>
  63. <view class="" style="display: flex;">
  64. {{currentSize}}
  65. <u-icon name="arrow-right" size="20"></u-icon>
  66. </view>
  67. </view> -->
  68. <view class="li" @click="clearStroge" v-if="isApp">
  69. <view style="display: flex;">
  70. <u-icon name="error-circle-fill" color="#FA746B" size="20"></u-icon>
  71. <view class="txt">
  72. 重启程序
  73. </view>
  74. </view>
  75. <view class="" style="display: flex;">
  76. <u-icon name="arrow-right" size="20"></u-icon>
  77. </view>
  78. </view>
  79. <u-toast ref="uToast"></u-toast>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. export default {
  85. data() {
  86. return {
  87. userInfo: {},
  88. isApp: false,
  89. currentSize: ""
  90. }
  91. },
  92. onShow() {
  93. this.userInfo = uni.getStorageSync('userInfo')
  94. },
  95. mounted() {},
  96. onLoad() {
  97. // APP:
  98. // #ifdef APP-PLUS
  99. this.getStorageSize()
  100. this.isApp = true
  101. // #endif
  102. },
  103. methods: {
  104. getaltitude() {
  105. // const key = "74d5aa7c4270effe9a18d9cfa6149abf";
  106. // const lat = 39.9; // 指定纬度
  107. // const lng = 116.4; // 指定经度
  108. // wx.request({
  109. // url: `https://apis.map.qq.com/ws/elevation/v1/?locations=${lat},${lng}&key=${key}`,
  110. // method: "GET",
  111. // success: (res) => {
  112. // if (res.data.status === 0) {
  113. // console.log(`海拔:${res.data.result[0].elevation} 米`);
  114. // } else {
  115. // console.error("获取海拔失败", res.data);
  116. // }
  117. // },
  118. // fail: (err) => {
  119. // console.error("请求失败", err);
  120. // }
  121. // });
  122. uni.getLocation({
  123. type: 'gcj02',
  124. altitude:true,
  125. success(res) {
  126. console.log(res);
  127. },
  128. fail(fail) {
  129. console.log(fail);
  130. }
  131. })
  132. },
  133. // 辅助函数,将字节数转换为更友好的格式
  134. formatFileSize(bytes) {
  135. if (bytes === 0) return '0 Bytes';
  136. const k = 1024;
  137. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  138. const i = Math.floor(Math.log(bytes) / Math.log(k));
  139. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  140. },
  141. // 获取本地缓存大小
  142. getStorageSize() {
  143. let that = this;
  144. plus.cache.calculate(function(size) {
  145. let sizeCache = parseInt(size);
  146. if (sizeCache == 0) {
  147. that.currentSize = "0B";
  148. } else if (sizeCache < 1024) {
  149. that.currentSize = sizeCache + "B";
  150. } else if (sizeCache < 1048576) {
  151. that.currentSize = (sizeCache / 1024).toFixed(2) + "KB";
  152. } else if (sizeCache < 1073741824) {
  153. that.currentSize = (sizeCache / 1048576).toFixed(2) + "MB";
  154. } else {
  155. that.currentSize = (sizeCache / 1073741824).toFixed(2) + "GB";
  156. }
  157. });
  158. // plus.io.resolveLocalFileSystemURL('_documents/', function(entry) {
  159. // entry.getMetadata(function(metadata) {
  160. // // metadata.size 表示文件大小,单位为字节
  161. // var fileSizeInBytes = metadata.size;
  162. // // 将字节数转换为更友好的格式(KB、MB、GB等)
  163. // var fileSizeFormatted = that.formatFileSize(fileSizeInBytes);
  164. // console.log('本地数据大小:', fileSizeFormatted);
  165. // }, function(error) {
  166. // console.error('获取文件信息失败:', error.message);
  167. // });
  168. // }, function(error) {
  169. // console.error('解析文件路径失败:', error.message);
  170. // });
  171. },
  172. clearStroge() {
  173. uni.showModal({
  174. title: '提示',
  175. content: '是否重启程序?',
  176. success: function(res) {
  177. if (res.confirm) {
  178. plus.android.importClass("android.app.ActivityManager");
  179. var Context = plus.android.importClass("android.content.Context");
  180. var am = plus.android.runtimeMainActivity().getSystemService(Context
  181. .ACTIVITY_SERVICE);
  182. am.clearApplicationUserData();
  183. } else if (res.cancel) {
  184. console.log('用户点击取消');
  185. }
  186. }
  187. });
  188. },
  189. todetail(e) {
  190. uni.navigateTo({
  191. url: '/pages/main/set/aboutUs/aboutUs'
  192. })
  193. },
  194. toset() {
  195. uni.navigateTo({
  196. url: '/pages/main/set/setlist'
  197. })
  198. }
  199. }
  200. }
  201. </script>
  202. <style>
  203. .main .u-icon {
  204. /* justify-content: right; */
  205. }
  206. </style>
  207. <style lang="scss" scoped>
  208. .list {
  209. margin-top: 100rpx;
  210. padding: 0 35rpx;
  211. .li {
  212. display: flex;
  213. align-items: center;
  214. justify-content: space-between;
  215. margin-bottom: 50rpx;
  216. .txt {
  217. margin-left: 10rpx;
  218. }
  219. }
  220. }
  221. .top {
  222. color: #fff;
  223. background-color: #39BDFD;
  224. padding: 60rpx 20rpx;
  225. font-size: 24rpx;
  226. .user {
  227. margin-top: 100rpx;
  228. .txt {
  229. margin-top: 20rpx;
  230. }
  231. text-align: center;
  232. .name {
  233. background: #39BDFD;
  234. color: #fff;
  235. span {
  236. height: 50px;
  237. width: 50px;
  238. line-height: 50px;
  239. display: inline-block;
  240. border-radius: 50%;
  241. background: #ccc;
  242. font-size: 16px;
  243. }
  244. }
  245. image {
  246. width: 100rpx;
  247. height: 100rpx;
  248. border-radius: 50%;
  249. background-size: 100% 100%;
  250. }
  251. }
  252. // .icon {
  253. // text-align: right;
  254. // }
  255. }
  256. </style>