时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
6.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <script>
  2. export default {
  3. globalData: {
  4. wxlogin: () => {}, // 登录方法
  5. screenWidth: 0, // 屏幕宽度
  6. statusBarH: 0, // 状态栏的高度
  7. screenHeight: 0, // 屏幕高度
  8. customBarH: 0, // 标题导航栏高度
  9. windowHeight: 0, // 窗口可用高度,窗口总高度 - 状态栏的高度
  10. },
  11. onLaunch: function() {
  12. this.disableConsole();
  13. this.getSystemInfo();
  14. this.getUserInfo();
  15. },
  16. onShow: function() {
  17. // #ifdef MP-WEIXIN
  18. this.getUpdateWexin(); // 小程序更新检查
  19. // #endif
  20. },
  21. methods: {
  22. // 获取手机设备信息
  23. getSystemInfo(){
  24. let res = uni.getSystemInfoSync();
  25. this.globalData.screenWidth = res.screenWidth;
  26. this.globalData.statusBarH = res.statusBarHeight;
  27. this.globalData.screenHeight = res.screenHeight;
  28. this.globalData.customBarH = res.statusBarHeight + 45;
  29. this.globalData.windowHeight = res.windowHeight - (res.statusBarHeight - 20);
  30. // #ifdef MP
  31. setTimeout(() => {
  32. let custom = uni.getMenuButtonBoundingClientRect()
  33. this.globalData.customBarH = custom.bottom + custom.top - res.statusBarHeight;
  34. if (this.globalData.customBarH <= 0) {
  35. this.globalData.customBarH = 40 + this.globalData.statusBarH;
  36. }
  37. }, 30);
  38. // #endif
  39. // #ifdef MP-ALIPAY
  40. this.globalData.customBarH = res.statusBarHeight + res.titleBarHeight;
  41. // #endif
  42. },
  43. // 获取用户信息
  44. getUserInfo(){
  45. this.globalData.wxlogin = this.wxlogin;
  46. // 去缓存判断有无用户信息
  47. let userinfo = uni.getStorageSync('userinfo');
  48. if(userinfo && userinfo.id){
  49. return;
  50. }
  51. this.globalData.wxlogin();
  52. },
  53. wxlogin(){
  54. return new Promise((resolve, rejecj) => {
  55. uni.login({
  56. complete: result => {
  57. if(result.errMsg == 'login:ok'){
  58. let code = result.code;
  59. this.$http(this.API.API_WXLOGIN, { code }).then(res => {
  60. console.log("获得用户信息", res);
  61. uni.setStorageSync('userinfo', res.data);
  62. resolve(res.data);
  63. })
  64. }
  65. }
  66. })
  67. })
  68. },
  69. // 小程序版本更新检查
  70. getUpdateWexin(){
  71. const updateManager = uni.getUpdateManager(); // 获取版本更新管理器对象
  72. updateManager.onCheckForUpdate(function(res) {
  73. // 请求完新版本信息的回调
  74. if (res.hasUpdate) {
  75. updateManager.onUpdateReady(function(res2) {
  76. uni.showModal({
  77. title: '更新提示',
  78. content: '发现新版本,是否重启应用?',
  79. confirmColor: '#FE9903',
  80. showCancel: false,
  81. success(res2) {
  82. if (res2.confirm) {
  83. // 新的版本已经下载好,调用applyUpdate应用新版本并重启
  84. updateManager.applyUpdate();
  85. }
  86. }
  87. });
  88. });
  89. }
  90. });
  91. updateManager.onUpdateFailed(function(res) {
  92. // 新的版本下载失败
  93. uni.showModal({
  94. title: '提示',
  95. content: '检查到有新版本,但下载失败,请检查网络设置',
  96. confirmColor: '#FE9903',
  97. success(res) {
  98. if (res.confirm) {
  99. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  100. updateManager.applyUpdate();
  101. }
  102. }
  103. });
  104. });
  105. },
  106. // 判断正式服屏蔽console输出
  107. disableConsole(){
  108. if(this.API.DEV == 'prod'){
  109. console.log = () => {};
  110. }
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss">
  116. @import "uview-ui/index.scss";
  117. @import './colorui/main.css';
  118. @import './colorui/icon.css';
  119. @import "@/colorui/animation.css";
  120. @import '@/common/styles/common.css';
  121. @import "@/common/styles/iconfont.css";
  122. /*每个页面公共css */
  123. //底部按钮
  124. .btn-bottom {
  125. position: fixed;
  126. left: 0;
  127. bottom: 0;
  128. width: 100%;
  129. z-index: 1;
  130. }
  131. // loading加载
  132. .loading-more {
  133. align-items: center;
  134. justify-content: center;
  135. padding-top: 10px;
  136. padding-bottom: 10px;
  137. text-align: center;
  138. font-size: 28rpx;
  139. color: #999;
  140. }
  141. .loading-more-text::before {
  142. content: '';
  143. width: 20px;
  144. height: 20px;
  145. display: inline-block;
  146. vertical-align: middle;
  147. -webkit-animation: weuiLoading 1s steps(12, end) infinite;
  148. animation: weuiLoading 1s steps(12, end) infinite;
  149. background-repeat: no-repeat;
  150. background-image: url("data:image/svg+xml;charset=utf8, %3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 100 100'%3E%3Cpath fill='none' d='M0 0h100v100H0z'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23E9E9E9' rx='5' ry='5' transform='translate(0 -30)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23989697' rx='5' ry='5' transform='rotate(30 105.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%239B999A' rx='5' ry='5' transform='rotate(60 75.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23A3A1A2' rx='5' ry='5' transform='rotate(90 65 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23ABA9AA' rx='5' ry='5' transform='rotate(120 58.66 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23B2B2B2' rx='5' ry='5' transform='rotate(150 54.02 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23BAB8B9' rx='5' ry='5' transform='rotate(180 50 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23C2C0C1' rx='5' ry='5' transform='rotate(-150 45.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23CBCBCB' rx='5' ry='5' transform='rotate(-120 41.34 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23D2D2D2' rx='5' ry='5' transform='rotate(-90 35 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23DADADA' rx='5' ry='5' transform='rotate(-60 24.02 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23E2E2E2' rx='5' ry='5' transform='rotate(-30 -5.98 65)'/%3E%3C/svg%3E");
  151. background-size: 100%;
  152. }
  153. @-webkit-keyframes weuiLoading {
  154. 0% {
  155. transform: rotate3d(0, 0, 1, 0deg);
  156. }
  157. 100% {
  158. transform: rotate3d(0, 0, 1, 360deg);
  159. }
  160. }
  161. @keyframes weuiLoading {
  162. 0% {
  163. transform: rotate3d(0, 0, 1, 0deg);
  164. }
  165. 100% {
  166. transform: rotate3d(0, 0, 1, 360deg);
  167. }
  168. }
  169. </style>